From: Hu Tao Date: Wed, 30 Nov 2011 02:11:08 +0000 (+0800) Subject: qemu: filter blkio 0-device-weight at two other places X-Git-Tag: v0.9.8-rc1~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25a5f07c69fb33c00dba0bef974277a6092663a2;p=thirdparty%2Flibvirt.git qemu: filter blkio 0-device-weight at two other places filter 0-device-weight when: - getting blkio parameters with --config - starting up a domain When testing with blkio, I found these issues: (dom is down) virsh blkiotune dom --device-weights /dev/sda,300,/dev/sdb,500 virsh blkiotune dom --device-weights /dev/sda,300,/dev/sdb,0 virsh blkiotune dom weight : 800 device_weight : /dev/sda,200,/dev/sdb,0 # issue 1: shows 0 device weight of /dev/sdb that may confuse user (continued) virsh start dom # issue 2: If /dev/sdb doesn't exist, libvirt refuses to bring the # dom up because it wants to set the device weight to 0 of a # non-existing device. Since 0 means no weight-limit, we really don't # have to set it. --- diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index e5ca8f30e5..d663798abc 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -317,6 +317,8 @@ int qemuSetupCgroup(struct qemud_driver *driver, if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) { for (i = 0; i < vm->def->blkio.ndevices; i++) { virBlkioDeviceWeightPtr dw = &vm->def->blkio.devices[i]; + if (!dw->weight) + continue; rc = virCgroupSetBlkioDeviceWeight(cgroup, dw->path, dw->weight); if (rc != 0) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 39bd1bc87a..ed90c66d37 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6312,6 +6312,7 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom, if (vm->def->blkio.ndevices > 0) { virBuffer buf = VIR_BUFFER_INITIALIZER; bool comma = false; + for (j = 0; j < vm->def->blkio.ndevices; j++) { if (!vm->def->blkio.devices[j].weight) continue; @@ -6372,9 +6373,15 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom, case 1: /* blkiotune.device_weight */ if (persistentDef->blkio.ndevices > 0) { virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (j) + if (!persistentDef->blkio.devices[j].weight) + continue; + if (comma) virBufferAddChar(&buf, ','); + else + comma = true; virBufferAsprintf(&buf, "%s,%u", persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].weight); @@ -6384,7 +6391,8 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom, goto cleanup; } param->value.s = virBufferContentAndReset(&buf); - } else { + } + if (!param->value.s) { param->value.s = strdup(""); if (!param->value.s) { virReportOOMError();