[libvirt PATCH v2 08/24] qemu_snapshot: introduce qemuSnapshotCreateQcow2Files

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

 



Extract creation of qcow2 files for external snapshots to separate
function as we will need it for external snapshot revert code.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/qemu/qemu_snapshot.c | 67 +++++++++++++++++++++++++---------------
 1 file changed, 42 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index 8e1eb21b5d..227c201195 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -181,35 +181,21 @@ qemuSnapshotDomainDefUpdateDisk(virDomainDef *domdef,
 }
 
 
-/* The domain is expected to be locked and inactive. */
 static int
-qemuSnapshotCreateInactiveInternal(virQEMUDriver *driver,
-                                   virDomainObj *vm,
-                                   virDomainMomentObj *snap)
-{
-    return qemuDomainSnapshotForEachQcow2(driver, vm->def, snap, "-c", false);
-}
-
-
-/* The domain is expected to be locked and inactive. */
-static int
-qemuSnapshotCreateInactiveExternal(virQEMUDriver *driver,
-                                   virDomainObj *vm,
-                                   virDomainMomentObj *snap,
-                                   bool reuse)
+qemuSnapshotCreateQcow2Files(virDomainObj *vm,
+                             virDomainSnapshotDef *snapdef,
+                             virBitmap *created,
+                             bool reuse)
 {
     size_t i;
-    virDomainSnapshotDiskDef *snapdisk;
-    virDomainDiskDef *defdisk;
     const char *qemuImgPath;
-    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
-    int ret = -1;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-    virDomainSnapshotDef *snapdef = virDomainSnapshotObjGetDef(snap);
-    g_autoptr(virBitmap) created = virBitmapNew(snapdef->ndisks);
+    virQEMUDriver *driver = ((qemuDomainObjPrivate *) vm->privateData)->driver;
+    virDomainSnapshotDiskDef *snapdisk = NULL;
+    virDomainDiskDef *defdisk = NULL;
 
     if (!(qemuImgPath = qemuFindQemuImgBinary(driver)))
-        goto cleanup;
+        return -1;
 
     /* If reuse is true, then qemuSnapshotPrepare already
      * ensured that the new files exist, and it was up to the user to
@@ -218,6 +204,7 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *driver,
         g_autoptr(virCommand) cmd = NULL;
         snapdisk = &(snapdef->disks[i]);
         defdisk = vm->def->disks[i];
+
         if (snapdisk->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL)
             continue;
 
@@ -225,7 +212,7 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *driver,
             snapdisk->src->format = VIR_STORAGE_FILE_QCOW2;
 
         if (qemuDomainStorageSourceValidateDepth(defdisk->src, 1, defdisk->dst) < 0)
-            goto cleanup;
+            return -1;
 
         /* creates cmd line args: qemu-img create -f qcow2 -o */
         if (!(cmd = virCommandNewArgList(qemuImgPath,
@@ -234,7 +221,7 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *driver,
                                          virStorageFileFormatTypeToString(snapdisk->src->format),
                                          "-o",
                                          NULL)))
-            goto cleanup;
+            return -1;
 
         /* adds cmd line arg: backing_fmt=format,backing_file=/path/to/backing/file */
         virBufferAsprintf(&buf, "backing_fmt=%s,backing_file=",
@@ -251,9 +238,39 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *driver,
             ignore_value(virBitmapSetBit(created, i));
 
         if (virCommandRun(cmd, NULL) < 0)
-            goto cleanup;
+            return -1;
     }
 
+    return 0;
+}
+
+
+/* The domain is expected to be locked and inactive. */
+static int
+qemuSnapshotCreateInactiveInternal(virQEMUDriver *driver,
+                                   virDomainObj *vm,
+                                   virDomainMomentObj *snap)
+{
+    return qemuDomainSnapshotForEachQcow2(driver, vm->def, snap, "-c", false);
+}
+
+
+/* The domain is expected to be locked and inactive. */
+static int
+qemuSnapshotCreateInactiveExternal(virQEMUDriver *driver,
+                                   virDomainObj *vm,
+                                   virDomainMomentObj *snap,
+                                   bool reuse)
+{
+    virDomainSnapshotDiskDef *snapdisk;
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
+    int ret = -1;
+    virDomainSnapshotDef *snapdef = virDomainSnapshotObjGetDef(snap);
+    g_autoptr(virBitmap) created = virBitmapNew(snapdef->ndisks);
+
+    if (qemuSnapshotCreateQcow2Files(vm, snapdef, created, reuse) < 0)
+        goto cleanup;
+
     /* update disk definitions */
     if (qemuSnapshotDomainDefUpdateDisk(vm->def, snapdef, reuse) < 0)
         goto cleanup;
-- 
2.41.0




[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