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 1bc5d17000..a58a5ed78b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1730,6 +1730,7 @@ virCgroupSetupBlkioDeviceReadIops;
virCgroupSetupBlkioDeviceWeight;
virCgroupSetupBlkioDeviceWriteBps;
virCgroupSetupBlkioDeviceWriteIops;
+virCgroupSetupCpusetCpus;
virCgroupSupportsCpuBW;
virCgroupTerminateMachine;
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index eac1ee1ee0..618063bf43 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -69,14 +69,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 0c2f5f1b25..ee08b99064 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -1165,19 +1165,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 261e63f6ec..dcbd55c0f1 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -3666,3 +3666,18 @@ virCgroupSetupBlkioDeviceWriteBps(virCgroupPtr cgroup, const char *path,
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 d50a8d69d4..55132dedb6 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -245,6 +245,7 @@ int virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate);
int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus);
int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus);
+int virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask);
int virCgroupRemove(virCgroupPtr group);
--
2.24.1