[libvirt PATCH 7/9] vircgroup: introduce virCgroupV1Exists and virCgroupV2Exists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This will check if the cgroup actually exists on the system.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/util/vircgroupbackend.h |  4 ++++
 src/util/vircgroupv1.c      | 27 +++++++++++++++++++++++++++
 src/util/vircgroupv2.c      | 15 +++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 497dde5625..a338ffb618 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -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;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 51ada12f6e..8a9a63e0b7 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -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,
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index d590f83187..c96f405dfa 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -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,
-- 
2.29.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux