testDomainSnapshotCreateXML: Extract snapshot redefinition code

The test driver code was copied from qemu but wasn't refactored
recently. Split out the redefinition code similarly to what qemu driver
did.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-01-12 15:40:55 +01:00
parent bec2a922bd
commit 4584a451e6
1 changed files with 49 additions and 27 deletions

View File

@ -8739,6 +8739,33 @@ testDomainSnapshotAlignDisks(virDomainObj *vm,
return virDomainSnapshotAlignDisks(def, NULL, align_location, true); return virDomainSnapshotAlignDisks(def, NULL, align_location, true);
} }
static virDomainSnapshotPtr
testDomainSnapshotRedefine(virDomainObj *vm,
virDomainPtr domain,
virDomainSnapshotDef *snapdeftmp,
virDomainMomentObj **snapout,
virDomainXMLOption *xmlopt,
unsigned int flags)
{
virDomainMomentObj *snap = NULL;
g_autoptr(virDomainSnapshotDef) snapdef = virObjectRef(snapdeftmp);
if (virDomainSnapshotRedefinePrep(vm, &snapdef, &snap, xmlopt, flags) < 0)
return NULL;
if (!snap) {
if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, snapdef)))
return NULL;
snapdef = NULL;
}
*snapout = snap;
return virGetDomainSnapshot(domain, snap->def->name);
}
static virDomainSnapshotPtr static virDomainSnapshotPtr
testDomainSnapshotCreateXML(virDomainPtr domain, testDomainSnapshotCreateXML(virDomainPtr domain,
const char *xmlDesc, const char *xmlDesc,
@ -8805,37 +8832,32 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
goto cleanup; goto cleanup;
if (redefine) { if (redefine) {
if (virDomainSnapshotRedefinePrep(vm, &def, &snap, snapshot = testDomainSnapshotRedefine(vm, domain, def, &snap,
privconn->xmlopt, privconn->xmlopt, flags);
flags) < 0) goto cleanup;
goto cleanup;
} else {
if (!(def->parent.dom = virDomainDefCopy(vm->def,
privconn->xmlopt,
NULL,
true)))
goto cleanup;
if (testDomainSnapshotAlignDisks(vm, def, flags) < 0)
goto cleanup;
} }
if (!snap) { if (!(def->parent.dom = virDomainDefCopy(vm->def,
if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, def))) privconn->xmlopt,
goto cleanup; NULL,
def = NULL; true)))
} goto cleanup;
if (!redefine) { if (testDomainSnapshotAlignDisks(vm, def, flags) < 0)
snap->def->parent_name = g_strdup(virDomainSnapshotGetCurrentName(vm->snapshots)); goto cleanup;
if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT) && if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, def)))
virDomainObjIsActive(vm)) { goto cleanup;
testDomainShutdownState(domain, vm, def = NULL;
VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT);
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED, snap->def->parent_name = g_strdup(virDomainSnapshotGetCurrentName(vm->snapshots));
VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT);
} if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT) &&
virDomainObjIsActive(vm)) {
testDomainShutdownState(domain, vm,
VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT);
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT);
} }
snapshot = virGetDomainSnapshot(domain, snap->def->name); snapshot = virGetDomainSnapshot(domain, snap->def->name);