mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
vircgroup: introduce virCgroupV1Exists and virCgroupV2Exists
This will check if the cgroup actually exists on the system. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
382fa15cde
commit
badc2bcc73
@ -118,6 +118,9 @@ typedef int
|
||||
const char *key,
|
||||
char **path);
|
||||
|
||||
typedef bool
|
||||
(*virCgroupExistsCB)(virCgroupPtr group);
|
||||
|
||||
typedef int
|
||||
(*virCgroupMakeGroupCB)(virCgroupPtr parent,
|
||||
virCgroupPtr group,
|
||||
@ -382,6 +385,7 @@ struct _virCgroupBackend {
|
||||
virCgroupGetAnyControllerCB getAnyController;
|
||||
virCgroupPathOfControllerCB pathOfController;
|
||||
virCgroupMakeGroupCB makeGroup;
|
||||
virCgroupExistsCB exists;
|
||||
virCgroupRemoveCB remove;
|
||||
virCgroupAddTaskCB addTask;
|
||||
virCgroupHasEmptyTasksCB hasEmptyTasks;
|
||||
|
@ -690,6 +690,32 @@ virCgroupV1MakeGroup(virCgroupPtr parent,
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
virCgroupV1Exists(virCgroupPtr group)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
|
||||
g_autofree char *path = NULL;
|
||||
|
||||
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
|
||||
continue;
|
||||
|
||||
if (!group->legacy[i].mountPoint)
|
||||
continue;
|
||||
|
||||
if (virCgroupV1PathOfController(group, i, "", &path) < 0)
|
||||
return false;
|
||||
|
||||
if (!virFileExists(path)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virCgroupV1Remove(virCgroupPtr group)
|
||||
{
|
||||
@ -2154,6 +2180,7 @@ virCgroupBackend virCgroupV1Backend = {
|
||||
.getAnyController = virCgroupV1GetAnyController,
|
||||
.pathOfController = virCgroupV1PathOfController,
|
||||
.makeGroup = virCgroupV1MakeGroup,
|
||||
.exists = virCgroupV1Exists,
|
||||
.remove = virCgroupV1Remove,
|
||||
.addTask = virCgroupV1AddTask,
|
||||
.hasEmptyTasks = virCgroupV1HasEmptyTasks,
|
||||
|
@ -499,6 +499,20 @@ virCgroupV2MakeGroup(virCgroupPtr parent,
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
virCgroupV2Exists(virCgroupPtr group)
|
||||
{
|
||||
g_autofree char *path = NULL;
|
||||
int controller;
|
||||
|
||||
controller = virCgroupV2GetAnyController(group);
|
||||
if (virCgroupV2PathOfController(group, controller, "", &path) < 0)
|
||||
return false;
|
||||
|
||||
return virFileExists(path);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virCgroupV2Remove(virCgroupPtr group)
|
||||
{
|
||||
@ -1895,6 +1909,7 @@ virCgroupBackend virCgroupV2Backend = {
|
||||
.getAnyController = virCgroupV2GetAnyController,
|
||||
.pathOfController = virCgroupV2PathOfController,
|
||||
.makeGroup = virCgroupV2MakeGroup,
|
||||
.exists = virCgroupV2Exists,
|
||||
.remove = virCgroupV2Remove,
|
||||
.addTask = virCgroupV2AddTask,
|
||||
.hasEmptyTasks = virCgroupV2HasEmptyTasks,
|
||||
|
Loading…
Reference in New Issue
Block a user