[libvirt] [PATCH] Fix blkdeviotune for shutoff domain

Martin Kletzander mkletzan at redhat.com
Thu May 23 12:37:31 UTC 2013


Function qemuDomainSetBlockIoTune() was creating job and checking QEMU
capabilities even when !(flags & VIR_DOMAIN_AFFECT_LIVE) and the
domain was shutoff.  Fix this with a little cleanup.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=965016

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 src/qemu/qemu_driver.c | 52 ++++++++++++++++++++++----------------------------
 1 file changed, 23 insertions(+), 29 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3df26b8..49432f0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13921,27 +13921,12 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
     priv = vm->privateData;
     cfg = virQEMUDriverGetConfig(driver);

-    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
-        goto cleanup;
-
-    if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DRIVE_IOTUNE)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("block I/O throttling not supported with this "
-                         "QEMU binary"));
-        goto cleanup;
-    }
-
-    device = qemuDiskPathToAlias(vm, disk, &idx);
-    if (!device) {
-        goto cleanup;
-    }
-
-    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
+    if (!(device = qemuDiskPathToAlias(vm, disk, &idx)))
         goto cleanup;

     if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags,
                                         &persistentDef) < 0)
-        goto endjob;
+        goto cleanup;

     for (i = 0; i < nparams; i++) {
         virTypedParameterPtr param = &params[i];
@@ -13976,17 +13961,30 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
         (info.total_bytes_sec && info.write_bytes_sec)) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
                        _("total and read/write of bytes_sec cannot be set at the same time"));
-        goto endjob;
+        goto cleanup;
     }

     if ((info.total_iops_sec && info.read_iops_sec) ||
         (info.total_iops_sec && info.write_iops_sec)) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
                        _("total and read/write of iops_sec cannot be set at the same time"));
-        goto endjob;
+        goto cleanup;
     }

     if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+        if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+            goto cleanup;
+
+        if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DRIVE_IOTUNE)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("block I/O throttling not supported with this "
+                             "QEMU binary"));
+            goto cleanup;
+        }
+
+        if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
+            goto cleanup;
+
         /* If the user didn't specify bytes limits, inherit previous
          * values; likewise if the user didn't specify iops
          * limits.  */
@@ -14004,16 +14002,16 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
         qemuDomainObjEnterMonitor(driver, vm);
         ret = qemuMonitorSetBlockIoThrottle(priv->mon, device, &info);
         qemuDomainObjExitMonitor(driver, vm);
-        if (ret < 0)
-            goto endjob;
+        if (ret < 0) {
+            if (!qemuDomainObjEndJob(driver, vm))
+                vm = NULL;
+            goto cleanup;
+        }
         vm->def->disks[idx]->blkdeviotune = info;
     }

     if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
         sa_assert(persistentDef);
-        idx = virDomainDiskIndexByName(persistentDef, disk, true);
-        if (idx < 0)
-            goto endjob;
         oldinfo = &persistentDef->disks[idx]->blkdeviotune;
         if (!set_bytes) {
             info.total_bytes_sec = oldinfo->total_bytes_sec;
@@ -14030,14 +14028,10 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
         if (ret < 0) {
             virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                            _("Write to config file failed"));
-            goto endjob;
+            goto cleanup;
         }
     }

-endjob:
-    if (qemuDomainObjEndJob(driver, vm) == 0)
-        vm = NULL;
-
 cleanup:
     VIR_FREE(device);
     if (vm)
-- 
1.8.2.1




More information about the libvir-list mailing list