[PATCH 7/8] qemu: Aggregate interlocking of blockjobs by checkpoints in one place

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

 



Rather than having to fix 5 places once we support the combination add a
function called by all the blockjob/snapshot APIs.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c | 21 +++++++++++++++++++++
 src/qemu/qemu_domain.h |  4 ++++
 src/qemu/qemu_driver.c | 25 +++++--------------------
 3 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 19fa5420e7..e8a82fee0b 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -15513,3 +15513,24 @@ qemuDomainDefHasManagedPR(virDomainObjPtr vm)

     return jobPR;
 }
+
+
+/**
+ * qemuDomainSupportsCheckpointsBlockjobs:
+ * @vm: domain object
+ *
+ * Checks whether a block job is supported in possible combination with
+ * checkpoints (qcow2 bitmaps). Returns -1 if unsupported and reports an error
+ * 0 in case everything is supported.
+ */
+int
+qemuDomainSupportsCheckpointsBlockjobs(virDomainObjPtr vm)
+{
+    if (virDomainListCheckpoints(vm->checkpoints, NULL, NULL, NULL, 0) > 0) {
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                       _("cannot perform block operations while checkpoint exists"));
+        return -1;
+    }
+
+    return 0;
+}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index f45da882a8..01a54d4265 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -1217,3 +1217,7 @@ qemuDomainPausedReasonToSuspendedEvent(virDomainPausedReason reason);
 int
 qemuDomainValidateActualNetDef(const virDomainNetDef *net,
                                virQEMUCapsPtr qemuCaps);
+
+int
+qemuDomainSupportsCheckpointsBlockjobs(virDomainObjPtr vm)
+    ATTRIBUTE_RETURN_CHECK;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3ad1699eb1..3847c727cf 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15846,11 +15846,8 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
     if (virDomainSnapshotCreateXMLEnsureACL(domain->conn, vm->def, flags) < 0)
         goto cleanup;

-    if (virDomainListCheckpoints(vm->checkpoints, NULL, domain, NULL, 0) > 0) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("cannot create snapshot while checkpoint exists"));
+    if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0)
         goto cleanup;
-    }

     if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
         goto cleanup;
@@ -18374,11 +18371,8 @@ qemuDomainBlockRebase(virDomainPtr dom, const char *path, const char *base,
     if (virDomainBlockRebaseEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;

-    if (virDomainListCheckpoints(vm->checkpoints, NULL, dom, NULL, 0) > 0) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("cannot perform block rebase while checkpoint exists"));
+    if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0)
         goto cleanup;
-    }

     /* For normal rebase (enhanced blockpull), the common code handles
      * everything, including vm cleanup. */
@@ -18464,11 +18458,8 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *disk, const char *destxml,
     if (virDomainBlockCopyEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;

-    if (virDomainListCheckpoints(vm->checkpoints, NULL, dom, NULL, 0) > 0) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("cannot perform block copy while checkpoint exists"));
+    if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0)
         goto cleanup;
-    }

     for (i = 0; i < nparams; i++) {
         virTypedParameterPtr param = &params[i];
@@ -18532,11 +18523,8 @@ qemuDomainBlockPull(virDomainPtr dom, const char *path, unsigned long bandwidth,
     if (virDomainBlockPullEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;

-    if (virDomainListCheckpoints(vm->checkpoints, NULL, dom, NULL, 0) > 0) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("cannot perform block pull while checkpoint exists"));
+    if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0)
         goto cleanup;
-    }

     ret = qemuDomainBlockPullCommon(vm, path, NULL, bandwidth, flags);

@@ -18591,11 +18579,8 @@ qemuDomainBlockCommit(virDomainPtr dom,
     if (virDomainBlockCommitEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;

-    if (virDomainListCheckpoints(vm->checkpoints, NULL, dom, NULL, 0) > 0) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("cannot perform block commit while checkpoint exists"));
+    if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0)
         goto cleanup;
-    }

     if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
         goto cleanup;
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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