]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_block: move qemuDomainBlockPivot out of qemu_driver
authorPavel Hrdina <phrdina@redhat.com>
Tue, 16 Aug 2022 09:31:26 +0000 (11:31 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 9 Jan 2023 12:32:39 +0000 (13:32 +0100)
Move the code for finishing a job in the ready state to qemu_block.c.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_block.c
src/qemu/qemu_block.h
src/qemu/qemu_driver.c

index 825db3e088d5ff647b4af3ac44351f54a83501f6..6d31269dddc36a4fce98a25b369d13eb8ad12bd8 100644 (file)
@@ -3373,3 +3373,124 @@ qemuBlockCommit(virDomainObj *vm,
 
     return ret;
 }
+
+
+/* Called while holding the VM job lock, to implement a block job
+ * abort with pivot; this updates the VM definition as appropriate, on
+ * either success or failure.  */
+int
+qemuBlockPivot(virDomainObj *vm,
+               qemuBlockJobData *job,
+               virDomainDiskDef *disk)
+{
+    g_autoptr(qemuBlockStorageSourceChainData) chainattachdata = NULL;
+    int ret = -1;
+    qemuDomainObjPrivate *priv = vm->privateData;
+    g_autoptr(virJSONValue) bitmapactions = NULL;
+    g_autoptr(virJSONValue) reopenactions = NULL;
+    int rc = 0;
+
+    if (job->state != QEMU_BLOCKJOB_STATE_READY) {
+        virReportError(VIR_ERR_BLOCK_COPY_ACTIVE,
+                       _("block job '%s' not ready for pivot yet"),
+                       job->name);
+        return -1;
+    }
+
+    switch ((qemuBlockJobType) job->type) {
+    case QEMU_BLOCKJOB_TYPE_NONE:
+    case QEMU_BLOCKJOB_TYPE_LAST:
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("invalid job type '%d'"), job->type);
+        return -1;
+
+    case QEMU_BLOCKJOB_TYPE_PULL:
+    case QEMU_BLOCKJOB_TYPE_COMMIT:
+    case QEMU_BLOCKJOB_TYPE_BACKUP:
+    case QEMU_BLOCKJOB_TYPE_INTERNAL:
+    case QEMU_BLOCKJOB_TYPE_CREATE:
+    case QEMU_BLOCKJOB_TYPE_BROKEN:
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       _("job type '%s' does not support pivot"),
+                       qemuBlockjobTypeToString(job->type));
+        return -1;
+
+    case QEMU_BLOCKJOB_TYPE_COPY:
+        if (!job->jobflagsmissing) {
+            bool shallow = job->jobflags & VIR_DOMAIN_BLOCK_COPY_SHALLOW;
+            bool reuse = job->jobflags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT;
+
+            bitmapactions = virJSONValueNewArray();
+
+            if (qemuMonitorTransactionBitmapAdd(bitmapactions,
+                                                disk->mirror->nodeformat,
+                                                "libvirt-tmp-activewrite",
+                                                false,
+                                                false,
+                                                0) < 0)
+                return -1;
+
+            /* Open and install the backing chain of 'mirror' late if we can use
+             * blockdev-snapshot to do it. This is to appease oVirt that wants
+             * to copy data into the backing chain while the top image is being
+             * copied shallow */
+            if (reuse && shallow &&
+                virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV_SNAPSHOT_ALLOW_WRITE_ONLY) &&
+                virStorageSourceHasBacking(disk->mirror)) {
+
+                if (!(chainattachdata = qemuBuildStorageSourceChainAttachPrepareBlockdev(disk->mirror->backingStore)))
+                    return -1;
+
+                reopenactions = virJSONValueNewArray();
+
+                if (qemuMonitorTransactionSnapshotBlockdev(reopenactions,
+                                                           disk->mirror->backingStore->nodeformat,
+                                                           disk->mirror->nodeformat))
+                    return -1;
+            }
+
+        }
+        break;
+
+    case QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT:
+        bitmapactions = virJSONValueNewArray();
+
+        if (qemuMonitorTransactionBitmapAdd(bitmapactions,
+                                            job->data.commit.base->nodeformat,
+                                            "libvirt-tmp-activewrite",
+                                            false,
+                                            false,
+                                            0) < 0)
+            return -1;
+
+        break;
+    }
+
+    qemuDomainObjEnterMonitor(vm);
+
+    if (chainattachdata) {
+        if ((rc = qemuBlockStorageSourceChainAttach(priv->mon, chainattachdata)) == 0) {
+            /* install backing images on success, or unplug them on failure */
+            if ((rc = qemuMonitorTransaction(priv->mon, &reopenactions)) != 0)
+                qemuBlockStorageSourceChainDetach(priv->mon, chainattachdata);
+        }
+    }
+
+    if (bitmapactions && rc == 0)
+        ignore_value(qemuMonitorTransaction(priv->mon, &bitmapactions));
+
+    if (rc == 0)
+        ret = qemuMonitorJobComplete(priv->mon, job->name);
+
+    qemuDomainObjExitMonitor(vm);
+
+    /* The pivot failed. The block job in QEMU remains in the synchronised state */
+    if (ret < 0)
+        return -1;
+
+    if (disk && disk->mirror)
+        disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT;
+    job->state = QEMU_BLOCKJOB_STATE_PIVOTING;
+
+    return ret;
+}
index 85b4805d891d9aa23da171efa941b96a7448944d..52deb15a3d894cd5d88aa257ab8049f7380ff2ee 100644 (file)
@@ -285,3 +285,8 @@ qemuBlockCommit(virDomainObj *vm,
                 virStorageSource *top_parent,
                 unsigned long bandwidth,
                 unsigned int flags);
+
+int
+qemuBlockPivot(virDomainObj *vm,
+               qemuBlockJobData *job,
+               virDomainDiskDef *disk);
index 331e6ca50bfd78945e0e151803e5d3576ebf8862..c35e5e1a31ab34aa179e65560b7d19333a9a25f9 100644 (file)
@@ -13996,127 +13996,6 @@ qemuDomainOpenChannel(virDomainPtr dom,
 }
 
 
-/* Called while holding the VM job lock, to implement a block job
- * abort with pivot; this updates the VM definition as appropriate, on
- * either success or failure.  */
-static int
-qemuDomainBlockPivot(virDomainObj *vm,
-                     qemuBlockJobData *job,
-                     virDomainDiskDef *disk)
-{
-    g_autoptr(qemuBlockStorageSourceChainData) chainattachdata = NULL;
-    int ret = -1;
-    qemuDomainObjPrivate *priv = vm->privateData;
-    g_autoptr(virJSONValue) bitmapactions = NULL;
-    g_autoptr(virJSONValue) reopenactions = NULL;
-    int rc = 0;
-
-    if (job->state != QEMU_BLOCKJOB_STATE_READY) {
-        virReportError(VIR_ERR_BLOCK_COPY_ACTIVE,
-                       _("block job '%s' not ready for pivot yet"),
-                       job->name);
-        return -1;
-    }
-
-    switch ((qemuBlockJobType) job->type) {
-    case QEMU_BLOCKJOB_TYPE_NONE:
-    case QEMU_BLOCKJOB_TYPE_LAST:
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("invalid job type '%d'"), job->type);
-        return -1;
-
-    case QEMU_BLOCKJOB_TYPE_PULL:
-    case QEMU_BLOCKJOB_TYPE_COMMIT:
-    case QEMU_BLOCKJOB_TYPE_BACKUP:
-    case QEMU_BLOCKJOB_TYPE_INTERNAL:
-    case QEMU_BLOCKJOB_TYPE_CREATE:
-    case QEMU_BLOCKJOB_TYPE_BROKEN:
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       _("job type '%s' does not support pivot"),
-                       qemuBlockjobTypeToString(job->type));
-        return -1;
-
-    case QEMU_BLOCKJOB_TYPE_COPY:
-        if (!job->jobflagsmissing) {
-            bool shallow = job->jobflags & VIR_DOMAIN_BLOCK_COPY_SHALLOW;
-            bool reuse = job->jobflags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT;
-
-            bitmapactions = virJSONValueNewArray();
-
-            if (qemuMonitorTransactionBitmapAdd(bitmapactions,
-                                                disk->mirror->nodeformat,
-                                                "libvirt-tmp-activewrite",
-                                                false,
-                                                false,
-                                                0) < 0)
-                return -1;
-
-            /* Open and install the backing chain of 'mirror' late if we can use
-             * blockdev-snapshot to do it. This is to appease oVirt that wants
-             * to copy data into the backing chain while the top image is being
-             * copied shallow */
-            if (reuse && shallow &&
-                virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV_SNAPSHOT_ALLOW_WRITE_ONLY) &&
-                virStorageSourceHasBacking(disk->mirror)) {
-
-                if (!(chainattachdata = qemuBuildStorageSourceChainAttachPrepareBlockdev(disk->mirror->backingStore)))
-                    return -1;
-
-                reopenactions = virJSONValueNewArray();
-
-                if (qemuMonitorTransactionSnapshotBlockdev(reopenactions,
-                                                           disk->mirror->backingStore->nodeformat,
-                                                           disk->mirror->nodeformat))
-                    return -1;
-            }
-
-        }
-        break;
-
-    case QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT:
-        bitmapactions = virJSONValueNewArray();
-
-        if (qemuMonitorTransactionBitmapAdd(bitmapactions,
-                                            job->data.commit.base->nodeformat,
-                                            "libvirt-tmp-activewrite",
-                                            false,
-                                            false,
-                                            0) < 0)
-            return -1;
-
-        break;
-    }
-
-    qemuDomainObjEnterMonitor(vm);
-
-    if (chainattachdata) {
-        if ((rc = qemuBlockStorageSourceChainAttach(priv->mon, chainattachdata)) == 0) {
-            /* install backing images on success, or unplug them on failure */
-            if ((rc = qemuMonitorTransaction(priv->mon, &reopenactions)) != 0)
-                qemuBlockStorageSourceChainDetach(priv->mon, chainattachdata);
-        }
-    }
-
-    if (bitmapactions && rc == 0)
-        ignore_value(qemuMonitorTransaction(priv->mon, &bitmapactions));
-
-    if (rc == 0)
-        ret = qemuMonitorJobComplete(priv->mon, job->name);
-
-    qemuDomainObjExitMonitor(vm);
-
-    /* The pivot failed. The block job in QEMU remains in the synchronised state */
-    if (ret < 0)
-        return -1;
-
-    if (disk && disk->mirror)
-        disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT;
-    job->state = QEMU_BLOCKJOB_STATE_PIVOTING;
-
-    return ret;
-}
-
-
 /* bandwidth in MiB/s per public API. Caller must lock vm beforehand,
  * and not access it afterwards.  */
 static int
@@ -14279,7 +14158,7 @@ qemuDomainBlockJobAbort(virDomainPtr dom,
         qemuBlockJobSyncBegin(job);
 
     if (pivot) {
-        if ((ret = qemuDomainBlockPivot(vm, job, disk)) < 0)
+        if ((ret = qemuBlockPivot(vm, job, disk)) < 0)
             goto endjob;
     } else {
         qemuDomainObjEnterMonitor(vm);