]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: filter blkio 0-device-weight at two other places
authorHu Tao <hutao@cn.fujitsu.com>
Wed, 30 Nov 2011 02:11:08 +0000 (10:11 +0800)
committerEric Blake <eblake@redhat.com>
Wed, 30 Nov 2011 19:34:30 +0000 (12:34 -0700)
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.

src/qemu/qemu_cgroup.c
src/qemu/qemu_driver.c

index e5ca8f30e5c1f6f882b19fc8ba80fd7d0242a1f1..d663798abc2943300b63b179d372e627a8600667 100644 (file)
@@ -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) {
index 39bd1bc87a24e325fad7e20fbb2c823d54284543..ed90c66d3754ee3329e89988c2d0d7c2f5d8b62f 100644 (file)
@@ -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();