提交 dca927c8 编写于 作者: D Daniel P. Berrange

Rename virCgroupMounted to virCgroupHasController & make it more robust

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: NDaniel P. Berrange <berrange@redhat.com>
上级 70bb34eb
......@@ -1117,10 +1117,10 @@ virCgroupGetMemorySoftLimit;
virCgroupGetMemoryUsage;
virCgroupGetMemSwapHardLimit;
virCgroupGetMemSwapUsage;
virCgroupHasController;
virCgroupKill;
virCgroupKillPainfully;
virCgroupKillRecursive;
virCgroupMounted;
virCgroupMoveTask;
virCgroupPathOfController;
virCgroupRemove;
......
......@@ -1642,17 +1642,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);
}
......
......@@ -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;
......
......@@ -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
......
......@@ -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;
}
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册