Rather than callers second-guessing when the snapshot definition is assigned turn it into a double pointer and clear it on success. Fix callers to work with the new semantics. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/conf/virdomainsnapshotobjlist.c | 10 ++++++++-- src/conf/virdomainsnapshotobjlist.h | 2 +- src/qemu/qemu_driver.c | 4 +--- src/qemu/qemu_snapshot.c | 6 ++---- src/test/test_driver.c | 12 ++++-------- src/vz/vz_sdk.c | 3 +-- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/conf/virdomainsnapshotobjlist.c b/src/conf/virdomainsnapshotobjlist.c index 0ccdf31ae0..6b074d5994 100644 --- a/src/conf/virdomainsnapshotobjlist.c +++ b/src/conf/virdomainsnapshotobjlist.c @@ -42,9 +42,15 @@ struct _virDomainSnapshotObjList { virDomainMomentObj * virDomainSnapshotAssignDef(virDomainSnapshotObjList *snapshots, - virDomainSnapshotDef *def) + virDomainSnapshotDef **snapdefptr) { - return virDomainMomentAssignDef(snapshots->base, &def->parent); + virDomainSnapshotDef *snapdef = *snapdefptr; + virDomainMomentObj *ret = virDomainMomentAssignDef(snapshots->base, &snapdef->parent); + + if (ret) + *snapdefptr = NULL; + + return ret; } diff --git a/src/conf/virdomainsnapshotobjlist.h b/src/conf/virdomainsnapshotobjlist.h index eebeb9f5a3..bdbc17f6d5 100644 --- a/src/conf/virdomainsnapshotobjlist.h +++ b/src/conf/virdomainsnapshotobjlist.h @@ -30,7 +30,7 @@ virDomainSnapshotObjList *virDomainSnapshotObjListNew(void); void virDomainSnapshotObjListFree(virDomainSnapshotObjList *snapshots); virDomainMomentObj *virDomainSnapshotAssignDef(virDomainSnapshotObjList *snapshots, - virDomainSnapshotDef *def); + virDomainSnapshotDef **snapdefptr); int virDomainSnapshotObjListGetNames(virDomainSnapshotObjList *snapshots, virDomainMomentObj *from, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b3588f9478..e150b86cef 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -396,9 +396,7 @@ qemuDomainSnapshotLoad(virDomainObj *vm, continue; } - snap = virDomainSnapshotAssignDef(vm->snapshots, snapdef); - if (snap) - snapdef = NULL; + snap = virDomainSnapshotAssignDef(vm->snapshots, &snapdef); if (cur && snap) { if (current) virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index c5379d583e..3e35ff5463 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -1721,9 +1721,8 @@ qemuSnapshotRedefine(virDomainObj *vm, return NULL; if (!snap) { - if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, snapdef))) + if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, &snapdef))) return NULL; - snapdef = NULL; } /* XXX Should we validate that the redefined snapshot even * makes sense, such as checking that qemu-img recognizes the @@ -1772,9 +1771,8 @@ qemuSnapshotCreate(virDomainObj *vm, snap->def = &snapdef->parent; snapdef = NULL; } else { - if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, snapdef))) + if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, &snapdef))) return NULL; - snapdef = NULL; if ((current = virDomainSnapshotGetCurrent(vm->snapshots))) { snap->def->parent_name = g_strdup(current->def->name); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index e772b2be2b..14617d4f0d 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -968,7 +968,7 @@ testParseDomainSnapshots(testDriver *privconn, for (i = 0; i < nsdata->num_snap_nodes; i++) { virDomainMomentObj *snap; - virDomainSnapshotDef *def; + g_autoptr(virDomainSnapshotDef) def = NULL; xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file, "domainsnapshot"); if (!node) @@ -984,10 +984,8 @@ testParseDomainSnapshots(testDriver *privconn, if (!def) return -1; - if (!(snap = virDomainSnapshotAssignDef(domobj->snapshots, def))) { - virObjectUnref(def); + if (!(snap = virDomainSnapshotAssignDef(domobj->snapshots, &def))) return -1; - } if (cur) { if (virDomainSnapshotGetCurrent(domobj->snapshots)) { @@ -8755,9 +8753,8 @@ testDomainSnapshotRedefine(virDomainObj *vm, return NULL; if (!snap) { - if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, snapdef))) + if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, &snapdef))) return NULL; - snapdef = NULL; } *snapout = snap; @@ -8846,9 +8843,8 @@ testDomainSnapshotCreateXML(virDomainPtr domain, if (testDomainSnapshotAlignDisks(vm, def, flags) < 0) goto cleanup; - if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, def))) + if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, &def))) goto cleanup; - def = NULL; snap->def->parent_name = g_strdup(virDomainSnapshotGetCurrentName(vm->snapshots)); diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 5ed33902fd..94c6cd5c7a 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -4661,9 +4661,8 @@ prlsdkParseSnapshotTree(const char *treexml) } VIR_FREE(xmlstr); - if (!(snapshot = virDomainSnapshotAssignDef(snapshots, def))) + if (!(snapshot = virDomainSnapshotAssignDef(snapshots, &def))) goto cleanup; - def = NULL; xmlstr = virXPathString("string(./@current)", ctxt); if (xmlstr && STREQ("yes", xmlstr)) { -- 2.31.1