|
|
397dc2 |
From f835b834d7922bed1ccda35885e42ab7c3f4a70f Mon Sep 17 00:00:00 2001
|
|
|
397dc2 |
Message-Id: <f835b834d7922bed1ccda35885e42ab7c3f4a70f@dist-git>
|
|
|
397dc2 |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
|
397dc2 |
Date: Fri, 19 Feb 2021 13:33:58 +0100
|
|
|
397dc2 |
Subject: [PATCH] vircgroup: introduce virCgroupV1Exists and virCgroupV2Exists
|
|
|
397dc2 |
MIME-Version: 1.0
|
|
|
397dc2 |
Content-Type: text/plain; charset=UTF-8
|
|
|
397dc2 |
Content-Transfer-Encoding: 8bit
|
|
|
397dc2 |
|
|
|
397dc2 |
This will check if the cgroup actually exists on the system.
|
|
|
397dc2 |
|
|
|
397dc2 |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
397dc2 |
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
397dc2 |
(cherry picked from commit badc2bcc7398d8c0a739998a80411ddebf129512)
|
|
|
397dc2 |
|
|
|
397dc2 |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1798463
|
|
|
397dc2 |
|
|
|
397dc2 |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
397dc2 |
Message-Id: <14297ed923f0f23cc52506e61e637c8f45e331ee.1613737828.git.phrdina@redhat.com>
|
|
|
397dc2 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
397dc2 |
---
|
|
|
397dc2 |
src/util/vircgroupbackend.h | 4 ++++
|
|
|
397dc2 |
src/util/vircgroupv1.c | 27 +++++++++++++++++++++++++++
|
|
|
397dc2 |
src/util/vircgroupv2.c | 15 +++++++++++++++
|
|
|
397dc2 |
3 files changed, 46 insertions(+)
|
|
|
397dc2 |
|
|
|
397dc2 |
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
|
|
|
397dc2 |
index ac7b3ae517..dabc7bd4b4 100644
|
|
|
397dc2 |
--- a/src/util/vircgroupbackend.h
|
|
|
397dc2 |
+++ b/src/util/vircgroupbackend.h
|
|
|
397dc2 |
@@ -115,6 +115,9 @@ typedef int
|
|
|
397dc2 |
const char *key,
|
|
|
397dc2 |
char **path);
|
|
|
397dc2 |
|
|
|
397dc2 |
+typedef bool
|
|
|
397dc2 |
+(*virCgroupExistsCB)(virCgroupPtr group);
|
|
|
397dc2 |
+
|
|
|
397dc2 |
typedef int
|
|
|
397dc2 |
(*virCgroupMakeGroupCB)(virCgroupPtr parent,
|
|
|
397dc2 |
virCgroupPtr group,
|
|
|
397dc2 |
@@ -378,6 +381,7 @@ struct _virCgroupBackend {
|
|
|
397dc2 |
virCgroupGetAnyControllerCB getAnyController;
|
|
|
397dc2 |
virCgroupPathOfControllerCB pathOfController;
|
|
|
397dc2 |
virCgroupMakeGroupCB makeGroup;
|
|
|
397dc2 |
+ virCgroupExistsCB exists;
|
|
|
397dc2 |
virCgroupRemoveCB remove;
|
|
|
397dc2 |
virCgroupAddTaskCB addTask;
|
|
|
397dc2 |
virCgroupHasEmptyTasksCB hasEmptyTasks;
|
|
|
397dc2 |
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
|
|
|
397dc2 |
index eb2b611cee..57d617cb69 100644
|
|
|
397dc2 |
--- a/src/util/vircgroupv1.c
|
|
|
397dc2 |
+++ b/src/util/vircgroupv1.c
|
|
|
397dc2 |
@@ -670,6 +670,32 @@ virCgroupV1MakeGroup(virCgroupPtr parent,
|
|
|
397dc2 |
}
|
|
|
397dc2 |
|
|
|
397dc2 |
|
|
|
397dc2 |
+static bool
|
|
|
397dc2 |
+virCgroupV1Exists(virCgroupPtr group)
|
|
|
397dc2 |
+{
|
|
|
397dc2 |
+ size_t i;
|
|
|
397dc2 |
+
|
|
|
397dc2 |
+ for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
|
|
|
397dc2 |
+ g_autofree char *path = NULL;
|
|
|
397dc2 |
+
|
|
|
397dc2 |
+ if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
|
|
|
397dc2 |
+ continue;
|
|
|
397dc2 |
+
|
|
|
397dc2 |
+ if (!group->legacy[i].mountPoint)
|
|
|
397dc2 |
+ continue;
|
|
|
397dc2 |
+
|
|
|
397dc2 |
+ if (virCgroupV1PathOfController(group, i, "", &path) < 0)
|
|
|
397dc2 |
+ return false;
|
|
|
397dc2 |
+
|
|
|
397dc2 |
+ if (!virFileExists(path)) {
|
|
|
397dc2 |
+ return false;
|
|
|
397dc2 |
+ }
|
|
|
397dc2 |
+ }
|
|
|
397dc2 |
+
|
|
|
397dc2 |
+ return true;
|
|
|
397dc2 |
+}
|
|
|
397dc2 |
+
|
|
|
397dc2 |
+
|
|
|
397dc2 |
static int
|
|
|
397dc2 |
virCgroupV1Remove(virCgroupPtr group)
|
|
|
397dc2 |
{
|
|
|
397dc2 |
@@ -2136,6 +2162,7 @@ virCgroupBackend virCgroupV1Backend = {
|
|
|
397dc2 |
.getAnyController = virCgroupV1GetAnyController,
|
|
|
397dc2 |
.pathOfController = virCgroupV1PathOfController,
|
|
|
397dc2 |
.makeGroup = virCgroupV1MakeGroup,
|
|
|
397dc2 |
+ .exists = virCgroupV1Exists,
|
|
|
397dc2 |
.remove = virCgroupV1Remove,
|
|
|
397dc2 |
.addTask = virCgroupV1AddTask,
|
|
|
397dc2 |
.hasEmptyTasks = virCgroupV1HasEmptyTasks,
|
|
|
397dc2 |
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
|
|
|
397dc2 |
index 5e19ed8332..d15e2354cf 100644
|
|
|
397dc2 |
--- a/src/util/vircgroupv2.c
|
|
|
397dc2 |
+++ b/src/util/vircgroupv2.c
|
|
|
397dc2 |
@@ -493,6 +493,20 @@ virCgroupV2MakeGroup(virCgroupPtr parent,
|
|
|
397dc2 |
}
|
|
|
397dc2 |
|
|
|
397dc2 |
|
|
|
397dc2 |
+static bool
|
|
|
397dc2 |
+virCgroupV2Exists(virCgroupPtr group)
|
|
|
397dc2 |
+{
|
|
|
397dc2 |
+ g_autofree char *path = NULL;
|
|
|
397dc2 |
+ int controller;
|
|
|
397dc2 |
+
|
|
|
397dc2 |
+ controller = virCgroupV2GetAnyController(group);
|
|
|
397dc2 |
+ if (virCgroupV2PathOfController(group, controller, "", &path) < 0)
|
|
|
397dc2 |
+ return false;
|
|
|
397dc2 |
+
|
|
|
397dc2 |
+ return virFileExists(path);
|
|
|
397dc2 |
+}
|
|
|
397dc2 |
+
|
|
|
397dc2 |
+
|
|
|
397dc2 |
static int
|
|
|
397dc2 |
virCgroupV2Remove(virCgroupPtr group)
|
|
|
397dc2 |
{
|
|
|
397dc2 |
@@ -1886,6 +1900,7 @@ virCgroupBackend virCgroupV2Backend = {
|
|
|
397dc2 |
.getAnyController = virCgroupV2GetAnyController,
|
|
|
397dc2 |
.pathOfController = virCgroupV2PathOfController,
|
|
|
397dc2 |
.makeGroup = virCgroupV2MakeGroup,
|
|
|
397dc2 |
+ .exists = virCgroupV2Exists,
|
|
|
397dc2 |
.remove = virCgroupV2Remove,
|
|
|
397dc2 |
.addTask = virCgroupV2AddTask,
|
|
|
397dc2 |
.hasEmptyTasks = virCgroupV2HasEmptyTasks,
|
|
|
397dc2 |
--
|
|
|
397dc2 |
2.30.0
|
|
|
397dc2 |
|