diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9369ed47b5..c299c0319a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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, " %lu\n", def->mem.cur_balloon); + /* add blkiotune only if there are any */ + if (def->blkio.weight) { + virBufferVSprintf(&buf, " \n"); + virBufferVSprintf(&buf, " %u\n", + def->blkio.weight); + virBufferVSprintf(&buf, " \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) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5d35e43639..491301fdf7 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1028,6 +1028,10 @@ struct _virDomainDef { char *name; char *description; + struct { + unsigned int weight; + } blkio; + struct { unsigned long max_balloon; unsigned long cur_balloon; diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 82d3695dc7..8cd6ce9e39 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -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); diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 9f9e99ee8b..9ba60b10b9 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -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 index 0000000000..651793da96 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-blkiotune.args @@ -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 index 0000000000..4fa03ef26f --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-blkiotune.xml @@ -0,0 +1,28 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + + 800 + + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 9512bdc304..52808b51ae 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -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); diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index dad91d4e77..15d94b764f 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -182,6 +182,7 @@ mymain(int argc, char **argv) DO_TEST("encrypted-disk"); DO_TEST("memtune"); + DO_TEST("blkiotune"); DO_TEST("smp");