[libvirt] [PATCH 06/10] qemu: Disband qemuDomainSnapshotCreateSingleDiskActive

Peter Krempa posted 10 patches 6 years, 5 months ago
There is a newer version of this series
[libvirt] [PATCH 06/10] qemu: Disband qemuDomainSnapshotCreateSingleDiskActive
Posted by Peter Krempa 6 years, 5 months ago
After we always assume support for the 'transaction' command
(c358adc57113b) and follow-up cleanups
qemuDomainSnapshotCreateSingleDiskActive lost it's value. Move the code
into appropriate helpers and remove the function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_driver.c | 53 ++++++++++++++++--------------------------
 1 file changed, 20 insertions(+), 33 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 57d864cdd2..9248f912d0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15368,6 +15368,22 @@ qemuDomainSnapshotDiskDataCollectOne(virQEMUDriverPtr driver,
         }
     }

+    /* pre-create the image file so that we can label it before handing it to qemu */
+    if (!reuse && dd->src->type != VIR_STORAGE_TYPE_BLOCK) {
+        if (virStorageFileCreate(dd->src) < 0) {
+            virReportSystemError(errno, _("failed to create image file '%s'"),
+                                 NULLSTR(dd->src->path));
+            return -1;
+        }
+        dd->created = true;
+    }
+
+    /* set correct security, cgroup and locking options on the new image */
+    if (qemuDomainStorageSourceAccessAllow(driver, vm, dd->src, false, true) < 0)
+        return -1;
+
+    dd->prepared = true;
+
     return 0;
 }

@@ -15463,36 +15479,6 @@ qemuDomainSnapshotUpdateDiskSources(virQEMUDriverPtr driver,
 }


-static int
-qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
-                                         virDomainObjPtr vm,
-                                         qemuDomainSnapshotDiskDataPtr dd,
-                                         virJSONValuePtr actions,
-                                         bool reuse)
-{
-    if (qemuBlockSnapshotAddLegacy(actions, dd->disk, dd->src, reuse) < 0)
-        return -1;
-
-    /* pre-create the image file so that we can label it before handing it to qemu */
-    if (!reuse && dd->src->type != VIR_STORAGE_TYPE_BLOCK) {
-        if (virStorageFileCreate(dd->src) < 0) {
-            virReportSystemError(errno, _("failed to create image file '%s'"),
-                                 NULLSTR(dd->src->path));
-            return -1;
-        }
-        dd->created = true;
-    }
-
-    /* set correct security, cgroup and locking options on the new image */
-    if (qemuDomainStorageSourceAccessAllow(driver, vm, dd->src, false, true) < 0)
-        return -1;
-
-    dd->prepared = true;
-
-    return 0;
-}
-
-
 /* The domain is expected to be locked and active. */
 static int
 qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
@@ -15535,9 +15521,10 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
       * VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL with a valid file name and
       * qcow2 format.  */
     for (i = 0; i < ndiskdata; i++) {
-        if (qemuDomainSnapshotCreateSingleDiskActive(driver, vm,
-                                                     &diskdata[i],
-                                                     actions, reuse) < 0)
+        if (qemuBlockSnapshotAddLegacy(actions,
+                                       diskdata[i].disk,
+                                       diskdata[i].src,
+                                       reuse) < 0)
             goto cleanup;
     }

-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 06/10] qemu: Disband qemuDomainSnapshotCreateSingleDiskActive
Posted by Ján Tomko 6 years, 5 months ago
On Fri, Aug 16, 2019 at 03:54:40PM +0200, Peter Krempa wrote:
>After we always assume support for the 'transaction' command
>(c358adc57113b) and follow-up cleanups
>qemuDomainSnapshotCreateSingleDiskActive lost it's value. Move the code

its

>into appropriate helpers and remove the function.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/qemu/qemu_driver.c | 53 ++++++++++++++++--------------------------
> 1 file changed, 20 insertions(+), 33 deletions(-)
>
>diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
>index 57d864cdd2..9248f912d0 100644
>--- a/src/qemu/qemu_driver.c
>+++ b/src/qemu/qemu_driver.c
>@@ -15368,6 +15368,22 @@ qemuDomainSnapshotDiskDataCollectOne(virQEMUDriverPtr driver,
>         }
>     }
>
>+    /* pre-create the image file so that we can label it before handing it to qemu */
>+    if (!reuse && dd->src->type != VIR_STORAGE_TYPE_BLOCK) {
>+        if (virStorageFileCreate(dd->src) < 0) {
>+            virReportSystemError(errno, _("failed to create image file '%s'"),
>+                                 NULLSTR(dd->src->path));
>+            return -1;
>+        }
>+        dd->created = true;
>+    }
>+
>+    /* set correct security, cgroup and locking options on the new image */
>+    if (qemuDomainStorageSourceAccessAllow(driver, vm, dd->src, false, true) < 0)
>+        return -1;
>+
>+    dd->prepared = true;
>+
>     return 0;

I don't think qemuDomainSnapshotDiskDataCollectOne is an appropriate
place to be creating image files.

Either rename them to qemuDomainSnapshotDiskPrepareData or something
that implies the change,

> }
>
>@@ -15463,36 +15479,6 @@ qemuDomainSnapshotUpdateDiskSources(virQEMUDriverPtr driver,
> }
>
>
>-static int
>-qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
>-                                         virDomainObjPtr vm,
>-                                         qemuDomainSnapshotDiskDataPtr dd,
>-                                         virJSONValuePtr actions,
>-                                         bool reuse)
>-{
>-    if (qemuBlockSnapshotAddLegacy(actions, dd->disk, dd->src, reuse) < 0)
>-        return -1;
>-

or just split out this call out of qemuDomainSnapshotCreateSingleDiskActive

>-    /* pre-create the image file so that we can label it before handing it to qemu */
>-    if (!reuse && dd->src->type != VIR_STORAGE_TYPE_BLOCK) {
>-        if (virStorageFileCreate(dd->src) < 0) {
>-            virReportSystemError(errno, _("failed to create image file '%s'"),
>-                                 NULLSTR(dd->src->path));
>-            return -1;
>-        }
>-        dd->created = true;
>-    }
>-
>-    /* set correct security, cgroup and locking options on the new image */
>-    if (qemuDomainStorageSourceAccessAllow(driver, vm, dd->src, false, true) < 0)
>-        return -1;
>-
>-    dd->prepared = true;
>-
>-    return 0;
>-}
>-
>-
> /* The domain is expected to be locked and active. */
> static int
> qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
>@@ -15535,9 +15521,10 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,

And iterate over diskdata here as well.

With that change

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
>       * VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL with a valid file name and
>       * qcow2 format.  */
>     for (i = 0; i < ndiskdata; i++) {
>-        if (qemuDomainSnapshotCreateSingleDiskActive(driver, vm,
>-                                                     &diskdata[i],
>-                                                     actions, reuse) < 0)
>+        if (qemuBlockSnapshotAddLegacy(actions,
>+                                       diskdata[i].disk,
>+                                       diskdata[i].src,
>+                                       reuse) < 0)

>             goto cleanup;
>     }
>
>-- 
>2.21.0
>
>--
>libvir-list mailing list
>libvir-list@redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list