This changes the snapshot delete call order. Previously we did snapshot XML reparenting before the actual snapshot deletion. Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx> --- src/qemu/qemu_snapshot.c | 64 +++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index b94506c177..cbacb05c16 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2281,6 +2281,34 @@ qemuSnapshotChildrenReparent(void *payload, } +static int +qemuSnapshotDiscardMetadata(virDomainObj *vm, + virDomainMomentObj *snap, + virQEMUDriver *driver) +{ + g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); + + if (snap->nchildren) { + virQEMUMomentReparent rep; + + rep.dir = cfg->snapshotDir; + rep.parent = snap->parent; + rep.vm = vm; + rep.err = 0; + rep.xmlopt = driver->xmlopt; + rep.writeMetadata = qemuDomainSnapshotWriteMetadata; + virDomainMomentForEachChild(snap, + qemuSnapshotChildrenReparent, + &rep); + if (rep.err < 0) + return -1; + virDomainMomentMoveChildren(snap, snap->parent); + } + + return 0; +} + + /* Discard one snapshot (or its metadata), without reparenting any children. */ static int qemuSnapshotDiscard(virQEMUDriver *driver, @@ -2323,6 +2351,11 @@ qemuSnapshotDiscard(virQEMUDriver *driver, } } + if (update_parent && + qemuSnapshotDiscardMetadata(vm, snap, driver) < 0) { + return -1; + } + snapFile = g_strdup_printf("%s/%s/%s.xml", cfg->snapshotDir, vm->def->name, snap->def->name); @@ -2375,43 +2408,12 @@ qemuSnapshotDiscardAllMetadata(virQEMUDriver *driver, } -static int -qemuSnapshotDiscardMetadata(virDomainObj *vm, - virDomainMomentObj *snap, - virQEMUDriver *driver) -{ - g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); - - if (snap->nchildren) { - virQEMUMomentReparent rep; - - rep.dir = cfg->snapshotDir; - rep.parent = snap->parent; - rep.vm = vm; - rep.err = 0; - rep.xmlopt = driver->xmlopt; - rep.writeMetadata = qemuDomainSnapshotWriteMetadata; - virDomainMomentForEachChild(snap, - qemuSnapshotChildrenReparent, - &rep); - if (rep.err < 0) - return -1; - virDomainMomentMoveChildren(snap, snap->parent); - } - - return 0; -} - - static int qemuSnapshotDeleteSingle(virDomainObj *vm, virDomainMomentObj *snap, virQEMUDriver *driver, bool metadata_only) { - if (qemuSnapshotDiscardMetadata(vm, snap, driver) < 0) - return -1; - return qemuSnapshotDiscard(driver, vm, snap, true, metadata_only); } -- 2.37.2