c401cc
From e08104f5750faaf4a182915cbb759aad09285aef Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <e08104f5750faaf4a182915cbb759aad09285aef.1389183250.git.jdenemar@redhat.com>
c401cc
From: Jiri Denemark <jdenemar@redhat.com>
c401cc
Date: Fri, 20 Dec 2013 15:08:06 +0100
c401cc
Subject: [PATCH] qemu: Fix job usage in qemuDomainBlockCopy
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1048643
c401cc
c401cc
Every API that is going to begin a job should do that before fetching
c401cc
data from vm->def.
c401cc
c401cc
(cherry picked from commit ff5f30b6bfa317f2a4c33f69289baf4e887eb048)
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/qemu/qemu_driver.c | 25 ++++++++++---------------
c401cc
 1 file changed, 10 insertions(+), 15 deletions(-)
c401cc
c401cc
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
c401cc
index 1ff07bb..0cf2d4a 100644
c401cc
--- a/src/qemu/qemu_driver.c
c401cc
+++ b/src/qemu/qemu_driver.c
c401cc
@@ -14637,7 +14637,7 @@ qemuDomainBlockCopy(virDomainObjPtr vm,
c401cc
     virQEMUDriverPtr driver = conn->privateData;
c401cc
     qemuDomainObjPrivatePtr priv;
c401cc
     char *device = NULL;
c401cc
-    virDomainDiskDefPtr disk;
c401cc
+    virDomainDiskDefPtr disk = NULL;
c401cc
     int ret = -1;
c401cc
     int idx;
c401cc
     struct stat st;
c401cc
@@ -14652,29 +14652,32 @@ qemuDomainBlockCopy(virDomainObjPtr vm,
c401cc
     priv = vm->privateData;
c401cc
     cfg = virQEMUDriverGetConfig(driver);
c401cc
 
c401cc
+    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
c401cc
+        goto cleanup;
c401cc
+
c401cc
     if (!virDomainObjIsActive(vm)) {
c401cc
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
c401cc
                        _("domain is not running"));
c401cc
-        goto cleanup;
c401cc
+        goto endjob;
c401cc
     }
c401cc
 
c401cc
     device = qemuDiskPathToAlias(vm, path, &idx);
c401cc
     if (!device) {
c401cc
-        goto cleanup;
c401cc
+        goto endjob;
c401cc
     }
c401cc
     disk = vm->def->disks[idx];
c401cc
     if (disk->mirror) {
c401cc
         virReportError(VIR_ERR_BLOCK_COPY_ACTIVE,
c401cc
                        _("disk '%s' already in active block copy job"),
c401cc
                        disk->dst);
c401cc
-        goto cleanup;
c401cc
+        goto endjob;
c401cc
     }
c401cc
 
c401cc
     if (!(virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DRIVE_MIRROR) &&
c401cc
           virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKJOB_ASYNC))) {
c401cc
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
c401cc
                        _("block copy is not supported with this QEMU binary"));
c401cc
-        goto cleanup;
c401cc
+        goto endjob;
c401cc
     }
c401cc
     if (vm->persistent) {
c401cc
         /* XXX if qemu ever lets us start a new domain with mirroring
c401cc
@@ -14683,17 +14686,9 @@ qemuDomainBlockCopy(virDomainObjPtr vm,
c401cc
          * this on persistent domains.  */
c401cc
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
c401cc
                        _("domain is not transient"));
c401cc
-        goto cleanup;
c401cc
-    }
c401cc
-
c401cc
-    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
c401cc
-        goto cleanup;
c401cc
-
c401cc
-    if (!virDomainObjIsActive(vm)) {
c401cc
-        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
c401cc
-                       _("domain is not running"));
c401cc
         goto endjob;
c401cc
     }
c401cc
+
c401cc
     if (qemuDomainDetermineDiskChain(driver, disk, false) < 0)
c401cc
         goto endjob;
c401cc
 
c401cc
@@ -14783,7 +14778,7 @@ qemuDomainBlockCopy(virDomainObjPtr vm,
c401cc
 endjob:
c401cc
     if (need_unlink && unlink(dest))
c401cc
         VIR_WARN("unable to unlink just-created %s", dest);
c401cc
-    if (ret < 0)
c401cc
+    if (ret < 0 && disk)
c401cc
         disk->mirrorFormat = VIR_STORAGE_FILE_NONE;
c401cc
     VIR_FREE(mirror);
c401cc
     if (qemuDomainObjEndJob(driver, vm) == 0) {
c401cc
-- 
c401cc
1.8.5.2
c401cc