The code from qemuSetupCgroupCpusetCpus() and virLXCCgroupSetupCpusetTune() can be centralized in a new helper called virCgroupSetupCpusetCpus(). Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx> --- 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