[libvirt] [PATCH RFC 26/39] qemu: process: Setup disk io throttling for -blockdev

Peter Krempa pkrempa at redhat.com
Wed Jul 25 15:57:57 UTC 2018


The proper way to do this would be to use the 'throttle' driver but
unfortunately it can't change the 'throttle_group' so we can't provide
feature parity. This hack uses the block_set_io_throttle command to do
so until we can properly replace it.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/qemu/qemu_process.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 4b681a892e..928036172d 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6233,6 +6233,53 @@ qemuProcessGenID(virDomainObjPtr vm,
 }


+/**
+ * qemuProcessSetupDiskThrottlingBlockdev:
+ *
+ * Sets up disk trottling for -blockdev via block_set_io_throttle monitor
+ * command. This hack should be replaced by proper use of the 'throttle'
+ * blockdev driver in qemu once it will support changing of the throttle group.
+ */
+static int
+qemuProcessSetupDiskThrottlingBlockdev(virQEMUDriverPtr driver,
+                                       virDomainObjPtr vm,
+                                       qemuDomainAsyncJob asyncJob)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    size_t i;
+    int ret = -1;
+
+    if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV))
+        return 0;
+
+    VIR_DEBUG("Setting up disk throttling for -blockdev via block_set_io_throttle");
+
+    if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
+        return -1;
+
+    for (i = 0; i < vm->def->ndisks; i++) {
+        virDomainDiskDefPtr disk = vm->def->disks[i];
+        qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+
+        if (!qemuDiskConfigBlkdeviotuneEnabled(disk))
+            continue;
+
+        if (qemuMonitorSetBlockIoThrottle(qemuDomainGetMonitor(vm), NULL,
+                                          diskPriv->backendQomName,
+                                          &disk->blkdeviotune,
+                                          true, true, true) < 0)
+            goto cleanup;
+    }
+
+    ret = 0;
+
+ cleanup:
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+        ret = -1;
+    return ret;
+}
+
+
 /**
  * qemuProcessLaunch:
  *
@@ -6551,6 +6598,9 @@ qemuProcessLaunch(virConnectPtr conn,
     if (qemuProcessSetupBalloon(driver, vm, asyncJob) < 0)
         goto cleanup;

+    if (qemuProcessSetupDiskThrottlingBlockdev(driver, vm, asyncJob) < 0)
+        goto cleanup;
+
     /* Since CPUs were not started yet, the balloon could not return the memory
      * to the host and thus cur_balloon needs to be updated so that GetXMLdesc
      * and friends return the correct size in case they can't grab the job */
-- 
2.16.2




More information about the libvir-list mailing list