Blob Blame History Raw
From cef7b5074c5638c67828d44357809fae84354000 Mon Sep 17 00:00:00 2001
Message-Id: <cef7b5074c5638c67828d44357809fae84354000@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:05:58 +0200
Subject: [PATCH] vircgroup: Introduce virCgroupEnableMissingControllers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit fc221c053ba3a0f5b9ce609936e010180bbda64f)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <c00a45e34f017f784f46831dba6275942f973bd8.1561993099.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroup.c | 127 ++++++++++++++++++++++++-------------------
 1 file changed, 70 insertions(+), 57 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 7888dab716..a2c971fbf4 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1494,68 +1494,22 @@ virCgroupNewDetectMachine(const char *name,
 }
 
 
-/*
- * Returns 0 on success, -1 on fatal error, -2 on systemd not available
- */
 static int
-virCgroupNewMachineSystemd(const char *name,
-                           const char *drivername,
-                           const unsigned char *uuid,
-                           const char *rootdir,
-                           pid_t pidleader,
-                           bool isContainer,
-                           size_t nnicindexes,
-                           int *nicindexes,
-                           const char *partition,
-                           int controllers,
-                           virCgroupPtr *group)
+virCgroupEnableMissingControllers(char *path,
+                                  pid_t pidleader,
+                                  int controllers,
+                                  virCgroupPtr *group)
 {
+    virCgroupPtr parent = NULL;
+    char *offset = path;
     int ret = -1;
-    int rv;
-    virCgroupPtr init, parent = NULL;
-    VIR_AUTOFREE(char *) path = NULL;
-    char *offset;
-
-    VIR_DEBUG("Trying to setup machine '%s' via systemd", name);
-    if ((rv = virSystemdCreateMachine(name,
-                                      drivername,
-                                      uuid,
-                                      rootdir,
-                                      pidleader,
-                                      isContainer,
-                                      nnicindexes,
-                                      nicindexes,
-                                      partition)) < 0)
-        return rv;
-
-    if (controllers != -1)
-        controllers |= (1 << VIR_CGROUP_CONTROLLER_SYSTEMD);
-
-    VIR_DEBUG("Detecting systemd placement");
-    if (virCgroupNewDetect(pidleader,
-                           controllers,
-                           &init) < 0)
-        return -1;
-
-    path = init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement;
-    init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement = NULL;
-    virCgroupFree(&init);
-
-    if (!path || STREQ(path, "/") || path[0] != '/') {
-        VIR_DEBUG("Systemd didn't setup its controller");
-        ret = -2;
-        goto cleanup;
-    }
-
-    offset = path;
 
     if (virCgroupNew(pidleader,
                      "",
                      NULL,
                      controllers,
                      &parent) < 0)
-        goto cleanup;
-
+        return ret;
 
     for (;;) {
         virCgroupPtr tmp;
@@ -1585,6 +1539,68 @@ virCgroupNewMachineSystemd(const char *name,
         }
     }
 
+    ret = 0;
+ cleanup:
+    virCgroupFree(&parent);
+    return ret;
+}
+
+
+/*
+ * Returns 0 on success, -1 on fatal error, -2 on systemd not available
+ */
+static int
+virCgroupNewMachineSystemd(const char *name,
+                           const char *drivername,
+                           const unsigned char *uuid,
+                           const char *rootdir,
+                           pid_t pidleader,
+                           bool isContainer,
+                           size_t nnicindexes,
+                           int *nicindexes,
+                           const char *partition,
+                           int controllers,
+                           virCgroupPtr *group)
+{
+    int rv;
+    virCgroupPtr init;
+    VIR_AUTOFREE(char *) path = NULL;
+
+    VIR_DEBUG("Trying to setup machine '%s' via systemd", name);
+    if ((rv = virSystemdCreateMachine(name,
+                                      drivername,
+                                      uuid,
+                                      rootdir,
+                                      pidleader,
+                                      isContainer,
+                                      nnicindexes,
+                                      nicindexes,
+                                      partition)) < 0)
+        return rv;
+
+    if (controllers != -1)
+        controllers |= (1 << VIR_CGROUP_CONTROLLER_SYSTEMD);
+
+    VIR_DEBUG("Detecting systemd placement");
+    if (virCgroupNewDetect(pidleader,
+                           controllers,
+                           &init) < 0)
+        return -1;
+
+    path = init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement;
+    init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement = NULL;
+    virCgroupFree(&init);
+
+    if (!path || STREQ(path, "/") || path[0] != '/') {
+        VIR_DEBUG("Systemd didn't setup its controller");
+        return -2;
+    }
+
+    if (virCgroupEnableMissingControllers(path, pidleader,
+                                          controllers, group) < 0) {
+        return -1;
+    }
+
     if (virCgroupAddTask(*group, pidleader) < 0) {
         virErrorPtr saved = virSaveLastError();
         virCgroupRemove(*group);
@@ -1595,10 +1611,7 @@ virCgroupNewMachineSystemd(const char *name,
         }
     }
 
-    ret = 0;
- cleanup:
-    virCgroupFree(&parent);
-    return ret;
+    return 0;
 }
 
 
-- 
2.22.0