]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: snapshot: split out preparation of a snapshot with blockdev
authorPeter Krempa <pkrempa@redhat.com>
Fri, 25 Oct 2019 07:30:56 +0000 (09:30 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Nov 2019 07:51:50 +0000 (08:51 +0100)
Separate the blockdev code since it makes the original function lengthy.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
ACKed-by: Eric Blake <eblake@redhat.com>
src/qemu/qemu_driver.c

index abfb540d808e7cf8b9756aa7be61c963ae6d3f3c..45363b0d6dee0d4f460f2eafb4c8499d9c5b8b4a 100644 (file)
@@ -15228,6 +15228,58 @@ qemuDomainSnapshotDiskCleanup(qemuDomainSnapshotDiskDataPtr data,
 }
 
 
+static int
+qemuDomainSnapshotDiskPrepareOneBlockdev(virQEMUDriverPtr driver,
+                                         virDomainObjPtr vm,
+                                         qemuDomainSnapshotDiskDataPtr dd,
+                                         virQEMUDriverConfigPtr cfg,
+                                         bool reuse,
+                                         virHashTablePtr blockNamedNodeData,
+                                         qemuDomainAsyncJob asyncJob)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    g_autoptr(virStorageSource) terminator = NULL;
+    int rc;
+
+    /* create a terminator for the snapshot disks so that qemu does not try
+     * to open them at first */
+    if (!(terminator = virStorageSourceNew()))
+        return -1;
+
+    if (qemuDomainPrepareStorageSourceBlockdev(dd->disk, dd->src,
+                                               priv, cfg) < 0)
+        return -1;
+
+    if (!(dd->crdata = qemuBuildStorageSourceChainAttachPrepareBlockdevTop(dd->src,
+                                                                           terminator,
+                                                                           priv->qemuCaps)))
+        return -1;
+
+    if (reuse) {
+        if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
+            return -1;
+
+        rc = qemuBlockStorageSourceAttachApply(qemuDomainGetMonitor(vm),
+                                               dd->crdata->srcdata[0]);
+
+        if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
+            return -1;
+    } else {
+        if (qemuBlockStorageSourceCreateDetectSize(blockNamedNodeData,
+                                                   dd->src, dd->disk->src) < 0)
+            return -1;
+
+        if (qemuBlockStorageSourceCreate(vm, dd->src, dd->disk->src,
+                                         NULL, dd->crdata->srcdata[0],
+                                         asyncJob) < 0)
+            return -1;
+    }
+
+    dd->blockdevadded = true;
+    return 0;
+}
+
+
 static int
 qemuDomainSnapshotDiskPrepareOne(virQEMUDriverPtr driver,
                                  virDomainObjPtr vm,
@@ -15240,12 +15292,9 @@ qemuDomainSnapshotDiskPrepareOne(virQEMUDriverPtr driver,
                                  bool blockdev,
                                  qemuDomainAsyncJob asyncJob)
 {
-    qemuDomainObjPrivatePtr priv = vm->privateData;
     virDomainDiskDefPtr persistdisk;
-    g_autoptr(virStorageSource) terminator = NULL;
     bool supportsCreate;
     bool supportsBacking;
-    int rc;
 
     dd->disk = disk;
 
@@ -15314,43 +15363,10 @@ qemuDomainSnapshotDiskPrepareOne(virQEMUDriverPtr driver,
 
     dd->prepared = true;
 
-    if (blockdev) {
-        /* create a terminator for the snapshot disks so that qemu does not try
-         * to open them at first */
-        if (!(terminator = virStorageSourceNew()))
-            return -1;
-
-        if (qemuDomainPrepareStorageSourceBlockdev(dd->disk, dd->src,
-                                                   priv, cfg) < 0)
-            return -1;
-
-        if (!(dd->crdata = qemuBuildStorageSourceChainAttachPrepareBlockdevTop(dd->src,
-                                                                               terminator,
-                                                                               priv->qemuCaps)))
-            return -1;
-
-        if (reuse) {
-            if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
-                return -1;
-
-            rc = qemuBlockStorageSourceAttachApply(qemuDomainGetMonitor(vm),
-                                                   dd->crdata->srcdata[0]);
-
-            if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
-                return -1;
-        } else {
-            if (qemuBlockStorageSourceCreateDetectSize(blockNamedNodeData,
-                                                       dd->src, dd->disk->src) < 0)
-                return -1;
-
-            if (qemuBlockStorageSourceCreate(vm, dd->src, dd->disk->src,
-                                             NULL, dd->crdata->srcdata[0],
-                                             asyncJob) < 0)
-                return -1;
-        }
-
-        dd->blockdevadded = true;
-    }
+    if (blockdev &&
+        qemuDomainSnapshotDiskPrepareOneBlockdev(driver, vm, dd, cfg, reuse,
+                                                 blockNamedNodeData, asyncJob) < 0)
+        return -1;
 
     return 0;
 }