mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
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: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
70bb34eb2e
commit
dca927c82f
@ -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,19 +1053,19 @@ 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,
|
||||
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,
|
||||
if (!virCgroupHasController(lxc_driver->cgroup,
|
||||
VIR_CGROUP_CONTROLLER_MEMORY)) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Unable to find 'memory' cgroups controller mount"));
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user