|
|
c480ed |
From cef7b5074c5638c67828d44357809fae84354000 Mon Sep 17 00:00:00 2001
|
|
|
c480ed |
Message-Id: <cef7b5074c5638c67828d44357809fae84354000@dist-git>
|
|
|
c480ed |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
Date: Mon, 1 Jul 2019 17:05:58 +0200
|
|
|
c480ed |
Subject: [PATCH] vircgroup: Introduce virCgroupEnableMissingControllers
|
|
|
c480ed |
MIME-Version: 1.0
|
|
|
c480ed |
Content-Type: text/plain; charset=UTF-8
|
|
|
c480ed |
Content-Transfer-Encoding: 8bit
|
|
|
c480ed |
|
|
|
c480ed |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
(cherry picked from commit fc221c053ba3a0f5b9ce609936e010180bbda64f)
|
|
|
c480ed |
|
|
|
c480ed |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
|
|
|
c480ed |
|
|
|
c480ed |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
Message-Id: <c00a45e34f017f784f46831dba6275942f973bd8.1561993099.git.phrdina@redhat.com>
|
|
|
c480ed |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c480ed |
---
|
|
|
c480ed |
src/util/vircgroup.c | 127 ++++++++++++++++++++++++-------------------
|
|
|
c480ed |
1 file changed, 70 insertions(+), 57 deletions(-)
|
|
|
c480ed |
|
|
|
c480ed |
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
|
|
|
c480ed |
index 7888dab716..a2c971fbf4 100644
|
|
|
c480ed |
--- a/src/util/vircgroup.c
|
|
|
c480ed |
+++ b/src/util/vircgroup.c
|
|
|
c480ed |
@@ -1494,68 +1494,22 @@ virCgroupNewDetectMachine(const char *name,
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
-/*
|
|
|
c480ed |
- * Returns 0 on success, -1 on fatal error, -2 on systemd not available
|
|
|
c480ed |
- */
|
|
|
c480ed |
static int
|
|
|
c480ed |
-virCgroupNewMachineSystemd(const char *name,
|
|
|
c480ed |
- const char *drivername,
|
|
|
c480ed |
- const unsigned char *uuid,
|
|
|
c480ed |
- const char *rootdir,
|
|
|
c480ed |
- pid_t pidleader,
|
|
|
c480ed |
- bool isContainer,
|
|
|
c480ed |
- size_t nnicindexes,
|
|
|
c480ed |
- int *nicindexes,
|
|
|
c480ed |
- const char *partition,
|
|
|
c480ed |
- int controllers,
|
|
|
c480ed |
- virCgroupPtr *group)
|
|
|
c480ed |
+virCgroupEnableMissingControllers(char *path,
|
|
|
c480ed |
+ pid_t pidleader,
|
|
|
c480ed |
+ int controllers,
|
|
|
c480ed |
+ virCgroupPtr *group)
|
|
|
c480ed |
{
|
|
|
c480ed |
+ virCgroupPtr parent = NULL;
|
|
|
c480ed |
+ char *offset = path;
|
|
|
c480ed |
int ret = -1;
|
|
|
c480ed |
- int rv;
|
|
|
c480ed |
- virCgroupPtr init, parent = NULL;
|
|
|
c480ed |
- VIR_AUTOFREE(char *) path = NULL;
|
|
|
c480ed |
- char *offset;
|
|
|
c480ed |
-
|
|
|
c480ed |
- VIR_DEBUG("Trying to setup machine '%s' via systemd", name);
|
|
|
c480ed |
- if ((rv = virSystemdCreateMachine(name,
|
|
|
c480ed |
- drivername,
|
|
|
c480ed |
- uuid,
|
|
|
c480ed |
- rootdir,
|
|
|
c480ed |
- pidleader,
|
|
|
c480ed |
- isContainer,
|
|
|
c480ed |
- nnicindexes,
|
|
|
c480ed |
- nicindexes,
|
|
|
c480ed |
- partition)) < 0)
|
|
|
c480ed |
- return rv;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (controllers != -1)
|
|
|
c480ed |
- controllers |= (1 << VIR_CGROUP_CONTROLLER_SYSTEMD);
|
|
|
c480ed |
-
|
|
|
c480ed |
- VIR_DEBUG("Detecting systemd placement");
|
|
|
c480ed |
- if (virCgroupNewDetect(pidleader,
|
|
|
c480ed |
- controllers,
|
|
|
c480ed |
- &init) < 0)
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
-
|
|
|
c480ed |
- path = init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement;
|
|
|
c480ed |
- init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement = NULL;
|
|
|
c480ed |
- virCgroupFree(&init);
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (!path || STREQ(path, "/") || path[0] != '/') {
|
|
|
c480ed |
- VIR_DEBUG("Systemd didn't setup its controller");
|
|
|
c480ed |
- ret = -2;
|
|
|
c480ed |
- goto cleanup;
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- offset = path;
|
|
|
c480ed |
|
|
|
c480ed |
if (virCgroupNew(pidleader,
|
|
|
c480ed |
"",
|
|
|
c480ed |
NULL,
|
|
|
c480ed |
controllers,
|
|
|
c480ed |
&parent) < 0)
|
|
|
c480ed |
- goto cleanup;
|
|
|
c480ed |
-
|
|
|
c480ed |
+ return ret;
|
|
|
c480ed |
|
|
|
c480ed |
for (;;) {
|
|
|
c480ed |
virCgroupPtr tmp;
|
|
|
c480ed |
@@ -1585,6 +1539,68 @@ virCgroupNewMachineSystemd(const char *name,
|
|
|
c480ed |
}
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
+ ret = 0;
|
|
|
c480ed |
+ cleanup:
|
|
|
c480ed |
+ virCgroupFree(&parent);
|
|
|
c480ed |
+ return ret;
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
+/*
|
|
|
c480ed |
+ * Returns 0 on success, -1 on fatal error, -2 on systemd not available
|
|
|
c480ed |
+ */
|
|
|
c480ed |
+static int
|
|
|
c480ed |
+virCgroupNewMachineSystemd(const char *name,
|
|
|
c480ed |
+ const char *drivername,
|
|
|
c480ed |
+ const unsigned char *uuid,
|
|
|
c480ed |
+ const char *rootdir,
|
|
|
c480ed |
+ pid_t pidleader,
|
|
|
c480ed |
+ bool isContainer,
|
|
|
c480ed |
+ size_t nnicindexes,
|
|
|
c480ed |
+ int *nicindexes,
|
|
|
c480ed |
+ const char *partition,
|
|
|
c480ed |
+ int controllers,
|
|
|
c480ed |
+ virCgroupPtr *group)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ int rv;
|
|
|
c480ed |
+ virCgroupPtr init;
|
|
|
c480ed |
+ VIR_AUTOFREE(char *) path = NULL;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ VIR_DEBUG("Trying to setup machine '%s' via systemd", name);
|
|
|
c480ed |
+ if ((rv = virSystemdCreateMachine(name,
|
|
|
c480ed |
+ drivername,
|
|
|
c480ed |
+ uuid,
|
|
|
c480ed |
+ rootdir,
|
|
|
c480ed |
+ pidleader,
|
|
|
c480ed |
+ isContainer,
|
|
|
c480ed |
+ nnicindexes,
|
|
|
c480ed |
+ nicindexes,
|
|
|
c480ed |
+ partition)) < 0)
|
|
|
c480ed |
+ return rv;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (controllers != -1)
|
|
|
c480ed |
+ controllers |= (1 << VIR_CGROUP_CONTROLLER_SYSTEMD);
|
|
|
c480ed |
+
|
|
|
c480ed |
+ VIR_DEBUG("Detecting systemd placement");
|
|
|
c480ed |
+ if (virCgroupNewDetect(pidleader,
|
|
|
c480ed |
+ controllers,
|
|
|
c480ed |
+ &init) < 0)
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ path = init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement;
|
|
|
c480ed |
+ init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement = NULL;
|
|
|
c480ed |
+ virCgroupFree(&init);
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (!path || STREQ(path, "/") || path[0] != '/') {
|
|
|
c480ed |
+ VIR_DEBUG("Systemd didn't setup its controller");
|
|
|
c480ed |
+ return -2;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virCgroupEnableMissingControllers(path, pidleader,
|
|
|
c480ed |
+ controllers, group) < 0) {
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
if (virCgroupAddTask(*group, pidleader) < 0) {
|
|
|
c480ed |
virErrorPtr saved = virSaveLastError();
|
|
|
c480ed |
virCgroupRemove(*group);
|
|
|
c480ed |
@@ -1595,10 +1611,7 @@ virCgroupNewMachineSystemd(const char *name,
|
|
|
c480ed |
}
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
- ret = 0;
|
|
|
c480ed |
- cleanup:
|
|
|
c480ed |
- virCgroupFree(&parent);
|
|
|
c480ed |
- return ret;
|
|
|
c480ed |
+ return 0;
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
--
|
|
|
c480ed |
2.22.0
|
|
|
c480ed |
|