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