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

[libvirt] [PATCH 13/17] vircgroup: Introduce virCgroupEnableMissingControllers



Signed-off-by: Pavel Hrdina <phrdina redhat com>
---
 src/util/vircgroup.c | 103 ++++++++++++++++++++++++-------------------
 1 file changed, 58 insertions(+), 45 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 45fe2595d1..99cbdaa59b 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1494,6 +1494,58 @@ virCgroupNewDetectMachine(const char *name,
 }
 
 
+static int
+virCgroupEnableMissingControllers(char *path,
+                                  pid_t pidleader,
+                                  int controllers,
+                                  virCgroupPtr *group)
+{
+    virCgroupPtr parent = NULL;
+    char *offset = path;
+    int ret = -1;
+
+    if (virCgroupNew(pidleader,
+                     "",
+                     NULL,
+                     controllers,
+                     &parent) < 0)
+        return ret;
+
+    for (;;) {
+        virCgroupPtr tmp;
+        char *t = strchr(offset + 1, '/');
+        if (t)
+            *t = '\0';
+
+        if (virCgroupNew(pidleader,
+                         path,
+                         parent,
+                         controllers,
+                         &tmp) < 0)
+            goto cleanup;
+
+        if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_NONE) < 0) {
+            virCgroupFree(&tmp);
+            goto cleanup;
+        }
+        if (t) {
+            *t = '/';
+            offset = t;
+            virCgroupFree(&parent);
+            parent = tmp;
+        } else {
+            *group = tmp;
+            break;
+        }
+    }
+
+    ret = 0;
+ cleanup:
+    virCgroupFree(&parent);
+    return ret;
+}
+
+
 /*
  * Returns 0 on success, -1 on fatal error, -2 on systemd not available
  */
@@ -1510,11 +1562,9 @@ virCgroupNewMachineSystemd(const char *name,
                            int controllers,
                            virCgroupPtr *group)
 {
-    int ret = -1;
     int rv;
-    virCgroupPtr init, parent = NULL;
+    virCgroupPtr init;
     VIR_AUTOFREE(char *) path = NULL;
-    char *offset;
 
     VIR_DEBUG("Trying to setup machine '%s' via systemd", name);
     if ((rv = virSystemdCreateMachine(name,
@@ -1543,46 +1593,12 @@ virCgroupNewMachineSystemd(const char *name,
 
     if (!path || STREQ(path, "/") || path[0] != '/') {
         VIR_DEBUG("Systemd didn't setup its controller");
-        ret = -2;
-        goto cleanup;
+        return -2;
     }
 
-    offset = path;
-
-    if (virCgroupNew(pidleader,
-                     "",
-                     NULL,
-                     controllers,
-                     &parent) < 0)
-        goto cleanup;
-
-
-    for (;;) {
-        virCgroupPtr tmp;
-        char *t = strchr(offset + 1, '/');
-        if (t)
-            *t = '\0';
-
-        if (virCgroupNew(pidleader,
-                         path,
-                         parent,
-                         controllers,
-                         &tmp) < 0)
-            goto cleanup;
-
-        if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_NONE) < 0) {
-            virCgroupFree(&tmp);
-            goto cleanup;
-        }
-        if (t) {
-            *t = '/';
-            offset = t;
-            virCgroupFree(&parent);
-            parent = tmp;
-        } else {
-            *group = tmp;
-            break;
-        }
+    if (virCgroupEnableMissingControllers(path, pidleader,
+                                          controllers, group) < 0) {
+        return -1;
     }
 
     if (virCgroupAddTask(*group, pidleader) < 0) {
@@ -1595,10 +1611,7 @@ virCgroupNewMachineSystemd(const char *name,
         }
     }
 
-    ret = 0;
- cleanup:
-    virCgroupFree(&parent);
-    return ret;
+    return 0;
 }
 
 
-- 
2.17.1


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