From 17e8af6b45a9874d52b4b7cf9b693e4168e388dc Mon Sep 17 00:00:00 2001 From: Daniel Henrique Barboza Date: Mon, 17 Feb 2020 16:29:09 -0500 Subject: [PATCH] lxc,qemu: use virCgroupSetupBlkioDevice* helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Ján Tomko Reviewed-by: Ján Tomko --- src/lxc/lxc_cgroup.c | 30 ++++++++++-------------------- src/lxc/lxc_driver.c | 41 +++++++++++------------------------------ src/qemu/qemu_cgroup.c | 32 ++++++++++++-------------------- src/qemu/qemu_driver.c | 41 +++++++++++------------------------------ 4 files changed, 44 insertions(+), 100 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 7f3701593a..3c7e31c36b 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -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; } } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index f7376188f0..439cc317c6 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -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; } diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 45701b4c6e..da96a60a08 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -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; } } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 39e1f044e0..411beef537 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -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; } -- GitLab