[PATCH v1 00/14] vircgroup code duplication purge

Hi, This is my attempt to a side quest from Cole Robinson reported in the wiki. It started with an innocent code duplication reduction work, then I got dragged into code duplication inside LXC and QEMU drivers. There is a significant amount of code sharing between LXC and QEMU drivers that should be handled in a work on its own, but I didn't shy away from the duplications that are related to vircgroup code in some capacity. Last 3 patches are an attempt to clean up libvirt_private.syms a bit, turning some vircgroup functions to static after the changes made. These are trivial, but annoying changes to review in a single patch - hence 3 patches to allow for happier reviews. The maintainer is free to merge the those together when pushing. Daniel Henrique Barboza (14): vircgroup: add virCgroupSetupBlkioTune() vircgroup: add virCgroupSetupMemtune() vircgroup: add virCgroupSetupCpusetCpus() vircgroup: add virCgroupSetAndRetrieveCpuShares() vircgroup: add virCgroupSetupCpuPeriodQuota() domain_conf: add virDomainMergeBlkioDevice() domain_conf: add virDomainParseBlkioDeviceStr() vircgroup: add virCgroupSetupDomainBlkioParameters() domain_conf: add virDomainParseMergePersistentDefBlkioParams() vircgroup: add virCgroupSetMemoryLimitParameters() vircgroup: add virCgroupGetCpuPeriodQuota() vircgroup: turn virCgroup{Get/Set}BlkioDevice* static vircgroup: turn SetMemory and SetCpusetCpus functions static vircgroup: turn more cgroup functions static src/conf/domain_conf.c | 222 ++++++++++++++++++++ src/conf/domain_conf.h | 13 ++ src/libvirt_private.syms | 31 +-- src/lxc/lxc_cgroup.c | 91 +------- src/lxc/lxc_driver.c | 428 ++------------------------------------ src/qemu/qemu_cgroup.c | 113 +--------- src/qemu/qemu_driver.c | 399 +---------------------------------- src/util/vircgroup.c | 436 +++++++++++++++++++++++++++++++++++---- src/util/vircgroup.h | 75 +++---- 9 files changed, 707 insertions(+), 1101 deletions(-) -- 2.24.1

This new util function puts the duplicated code from qemu_cgroup.c:qemuSetupBlkioCgroup() and lxc_cgroup.c:virLXCCgroupSetupBlkioTune() in a single function to be used in both places. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 49 +---------------------------------- src/qemu/qemu_cgroup.c | 47 +--------------------------------- src/util/vircgroup.c | 55 ++++++++++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 3 +++ 5 files changed, 61 insertions(+), 94 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index dc0449d1d8..64163a5e56 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1728,6 +1728,7 @@ virCgroupSetMemoryHardLimit; virCgroupSetMemorySoftLimit; virCgroupSetMemSwapHardLimit; virCgroupSetOwner; +virCgroupSetupBlkioTune; virCgroupSupportsCpuBW; virCgroupTerminateMachine; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 7f3701593a..96d43b06f2 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -101,54 +101,7 @@ static int virLXCCgroupSetupCpusetTune(virDomainDefPtr def, static int virLXCCgroupSetupBlkioTune(virDomainDefPtr def, virCgroupPtr cgroup) { - size_t i; - - if (def->blkio.weight && - virCgroupSetBlkioWeight(cgroup, def->blkio.weight) < 0) - return -1; - - if (def->blkio.ndevices) { - for (i = 0; i < def->blkio.ndevices; i++) { - virBlkioDevicePtr dev = &def->blkio.devices[i]; - - if (dev->weight && - (virCgroupSetBlkioDeviceWeight(cgroup, dev->path, - dev->weight) < 0 || - virCgroupGetBlkioDeviceWeight(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)) - return -1; - - if (dev->wiops && - (virCgroupSetBlkioDeviceWriteIops(cgroup, dev->path, - dev->wiops) < 0 || - virCgroupGetBlkioDeviceWriteIops(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)) - return -1; - - if (dev->wbps && - (virCgroupSetBlkioDeviceWriteBps(cgroup, dev->path, - dev->wbps) < 0 || - virCgroupGetBlkioDeviceWriteBps(cgroup, dev->path, - &dev->wbps) < 0)) - return -1; - } - } - - return 0; + return virCgroupSetupBlkioTune(cgroup, def->blkio); } diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 45701b4c6e..a5eaa24d90 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -591,7 +591,6 @@ static int qemuSetupBlkioCgroup(virDomainObjPtr vm) { qemuDomainObjPrivatePtr priv = vm->privateData; - size_t i; if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_BLKIO)) { @@ -604,51 +603,7 @@ qemuSetupBlkioCgroup(virDomainObjPtr vm) } } - if (vm->def->blkio.weight != 0 && - virCgroupSetBlkioWeight(priv->cgroup, vm->def->blkio.weight) < 0) - return -1; - - if (vm->def->blkio.ndevices) { - for (i = 0; i < vm->def->blkio.ndevices; i++) { - virBlkioDevicePtr dev = &vm->def->blkio.devices[i]; - if (dev->weight && - (virCgroupSetBlkioDeviceWeight(priv->cgroup, dev->path, - dev->weight) < 0 || - virCgroupGetBlkioDeviceWeight(priv->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)) - return -1; - - if (dev->wiops && - (virCgroupSetBlkioDeviceWriteIops(priv->cgroup, dev->path, - dev->wiops) < 0 || - virCgroupGetBlkioDeviceWriteIops(priv->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)) - return -1; - - if (dev->wbps && - (virCgroupSetBlkioDeviceWriteBps(priv->cgroup, dev->path, - dev->wbps) < 0 || - virCgroupGetBlkioDeviceWriteBps(priv->cgroup, dev->path, - &dev->wbps) < 0)) - return -1; - } - } - - return 0; + return virCgroupSetupBlkioTune(priv->cgroup, vm->def->blkio); } diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0680ff7c24..0d83e2094f 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -35,6 +35,7 @@ #define LIBVIRT_VIRCGROUPPRIV_H_ALLOW #include "vircgrouppriv.h" +#include "conf/domain_conf.h" #include "virutil.h" #include "viralloc.h" #include "vircgroupbackend.h" @@ -3581,3 +3582,57 @@ virCgroupDelThread(virCgroupPtr cgroup, return 0; } + + +int +virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune blkio) +{ + size_t i; + + if (blkio.weight != 0 && + virCgroupSetBlkioWeight(cgroup, blkio.weight) < 0) + return -1; + + if (blkio.ndevices) { + for (i = 0; i < blkio.ndevices; i++) { + virBlkioDevicePtr dev = &blkio.devices[i]; + + if (dev->weight != 0 && + (virCgroupSetBlkioDeviceWeight(cgroup, dev->path, + dev->weight) < 0 || + virCgroupGetBlkioDeviceWeight(cgroup, dev->path, + &dev->weight) < 0)) + return -1; + + if (dev->riops != 0 && + (virCgroupSetBlkioDeviceReadIops(cgroup, dev->path, + dev->riops) < 0 || + virCgroupGetBlkioDeviceReadIops(cgroup, dev->path, + &dev->riops) < 0)) + return -1; + + if (dev->wiops != 0 && + (virCgroupSetBlkioDeviceWriteIops(cgroup, dev->path, + dev->wiops) < 0 || + virCgroupGetBlkioDeviceWriteIops(cgroup, dev->path, + &dev->wiops) < 0)) + return -1; + + if (dev->rbps != 0 && + (virCgroupSetBlkioDeviceReadBps(cgroup, dev->path, + dev->rbps) < 0 || + virCgroupGetBlkioDeviceReadBps(cgroup, dev->path, + &dev->rbps) < 0)) + return -1; + + if (dev->wbps != 0 && + (virCgroupSetBlkioDeviceWriteBps(cgroup, dev->path, + dev->wbps) < 0 || + virCgroupGetBlkioDeviceWriteBps(cgroup, dev->path, + &dev->wbps) < 0)) + return -1; + } + } + + return 0; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 15263f534a..d2d7e7ab51 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -24,6 +24,7 @@ #include "virutil.h" #include "virbitmap.h" #include "virenum.h" +#include "conf/virconftypes.h" struct _virCgroup; typedef struct _virCgroup virCgroup; @@ -285,3 +286,5 @@ int virCgroupSetOwner(virCgroupPtr cgroup, int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller); bool virCgroupControllerAvailable(int controller); + +int virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune blkio); -- 2.24.1

On Mon, Feb 10, 2020 at 07:05:07PM -0300, Daniel Henrique Barboza wrote:
This new util function puts the duplicated code from qemu_cgroup.c:qemuSetupBlkioCgroup() and lxc_cgroup.c:virLXCCgroupSetupBlkioTune() in a single function to be used in both places.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 49 +---------------------------------- src/qemu/qemu_cgroup.c | 47 +--------------------------------- src/util/vircgroup.c | 55 ++++++++++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 3 +++ 5 files changed, 61 insertions(+), 94 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0680ff7c24..0d83e2094f 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -35,6 +35,7 @@ #define LIBVIRT_VIRCGROUPPRIV_H_ALLOW #include "vircgrouppriv.h"
+#include "conf/domain_conf.h" #include "virutil.h" #include "viralloc.h" #include "vircgroupbackend.h" diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 15263f534a..d2d7e7ab51 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -24,6 +24,7 @@ #include "virutil.h" #include "virbitmap.h" #include "virenum.h" +#include "conf/virconftypes.h"
src/util should be below src/conf and not including stuff from it (even though we do have some debt there at the moment) The last time this came up: https://www.redhat.com/archives/libvir-list/2018-June/msg00381.html And there should've been a syntax-check rule yelling about this, but I see the out-of-srcdir build broke it: https://www.redhat.com/archives/libvir-list/2020-February/msg00442.html Jano

On 2/10/20 10:39 PM, Ján Tomko wrote:
On Mon, Feb 10, 2020 at 07:05:07PM -0300, Daniel Henrique Barboza wrote:
This new util function puts the duplicated code from qemu_cgroup.c:qemuSetupBlkioCgroup() and lxc_cgroup.c:virLXCCgroupSetupBlkioTune() in a single function to be used in both places.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 49 +---------------------------------- src/qemu/qemu_cgroup.c | 47 +--------------------------------- src/util/vircgroup.c | 55 ++++++++++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 3 +++ 5 files changed, 61 insertions(+), 94 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0680ff7c24..0d83e2094f 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -35,6 +35,7 @@ #define LIBVIRT_VIRCGROUPPRIV_H_ALLOW #include "vircgrouppriv.h"
+#include "conf/domain_conf.h" #include "virutil.h" #include "viralloc.h" #include "vircgroupbackend.h" diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 15263f534a..d2d7e7ab51 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -24,6 +24,7 @@ #include "virutil.h" #include "virbitmap.h" #include "virenum.h" +#include "conf/virconftypes.h"
src/util should be below src/conf and not including stuff from it (even though we do have some debt there at the moment)
The last time this came up: https://www.redhat.com/archives/libvir-list/2018-June/msg00381.html
And there should've been a syntax-check rule yelling about this, but I see the out-of-srcdir build broke it: https://www.redhat.com/archives/libvir-list/2020-February/msg00442.html
Just saw that you fixed this check on newest master. syntax-check is not pleased with these patches anymore. I'll send a v2. Thanks, DHB
Jano

On 2/11/20 7:28 AM, Daniel Henrique Barboza wrote:
On 2/10/20 10:39 PM, Ján Tomko wrote:
On Mon, Feb 10, 2020 at 07:05:07PM -0300, Daniel Henrique Barboza wrote:
This new util function puts the duplicated code from qemu_cgroup.c:qemuSetupBlkioCgroup() and lxc_cgroup.c:virLXCCgroupSetupBlkioTune() in a single function to be used in both places.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 49 +---------------------------------- src/qemu/qemu_cgroup.c | 47 +--------------------------------- src/util/vircgroup.c | 55 ++++++++++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 3 +++ 5 files changed, 61 insertions(+), 94 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0680ff7c24..0d83e2094f 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -35,6 +35,7 @@ #define LIBVIRT_VIRCGROUPPRIV_H_ALLOW #include "vircgrouppriv.h"
+#include "conf/domain_conf.h" #include "virutil.h" #include "viralloc.h" #include "vircgroupbackend.h" diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 15263f534a..d2d7e7ab51 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -24,6 +24,7 @@ #include "virutil.h" #include "virbitmap.h" #include "virenum.h" +#include "conf/virconftypes.h"
src/util should be below src/conf and not including stuff from it (even though we do have some debt there at the moment)
The last time this came up: https://www.redhat.com/archives/libvir-list/2018-June/msg00381.html
And there should've been a syntax-check rule yelling about this, but I see the out-of-srcdir build broke it: https://www.redhat.com/archives/libvir-list/2020-February/msg00442.html
Just saw that you fixed this check on newest master. syntax-check is not pleased with these patches anymore.
I'll send a v2.
I asked about this case in December, danpb suggested creating a new src/hypervisor/ directory for containing shared driver code like this: https://www.redhat.com/archives/libvir-list/2019-December/msg00817.html - Cole

On 2/11/20 11:35 AM, Cole Robinson wrote:
On 2/11/20 7:28 AM, Daniel Henrique Barboza wrote:
[...]
I asked about this case in December, danpb suggested creating a new src/hypervisor/ directory for containing shared driver code like this:
https://www.redhat.com/archives/libvir-list/2019-December/msg00817.html
Thanks, I'm going for it. Do you have any suggestions for the file names? I see that you mentioned "domain_cgroup" in that thread, thus I'm thinking about creating a new src/hypervisor/domain_cgroup.c for the shared code between lxc_cgroup.c and qemu_cgroup.c. I'm also considering a src/hypervisor/domain_driver.c for the driver common code between lxc_driver.c and qemu_driver.c that I ended up finding in this work. DHB
- Cole

On 2/11/20 4:21 PM, Daniel Henrique Barboza wrote:
On 2/11/20 11:35 AM, Cole Robinson wrote:
On 2/11/20 7:28 AM, Daniel Henrique Barboza wrote:
[...]
I asked about this case in December, danpb suggested creating a new src/hypervisor/ directory for containing shared driver code like this:
https://www.redhat.com/archives/libvir-list/2019-December/msg00817.html
Thanks, I'm going for it.
Do you have any suggestions for the file names? I see that you mentioned "domain_cgroup" in that thread, thus I'm thinking about creating a new src/hypervisor/domain_cgroup.c for the shared code between lxc_cgroup.c and qemu_cgroup.c.
I'm also considering a src/hypervisor/domain_driver.c for the driver common code between lxc_driver.c and qemu_driver.c that I ended up finding in this work.
Those both sound reasonable to me. Thanks, Cole

virLXCCgroupSetupMemTune() and qemuSetupMemoryCgroup() shares duplicated code that can be put in a new helper to avoid code repetition. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 14 +------------- src/qemu/qemu_cgroup.c | 14 +------------- src/util/vircgroup.c | 19 +++++++++++++++++++ src/util/vircgroup.h | 1 + 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 64163a5e56..075bb8b3a1 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1729,6 +1729,7 @@ virCgroupSetMemorySoftLimit; virCgroupSetMemSwapHardLimit; virCgroupSetOwner; virCgroupSetupBlkioTune; +virCgroupSetupMemtune; virCgroupSupportsCpuBW; virCgroupTerminateMachine; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 96d43b06f2..b156a3273a 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -111,19 +111,7 @@ static int virLXCCgroupSetupMemTune(virDomainDefPtr def, if (virCgroupSetMemory(cgroup, virDomainDefGetMemoryInitial(def)) < 0) return -1; - if (virMemoryLimitIsSet(def->mem.hard_limit)) - if (virCgroupSetMemoryHardLimit(cgroup, def->mem.hard_limit) < 0) - return -1; - - if (virMemoryLimitIsSet(def->mem.soft_limit)) - if (virCgroupSetMemorySoftLimit(cgroup, def->mem.soft_limit) < 0) - return -1; - - if (virMemoryLimitIsSet(def->mem.swap_hard_limit)) - if (virCgroupSetMemSwapHardLimit(cgroup, def->mem.swap_hard_limit) < 0) - return -1; - - return 0; + return virCgroupSetupMemtune(cgroup, def->mem); } diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index a5eaa24d90..0b78cebd34 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -624,19 +624,7 @@ qemuSetupMemoryCgroup(virDomainObjPtr vm) } } - if (virMemoryLimitIsSet(vm->def->mem.hard_limit)) - if (virCgroupSetMemoryHardLimit(priv->cgroup, vm->def->mem.hard_limit) < 0) - return -1; - - if (virMemoryLimitIsSet(vm->def->mem.soft_limit)) - if (virCgroupSetMemorySoftLimit(priv->cgroup, vm->def->mem.soft_limit) < 0) - return -1; - - if (virMemoryLimitIsSet(vm->def->mem.swap_hard_limit)) - if (virCgroupSetMemSwapHardLimit(priv->cgroup, vm->def->mem.swap_hard_limit) < 0) - return -1; - - return 0; + return virCgroupSetupMemtune(priv->cgroup, vm->def->mem); } diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0d83e2094f..814c954284 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3636,3 +3636,22 @@ virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune blkio) return 0; } + + +int +virCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem) +{ + if (virMemoryLimitIsSet(mem.hard_limit)) + if (virCgroupSetMemoryHardLimit(cgroup, mem.hard_limit) < 0) + return -1; + + if (virMemoryLimitIsSet(mem.soft_limit)) + if (virCgroupSetMemorySoftLimit(cgroup, mem.soft_limit) < 0) + return -1; + + if (virMemoryLimitIsSet(mem.swap_hard_limit)) + if (virCgroupSetMemSwapHardLimit(cgroup, mem.swap_hard_limit) < 0) + return -1; + + return 0; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index d2d7e7ab51..3cb9bc24f9 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -288,3 +288,4 @@ int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller); bool virCgroupControllerAvailable(int controller); int virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune blkio); +int virCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem); -- 2.24.1

The code from qemuSetupCgroupCpusetCpus() and virLXCCgroupSetupCpusetTune() can be centralized in a new helper called virCgroupSetupCpusetCpus(). Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 11 +++-------- src/qemu/qemu_cgroup.c | 14 +------------- src/util/vircgroup.c | 15 +++++++++++++++ src/util/vircgroup.h | 1 + 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 075bb8b3a1..817f73fc98 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1729,6 +1729,7 @@ virCgroupSetMemorySoftLimit; virCgroupSetMemSwapHardLimit; virCgroupSetOwner; virCgroupSetupBlkioTune; +virCgroupSetupCpusetCpus; virCgroupSetupMemtune; virCgroupSupportsCpuBW; virCgroupTerminateMachine; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index b156a3273a..3f15614c7f 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -68,14 +68,9 @@ static int virLXCCgroupSetupCpusetTune(virDomainDefPtr def, virDomainNumatuneMemMode mode; if (def->placement_mode != VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO && - def->cpumask) { - if (!(mask = virBitmapFormat(def->cpumask))) - return -1; - - if (virCgroupSetCpusetCpus(cgroup, mask) < 0) - goto cleanup; - /* free mask to make sure we won't use it in a wrong way later */ - VIR_FREE(mask); + def->cpumask && + virCgroupSetupCpusetCpus(cgroup, def->cpumask) < 0) { + return -1; } if (virDomainNumatuneGetMode(def->numa, -1, &mode) < 0 || diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 0b78cebd34..0181e869fe 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -1164,19 +1164,7 @@ int qemuSetupCgroupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask) { - int ret = -1; - char *new_cpus = NULL; - - if (!(new_cpus = virBitmapFormat(cpumask))) - goto cleanup; - - if (virCgroupSetCpusetCpus(cgroup, new_cpus) < 0) - goto cleanup; - - ret = 0; - cleanup: - VIR_FREE(new_cpus); - return ret; + return virCgroupSetupCpusetCpus(cgroup, cpumask); } diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 814c954284..75037ff8dd 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3655,3 +3655,18 @@ virCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem) return 0; } + + +int +virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask) +{ + g_autofree char *new_cpus = NULL; + + if (!(new_cpus = virBitmapFormat(cpumask))) + return -1; + + if (virCgroupSetCpusetCpus(cgroup, new_cpus) < 0) + return -1; + + return 0; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 3cb9bc24f9..0c84bb762b 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -289,3 +289,4 @@ bool virCgroupControllerAvailable(int controller); int virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune blkio); int virCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem); +int virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask); -- 2.24.1

The code that calls virCgroupSetCpuShares() and virCgroupGetCpuShares() is repeated in 4 different places. Let's put it in a new virCgroupSetAndRetrieveCpuShares() to avoid code repetition. There's a reason of why we execute a Get in the same value we just executed Set, explained in detail by commit 97814d8ab3. Let's add a gist of the reasoning behind it as a comment in this new function as well. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 6 +++--- src/lxc/lxc_driver.c | 7 +++---- src/qemu/qemu_cgroup.c | 7 ++++--- src/qemu/qemu_driver.c | 6 ++---- src/util/vircgroup.c | 21 +++++++++++++++++++++ src/util/vircgroup.h | 3 +++ 7 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 817f73fc98..6aa3f670db 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1710,6 +1710,7 @@ virCgroupNewSelf; virCgroupNewThread; virCgroupPathOfController; virCgroupRemove; +virCgroupSetAndRetrieveCpuShares; virCgroupSetBlkioDeviceReadBps; virCgroupSetBlkioDeviceReadIops; virCgroupSetBlkioDeviceWeight; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 3f15614c7f..2ccc1ae5a1 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -39,11 +39,11 @@ static int virLXCCgroupSetupCpuTune(virDomainDefPtr def, { if (def->cputune.sharesSpecified) { unsigned long long val; - if (virCgroupSetCpuShares(cgroup, def->cputune.shares) < 0) - return -1; - if (virCgroupGetCpuShares(cgroup, &val) < 0) + if (virCgroupSetAndRetrieveCpuShares(cgroup, def->cputune.shares, + &val) < 0) return -1; + def->cputune.shares = val; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index f7376188f0..51f1284d56 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1959,10 +1959,9 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) { if (def) { unsigned long long val; - if (virCgroupSetCpuShares(priv->cgroup, params[i].value.ul) < 0) - goto endjob; - - if (virCgroupGetCpuShares(priv->cgroup, &val) < 0) + if (virCgroupSetAndRetrieveCpuShares(priv->cgroup, + params[i].value.ul, + &val) < 0) goto endjob; def->cputune.shares = val; diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 0181e869fe..0ca62ba3ee 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -893,11 +893,12 @@ qemuSetupCpuCgroup(virDomainObjPtr vm) if (vm->def->cputune.sharesSpecified) { unsigned long long val; - if (virCgroupSetCpuShares(priv->cgroup, vm->def->cputune.shares) < 0) - return -1; - if (virCgroupGetCpuShares(priv->cgroup, &val) < 0) + if (virCgroupSetAndRetrieveCpuShares(priv->cgroup, + vm->def->cputune.shares, + &val) < 0) return -1; + if (vm->def->cputune.shares != val) { vm->def->cputune.shares = val; if (virTypedParamsAddULLong(&eventParams, &eventNparams, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2813f084cd..0d58893d7e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10667,10 +10667,8 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom, if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) { if (def) { unsigned long long val; - if (virCgroupSetCpuShares(priv->cgroup, value_ul) < 0) - goto endjob; - - if (virCgroupGetCpuShares(priv->cgroup, &val) < 0) + if (virCgroupSetAndRetrieveCpuShares(priv->cgroup, value_ul, + &val) < 0) goto endjob; def->cputune.shares = val; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 75037ff8dd..cfb34a0f0e 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3670,3 +3670,24 @@ virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask) return 0; } + + +/* Per commit 97814d8ab3, the Linux kernel can consider a 'shares' + * value of '0' and '1' as 2, and any value larger than a maximum + * is reduced to maximum. + * + * The 'realValue' pointer holds the actual 'shares' value set by + * the kernel if the function returned success. */ +int +virCgroupSetAndRetrieveCpuShares(virCgroupPtr cgroup, + unsigned long long shares, + unsigned long long *realValue) +{ + if (virCgroupSetCpuShares(cgroup, shares) < 0) + return -1; + + if (virCgroupGetCpuShares(cgroup, realValue) < 0) + return -1; + + return 0; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 0c84bb762b..ed8ee30a58 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -290,3 +290,6 @@ bool virCgroupControllerAvailable(int controller); int virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune blkio); int virCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem); int virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask); +int virCgroupSetAndRetrieveCpuShares(virCgroupPtr cgroup, + unsigned long long shares, + unsigned long long *realValue); -- 2.24.1

qemuSetupCgroupVcpuBW() and lxcSetVcpuBWLive() shares the same code to set CPU CFS period and quota. This code can be moved to a new virCgroupSetupCpuPeriodQuota() helper to avoid code repetition. A similar code is also executed in virLXCCgroupSetupCpuTune(), but without the rollback on error. Use the new helper in this function as well since the 'period' rollback, if not a straight improvement for virLXCCgroupSetupCpuTune(), is benign. And we end up cutting more code repetition. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 11 ++--------- src/lxc/lxc_driver.c | 32 +------------------------------- src/qemu/qemu_cgroup.c | 31 +------------------------------ src/util/vircgroup.c | 38 ++++++++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 3 +++ 6 files changed, 46 insertions(+), 70 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6aa3f670db..38fe847cef 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1730,6 +1730,7 @@ virCgroupSetMemorySoftLimit; virCgroupSetMemSwapHardLimit; virCgroupSetOwner; virCgroupSetupBlkioTune; +virCgroupSetupCpuPeriodQuota; virCgroupSetupCpusetCpus; virCgroupSetupMemtune; virCgroupSupportsCpuBW; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 2ccc1ae5a1..d520f9cb3b 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -47,15 +47,8 @@ static int virLXCCgroupSetupCpuTune(virDomainDefPtr def, def->cputune.shares = val; } - if (def->cputune.quota != 0 && - virCgroupSetCpuCfsQuota(cgroup, def->cputune.quota) < 0) - return -1; - - if (def->cputune.period != 0 && - virCgroupSetCpuCfsPeriod(cgroup, def->cputune.period) < 0) - return -1; - - return 0; + return virCgroupSetupCpuPeriodQuota(cgroup, def->cputune.period, + def->cputune.quota); } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 51f1284d56..69016881dc 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1857,37 +1857,7 @@ lxcGetVcpuBWLive(virCgroupPtr cgroup, unsigned long long *period, static int lxcSetVcpuBWLive(virCgroupPtr cgroup, unsigned long long period, long long quota) { - unsigned long long old_period; - - if (period == 0 && quota == 0) - return 0; - - if (period) { - /* get old period, and we can rollback if set quota failed */ - if (virCgroupGetCpuCfsPeriod(cgroup, &old_period) < 0) - return -1; - - if (virCgroupSetCpuCfsPeriod(cgroup, period) < 0) - return -1; - } - - if (quota) { - if (virCgroupSetCpuCfsQuota(cgroup, quota) < 0) - goto error; - } - - return 0; - - error: - if (period) { - virErrorPtr saved; - - virErrorPreserveLast(&saved); - virCgroupSetCpuCfsPeriod(cgroup, old_period); - virErrorRestore(&saved); - } - - return -1; + return virCgroupSetupCpuPeriodQuota(cgroup, period, quota); } diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 0ca62ba3ee..636c531bd5 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -1128,36 +1128,7 @@ qemuSetupCgroupVcpuBW(virCgroupPtr cgroup, unsigned long long period, long long quota) { - unsigned long long old_period; - - if (period == 0 && quota == 0) - return 0; - - if (period) { - /* get old period, and we can rollback if set quota failed */ - if (virCgroupGetCpuCfsPeriod(cgroup, &old_period) < 0) - return -1; - - if (virCgroupSetCpuCfsPeriod(cgroup, period) < 0) - return -1; - } - - if (quota && - virCgroupSetCpuCfsQuota(cgroup, quota) < 0) - goto error; - - return 0; - - error: - if (period) { - virErrorPtr saved; - - virErrorPreserveLast(&saved); - ignore_value(virCgroupSetCpuCfsPeriod(cgroup, old_period)); - virErrorRestore(&saved); - } - - return -1; + return virCgroupSetupCpuPeriodQuota(cgroup, period, quota); } diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index cfb34a0f0e..9dc60f66c9 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3691,3 +3691,41 @@ virCgroupSetAndRetrieveCpuShares(virCgroupPtr cgroup, return 0; } + + +int +virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, + unsigned long long period, + long long quota) +{ + unsigned long long old_period; + + if (period == 0 && quota == 0) + return 0; + + if (period) { + /* get old period, and we can rollback if set quota failed */ + if (virCgroupGetCpuCfsPeriod(cgroup, &old_period) < 0) + return -1; + + if (virCgroupSetCpuCfsPeriod(cgroup, period) < 0) + return -1; + } + + if (quota && + virCgroupSetCpuCfsQuota(cgroup, quota) < 0) + goto error; + + return 0; + + error: + if (period) { + virErrorPtr saved; + + virErrorPreserveLast(&saved); + ignore_value(virCgroupSetCpuCfsPeriod(cgroup, old_period)); + virErrorRestore(&saved); + } + + return -1; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index ed8ee30a58..97ffa3f7df 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -293,3 +293,6 @@ int virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask); int virCgroupSetAndRetrieveCpuShares(virCgroupPtr cgroup, unsigned long long shares, unsigned long long *realValue); +int virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, + unsigned long long period, + long long quota); -- 2.24.1

lxcDomainMergeBlkioDevice() and -qemuDomainMergeBlkioDevice() are the same functions. Put the code in a new virDomainMergeBlkioDevice() inside domain_conf.c and update both callers. This change is a preliminary step for more code reduction of cgroup related code inside lxcDomainSetBlkioParameters() and qemuDomainSetBlkioParameters(). Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/conf/domain_conf.c | 70 +++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 6 +++ src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 72 +----------------------------------- src/qemu/qemu_driver.c | 80 +++------------------------------------- 5 files changed, 85 insertions(+), 144 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index de74a2a2d5..88bcf1b64b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1625,6 +1625,76 @@ virDomainBlkioDeviceParseXML(xmlNodePtr root, } +/* Modify dest_array to reflect all blkio device changes described in + * src_array. */ +int +virDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array, + size_t *dest_size, + virBlkioDevicePtr src_array, + size_t src_size, + const char *type) +{ + size_t i, j; + virBlkioDevicePtr dest, src; + + for (i = 0; i < src_size; i++) { + bool found = false; + + src = &src_array[i]; + for (j = 0; j < *dest_size; j++) { + dest = &(*dest_array)[j]; + if (STREQ(src->path, dest->path)) { + found = true; + + if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { + dest->weight = src->weight; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { + dest->riops = src->riops; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { + dest->wiops = src->wiops; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { + dest->rbps = src->rbps; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { + dest->wbps = src->wbps; + } else { + virReportError(VIR_ERR_INVALID_ARG, _("Unknown parameter %s"), + type); + return -1; + } + break; + } + } + if (!found) { + if (!src->weight && !src->riops && !src->wiops && !src->rbps && !src->wbps) + continue; + if (VIR_EXPAND_N(*dest_array, *dest_size, 1) < 0) + return -1; + dest = &(*dest_array)[*dest_size - 1]; + + if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { + dest->weight = src->weight; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { + dest->riops = src->riops; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { + dest->wiops = src->wiops; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { + dest->rbps = src->rbps; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { + dest->wbps = src->wbps; + } else { + *dest_size = *dest_size - 1; + return -1; + } + + dest->path = src->path; + src->path = NULL; + } + } + + return 0; +} + + /** * virDomainDefCheckUnsupportedMemoryHotplug: * @def: domain definition diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 2db3c19473..460aad9278 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2209,6 +2209,12 @@ struct _virDomainPanicDef { void virBlkioDeviceArrayClear(virBlkioDevicePtr deviceWeights, int ndevices); +int virDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array, + size_t *dest_size, + virBlkioDevicePtr src_array, + size_t src_size, + const char *type); + struct _virDomainResourceDef { char *partition; }; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 38fe847cef..70e45f1e8a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -491,6 +491,7 @@ virDomainMemoryModelTypeToString; virDomainMemoryRemove; virDomainMemorySourceTypeFromString; virDomainMemorySourceTypeToString; +virDomainMergeBlkioDevice; virDomainNetAllocateActualDevice; virDomainNetAppendIPAddress; virDomainNetARPInterfaces; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 69016881dc..e42fd99c72 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2215,74 +2215,6 @@ lxcDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, return -1; } -static int -lxcDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array, - size_t *dest_size, - virBlkioDevicePtr src_array, - size_t src_size, - const char *type) -{ - size_t i, j; - virBlkioDevicePtr dest, src; - - for (i = 0; i < src_size; i++) { - bool found = false; - - src = &src_array[i]; - for (j = 0; j < *dest_size; j++) { - dest = &(*dest_array)[j]; - if (STREQ(src->path, dest->path)) { - found = true; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - dest->weight = src->weight; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { - dest->riops = src->riops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { - dest->wiops = src->wiops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - dest->rbps = src->rbps; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - dest->wbps = src->wbps; - } else { - virReportError(VIR_ERR_INVALID_ARG, _("Unknown parameter %s"), - type); - return -1; - } - - break; - } - } - if (!found) { - if (!src->weight && !src->riops && !src->wiops && !src->rbps && !src->wbps) - continue; - if (VIR_EXPAND_N(*dest_array, *dest_size, 1) < 0) - return -1; - dest = &(*dest_array)[*dest_size - 1]; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - dest->weight = src->weight; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { - dest->riops = src->riops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { - dest->wiops = src->wiops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - dest->rbps = src->rbps; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - dest->wbps = src->wbps; - } else { - *dest_size = *dest_size - 1; - return -1; - } - - dest->path = src->path; - src->path = NULL; - } - } - - return 0; -} - static int lxcDomainBlockStats(virDomainPtr dom, @@ -2633,7 +2565,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, } if (j != ndevices || - lxcDomainMergeBlkioDevice(&def->blkio.devices, + virDomainMergeBlkioDevice(&def->blkio.devices, &def->blkio.ndevices, devices, ndevices, param->field) < 0) ret = -1; @@ -2665,7 +2597,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, ret = -1; continue; } - if (lxcDomainMergeBlkioDevice(&persistentDef->blkio.devices, + if (virDomainMergeBlkioDevice(&persistentDef->blkio.devices, &persistentDef->blkio.ndevices, devices, ndevices, param->field) < 0) ret = -1; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0d58893d7e..509a57b01c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9419,74 +9419,6 @@ qemuDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, return -1; } -/* Modify dest_array to reflect all blkio device changes described in - * src_array. */ -static int -qemuDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array, - size_t *dest_size, - virBlkioDevicePtr src_array, - size_t src_size, - const char *type) -{ - size_t i, j; - virBlkioDevicePtr dest, src; - - for (i = 0; i < src_size; i++) { - bool found = false; - - src = &src_array[i]; - for (j = 0; j < *dest_size; j++) { - dest = &(*dest_array)[j]; - if (STREQ(src->path, dest->path)) { - found = true; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - dest->weight = src->weight; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { - dest->riops = src->riops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { - dest->wiops = src->wiops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - dest->rbps = src->rbps; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - dest->wbps = src->wbps; - } else { - virReportError(VIR_ERR_INVALID_ARG, _("Unknown parameter %s"), - type); - return -1; - } - break; - } - } - if (!found) { - if (!src->weight && !src->riops && !src->wiops && !src->rbps && !src->wbps) - continue; - if (VIR_EXPAND_N(*dest_array, *dest_size, 1) < 0) - return -1; - dest = &(*dest_array)[*dest_size - 1]; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - dest->weight = src->weight; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { - dest->riops = src->riops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { - dest->wiops = src->wiops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - dest->rbps = src->rbps; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - dest->wbps = src->wbps; - } else { - *dest_size = *dest_size - 1; - return -1; - } - - dest->path = src->path; - src->path = NULL; - } - } - - return 0; -} static int qemuDomainSetBlkioParameters(virDomainPtr dom, @@ -9647,9 +9579,9 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, } if (j != ndevices || - qemuDomainMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, param->field) < 0) + virDomainMergeBlkioDevice(&def->blkio.devices, + &def->blkio.ndevices, + devices, ndevices, param->field) < 0) ret = -1; virBlkioDeviceArrayClear(devices, ndevices); VIR_FREE(devices); @@ -9682,9 +9614,9 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, ret = -1; continue; } - if (qemuDomainMergeBlkioDevice(&persistentDef->blkio.devices, - &persistentDef->blkio.ndevices, - devices, ndevices, param->field) < 0) + if (virDomainMergeBlkioDevice(&persistentDef->blkio.devices, + &persistentDef->blkio.ndevices, + devices, ndevices, param->field) < 0) ret = -1; virBlkioDeviceArrayClear(devices, ndevices); VIR_FREE(devices); -- 2.24.1

lxcDomainParseBlkioDeviceStr() and qemuDomainParseBlkioDeviceStr() are the same function. Avoid code repetition by putting the code in a new helper. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/conf/domain_conf.c | 111 ++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 3 + src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 111 +--------------------------------- src/qemu/qemu_driver.c | 126 +++------------------------------------ 5 files changed, 125 insertions(+), 227 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 88bcf1b64b..df8a71290d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1695,6 +1695,117 @@ virDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array, } +/* blkioDeviceStr in the form of /device/path,weight,/device/path,weight + * for example, /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0,800 + */ +int +virDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, + virBlkioDevicePtr *dev, size_t *size) +{ + char *temp; + int ndevices = 0; + int nsep = 0; + size_t i; + virBlkioDevicePtr result = NULL; + + *dev = NULL; + *size = 0; + + if (STREQ(blkioDeviceStr, "")) + return 0; + + temp = blkioDeviceStr; + while (temp) { + temp = strchr(temp, ','); + if (temp) { + temp++; + nsep++; + } + } + + /* A valid string must have even number of fields, hence an odd + * number of commas. */ + if (!(nsep & 1)) + goto parse_error; + + ndevices = (nsep + 1) / 2; + + if (VIR_ALLOC_N(result, ndevices) < 0) + return -1; + + i = 0; + temp = blkioDeviceStr; + while (temp) { + char *p = temp; + + /* device path */ + p = strchr(p, ','); + if (!p) + goto parse_error; + + result[i].path = g_strndup(temp, p - temp); + + /* value */ + temp = p + 1; + + if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { + if (virStrToLong_uip(temp, &p, 10, &result[i].weight) < 0) + goto number_error; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { + if (virStrToLong_uip(temp, &p, 10, &result[i].riops) < 0) + goto number_error; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { + if (virStrToLong_uip(temp, &p, 10, &result[i].wiops) < 0) + goto number_error; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { + if (virStrToLong_ullp(temp, &p, 10, &result[i].rbps) < 0) + goto number_error; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { + if (virStrToLong_ullp(temp, &p, 10, &result[i].wbps) < 0) + goto number_error; + } else { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown parameter '%s'"), type); + goto cleanup; + } + + i++; + + if (*p == '\0') + break; + else if (*p != ',') + goto parse_error; + temp = p + 1; + } + + if (!i) + VIR_FREE(result); + + *dev = result; + *size = i; + + return 0; + + parse_error: + virReportError(VIR_ERR_INVALID_ARG, + _("unable to parse blkio device '%s' '%s'"), + type, blkioDeviceStr); + goto cleanup; + + number_error: + virReportError(VIR_ERR_INVALID_ARG, + _("invalid value '%s' for parameter '%s' of device '%s'"), + temp, type, result[i].path); + + cleanup: + if (result) { + virBlkioDeviceArrayClear(result, ndevices); + VIR_FREE(result); + } + return -1; +} + + /** * virDomainDefCheckUnsupportedMemoryHotplug: * @def: domain definition diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 460aad9278..e1daf26e07 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2215,6 +2215,9 @@ int virDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array, size_t src_size, const char *type); +int virDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, + virBlkioDevicePtr *dev, size_t *size); + struct _virDomainResourceDef { char *partition; }; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 70e45f1e8a..d483b75aeb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -563,6 +563,7 @@ virDomainOsDefFirmwareTypeFromString; virDomainOsDefFirmwareTypeToString; virDomainOSTypeFromString; virDomainOSTypeToString; +virDomainParseBlkioDeviceStr; virDomainParseMemory; virDomainPausedReasonTypeFromString; virDomainPausedReasonTypeToString; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index e42fd99c72..96e61ff4ca 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2108,113 +2108,6 @@ lxcDomainGetSchedulerParameters(virDomainPtr domain, return lxcDomainGetSchedulerParametersFlags(domain, params, nparams, 0); } -static int -lxcDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, - virBlkioDevicePtr *dev, size_t *size) -{ - char *temp; - int ndevices = 0; - int nsep = 0; - size_t i; - virBlkioDevicePtr result = NULL; - - *dev = NULL; - *size = 0; - - if (STREQ(blkioDeviceStr, "")) - return 0; - - temp = blkioDeviceStr; - while (temp) { - temp = strchr(temp, ','); - if (temp) { - temp++; - nsep++; - } - } - - /* A valid string must have even number of fields, hence an odd - * number of commas. */ - if (!(nsep & 1)) - goto parse_error; - - ndevices = (nsep + 1) / 2; - - if (VIR_ALLOC_N(result, ndevices) < 0) - return -1; - - i = 0; - temp = blkioDeviceStr; - while (temp) { - char *p = temp; - - /* device path */ - p = strchr(p, ','); - if (!p) - goto parse_error; - - result[i].path = g_strndup(temp, p - temp); - - /* value */ - temp = p + 1; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - if (virStrToLong_uip(temp, &p, 10, &result[i].weight) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { - if (virStrToLong_uip(temp, &p, 10, &result[i].riops) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { - if (virStrToLong_uip(temp, &p, 10, &result[i].wiops) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - if (virStrToLong_ullp(temp, &p, 10, &result[i].rbps) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - if (virStrToLong_ullp(temp, &p, 10, &result[i].wbps) < 0) - goto number_error; - } else { - virReportError(VIR_ERR_INVALID_ARG, - _("unknown parameter '%s'"), type); - goto cleanup; - } - - i++; - - if (*p == '\0') - break; - else if (*p != ',') - goto parse_error; - temp = p + 1; - } - - if (!i) - VIR_FREE(result); - - *dev = result; - *size = i; - - return 0; - - parse_error: - virReportError(VIR_ERR_INVALID_ARG, - _("unable to parse blkio device '%s' '%s'"), - type, blkioDeviceStr); - goto cleanup; - - number_error: - virReportError(VIR_ERR_INVALID_ARG, - _("invalid value '%s' for parameter '%s' of device '%s'"), - temp, type, result[i].path); - - cleanup: - if (result) { - virBlkioDeviceArrayClear(result, ndevices); - VIR_FREE(result); - } - return -1; -} - static int lxcDomainBlockStats(virDomainPtr dom, @@ -2486,7 +2379,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices = NULL; size_t j; - if (lxcDomainParseBlkioDeviceStr(params[i].value.s, + if (virDomainParseBlkioDeviceStr(params[i].value.s, param->field, &devices, &ndevices) < 0) { @@ -2590,7 +2483,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices = NULL; size_t ndevices; - if (lxcDomainParseBlkioDeviceStr(params[i].value.s, + if (virDomainParseBlkioDeviceStr(params[i].value.s, param->field, &devices, &ndevices) < 0) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 509a57b01c..d458b59b99 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9309,116 +9309,6 @@ static char *qemuDomainGetSchedulerType(virDomainPtr dom, return ret; } -/* blkioDeviceStr in the form of /device/path,weight,/device/path,weight - * for example, /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0,800 - */ -static int -qemuDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, - virBlkioDevicePtr *dev, size_t *size) -{ - char *temp; - int ndevices = 0; - int nsep = 0; - size_t i; - virBlkioDevicePtr result = NULL; - - *dev = NULL; - *size = 0; - - if (STREQ(blkioDeviceStr, "")) - return 0; - - temp = blkioDeviceStr; - while (temp) { - temp = strchr(temp, ','); - if (temp) { - temp++; - nsep++; - } - } - - /* A valid string must have even number of fields, hence an odd - * number of commas. */ - if (!(nsep & 1)) - goto parse_error; - - ndevices = (nsep + 1) / 2; - - if (VIR_ALLOC_N(result, ndevices) < 0) - return -1; - - i = 0; - temp = blkioDeviceStr; - while (temp) { - char *p = temp; - - /* device path */ - p = strchr(p, ','); - if (!p) - goto parse_error; - - result[i].path = g_strndup(temp, p - temp); - - /* value */ - temp = p + 1; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - if (virStrToLong_uip(temp, &p, 10, &result[i].weight) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { - if (virStrToLong_uip(temp, &p, 10, &result[i].riops) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { - if (virStrToLong_uip(temp, &p, 10, &result[i].wiops) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - if (virStrToLong_ullp(temp, &p, 10, &result[i].rbps) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - if (virStrToLong_ullp(temp, &p, 10, &result[i].wbps) < 0) - goto number_error; - } else { - virReportError(VIR_ERR_INVALID_ARG, - _("unknown parameter '%s'"), type); - goto cleanup; - } - - i++; - - if (*p == '\0') - break; - else if (*p != ',') - goto parse_error; - temp = p + 1; - } - - if (!i) - VIR_FREE(result); - - *dev = result; - *size = i; - - return 0; - - parse_error: - virReportError(VIR_ERR_INVALID_ARG, - _("unable to parse blkio device '%s' '%s'"), - type, blkioDeviceStr); - goto cleanup; - - number_error: - virReportError(VIR_ERR_INVALID_ARG, - _("invalid value '%s' for parameter '%s' of device '%s'"), - temp, type, result[i].path); - - cleanup: - if (result) { - virBlkioDeviceArrayClear(result, ndevices); - VIR_FREE(result); - } - return -1; -} - static int qemuDomainSetBlkioParameters(virDomainPtr dom, @@ -9500,10 +9390,10 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices = NULL; size_t j; - if (qemuDomainParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { + if (virDomainParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { ret = -1; continue; } @@ -9607,10 +9497,10 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices = NULL; size_t ndevices; - if (qemuDomainParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { + if (virDomainParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { ret = -1; continue; } -- 2.24.1

After the introduction of virDomainMergeBlkioDevice() in a previous patch, it is now clear that lxcDomainSetBlkioParameters() and qemuDomainSetBlkioParameters() uses the same loop to set cgroup blkio parameter of a domain. Avoid the repetition by adding a new helper called virCgroupSetupDomainBlkioParameters(). Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 104 +---------------------------------- src/qemu/qemu_driver.c | 105 +---------------------------------- src/util/vircgroup.c | 115 +++++++++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 4 ++ 5 files changed, 124 insertions(+), 205 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d483b75aeb..196c7bdb23 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1734,6 +1734,7 @@ virCgroupSetOwner; virCgroupSetupBlkioTune; virCgroupSetupCpuPeriodQuota; virCgroupSetupCpusetCpus; +virCgroupSetupDomainBlkioParameters; virCgroupSetupMemtune; virCgroupSupportsCpuBW; virCgroupTerminateMachine; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 96e61ff4ca..9a585d0d07 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2364,108 +2364,8 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, ret = 0; if (def) { - for (i = 0; i < nparams; i++) { - virTypedParameterPtr param = ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - if (virCgroupSetBlkioWeight(priv->cgroup, params[i].value.ui) < 0) - ret = -1; - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) || - 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)) { - size_t ndevices; - virBlkioDevicePtr devices = NULL; - size_t j; - - if (virDomainParseBlkioDeviceStr(params[i].value.s, - param->field, - &devices, - &ndevices) < 0) { - ret = -1; - continue; - } - - 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) { - 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) { - 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) { - 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) { - 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) { - ret = -1; - break; - } - } - } else { - virReportError(VIR_ERR_INVALID_ARG, _("Unknown blkio parameter %s"), - param->field); - ret = -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - - continue; - } - - if (j != ndevices || - virDomainMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, param->field) < 0) - ret = -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret = virCgroupSetupDomainBlkioParameters(priv->cgroup, def, + params, nparams); } if (ret < 0) goto endjob; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d458b59b99..da4e6d7a93 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9374,109 +9374,8 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, ret = 0; if (def) { - for (i = 0; i < nparams; i++) { - virTypedParameterPtr param = ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - if (virCgroupSetBlkioWeight(priv->cgroup, param->value.ui) < 0 || - virCgroupGetBlkioWeight(priv->cgroup, &def->blkio.weight) < 0) - ret = -1; - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) || - 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)) { - size_t ndevices; - virBlkioDevicePtr devices = NULL; - size_t j; - - if (virDomainParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { - ret = -1; - continue; - } - - 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) { - 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) { - 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) { - 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) { - 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) { - ret = -1; - break; - } - } - } else { - virReportError(VIR_ERR_INVALID_ARG, _("Unknown blkio parameter %s"), - param->field); - ret = -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - - continue; - } - - if (j != ndevices || - virDomainMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, param->field) < 0) - ret = -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret = virCgroupSetupDomainBlkioParameters(priv->cgroup, def, + params, nparams); if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 9dc60f66c9..67855b685f 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3729,3 +3729,118 @@ virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, return -1; } + + +int +virCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup, virDomainDefPtr def, + virTypedParameterPtr params, int nparams) +{ + size_t i; + int ret = 0; + + for (i = 0; i < nparams; i++) { + virTypedParameterPtr param = ¶ms[i]; + + if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { + if (virCgroupSetBlkioWeight(cgroup, param->value.ui) < 0) + ret = -1; + } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) || + 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)) { + size_t ndevices; + virBlkioDevicePtr devices = NULL; + size_t j; + + if (virDomainParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { + ret = -1; + continue; + } + + if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { + for (j = 0; j < ndevices; j++) { + if (virCgroupSetBlkioDeviceWeight(cgroup, + devices[j].path, + devices[j].weight) < 0 || + virCgroupGetBlkioDeviceWeight(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(cgroup, + devices[j].path, + devices[j].riops) < 0 || + virCgroupGetBlkioDeviceReadIops(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(cgroup, + devices[j].path, + devices[j].wiops) < 0 || + virCgroupGetBlkioDeviceWriteIops(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(cgroup, + devices[j].path, + devices[j].rbps) < 0 || + virCgroupGetBlkioDeviceReadBps(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(cgroup, + devices[j].path, + devices[j].wbps) < 0 || + virCgroupGetBlkioDeviceWriteBps(cgroup, + devices[j].path, + &devices[j].wbps) < 0) { + ret = -1; + break; + } + } + } else { + virReportError(VIR_ERR_INVALID_ARG, _("Unknown blkio parameter %s"), + param->field); + ret = -1; + virBlkioDeviceArrayClear(devices, ndevices); + VIR_FREE(devices); + + continue; + } + + if (j != ndevices || + virDomainMergeBlkioDevice(&def->blkio.devices, + &def->blkio.ndevices, + devices, ndevices, param->field) < 0) + ret = -1; + + virBlkioDeviceArrayClear(devices, ndevices); + VIR_FREE(devices); + } + } + + return ret; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 97ffa3f7df..85309e800d 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -296,3 +296,7 @@ int virCgroupSetAndRetrieveCpuShares(virCgroupPtr cgroup, int virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, unsigned long long period, long long quota); +int virCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup, + virDomainDefPtr def, + virTypedParameterPtr params, + int nparams); -- 2.24.1

This new helper avoids more code repetition inside lxcDomainSetBlkioParameters() and qemuDomainSetBlkioParameters(). Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/conf/domain_conf.c | 41 ++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 4 ++++ src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 32 +++---------------------------- src/qemu/qemu_driver.c | 32 +++---------------------------- 5 files changed, 52 insertions(+), 58 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index df8a71290d..fa1ef10899 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1806,6 +1806,47 @@ virDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, } +int +virDomainParseMergePersistentDefBlkioParams(virDomainDefPtr persistentDef, + virTypedParameterPtr params, + int nparams) +{ + size_t i; + int ret = 0; + + for (i = 0; i < nparams; i++) { + virTypedParameterPtr param = ¶ms[i]; + + if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { + persistentDef->blkio.weight = param->value.ui; + } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) || + 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)) { + virBlkioDevicePtr devices = NULL; + size_t ndevices; + + if (virDomainParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { + ret = -1; + continue; + } + if (virDomainMergeBlkioDevice(&persistentDef->blkio.devices, + &persistentDef->blkio.ndevices, + devices, ndevices, param->field) < 0) + ret = -1; + virBlkioDeviceArrayClear(devices, ndevices); + VIR_FREE(devices); + } + } + + return ret; +} + + /** * virDomainDefCheckUnsupportedMemoryHotplug: * @def: domain definition diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e1daf26e07..c09bc31c12 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2218,6 +2218,10 @@ int virDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array, int virDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, virBlkioDevicePtr *dev, size_t *size); +int virDomainParseMergePersistentDefBlkioParams(virDomainDefPtr persistentDef, + virTypedParameterPtr params, + int nparams); + struct _virDomainResourceDef { char *partition; }; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 196c7bdb23..1422fbc3d9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -565,6 +565,7 @@ virDomainOSTypeFromString; virDomainOSTypeToString; virDomainParseBlkioDeviceStr; virDomainParseMemory; +virDomainParseMergePersistentDefBlkioParams; virDomainPausedReasonTypeFromString; virDomainPausedReasonTypeToString; virDomainPMSuspendedReasonTypeFromString; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 9a585d0d07..1fabba40bd 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2313,7 +2313,6 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, unsigned int flags) { virLXCDriverPtr driver = dom->conn->privateData; - size_t i; virDomainObjPtr vm = NULL; virDomainDefPtr def = NULL; virDomainDefPtr persistentDef = NULL; @@ -2370,34 +2369,9 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, if (ret < 0) goto endjob; if (persistentDef) { - for (i = 0; i < nparams; i++) { - virTypedParameterPtr param = ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - persistentDef->blkio.weight = params[i].value.ui; - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) || - 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)) { - virBlkioDevicePtr devices = NULL; - size_t ndevices; - - if (virDomainParseBlkioDeviceStr(params[i].value.s, - param->field, - &devices, - &ndevices) < 0) { - ret = -1; - continue; - } - if (virDomainMergeBlkioDevice(&persistentDef->blkio.devices, - &persistentDef->blkio.ndevices, - devices, ndevices, param->field) < 0) - ret = -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret = virDomainParseMergePersistentDefBlkioParams(persistentDef, + params, + nparams); if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) ret = -1; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index da4e6d7a93..c154efbaf6 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9317,7 +9317,6 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, unsigned int flags) { virQEMUDriverPtr driver = dom->conn->privateData; - size_t i; virDomainObjPtr vm = NULL; virDomainDefPtr def; virDomainDefPtr persistentDef; @@ -9383,34 +9382,9 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, if (ret < 0) goto endjob; if (persistentDef) { - for (i = 0; i < nparams; i++) { - virTypedParameterPtr param = ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - persistentDef->blkio.weight = param->value.ui; - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) || - 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)) { - virBlkioDevicePtr devices = NULL; - size_t ndevices; - - if (virDomainParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { - ret = -1; - continue; - } - if (virDomainMergeBlkioDevice(&persistentDef->blkio.devices, - &persistentDef->blkio.ndevices, - devices, ndevices, param->field) < 0) - ret = -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret = virDomainParseMergePersistentDefBlkioParams(persistentDef, + params, + nparams); if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) ret = -1; -- 2.24.1

lxcDomainSetMemoryParameters() and qemuDomainSetMemoryParameters() has duplicated chunks of code that can be put in a new helper. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 70 ++--------------------------------- src/qemu/qemu_driver.c | 70 ++--------------------------------- src/util/vircgroup.c | 79 ++++++++++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 6 +++ 5 files changed, 92 insertions(+), 134 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1422fbc3d9..7143e12838 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1729,6 +1729,7 @@ virCgroupSetCpuShares; virCgroupSetFreezerState; virCgroupSetMemory; virCgroupSetMemoryHardLimit; +virCgroupSetMemoryLimitParameters; virCgroupSetMemorySoftLimit; virCgroupSetMemSwapHardLimit; virCgroupSetOwner; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 1fabba40bd..b5c02b3ccb 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -747,13 +747,6 @@ lxcDomainSetMemoryParameters(virDomainPtr dom, virLXCDomainObjPrivatePtr priv = NULL; virLXCDriverConfigPtr cfg = NULL; virLXCDriverPtr driver = dom->conn->privateData; - unsigned long long hard_limit; - unsigned long long soft_limit; - unsigned long long swap_hard_limit; - bool set_hard_limit = false; - bool set_soft_limit = false; - bool set_swap_hard_limit = false; - int rc; int ret = -1; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | @@ -792,66 +785,9 @@ lxcDomainSetMemoryParameters(virDomainPtr dom, goto endjob; } -#define VIR_GET_LIMIT_PARAMETER(PARAM, VALUE) \ - if ((rc = virTypedParamsGetULLong(params, nparams, PARAM, &VALUE)) < 0) \ - goto endjob; \ - \ - if (rc == 1) \ - set_ ## VALUE = true; - - VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT, swap_hard_limit) - VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_HARD_LIMIT, hard_limit) - VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SOFT_LIMIT, soft_limit) - -#undef VIR_GET_LIMIT_PARAMETER - - /* Swap hard limit must be greater than hard limit. */ - if (set_swap_hard_limit || set_hard_limit) { - unsigned long long mem_limit = vm->def->mem.hard_limit; - unsigned long long swap_limit = vm->def->mem.swap_hard_limit; - - if (set_swap_hard_limit) - swap_limit = swap_hard_limit; - - if (set_hard_limit) - mem_limit = hard_limit; - - if (mem_limit > swap_limit) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("memory hard_limit tunable value must be lower " - "than or equal to swap_hard_limit")); - goto endjob; - } - } - -#define VIR_SET_MEM_PARAMETER(FUNC, VALUE) \ - if (set_ ## VALUE) { \ - if (def) { \ - if ((rc = FUNC(priv->cgroup, VALUE)) < 0) \ - goto endjob; \ - def->mem.VALUE = VALUE; \ - } \ - \ - if (persistentDef) \ - persistentDef->mem.VALUE = VALUE; \ - } - - /* Soft limit doesn't clash with the others */ - VIR_SET_MEM_PARAMETER(virCgroupSetMemorySoftLimit, soft_limit); - - /* set hard limit before swap hard limit if decreasing it */ - if (def && def->mem.hard_limit > hard_limit) { - VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit); - /* inhibit changing the limit a second time */ - set_hard_limit = false; - } - - VIR_SET_MEM_PARAMETER(virCgroupSetMemSwapHardLimit, swap_hard_limit); - - /* otherwise increase it after swap hard limit */ - VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit); - -#undef VIR_SET_MEM_PARAMETER + if (virCgroupSetMemoryLimitParameters(priv->cgroup, vm, def, persistentDef, + params, nparams) < 0) + goto endjob; if (def && virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c154efbaf6..d2177d73a2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9500,14 +9500,7 @@ qemuDomainSetMemoryParameters(virDomainPtr dom, virDomainDefPtr def = NULL; virDomainDefPtr persistentDef = NULL; virDomainObjPtr vm = NULL; - unsigned long long swap_hard_limit; - unsigned long long hard_limit = 0; - unsigned long long soft_limit = 0; - bool set_swap_hard_limit = false; - bool set_hard_limit = false; - bool set_soft_limit = false; g_autoptr(virQEMUDriverConfig) cfg = NULL; - int rc; int ret = -1; qemuDomainObjPrivatePtr priv; @@ -9554,66 +9547,9 @@ qemuDomainSetMemoryParameters(virDomainPtr dom, goto endjob; } -#define VIR_GET_LIMIT_PARAMETER(PARAM, VALUE) \ - if ((rc = virTypedParamsGetULLong(params, nparams, PARAM, &VALUE)) < 0) \ - goto endjob; \ - \ - if (rc == 1) \ - set_ ## VALUE = true; - - VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT, swap_hard_limit) - VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_HARD_LIMIT, hard_limit) - VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SOFT_LIMIT, soft_limit) - -#undef VIR_GET_LIMIT_PARAMETER - - /* Swap hard limit must be greater than hard limit. */ - if (set_swap_hard_limit || set_hard_limit) { - unsigned long long mem_limit = vm->def->mem.hard_limit; - unsigned long long swap_limit = vm->def->mem.swap_hard_limit; - - if (set_swap_hard_limit) - swap_limit = swap_hard_limit; - - if (set_hard_limit) - mem_limit = hard_limit; - - if (mem_limit > swap_limit) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("memory hard_limit tunable value must be lower " - "than or equal to swap_hard_limit")); - goto endjob; - } - } - -#define VIR_SET_MEM_PARAMETER(FUNC, VALUE) \ - if (set_ ## VALUE) { \ - if (def) { \ - if ((rc = FUNC(priv->cgroup, VALUE)) < 0) \ - goto endjob; \ - def->mem.VALUE = VALUE; \ - } \ - \ - if (persistentDef) \ - persistentDef->mem.VALUE = VALUE; \ - } - - /* Soft limit doesn't clash with the others */ - VIR_SET_MEM_PARAMETER(virCgroupSetMemorySoftLimit, soft_limit); - - /* set hard limit before swap hard limit if decreasing it */ - if (def && def->mem.hard_limit > hard_limit) { - VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit); - /* inhibit changing the limit a second time */ - set_hard_limit = false; - } - - VIR_SET_MEM_PARAMETER(virCgroupSetMemSwapHardLimit, swap_hard_limit); - - /* otherwise increase it after swap hard limit */ - VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit); - -#undef VIR_SET_MEM_PARAMETER + if (virCgroupSetMemoryLimitParameters(priv->cgroup, vm, def, persistentDef, + params, nparams) < 0) + goto endjob; if (def && virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 67855b685f..530f1b7223 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3844,3 +3844,82 @@ virCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup, virDomainDefPtr def, return ret; } + + +int +virCgroupSetMemoryLimitParameters(virCgroupPtr cgroup, virDomainObjPtr vm, + virDomainDefPtr liveDef, + virDomainDefPtr persistentDef, + virTypedParameterPtr params, int nparams) +{ + unsigned long long swap_hard_limit; + unsigned long long hard_limit = 0; + unsigned long long soft_limit = 0; + bool set_swap_hard_limit = false; + bool set_hard_limit = false; + bool set_soft_limit = false; + int rc; + +#define VIR_GET_LIMIT_PARAMETER(PARAM, VALUE) \ + if ((rc = virTypedParamsGetULLong(params, nparams, PARAM, &VALUE)) < 0) \ + return -1; \ + \ + if (rc == 1) \ + set_ ## VALUE = true; + + VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT, swap_hard_limit) + VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_HARD_LIMIT, hard_limit) + VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SOFT_LIMIT, soft_limit) + +#undef VIR_GET_LIMIT_PARAMETER + + /* Swap hard limit must be greater than hard limit. */ + if (set_swap_hard_limit || set_hard_limit) { + unsigned long long mem_limit = vm->def->mem.hard_limit; + unsigned long long swap_limit = vm->def->mem.swap_hard_limit; + + if (set_swap_hard_limit) + swap_limit = swap_hard_limit; + + if (set_hard_limit) + mem_limit = hard_limit; + + if (mem_limit > swap_limit) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("memory hard_limit tunable value must be lower " + "than or equal to swap_hard_limit")); + return -1; + } + } + +#define VIR_SET_MEM_PARAMETER(FUNC, VALUE) \ + if (set_ ## VALUE) { \ + if (liveDef) { \ + if ((rc = FUNC(cgroup, VALUE)) < 0) \ + return -1; \ + liveDef->mem.VALUE = VALUE; \ + } \ + \ + if (persistentDef) \ + persistentDef->mem.VALUE = VALUE; \ + } + + /* Soft limit doesn't clash with the others */ + VIR_SET_MEM_PARAMETER(virCgroupSetMemorySoftLimit, soft_limit); + + /* set hard limit before swap hard limit if decreasing it */ + if (liveDef && liveDef->mem.hard_limit > hard_limit) { + VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit); + /* inhibit changing the limit a second time */ + set_hard_limit = false; + } + + VIR_SET_MEM_PARAMETER(virCgroupSetMemSwapHardLimit, swap_hard_limit); + + /* otherwise increase it after swap hard limit */ + VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit); + +#undef VIR_SET_MEM_PARAMETER + + return 0; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 85309e800d..5d238937d2 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -300,3 +300,9 @@ int virCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup, virDomainDefPtr def, virTypedParameterPtr params, int nparams); +int virCgroupSetMemoryLimitParameters(virCgroupPtr cgroup, + virDomainObjPtr vm, + virDomainDefPtr liveDef, + virDomainDefPtr persistentDef, + virTypedParameterPtr params, + int nparams); -- 2.24.1

Another vircgroup helper to avoid code repetition between the LXC and QEMU driver. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 8 +------- src/qemu/qemu_driver.c | 8 +------- src/util/vircgroup.c | 14 ++++++++++++++ src/util/vircgroup.h | 2 ++ 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7143e12838..ffd76253b3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1685,6 +1685,7 @@ virCgroupGetCpuacctStat; virCgroupGetCpuacctUsage; virCgroupGetCpuCfsPeriod; virCgroupGetCpuCfsQuota; +virCgroupGetCpuPeriodQuota; virCgroupGetCpusetCpus; virCgroupGetCpusetMemoryMigrate; virCgroupGetCpusetMems; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index b5c02b3ccb..2b4b68ba41 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1780,13 +1780,7 @@ static int lxcGetVcpuBWLive(virCgroupPtr cgroup, unsigned long long *period, long long *quota) { - if (virCgroupGetCpuCfsPeriod(cgroup, period) < 0) - return -1; - - if (virCgroupGetCpuCfsQuota(cgroup, quota) < 0) - return -1; - - return 0; + return virCgroupGetCpuPeriodQuota(cgroup, period, quota); } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d2177d73a2..148424d5f0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10530,13 +10530,7 @@ static int qemuGetVcpuBWLive(virCgroupPtr cgroup, unsigned long long *period, long long *quota) { - if (virCgroupGetCpuCfsPeriod(cgroup, period) < 0) - return -1; - - if (virCgroupGetCpuCfsQuota(cgroup, quota) < 0) - return -1; - - return 0; + return virCgroupGetCpuPeriodQuota(cgroup, period, quota); } static int diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 530f1b7223..dad475c436 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3731,6 +3731,20 @@ virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, } +int +virCgroupGetCpuPeriodQuota(virCgroupPtr cgroup, unsigned long long *period, + long long *quota) +{ + if (virCgroupGetCpuCfsPeriod(cgroup, period) < 0) + return -1; + + if (virCgroupGetCpuCfsQuota(cgroup, quota) < 0) + return -1; + + return 0; +} + + int virCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup, virDomainDefPtr def, virTypedParameterPtr params, int nparams) diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 5d238937d2..10c4b75863 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -290,6 +290,8 @@ bool virCgroupControllerAvailable(int controller); int virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune blkio); int virCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem); int virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask); +int virCgroupGetCpuPeriodQuota(virCgroupPtr cgroup, unsigned long long *period, + long long *quota); int virCgroupSetAndRetrieveCpuShares(virCgroupPtr cgroup, unsigned long long shares, unsigned long long *realValue); -- 2.24.1

The new virCgroupSetupBlkioTune() centralized all the code that call those functions inside vircgroup.c. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 11 ---------- src/util/vircgroup.c | 44 ++++++++++++++++++++-------------------- src/util/vircgroup.h | 41 ------------------------------------- 3 files changed, 22 insertions(+), 74 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ffd76253b3..3dc65916bf 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1672,11 +1672,6 @@ virCgroupDenyAllDevices; virCgroupDenyDevice; virCgroupDenyDevicePath; virCgroupFree; -virCgroupGetBlkioDeviceReadBps; -virCgroupGetBlkioDeviceReadIops; -virCgroupGetBlkioDeviceWeight; -virCgroupGetBlkioDeviceWriteBps; -virCgroupGetBlkioDeviceWriteIops; virCgroupGetBlkioIoDeviceServiced; virCgroupGetBlkioIoServiced; virCgroupGetBlkioWeight; @@ -1715,12 +1710,6 @@ virCgroupNewThread; virCgroupPathOfController; virCgroupRemove; virCgroupSetAndRetrieveCpuShares; -virCgroupSetBlkioDeviceReadBps; -virCgroupSetBlkioDeviceReadIops; -virCgroupSetBlkioDeviceWeight; -virCgroupSetBlkioDeviceWriteBps; -virCgroupSetBlkioDeviceWriteIops; -virCgroupSetBlkioWeight; virCgroupSetCpuCfsPeriod; virCgroupSetCpuCfsQuota; virCgroupSetCpusetCpus; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index dad475c436..8ee37cde7c 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1385,7 +1385,7 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, @@ -1416,7 +1416,7 @@ virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight) * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int riops) @@ -1434,7 +1434,7 @@ virCgroupSetBlkioDeviceReadIops(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int wiops) @@ -1452,7 +1452,7 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long rbps) @@ -1469,7 +1469,7 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long wbps) @@ -1488,7 +1488,7 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int weight) @@ -1505,7 +1505,7 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int *riops) @@ -1522,7 +1522,7 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int *wiops) @@ -1539,7 +1539,7 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long *rbps) @@ -1556,7 +1556,7 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long *wbps) @@ -1573,7 +1573,7 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int *weight) @@ -2974,7 +2974,7 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group G_GNUC_UNUSED, } -int +static int virCgroupSetBlkioWeight(virCgroupPtr group G_GNUC_UNUSED, unsigned int weight G_GNUC_UNUSED) { @@ -2994,7 +2994,7 @@ virCgroupGetBlkioWeight(virCgroupPtr group G_GNUC_UNUSED, } -int +static int virCgroupSetBlkioDeviceWeight(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned int weight G_GNUC_UNUSED) @@ -3004,7 +3004,7 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group G_GNUC_UNUSED, return -1; } -int +static int virCgroupSetBlkioDeviceReadIops(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned int riops G_GNUC_UNUSED) @@ -3014,7 +3014,7 @@ virCgroupSetBlkioDeviceReadIops(virCgroupPtr group G_GNUC_UNUSED, return -1; } -int +static int virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned int wiops G_GNUC_UNUSED) @@ -3024,7 +3024,7 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group G_GNUC_UNUSED, return -1; } -int +static int virCgroupSetBlkioDeviceReadBps(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned long long rbps G_GNUC_UNUSED) @@ -3034,7 +3034,7 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group G_GNUC_UNUSED, return -1; } -int +static int virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned long long wbps G_GNUC_UNUSED) @@ -3044,7 +3044,7 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group G_GNUC_UNUSED, return -1; } -int +static int virCgroupGetBlkioDeviceWeight(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned int *weight G_GNUC_UNUSED) @@ -3054,7 +3054,7 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group G_GNUC_UNUSED, return -1; } -int +static int virCgroupGetBlkioDeviceReadIops(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned int *riops G_GNUC_UNUSED) @@ -3064,7 +3064,7 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group G_GNUC_UNUSED, return -1; } -int +static int virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned int *wiops G_GNUC_UNUSED) @@ -3074,7 +3074,7 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group G_GNUC_UNUSED, return -1; } -int +static int virCgroupGetBlkioDeviceReadBps(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned long long *rbps G_GNUC_UNUSED) @@ -3084,7 +3084,7 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group G_GNUC_UNUSED, return -1; } -int +static int virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned long long *wbps G_GNUC_UNUSED) diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 10c4b75863..35a11e6b67 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -121,7 +121,6 @@ int virCgroupAddProcess(virCgroupPtr group, pid_t pid); int virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid); int virCgroupAddThread(virCgroupPtr group, pid_t pid); -int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight); int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight); int virCgroupGetBlkioIoServiced(virCgroupPtr group, @@ -136,46 +135,6 @@ int virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group, long long *requests_read, long long *requests_write); -int virCgroupSetBlkioDeviceWeight(virCgroupPtr group, - const char *path, - unsigned int weight); - -int virCgroupSetBlkioDeviceReadIops(virCgroupPtr group, - const char *path, - unsigned int riops); - -int virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group, - const char *path, - unsigned int wiops); - -int virCgroupSetBlkioDeviceReadBps(virCgroupPtr group, - const char *path, - unsigned long long rbps); - -int virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, - const char *path, - unsigned long long wbps); - -int virCgroupGetBlkioDeviceWeight(virCgroupPtr group, - const char *path, - unsigned int *weight); - -int virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, - const char *path, - unsigned int *riops); - -int virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, - const char *path, - unsigned int *wiops); - -int virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, - const char *path, - unsigned long long *rbps); - -int virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, - const char *path, - unsigned long long *wbps); - int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb); int virCgroupGetMemoryStat(virCgroupPtr group, unsigned long long *cache, -- 2.24.1

The new virCgroupSetupMemtune() virCgroupSetupCpusetCpus() made the cgroup SetMemory and SetCpusetCpus functions to be called only inside vircgroup.c. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 4 ---- src/util/vircgroup.c | 16 ++++++++-------- src/util/vircgroup.h | 4 ---- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3dc65916bf..1ec73a13c2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1712,16 +1712,12 @@ virCgroupRemove; virCgroupSetAndRetrieveCpuShares; virCgroupSetCpuCfsPeriod; virCgroupSetCpuCfsQuota; -virCgroupSetCpusetCpus; virCgroupSetCpusetMemoryMigrate; virCgroupSetCpusetMems; virCgroupSetCpuShares; virCgroupSetFreezerState; virCgroupSetMemory; -virCgroupSetMemoryHardLimit; virCgroupSetMemoryLimitParameters; -virCgroupSetMemorySoftLimit; -virCgroupSetMemSwapHardLimit; virCgroupSetOwner; virCgroupSetupBlkioTune; virCgroupSetupCpuPeriodQuota; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 8ee37cde7c..f0103d8062 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1653,7 +1653,7 @@ virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb) * * Returns: 0 on success */ -int +static int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, @@ -1685,7 +1685,7 @@ virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb) * * Returns: 0 on success */ -int +static int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, @@ -1717,7 +1717,7 @@ virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb) * * Returns: 0 on success */ -int +static int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, @@ -1829,7 +1829,7 @@ virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate) * * Returns: 0 on success */ -int +static int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, @@ -3129,7 +3129,7 @@ virCgroupGetMemoryUsage(virCgroupPtr group G_GNUC_UNUSED, } -int +static int virCgroupSetMemoryHardLimit(virCgroupPtr group G_GNUC_UNUSED, unsigned long long kb G_GNUC_UNUSED) { @@ -3149,7 +3149,7 @@ virCgroupGetMemoryHardLimit(virCgroupPtr group G_GNUC_UNUSED, } -int +static int virCgroupSetMemorySoftLimit(virCgroupPtr group G_GNUC_UNUSED, unsigned long long kb G_GNUC_UNUSED) { @@ -3169,7 +3169,7 @@ virCgroupGetMemorySoftLimit(virCgroupPtr group G_GNUC_UNUSED, } -int +static int virCgroupSetMemSwapHardLimit(virCgroupPtr group G_GNUC_UNUSED, unsigned long long kb G_GNUC_UNUSED) { @@ -3239,7 +3239,7 @@ virCgroupGetCpusetMemoryMigrate(virCgroupPtr group G_GNUC_UNUSED, } -int +static int virCgroupSetCpusetCpus(virCgroupPtr group G_GNUC_UNUSED, const char *cpus G_GNUC_UNUSED) { diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 35a11e6b67..1607e951b1 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -145,11 +145,8 @@ int virCgroupGetMemoryStat(virCgroupPtr group, unsigned long long *unevictable); int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb); -int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb); int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb); -int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb); int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb); -int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb); int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb); int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb); @@ -223,7 +220,6 @@ int virCgroupGetCpusetMems(virCgroupPtr group, char **mems); int virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate); int virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate); -int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus); int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus); int virCgroupRemove(virCgroupPtr group); -- 2.24.1

The new functions virCgroupSetAndRetrieveCpuShares(), virCgroupSetupCpuPeriodQuota() and virCgroupGetCpuPeriodQuota() centralized all callers of {get/set}Cpu{Shares,CfsPeriod,CfsQuota} to be inside vircgroup.c. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/libvirt_private.syms | 5 ----- src/util/vircgroup.c | 20 ++++++++++---------- src/util/vircgroup.h | 7 ------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1ec73a13c2..eff741fe23 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1678,8 +1678,6 @@ virCgroupGetBlkioWeight; virCgroupGetCpuacctPercpuUsage; virCgroupGetCpuacctStat; virCgroupGetCpuacctUsage; -virCgroupGetCpuCfsPeriod; -virCgroupGetCpuCfsQuota; virCgroupGetCpuPeriodQuota; virCgroupGetCpusetCpus; virCgroupGetCpusetMemoryMigrate; @@ -1710,11 +1708,8 @@ virCgroupNewThread; virCgroupPathOfController; virCgroupRemove; virCgroupSetAndRetrieveCpuShares; -virCgroupSetCpuCfsPeriod; -virCgroupSetCpuCfsQuota; virCgroupSetCpusetMemoryMigrate; virCgroupSetCpusetMems; -virCgroupSetCpuShares; virCgroupSetFreezerState; virCgroupSetMemory; virCgroupSetMemoryLimitParameters; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index f0103d8062..c39f7b1957 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2249,7 +2249,7 @@ virCgroupGetDomainTotalCpuStats(virCgroupPtr group, } -int +static int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, @@ -2273,7 +2273,7 @@ virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares) * * Returns: 0 on success */ -int +static int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, @@ -2289,7 +2289,7 @@ virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period) * * Returns: 0 on success */ -int +static int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, @@ -2306,7 +2306,7 @@ virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period) * * Returns: 0 on success */ -int +static int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, @@ -2660,7 +2660,7 @@ virCgroupKillPainfully(virCgroupPtr group) * * Returns: 0 on success */ -int +static int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, @@ -3326,7 +3326,7 @@ virCgroupDenyDevicePath(virCgroupPtr group G_GNUC_UNUSED, } -int +static int virCgroupSetCpuShares(virCgroupPtr group G_GNUC_UNUSED, unsigned long long shares G_GNUC_UNUSED) { @@ -3346,7 +3346,7 @@ virCgroupGetCpuShares(virCgroupPtr group G_GNUC_UNUSED, } -int +static int virCgroupSetCpuCfsPeriod(virCgroupPtr group G_GNUC_UNUSED, unsigned long long cfs_period G_GNUC_UNUSED) { @@ -3356,7 +3356,7 @@ virCgroupSetCpuCfsPeriod(virCgroupPtr group G_GNUC_UNUSED, } -int +static int virCgroupGetCpuCfsPeriod(virCgroupPtr group G_GNUC_UNUSED, unsigned long long *cfs_period G_GNUC_UNUSED) { @@ -3366,7 +3366,7 @@ virCgroupGetCpuCfsPeriod(virCgroupPtr group G_GNUC_UNUSED, } -int +static int virCgroupSetCpuCfsQuota(virCgroupPtr group G_GNUC_UNUSED, long long cfs_quota G_GNUC_UNUSED) { @@ -3404,7 +3404,7 @@ virCgroupKillPainfully(virCgroupPtr group G_GNUC_UNUSED) } -int +static int virCgroupGetCpuCfsQuota(virCgroupPtr group G_GNUC_UNUSED, long long *cfs_quota G_GNUC_UNUSED) { diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 1607e951b1..1a47c234de 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -197,15 +197,8 @@ virCgroupGetDomainTotalCpuStats(virCgroupPtr group, virTypedParameterPtr params, int nparams); -int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares); int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares); -int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period); -int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period); - -int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota); -int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota); - int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage); int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage); int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user, -- 2.24.1
participants (3)
-
Cole Robinson
-
Daniel Henrique Barboza
-
Ján Tomko