[libvirt RFC 15/24] qemu_snapshot: call qemuSnapshotDiscardMetadata from qemuSnapshotDiscard

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux