From: "Daniel P. Berrange" <berrange(a)redhat.com>
The virCgroupMounted method is badly named, since a controller can be
mounted, but disabled in the current object. Rename the method to be
virCgroupHasController. Also make it tolerant to a NULL virCgroupPtr
and out-of-range controller index, to avoid duplication of these
checks in all callers
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/libvirt_private.syms | 2 +-
src/lxc/lxc_driver.c | 12 +-----------
src/lxc/lxc_process.c | 10 +++++-----
src/qemu/qemu_cgroup.c | 14 +-------------
src/util/vircgroup.c | 13 +++++++++----
src/util/vircgroup.h | 2 +-
6 files changed, 18 insertions(+), 35 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b9c656e..4db0734 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1116,10 +1116,10 @@ virCgroupGetMemorySoftLimit;
virCgroupGetMemoryUsage;
virCgroupGetMemSwapHardLimit;
virCgroupGetMemSwapUsage;
+virCgroupHasController;
virCgroupKill;
virCgroupKillPainfully;
virCgroupKillRecursive;
-virCgroupMounted;
virCgroupMoveTask;
virCgroupPathOfController;
virCgroupRemove;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 9c6f858..ea056c8 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1641,17 +1641,7 @@ cleanup:
static bool lxcCgroupControllerActive(virLXCDriverPtr driver,
int controller)
{
- if (driver->cgroup == NULL)
- return false;
- if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST)
- return false;
- if (!virCgroupMounted(driver->cgroup, controller))
- return false;
-#if 0
- if (driver->cgroupControllers & (1 << controller))
- return true;
-#endif
- return true;
+ return virCgroupHasController(driver->cgroup, controller);
}
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index f2f66e4..f311f63 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -1053,20 +1053,20 @@ int virLXCProcessStart(virConnectPtr conn,
return -1;
}
- if (!virCgroupMounted(lxc_driver->cgroup,
+ if (!virCgroupHasController(lxc_driver->cgroup,
VIR_CGROUP_CONTROLLER_CPUACCT)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to find 'cpuacct' cgroups controller
mount"));
return -1;
}
- if (!virCgroupMounted(lxc_driver->cgroup,
- VIR_CGROUP_CONTROLLER_DEVICES)) {
+ if (!virCgroupHasController(lxc_driver->cgroup,
+ VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to find 'devices' cgroups controller
mount"));
return -1;
}
- if (!virCgroupMounted(lxc_driver->cgroup,
- VIR_CGROUP_CONTROLLER_MEMORY)) {
+ if (!virCgroupHasController(lxc_driver->cgroup,
+ VIR_CGROUP_CONTROLLER_MEMORY)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to find 'memory' cgroups controller
mount"));
return -1;
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 2cdc2b7..5aa9416 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -48,19 +48,7 @@ static const char *const defaultDeviceACL[] = {
bool qemuCgroupControllerActive(virQEMUDriverPtr driver,
int controller)
{
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
- bool ret = false;
-
- if (driver->cgroup == NULL)
- goto cleanup;
- if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST)
- goto cleanup;
- if (!virCgroupMounted(driver->cgroup, controller))
- goto cleanup;
-
-cleanup:
- virObjectUnref(cfg);
- return ret;
+ return virCgroupHasController(driver->cgroup, controller);
}
static int
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 085421e..dc2b431 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -94,15 +94,20 @@ void virCgroupFree(virCgroupPtr *group)
}
/**
- * virCgroupMounted: query whether a cgroup subsystem is mounted or not
+ * virCgroupHasController: query whether a cgroup controller is present
*
- * @cgroup: The group structure to be queried
+ * @cgroup: The group structure to be queried, or NULL
* @controller: cgroup subsystem id
*
- * Returns true if a cgroup is subsystem is mounted.
+ * Returns true if a cgroup controller is mounted and is associated
+ * with this cgroup object.
*/
-bool virCgroupMounted(virCgroupPtr cgroup, int controller)
+bool virCgroupHasController(virCgroupPtr cgroup, int controller)
{
+ if (!cgroup)
+ return false;
+ if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST)
+ return false;
return cgroup->controllers[controller].mountPoint != NULL;
}
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index 725d2d0..4c1134d 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -161,7 +161,7 @@ int virCgroupRemoveRecursively(char *grppath);
int virCgroupRemove(virCgroupPtr group);
void virCgroupFree(virCgroupPtr *group);
-bool virCgroupMounted(virCgroupPtr cgroup, int controller);
+bool virCgroupHasController(virCgroupPtr cgroup, int controller);
int virCgroupKill(virCgroupPtr group, int signum);
int virCgroupKillRecursive(virCgroupPtr group, int signum);
--
1.8.1.4