[libvirt PATCH 12/25] vircgroup: introduce virCgroupDetectControllers helper

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

 



Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/util/vircgroup.c | 51 ++++++++++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 18 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 55fa49a398..f21a581946 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -410,6 +410,38 @@ virCgroupValidatePlacement(virCgroupPtr group,
 }
 
 
+static int
+virCgroupDetectControllers(virCgroupPtr group,
+                           int controllers,
+                           virCgroupPtr parent)
+{
+    size_t i;
+    int controllersAvailable = 0;
+
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
+        int rc;
+
+        if (!group->backends[i])
+            continue;
+
+        rc = group->backends[i]->detectControllers(group, controllers, parent,
+                                                   controllersAvailable);
+        if (rc < 0)
+            return -1;
+        controllersAvailable |= rc;
+    }
+
+    /* Check that at least 1 controller is available */
+    if (controllersAvailable == 0) {
+        virReportSystemError(ENXIO, "%s",
+                             _("At least one cgroup controller is required"));
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 virCgroupDetect(virCgroupPtr group,
                 pid_t pid,
@@ -417,9 +449,6 @@ virCgroupDetect(virCgroupPtr group,
                 const char *path,
                 virCgroupPtr parent)
 {
-    size_t i;
-    int controllersAvailable = 0;
-
     VIR_DEBUG("group=%p controllers=%d path=%s parent=%p",
               group, controllers, path, parent);
 
@@ -450,22 +479,8 @@ virCgroupDetect(virCgroupPtr group,
     if (virCgroupValidatePlacement(group, pid) < 0)
         return -1;
 
-    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
-        if (group->backends[i]) {
-            int rc = group->backends[i]->detectControllers(group, controllers, parent,
-                                                           controllersAvailable);
-            if (rc < 0)
-                return -1;
-            controllersAvailable |= rc;
-        }
-    }
-
-    /* Check that at least 1 controller is available */
-    if (controllersAvailable == 0) {
-        virReportSystemError(ENXIO, "%s",
-                             _("At least one cgroup controller is required"));
+    if (virCgroupDetectControllers(group, controllers, parent) < 0)
         return -1;
-    }
 
     return 0;
 }
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux