]> xenbits.xensource.com Git - libvirt.git/commitdiff
lxc,qemu: use virCgroupSetupBlkioDevice* helpers
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Mon, 17 Feb 2020 21:29:09 +0000 (16:29 -0500)
committerJán Tomko <jtomko@redhat.com>
Sun, 23 Feb 2020 13:02:22 +0000 (14:02 +0100)
There are code repetition of set() and get() blkio device
parameters across lxc and qemu files. Use the new vircgroup
helpers to trim the repetition a bit.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/lxc/lxc_cgroup.c
src/lxc/lxc_driver.c
src/qemu/qemu_cgroup.c
src/qemu/qemu_driver.c

index 7f3701593af99d9ded278a99561d6a35eccfeabe..3c7e31c36b420d3b4f217bffc66a501437fb3736 100644 (file)
@@ -112,38 +112,28 @@ static int virLXCCgroupSetupBlkioTune(virDomainDefPtr def,
             virBlkioDevicePtr dev = &def->blkio.devices[i];
 
             if (dev->weight &&
-                (virCgroupSetBlkioDeviceWeight(cgroup, dev->path,
-                                               dev->weight) < 0 ||
-                 virCgroupGetBlkioDeviceWeight(cgroup, dev->path,
-                                               &dev->weight) < 0))
+                virCgroupSetupBlkioDeviceWeight(cgroup, dev->path,
+                                                &dev->weight) < 0)
                 return -1;
 
             if (dev->riops &&
-                (virCgroupSetBlkioDeviceReadIops(cgroup, dev->path,
-                                                 dev->riops) < 0 ||
-                 virCgroupGetBlkioDeviceReadIops(cgroup, dev->path,
-                                                 &dev->riops) < 0))
+                virCgroupSetupBlkioDeviceReadIops(cgroup, dev->path,
+                                                  &dev->riops) < 0)
                 return -1;
 
             if (dev->wiops &&
-                (virCgroupSetBlkioDeviceWriteIops(cgroup, dev->path,
-                                                  dev->wiops) < 0 ||
-                 virCgroupGetBlkioDeviceWriteIops(cgroup, dev->path,
-                                                  &dev->wiops) < 0))
+                virCgroupSetupBlkioDeviceWriteIops(cgroup, dev->path,
+                                                   &dev->wiops) < 0)
                 return -1;
 
             if (dev->rbps &&
-                (virCgroupSetBlkioDeviceReadBps(cgroup, dev->path,
-                                                dev->rbps) < 0 ||
-                 virCgroupGetBlkioDeviceReadBps(cgroup, dev->path,
-                                                &dev->rbps) < 0))
+                virCgroupSetupBlkioDeviceReadBps(cgroup, dev->path,
+                                                 &dev->rbps) < 0)
                 return -1;
 
             if (dev->wbps &&
-                (virCgroupSetBlkioDeviceWriteBps(cgroup, dev->path,
-                                                 dev->wbps) < 0 ||
-                 virCgroupGetBlkioDeviceWriteBps(cgroup, dev->path,
-                                                 &dev->wbps) < 0))
+                virCgroupSetupBlkioDeviceWriteBps(cgroup, dev->path,
+                                                  &dev->wbps) < 0)
                 return -1;
         }
     }
index f7376188f0789968bb8aabccffa611869f7484f0..439cc317c6aeb03ddfdfa83e2f0c6566d51c13d6 100644 (file)
@@ -2581,6 +2581,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
                        STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS) ||
                        STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) ||
                        STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
+                virCgroupPtr cgroup = priv->cgroup;
                 size_t ndevices;
                 virBlkioDevicePtr devices = NULL;
                 size_t j;
@@ -2595,60 +2596,40 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
 
                 if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
                     for (j = 0; j < ndevices; j++) {
-                        if (virCgroupSetBlkioDeviceWeight(priv->cgroup,
-                                                          devices[j].path,
-                                                          devices[j].weight) < 0 ||
-                            virCgroupGetBlkioDeviceWeight(priv->cgroup,
-                                                          devices[j].path,
-                                                          &devices[j].weight) < 0) {
+                        if (virCgroupSetupBlkioDeviceWeight(cgroup, devices[j].path,
+                                                            &devices[j].weight) < 0) {
                             ret = -1;
                             break;
                         }
                     }
                 } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) {
                     for (j = 0; j < ndevices; j++) {
-                        if (virCgroupSetBlkioDeviceReadIops(priv->cgroup,
-                                                            devices[j].path,
-                                                            devices[j].riops) < 0 ||
-                            virCgroupGetBlkioDeviceReadIops(priv->cgroup,
-                                                            devices[j].path,
-                                                            &devices[j].riops) < 0) {
+                        if (virCgroupSetupBlkioDeviceReadIops(cgroup, devices[j].path,
+                                                              &devices[j].riops) < 0) {
                             ret = -1;
                             break;
                         }
                     }
                 } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) {
                     for (j = 0; j < ndevices; j++) {
-                        if (virCgroupSetBlkioDeviceWriteIops(priv->cgroup,
-                                                             devices[j].path,
-                                                             devices[j].wiops) < 0 ||
-                            virCgroupGetBlkioDeviceWriteIops(priv->cgroup,
-                                                             devices[j].path,
-                                                             &devices[j].wiops) < 0) {
+                        if (virCgroupSetupBlkioDeviceWriteIops(cgroup, devices[j].path,
+                                                               &devices[j].wiops) < 0) {
                             ret = -1;
                             break;
                         }
                     }
                 } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) {
                     for (j = 0; j < ndevices; j++) {
-                        if (virCgroupSetBlkioDeviceReadBps(priv->cgroup,
-                                                           devices[j].path,
-                                                           devices[j].rbps) < 0 ||
-                            virCgroupGetBlkioDeviceReadBps(priv->cgroup,
-                                                           devices[j].path,
-                                                           &devices[j].rbps) < 0) {
+                        if (virCgroupSetupBlkioDeviceReadBps(cgroup, devices[j].path,
+                                                             &devices[j].rbps) < 0) {
                             ret = -1;
                             break;
                         }
                     }
                 } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
                     for (j = 0; j < ndevices; j++) {
-                        if (virCgroupSetBlkioDeviceWriteBps(priv->cgroup,
-                                                            devices[j].path,
-                                                            devices[j].wbps) < 0 ||
-                            virCgroupGetBlkioDeviceWriteBps(priv->cgroup,
-                                                            devices[j].path,
-                                                            &devices[j].wbps) < 0) {
+                        if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devices[j].path,
+                                                              &devices[j].wbps) < 0) {
                             ret = -1;
                             break;
                         }
index 45701b4c6ef5e5512a2e8d5cfe82dcb63fa16342..da96a60a086567006d9f2f76c52f5170795b34ca 100644 (file)
@@ -611,39 +611,31 @@ qemuSetupBlkioCgroup(virDomainObjPtr vm)
     if (vm->def->blkio.ndevices) {
         for (i = 0; i < vm->def->blkio.ndevices; i++) {
             virBlkioDevicePtr dev = &vm->def->blkio.devices[i];
+            virCgroupPtr cgroup = priv->cgroup;
+
             if (dev->weight &&
-                (virCgroupSetBlkioDeviceWeight(priv->cgroup, dev->path,
-                                               dev->weight) < 0 ||
-                 virCgroupGetBlkioDeviceWeight(priv->cgroup, dev->path,
-                                               &dev->weight) < 0))
+                virCgroupSetupBlkioDeviceWeight(cgroup, dev->path,
+                                                &dev->weight) < 0)
                 return -1;
 
             if (dev->riops &&
-                (virCgroupSetBlkioDeviceReadIops(priv->cgroup, dev->path,
-                                                 dev->riops) < 0 ||
-                 virCgroupGetBlkioDeviceReadIops(priv->cgroup, dev->path,
-                                                 &dev->riops) < 0))
+                virCgroupSetupBlkioDeviceReadIops(cgroup, dev->path,
+                                                  &dev->riops) < 0)
                 return -1;
 
             if (dev->wiops &&
-                (virCgroupSetBlkioDeviceWriteIops(priv->cgroup, dev->path,
-                                                  dev->wiops) < 0 ||
-                 virCgroupGetBlkioDeviceWriteIops(priv->cgroup, dev->path,
-                                                  &dev->wiops) < 0))
+                virCgroupSetupBlkioDeviceWriteIops(cgroup, dev->path,
+                                                   &dev->wiops) < 0)
                 return -1;
 
             if (dev->rbps &&
-                (virCgroupSetBlkioDeviceReadBps(priv->cgroup, dev->path,
-                                                dev->rbps) < 0 ||
-                 virCgroupGetBlkioDeviceReadBps(priv->cgroup, dev->path,
-                                                &dev->rbps) < 0))
+                virCgroupSetupBlkioDeviceReadBps(cgroup, dev->path,
+                                                 &dev->rbps) < 0)
                 return -1;
 
             if (dev->wbps &&
-                (virCgroupSetBlkioDeviceWriteBps(priv->cgroup, dev->path,
-                                                 dev->wbps) < 0 ||
-                 virCgroupGetBlkioDeviceWriteBps(priv->cgroup, dev->path,
-                                                 &dev->wbps) < 0))
+                virCgroupSetupBlkioDeviceWriteBps(cgroup, dev->path,
+                                                  &dev->wbps) < 0)
                 return -1;
         }
     }
index 39e1f044e027ebd1d6775a3c96ef5a045f9d56ba..411beef537934038ea50c13dd88037904cbd0f0b 100644 (file)
@@ -9564,6 +9564,7 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
                        STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS) ||
                        STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) ||
                        STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
+                virCgroupPtr cgroup = priv->cgroup;
                 size_t ndevices;
                 virBlkioDevicePtr devices = NULL;
                 size_t j;
@@ -9578,60 +9579,40 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
 
                 if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
                     for (j = 0; j < ndevices; j++) {
-                        if (virCgroupSetBlkioDeviceWeight(priv->cgroup,
-                                                          devices[j].path,
-                                                          devices[j].weight) < 0 ||
-                            virCgroupGetBlkioDeviceWeight(priv->cgroup,
-                                                          devices[j].path,
-                                                          &devices[j].weight) < 0) {
+                        if (virCgroupSetupBlkioDeviceWeight(cgroup, devices[j].path,
+                                                            &devices[j].weight) < 0) {
                             ret = -1;
                             break;
                         }
                     }
                 } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) {
                     for (j = 0; j < ndevices; j++) {
-                        if (virCgroupSetBlkioDeviceReadIops(priv->cgroup,
-                                                            devices[j].path,
-                                                            devices[j].riops) < 0 ||
-                            virCgroupGetBlkioDeviceReadIops(priv->cgroup,
-                                                            devices[j].path,
-                                                            &devices[j].riops) < 0) {
+                        if (virCgroupSetupBlkioDeviceReadIops(cgroup, devices[j].path,
+                                                              &devices[j].riops) < 0) {
                             ret = -1;
                             break;
                         }
                     }
                 } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) {
                     for (j = 0; j < ndevices; j++) {
-                        if (virCgroupSetBlkioDeviceWriteIops(priv->cgroup,
-                                                             devices[j].path,
-                                                             devices[j].wiops) < 0 ||
-                            virCgroupGetBlkioDeviceWriteIops(priv->cgroup,
-                                                             devices[j].path,
-                                                             &devices[j].wiops) < 0) {
+                        if (virCgroupSetupBlkioDeviceWriteIops(cgroup, devices[j].path,
+                                                               &devices[j].wiops) < 0) {
                             ret = -1;
                             break;
                         }
                     }
                 } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) {
                     for (j = 0; j < ndevices; j++) {
-                        if (virCgroupSetBlkioDeviceReadBps(priv->cgroup,
-                                                           devices[j].path,
-                                                           devices[j].rbps) < 0 ||
-                            virCgroupGetBlkioDeviceReadBps(priv->cgroup,
-                                                           devices[j].path,
-                                                           &devices[j].rbps) < 0) {
+                        if (virCgroupSetupBlkioDeviceReadBps(cgroup, devices[j].path,
+                                                             &devices[j].rbps) < 0) {
                             ret = -1;
                             break;
                         }
                     }
                 } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
                     for (j = 0; j < ndevices; j++) {
-                        if (virCgroupSetBlkioDeviceWriteBps(priv->cgroup,
-                                                            devices[j].path,
-                                                            devices[j].wbps) < 0 ||
-                            virCgroupGetBlkioDeviceWriteBps(priv->cgroup,
-                                                            devices[j].path,
-                                                            &devices[j].wbps) < 0) {
+                        if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devices[j].path,
+                                                              &devices[j].wbps) < 0) {
                             ret = -1;
                             break;
                         }