Implement blkio tunable XML configuration and parsing.
Reviewed-by: "Nikunj A. Dadhania" <nikunj(a)linux.vnet.ibm.com>
Signed-off-by: Gui Jianfeng <guijianfeng(a)cn.fujitsu.com>
---
src/conf/domain_conf.c | 13 +++++++++++++
src/conf/domain_conf.h | 4 ++++
src/qemu/qemu_cgroup.c | 16 +++++++++++++++-
src/qemu/qemu_conf.c | 3 ++-
4 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9369ed4..94369e2 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 (virXPathULong("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>%lu</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)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 5d35e43..80d58a0 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1029,6 +1029,10 @@ struct _virDomainDef {
char *description;
struct {
+ unsigned long weight;
+ } blkio;
+
+ struct {
unsigned long max_balloon;
unsigned long cur_balloon;
unsigned long hugepage_backed;
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 82d3695..0622c9e 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -54,7 +54,6 @@ int qemuCgroupControllerActive(struct qemud_driver *driver,
return 0;
}
-
int qemuSetupDiskPathAllow(virDomainDiskDefPtr disk ATTRIBUTE_UNUSED,
const char *path,
size_t depth ATTRIBUTE_UNUSED,
@@ -270,6 +269,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 9f9e99e..9ba60b1 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)) {
--
1.7.1