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

[libvirt] [PATCH 3/7] vircgroup: Extract placement validation into function



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

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 6f27c50cbd..2bc4febf23 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -630,6 +630,36 @@ virCgroupDetectPlacement(virCgroupPtr group,
 }
 
 
+static int
+virCgroupValidatePlacement(virCgroupPtr group,
+                           pid_t pid)
+{
+    size_t i;
+
+    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+        if (!group->controllers[i].mountPoint)
+            continue;
+
+        if (!group->controllers[i].placement) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Could not find placement for controller %s at %s"),
+                           virCgroupControllerTypeToString(i),
+                           group->controllers[i].placement);
+            return -1;
+        }
+
+        VIR_DEBUG("Detected mount/mapping %zu:%s at %s in %s for pid %lld",
+                  i,
+                  virCgroupControllerTypeToString(i),
+                  group->controllers[i].mountPoint,
+                  group->controllers[i].placement,
+                  (long long) pid);
+    }
+
+    return 0;
+}
+
+
 static int
 virCgroupDetectControllers(virCgroupPtr group,
                            int controllers)
@@ -701,7 +731,6 @@ virCgroupDetect(virCgroupPtr group,
                 const char *path,
                 virCgroupPtr parent)
 {
-    size_t i;
     int rc;
 
     VIR_DEBUG("group=%p controllers=%d path=%s parent=%p",
@@ -738,25 +767,8 @@ virCgroupDetect(virCgroupPtr group,
         return -1;
 
     /* Check that for every mounted controller, we found our placement */
-    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
-        if (!group->controllers[i].mountPoint)
-            continue;
-
-        if (!group->controllers[i].placement) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Could not find placement for controller %s at %s"),
-                           virCgroupControllerTypeToString(i),
-                           group->controllers[i].placement);
-            return -1;
-        }
-
-        VIR_DEBUG("Detected mount/mapping %zu:%s at %s in %s for pid %lld",
-                  i,
-                  virCgroupControllerTypeToString(i),
-                  group->controllers[i].mountPoint,
-                  group->controllers[i].placement,
-                  (long long) pid);
-    }
+    if (virCgroupValidatePlacement(group, pid) < 0)
+        return -1;
 
     return 0;
 }
-- 
2.17.1


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