]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_driver: always check whether iothread is used by disk or not
authorPavel Hrdina <phrdina@redhat.com>
Sun, 12 Feb 2017 16:49:21 +0000 (17:49 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 20 Feb 2017 17:43:11 +0000 (18:43 +0100)
If virDomainDelIOThread API was called with VIR_DOMAIN_AFFECT_LIVE
and VIR_DOMAIN_AFFECT_CONFIG and both XML were already a different
it could result in removing iothread from config XML even if there
was a disk using that iothread.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/qemu/qemu_driver.c

index a6b902497380e5d681430c8c52fe5958c2b86cb4..6fb7836c7e061aedd808cc3bbe53765923d0e44f 100644 (file)
@@ -5741,6 +5741,25 @@ qemuDomainHotplugDelIOThread(virQEMUDriverPtr driver,
     goto cleanup;
 }
 
+static int
+qemuDomainDelIOThreadCheck(virDomainDefPtr def,
+                           unsigned int iothread_id)
+{
+    size_t i;
+
+    for (i = 0; i < def->ndisks; i++) {
+        if (def->disks[i]->iothread == iothread_id) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("cannot remove IOThread %u since it "
+                             "is being used by disk '%s'"),
+                           iothread_id, def->disks[i]->dst);
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
 static int
 qemuDomainChgIOThread(virQEMUDriverPtr driver,
                       virDomainObjPtr vm,
@@ -5775,6 +5794,9 @@ qemuDomainChgIOThread(virQEMUDriverPtr driver,
             if (qemuDomainHotplugAddIOThread(driver, vm, iothread_id) < 0)
                 goto endjob;
         } else {
+            if (qemuDomainDelIOThreadCheck(def, iothread_id) < 0)
+                goto endjob;
+
             if (qemuDomainHotplugDelIOThread(driver, vm, iothread_id) < 0)
                 goto endjob;
         }
@@ -5799,6 +5821,9 @@ qemuDomainChgIOThread(virQEMUDriverPtr driver,
                 goto endjob;
             }
 
+            if (qemuDomainDelIOThreadCheck(persistentDef, iothread_id) < 0)
+                goto endjob;
+
             virDomainIOThreadIDDel(persistentDef, iothread_id);
         }
 
@@ -5857,7 +5882,6 @@ qemuDomainDelIOThread(virDomainPtr dom,
     virQEMUDriverPtr driver = dom->conn->privateData;
     virDomainObjPtr vm = NULL;
     int ret = -1;
-    size_t i;
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -5874,17 +5898,6 @@ qemuDomainDelIOThread(virDomainPtr dom,
     if (virDomainDelIOThreadEnsureACL(dom->conn, vm->def, flags) < 0)
            goto cleanup;
 
-    /* If there is a disk using the IOThread to be removed, then fail. */
-    for (i = 0; i < vm->def->ndisks; i++) {
-        if (vm->def->disks[i]->iothread == iothread_id) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("cannot remove IOThread %u since it "
-                             "is being used by disk '%s'"),
-                           iothread_id, vm->def->disks[i]->dst);
-            goto cleanup;
-        }
-    }
-
     ret = qemuDomainChgIOThread(driver, vm, iothread_id, false, flags);
 
  cleanup: