]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Implement blkio tunable XML configuration and parsing.
authorGui Jianfeng <guijianfeng@cn.fujitsu.com>
Tue, 8 Feb 2011 06:59:38 +0000 (14:59 +0800)
committerEric Blake <eblake@redhat.com>
Tue, 8 Feb 2011 18:43:45 +0000 (11:43 -0700)
Implement blkio tunable XML configuration and parsing.

Reviewed-by: "Nikunj A. Dadhania" <nikunj@linux.vnet.ibm.com>
Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/qemu/qemu_cgroup.c
src/qemu/qemu_conf.c
tests/qemuxml2argvdata/qemuxml2argv-blkiotune.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-blkiotune.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c
tests/qemuxml2xmltest.c

index 9369ed47b5b6cb8f14c765435cb625e211215320..c299c0319a759ddd5030fcdc514ecab90344d8b0 100644 (file)
@@ -5149,6 +5149,11 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
     if (node)
         def->mem.hugepage_backed = 1;
 
+    /* Extract blkio cgroup tunables */
+    if (virXPathUInt("string(./blkiotune/weight)", ctxt,
+                     &def->blkio.weight) < 0)
+        def->blkio.weight = 0;
+
     /* Extract other memory tunables */
     if (virXPathULong("string(./memtune/hard_limit)", ctxt,
                       &def->mem.hard_limit) < 0)
@@ -7682,6 +7687,14 @@ char *virDomainDefFormat(virDomainDefPtr def,
     virBufferVSprintf(&buf, "  <currentMemory>%lu</currentMemory>\n",
                       def->mem.cur_balloon);
 
+    /* add blkiotune only if there are any */
+    if (def->blkio.weight) {
+        virBufferVSprintf(&buf, "  <blkiotune>\n");
+        virBufferVSprintf(&buf, "    <weight>%u</weight>\n",
+                          def->blkio.weight);
+        virBufferVSprintf(&buf, "  </blkiotune>\n");
+    }
+
     /* add memtune only if there are any */
     if (def->mem.hard_limit || def->mem.soft_limit || def->mem.min_guarantee ||
         def->mem.swap_hard_limit)
index 5d35e436393b28bfbeecb49298188e2d57e5743b..491301fdf7baea44a3c2e62bd1df75047e6cd6fa 100644 (file)
@@ -1028,6 +1028,10 @@ struct _virDomainDef {
     char *name;
     char *description;
 
+    struct {
+        unsigned int weight;
+    } blkio;
+
     struct {
         unsigned long max_balloon;
         unsigned long cur_balloon;
index 82d3695dc70ea69a2c01117d53b02ec7167ab23e..8cd6ce9e398efc70d6628263dc83d3bae7117871 100644 (file)
@@ -270,6 +270,21 @@ int qemuSetupCgroup(struct qemud_driver *driver,
         }
     }
 
+    if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) {
+        if (vm->def->blkio.weight != 0) {
+            rc = virCgroupSetBlkioWeight(cgroup, vm->def->blkio.weight);
+            if(rc != 0) {
+                virReportSystemError(-rc,
+                                     _("Unable to set io weight for domain %s"),
+                                     vm->def->name);
+                goto cleanup;
+            }
+        }
+    } else {
+        qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                        _("Block I/O tuning is not available on this host"));
+    }
+
     if ((rc = qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_MEMORY))) {
         if (vm->def->mem.hard_limit != 0) {
             rc = virCgroupSetMemoryHardLimit(cgroup, vm->def->mem.hard_limit);
index 9f9e99ee8b2571df412c081c8844b8dba2b2756d..9ba60b10b938537bbdc747ac72237b58e55826f1 100644 (file)
@@ -303,7 +303,8 @@ int qemudLoadDriverConfig(struct qemud_driver *driver,
         driver->cgroupControllers =
             (1 << VIR_CGROUP_CONTROLLER_CPU) |
             (1 << VIR_CGROUP_CONTROLLER_DEVICES) |
-            (1 << VIR_CGROUP_CONTROLLER_MEMORY);
+            (1 << VIR_CGROUP_CONTROLLER_MEMORY) |
+            (1 << VIR_CGROUP_CONTROLLER_BLKIO);
     }
     for (i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i++) {
         if (driver->cgroupControllers & (1 << i)) {
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-blkiotune.args b/tests/qemuxml2argvdata/qemuxml2argv-blkiotune.args
new file mode 100644 (file)
index 0000000..651793d
--- /dev/null
@@ -0,0 +1,4 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
+pc -m 214 -smp 1 -name QEMUGuest1 -nographic -monitor unix:/tmp/test-monitor,\
+server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial \
+none -parallel none -usb
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-blkiotune.xml b/tests/qemuxml2argvdata/qemuxml2argv-blkiotune.xml
new file mode 100644 (file)
index 0000000..4fa03ef
--- /dev/null
@@ -0,0 +1,28 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory>219136</memory>
+  <currentMemory>219136</currentMemory>
+  <blkiotune>
+    <weight>800</weight>
+  </blkiotune>
+  <vcpu>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' unit='0'/>
+    </disk>
+    <controller type='ide' index='0'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
index 9512bdc30483bc4fd1c4564383471bd8d5ea75d2..52808b51aeb93066e055998f0768480bb3ab756e 100644 (file)
@@ -480,6 +480,9 @@ mymain(int argc, char **argv)
     DO_TEST("cpu-exact2", 0, false);
     DO_TEST("cpu-strict1", 0, false);
 
+    DO_TEST("memtune", QEMUD_CMD_FLAG_NAME, false);
+    DO_TEST("blkiotune", QEMUD_CMD_FLAG_NAME, false);
+
     free(driver.stateDir);
     virCapabilitiesFree(driver.caps);
 
index dad91d4e772bcf1360a34fccafa5e34f05998bbf..15d94b764fd643ec4b1e1d7851a75d92dbaa3466 100644 (file)
@@ -182,6 +182,7 @@ mymain(int argc, char **argv)
 
     DO_TEST("encrypted-disk");
     DO_TEST("memtune");
+    DO_TEST("blkiotune");
 
     DO_TEST("smp");