1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-11 09:17:52 +03:00

snapshot: Refactor test to utilize virDomainMoment more

Similar to commit a487890d for qemu, a little bit of refactoring in
the snapshot delete code will make it easier to reuse functionality
for checkpoints.

Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Eric Blake 2019-06-12 10:48:15 -05:00
parent 65baca2180
commit 2503763ee1

View File

@ -7241,9 +7241,9 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
} }
typedef struct _testSnapRemoveData testSnapRemoveData; typedef struct _testMomentRemoveData testMomentRemoveData;
typedef testSnapRemoveData *testSnapRemoveDataPtr; typedef testMomentRemoveData *testMomentRemoveDataPtr;
struct _testSnapRemoveData { struct _testMomentRemoveData {
virDomainObjPtr vm; virDomainObjPtr vm;
bool current; bool current;
}; };
@ -7254,35 +7254,35 @@ testDomainSnapshotDiscardAll(void *payload,
void *data) void *data)
{ {
virDomainMomentObjPtr snap = payload; virDomainMomentObjPtr snap = payload;
testSnapRemoveDataPtr curr = data; testMomentRemoveDataPtr curr = data;
curr->current |= virDomainSnapshotObjListRemove(curr->vm->snapshots, snap); curr->current |= virDomainSnapshotObjListRemove(curr->vm->snapshots, snap);
return 0; return 0;
} }
typedef struct _testSnapReparentData testSnapReparentData; typedef struct _testMomentReparentData testMomentReparentData;
typedef testSnapReparentData *testSnapReparentDataPtr; typedef testMomentReparentData *testMomentReparentDataPtr;
struct _testSnapReparentData { struct _testMomentReparentData {
virDomainMomentObjPtr parent; virDomainMomentObjPtr parent;
virDomainObjPtr vm; virDomainObjPtr vm;
int err; int err;
}; };
static int static int
testDomainSnapshotReparentChildren(void *payload, testDomainMomentReparentChildren(void *payload,
const void *name ATTRIBUTE_UNUSED, const void *name ATTRIBUTE_UNUSED,
void *data) void *data)
{ {
virDomainMomentObjPtr snap = payload; virDomainMomentObjPtr moment = payload;
testSnapReparentDataPtr rep = data; testMomentReparentDataPtr rep = data;
if (rep->err < 0) if (rep->err < 0)
return 0; return 0;
VIR_FREE(snap->def->parent_name); VIR_FREE(moment->def->parent_name);
if (rep->parent->def && if (rep->parent->def &&
VIR_STRDUP(snap->def->parent_name, rep->parent->def->name) < 0) { VIR_STRDUP(moment->def->parent_name, rep->parent->def->name) < 0) {
rep->err = -1; rep->err = -1;
return 0; return 0;
} }
@ -7310,7 +7310,7 @@ testDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) { VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) {
testSnapRemoveData rem; testMomentRemoveData rem;
rem.vm = vm; rem.vm = vm;
rem.current = false; rem.current = false;
virDomainMomentForEachDescendant(snap, virDomainMomentForEachDescendant(snap,
@ -7319,12 +7319,12 @@ testDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
if (rem.current) if (rem.current)
virDomainSnapshotSetCurrent(vm->snapshots, snap); virDomainSnapshotSetCurrent(vm->snapshots, snap);
} else if (snap->nchildren) { } else if (snap->nchildren) {
testSnapReparentData rep; testMomentReparentData rep;
rep.parent = snap->parent; rep.parent = snap->parent;
rep.vm = vm; rep.vm = vm;
rep.err = 0; rep.err = 0;
virDomainMomentForEachChild(snap, virDomainMomentForEachChild(snap,
testDomainSnapshotReparentChildren, testDomainMomentReparentChildren,
&rep); &rep);
if (rep.err < 0) if (rep.err < 0)
goto cleanup; goto cleanup;