Replace the virCgroupNew{Vcpu|Emulator|IOThread} calls with the common
virCgroupNewThread API
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/libvirt_private.syms | 3 -
src/qemu/qemu_cgroup.c | 22 ++++---
src/qemu/qemu_driver.c | 41 +++++++-----
src/util/vircgroup.c | 160 +----------------------------------------------
src/util/vircgroup.h | 17 -----
5 files changed, 42 insertions(+), 201 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0800cb6..12614cb 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1180,14 +1180,11 @@ virCgroupMoveTask;
virCgroupNewDetect;
virCgroupNewDetectMachine;
virCgroupNewDomainPartition;
-virCgroupNewEmulator;
virCgroupNewIgnoreError;
-virCgroupNewIOThread;
virCgroupNewMachine;
virCgroupNewPartition;
virCgroupNewSelf;
virCgroupNewThread;
-virCgroupNewVcpu;
virCgroupPathOfController;
virCgroupRemove;
virCgroupRemoveRecursively;
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 50546a1..f287d24 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -629,7 +629,8 @@ qemuSetupCpusetMems(virDomainObjPtr vm)
goto cleanup;
if (mem_mask)
- if (virCgroupNewEmulator(priv->cgroup, false, &cgroup_temp) < 0 ||
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_EMULATOR_NAME, 0,
+ false, &cgroup_temp) < 0 ||
virCgroupSetCpusetMems(cgroup_temp, mem_mask) < 0)
goto cleanup;
@@ -790,7 +791,8 @@ qemuRestoreCgroupState(virDomainObjPtr vm)
goto error;
for (i = 0; i < priv->nvcpupids; i++) {
- if (virCgroupNewVcpu(priv->cgroup, i, false, &cgroup_temp) < 0 ||
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_VCPU_NAME, i,
+ false, &cgroup_temp) < 0 ||
virCgroupSetCpusetMemoryMigrate(cgroup_temp, true) < 0 ||
virCgroupGetCpusetMems(cgroup_temp, &nodeset) < 0 ||
virCgroupSetCpusetMems(cgroup_temp, nodeset) < 0)
@@ -800,7 +802,8 @@ qemuRestoreCgroupState(virDomainObjPtr vm)
}
for (i = 0; i < priv->niothreadpids; i++) {
- if (virCgroupNewIOThread(priv->cgroup, i + 1, false, &cgroup_temp) < 0
||
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_IOTHREAD_NAME, i + 1,
+ false, &cgroup_temp) < 0 ||
virCgroupSetCpusetMemoryMigrate(cgroup_temp, true) < 0 ||
virCgroupGetCpusetMems(cgroup_temp, &nodeset) < 0 ||
virCgroupSetCpusetMems(cgroup_temp, nodeset) < 0)
@@ -809,7 +812,8 @@ qemuRestoreCgroupState(virDomainObjPtr vm)
virCgroupFree(&cgroup_temp);
}
- if (virCgroupNewEmulator(priv->cgroup, false, &cgroup_temp) < 0 ||
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_EMULATOR_NAME, 0,
+ false, &cgroup_temp) < 0 ||
virCgroupSetCpusetMemoryMigrate(cgroup_temp, true) < 0 ||
virCgroupGetCpusetMems(cgroup_temp, &nodeset) < 0 ||
virCgroupSetCpusetMems(cgroup_temp, nodeset) < 0)
@@ -1010,7 +1014,8 @@ qemuSetupCgroupForVcpu(virDomainObjPtr vm)
goto cleanup;
for (i = 0; i < priv->nvcpupids; i++) {
- if (virCgroupNewVcpu(priv->cgroup, i, true, &cgroup_vcpu) < 0)
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_VCPU_NAME, i,
+ true, &cgroup_vcpu) < 0)
goto cleanup;
/* move the thread for vcpu to sub dir */
@@ -1096,7 +1101,8 @@ qemuSetupCgroupForEmulator(virDomainObjPtr vm)
if (priv->cgroup == NULL)
return 0; /* Not supported, so claim success */
- if (virCgroupNewEmulator(priv->cgroup, true, &cgroup_emulator) < 0)
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_EMULATOR_NAME, 0,
+ true, &cgroup_emulator) < 0)
goto cleanup;
if (virCgroupMoveTask(priv->cgroup, cgroup_emulator) < 0)
@@ -1183,8 +1189,8 @@ qemuSetupCgroupForIOThreads(virDomainObjPtr vm)
/* IOThreads are numbered 1..n, although the array is 0..n-1,
* so we will account for that here
*/
- if (virCgroupNewIOThread(priv->cgroup, i + 1, true,
- &cgroup_iothread) < 0)
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_IOTHREAD_NAME, i + 1,
+ true, &cgroup_iothread) < 0)
goto cleanup;
/* move the thread for iothread to sub dir */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6132674..be54b7e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4728,7 +4728,8 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver,
if (priv->cgroup) {
int rv = -1;
/* Create cgroup for the onlined vcpu */
- if (virCgroupNewVcpu(priv->cgroup, i, true, &cgroup_vcpu) < 0)
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_VCPU_NAME, i,
+ true, &cgroup_vcpu) < 0)
goto cleanup;
if (mem_mask &&
@@ -4801,7 +4802,8 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver,
} else {
for (i = oldvcpus - 1; i >= nvcpus; i--) {
if (priv->cgroup) {
- if (virCgroupNewVcpu(priv->cgroup, i, false, &cgroup_vcpu) <
0)
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_VCPU_NAME, i,
+ false, &cgroup_vcpu) < 0)
goto cleanup;
/* Remove cgroup for the offlined vcpu */
@@ -4894,7 +4896,8 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
if (flags & VIR_DOMAIN_AFFECT_LIVE && !(flags &
VIR_DOMAIN_VCPU_GUEST) &&
virNumaIsAvailable()) {
- if (virCgroupNewEmulator(priv->cgroup, false, &cgroup_temp) < 0)
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_EMULATOR_NAME, 0,
+ false, &cgroup_temp) < 0)
goto endjob;
if (!(all_nodes = virNumaGetHostNodeset()))
@@ -5136,7 +5139,8 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
/* Configure the corresponding cpuset cgroup before set affinity. */
if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
- if (virCgroupNewVcpu(priv->cgroup, vcpu, false, &cgroup_vcpu) < 0)
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_VCPU_NAME, vcpu,
+ false, &cgroup_vcpu) < 0)
goto endjob;
if (qemuSetupCgroupCpusetCpus(cgroup_vcpu, pcpumap) < 0) {
virReportError(VIR_ERR_OPERATION_INVALID,
@@ -5419,7 +5423,8 @@ qemuDomainPinEmulator(virDomainPtr dom,
/*
* Configure the corresponding cpuset cgroup.
*/
- if (virCgroupNewEmulator(priv->cgroup, false, &cgroup_emulator)
< 0)
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_EMULATOR_NAME,
+ 0, false, &cgroup_emulator) < 0)
goto endjob;
if (qemuSetupCgroupCpusetCpus(cgroup_emulator,
newVcpuPin[0]->cpumask) < 0) {
@@ -6014,8 +6019,8 @@ qemuDomainPinIOThread(virDomainPtr dom,
/* Configure the corresponding cpuset cgroup before set affinity. */
if (virCgroupHasController(priv->cgroup,
VIR_CGROUP_CONTROLLER_CPUSET)) {
- if (virCgroupNewIOThread(priv->cgroup, iothread_id,
- false, &cgroup_iothread) < 0)
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_IOTHREAD_NAME,
+ iothread_id, false, &cgroup_iothread) < 0)
goto endjob;
if (qemuSetupCgroupCpusetCpus(cgroup_iothread, pcpumap) < 0) {
virReportError(VIR_ERR_OPERATION_INVALID,
@@ -9956,21 +9961,23 @@ qemuDomainSetNumaParamsLive(virDomainObjPtr vm,
if (!(nodeset_str = virBitmapFormat(nodeset)))
goto cleanup;
- if (virCgroupNewEmulator(priv->cgroup, false, &cgroup_temp) < 0 ||
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_EMULATOR_NAME, 0,
+ false, &cgroup_temp) < 0 ||
virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0)
goto cleanup;
virCgroupFree(&cgroup_temp);
for (i = 0; i < priv->nvcpupids; i++) {
- if (virCgroupNewVcpu(priv->cgroup, i, false, &cgroup_temp) < 0 ||
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_VCPU_NAME, i,
+ false, &cgroup_temp) < 0 ||
virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0)
goto cleanup;
virCgroupFree(&cgroup_temp);
}
for (i = 0; i < priv->niothreadpids; i++) {
- if (virCgroupNewIOThread(priv->cgroup, i + 1, false,
- &cgroup_temp) < 0 ||
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_IOTHREAD_NAME, i + 1,
+ false, &cgroup_temp) < 0 ||
virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0)
goto cleanup;
virCgroupFree(&cgroup_temp);
@@ -10237,7 +10244,8 @@ qemuSetVcpusBWLive(virDomainObjPtr vm, virCgroupPtr cgroup,
*/
if (priv->nvcpupids != 0 && priv->vcpupids[0] != vm->pid) {
for (i = 0; i < priv->nvcpupids; i++) {
- if (virCgroupNewVcpu(cgroup, i, false, &cgroup_vcpu) < 0)
+ if (virCgroupNewThread(cgroup, VIR_CGROUP_VCPU_NAME, i,
+ false, &cgroup_vcpu) < 0)
goto cleanup;
if (qemuSetupCgroupVcpuBW(cgroup_vcpu, period, quota) < 0)
@@ -10267,7 +10275,8 @@ qemuSetEmulatorBandwidthLive(virDomainObjPtr vm, virCgroupPtr
cgroup,
if (priv->nvcpupids == 0 || priv->vcpupids[0] == vm->pid)
return 0;
- if (virCgroupNewEmulator(cgroup, false, &cgroup_emulator) < 0)
+ if (virCgroupNewThread(cgroup, VIR_CGROUP_EMULATOR_NAME, 0,
+ false, &cgroup_emulator) < 0)
goto cleanup;
if (qemuSetupCgroupVcpuBW(cgroup_emulator, period, quota) < 0)
@@ -10562,7 +10571,8 @@ qemuGetVcpusBWLive(virDomainObjPtr vm,
}
/* get period and quota for vcpu0 */
- if (virCgroupNewVcpu(priv->cgroup, 0, false, &cgroup_vcpu) < 0)
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_VCPU_NAME, 0,
+ false, &cgroup_vcpu) < 0)
goto cleanup;
rc = qemuGetVcpuBWLive(cgroup_vcpu, period, quota);
@@ -10595,7 +10605,8 @@ qemuGetEmulatorBandwidthLive(virDomainObjPtr vm, virCgroupPtr
cgroup,
}
/* get period and quota for emulator */
- if (virCgroupNewEmulator(cgroup, false, &cgroup_emulator) < 0)
+ if (virCgroupNewThread(cgroup, VIR_CGROUP_EMULATOR_NAME, 0,
+ false, &cgroup_emulator) < 0)
goto cleanup;
rc = qemuGetVcpuBWLive(cgroup_emulator, period, quota);
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 7fec0cc..f1665c8 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1482,128 +1482,6 @@ virCgroupNewThread(virCgroupPtr domain,
}
-/**
- * virCgroupNewVcpu:
- *
- * @domain: group for the domain
- * @vcpuid: id of the vcpu
- * @create: true to create if not already existing
- * @group: Pointer to returned virCgroupPtr
- *
- * Returns 0 on success, or -1 on error
- */
-int
-virCgroupNewVcpu(virCgroupPtr domain,
- int vcpuid,
- bool create,
- virCgroupPtr *group)
-{
- int ret = -1;
- char *name = NULL;
- int controllers;
-
- if (virAsprintf(&name, "vcpu%d", vcpuid) < 0)
- goto cleanup;
-
- controllers = ((1 << VIR_CGROUP_CONTROLLER_CPU) |
- (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
- (1 << VIR_CGROUP_CONTROLLER_CPUSET));
-
- if (virCgroupNew(-1, name, domain, controllers, group) < 0)
- goto cleanup;
-
- if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_NONE) < 0) {
- virCgroupRemove(*group);
- virCgroupFree(group);
- goto cleanup;
- }
-
- ret = 0;
- cleanup:
- VIR_FREE(name);
- return ret;
-}
-
-
-/**
- * virCgroupNewEmulator:
- *
- * @domain: group for the domain
- * @create: true to create if not already existing
- * @group: Pointer to returned virCgroupPtr
- *
- * Returns: 0 on success or -1 on error
- */
-int
-virCgroupNewEmulator(virCgroupPtr domain,
- bool create,
- virCgroupPtr *group)
-{
- int ret = -1;
- int controllers;
-
- controllers = ((1 << VIR_CGROUP_CONTROLLER_CPU) |
- (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
- (1 << VIR_CGROUP_CONTROLLER_CPUSET));
-
- if (virCgroupNew(-1, "emulator", domain, controllers, group) < 0)
- goto cleanup;
-
- if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_NONE) < 0) {
- virCgroupRemove(*group);
- virCgroupFree(group);
- goto cleanup;
- }
-
- ret = 0;
- cleanup:
- return ret;
-}
-
-
-/**
- * virCgroupNewIOThread:
- *
- * @domain: group for the domain
- * @iothreadid: id of the iothread
- * @create: true to create if not already existing
- * @group: Pointer to returned virCgroupPtr
- *
- * Returns 0 on success, or -1 on error
- */
-int
-virCgroupNewIOThread(virCgroupPtr domain,
- int iothreadid,
- bool create,
- virCgroupPtr *group)
-{
- int ret = -1;
- char *name = NULL;
- int controllers;
-
- if (virAsprintf(&name, "iothread%d", iothreadid) < 0)
- goto cleanup;
-
- controllers = ((1 << VIR_CGROUP_CONTROLLER_CPU) |
- (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
- (1 << VIR_CGROUP_CONTROLLER_CPUSET));
-
- if (virCgroupNew(-1, name, domain, controllers, group) < 0)
- goto cleanup;
-
- if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_NONE) < 0) {
- virCgroupRemove(*group);
- virCgroupFree(group);
- goto cleanup;
- }
-
- ret = 0;
- cleanup:
- VIR_FREE(name);
- return ret;
-}
-
-
int
virCgroupNewDetect(pid_t pid,
int controllers,
@@ -3106,7 +2984,8 @@ virCgroupGetPercpuVcpuSum(virCgroupPtr group,
unsigned long long tmp;
ssize_t j;
- if (virCgroupNewVcpu(group, i, false, &group_vcpu) < 0)
+ if (virCgroupNewThread(group, VIR_CGROUP_VCPU_NAME, i,
+ false, &group_vcpu) < 0)
goto cleanup;
if (virCgroupGetCpuacctPercpuUsage(group_vcpu, &buf) < 0)
@@ -4140,41 +4019,6 @@ virCgroupNewThread(virCgroupPtr domain ATTRIBUTE_UNUSED,
int
-virCgroupNewVcpu(virCgroupPtr domain ATTRIBUTE_UNUSED,
- int vcpuid ATTRIBUTE_UNUSED,
- bool create ATTRIBUTE_UNUSED,
- virCgroupPtr *group ATTRIBUTE_UNUSED)
-{
- virReportSystemError(ENXIO, "%s",
- _("Control groups not supported on this platform"));
- return -1;
-}
-
-
-int
-virCgroupNewEmulator(virCgroupPtr domain ATTRIBUTE_UNUSED,
- bool create ATTRIBUTE_UNUSED,
- virCgroupPtr *group ATTRIBUTE_UNUSED)
-{
- virReportSystemError(ENXIO, "%s",
- _("Control groups not supported on this platform"));
- return -1;
-}
-
-
-int
-virCgroupNewIOThread(virCgroupPtr domain ATTRIBUTE_UNUSED,
- int iothreadid ATTRIBUTE_UNUSED,
- bool create ATTRIBUTE_UNUSED,
- virCgroupPtr *group ATTRIBUTE_UNUSED)
-{
- virReportSystemError(ENXIO, "%s",
- _("Control groups not supported on this platform"));
- return -1;
-}
-
-
-int
virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED,
int controllers ATTRIBUTE_UNUSED,
virCgroupPtr *group ATTRIBUTE_UNUSED)
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index a756b03..cf90e0b 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -85,23 +85,6 @@ int virCgroupNewThread(virCgroupPtr domain,
virCgroupPtr *group)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(5);
-int virCgroupNewVcpu(virCgroupPtr domain,
- int vcpuid,
- bool create,
- virCgroupPtr *group)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
-
-int virCgroupNewEmulator(virCgroupPtr domain,
- bool create,
- virCgroupPtr *group)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
-
-int virCgroupNewIOThread(virCgroupPtr domain,
- int iothreadid,
- bool create,
- virCgroupPtr *group)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
-
int virCgroupNewDetect(pid_t pid,
int controllers,
virCgroupPtr *group);
--
2.1.0