render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From 489202ad9fe2dd9e417335c7274ba522adfc490b Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <489202ad9fe2dd9e417335c7274ba522adfc490b@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:06 +0200
c480ed
Subject: [PATCH] vircgroup: Extract placement validation into function
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit 3ae7b99094dc72616f902289afc407df738c9ce9)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <5728512c8e969952c0502fb4119f2930ae4bc49c.1561993099.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c | 52 +++++++++++++++++++++++++++-----------------
c480ed
 1 file changed, 32 insertions(+), 20 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index 6f27c50cbd..2bc4febf23 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -630,6 +630,36 @@ virCgroupDetectPlacement(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupValidatePlacement(virCgroupPtr group,
c480ed
+                           pid_t pid)
c480ed
+{
c480ed
+    size_t i;
c480ed
+
c480ed
+    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
c480ed
+        if (!group->controllers[i].mountPoint)
c480ed
+            continue;
c480ed
+
c480ed
+        if (!group->controllers[i].placement) {
c480ed
+            virReportError(VIR_ERR_INTERNAL_ERROR,
c480ed
+                           _("Could not find placement for controller %s at %s"),
c480ed
+                           virCgroupControllerTypeToString(i),
c480ed
+                           group->controllers[i].placement);
c480ed
+            return -1;
c480ed
+        }
c480ed
+
c480ed
+        VIR_DEBUG("Detected mount/mapping %zu:%s at %s in %s for pid %lld",
c480ed
+                  i,
c480ed
+                  virCgroupControllerTypeToString(i),
c480ed
+                  group->controllers[i].mountPoint,
c480ed
+                  group->controllers[i].placement,
c480ed
+                  (long long) pid);
c480ed
+    }
c480ed
+
c480ed
+    return 0;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 static int
c480ed
 virCgroupDetectControllers(virCgroupPtr group,
c480ed
                            int controllers)
c480ed
@@ -701,7 +731,6 @@ virCgroupDetect(virCgroupPtr group,
c480ed
                 const char *path,
c480ed
                 virCgroupPtr parent)
c480ed
 {
c480ed
-    size_t i;
c480ed
     int rc;
c480ed
 
c480ed
     VIR_DEBUG("group=%p controllers=%d path=%s parent=%p",
c480ed
@@ -738,25 +767,8 @@ virCgroupDetect(virCgroupPtr group,
c480ed
         return -1;
c480ed
 
c480ed
     /* Check that for every mounted controller, we found our placement */
c480ed
-    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
c480ed
-        if (!group->controllers[i].mountPoint)
c480ed
-            continue;
c480ed
-
c480ed
-        if (!group->controllers[i].placement) {
c480ed
-            virReportError(VIR_ERR_INTERNAL_ERROR,
c480ed
-                           _("Could not find placement for controller %s at %s"),
c480ed
-                           virCgroupControllerTypeToString(i),
c480ed
-                           group->controllers[i].placement);
c480ed
-            return -1;
c480ed
-        }
c480ed
-
c480ed
-        VIR_DEBUG("Detected mount/mapping %zu:%s at %s in %s for pid %lld",
c480ed
-                  i,
c480ed
-                  virCgroupControllerTypeToString(i),
c480ed
-                  group->controllers[i].mountPoint,
c480ed
-                  group->controllers[i].placement,
c480ed
-                  (long long) pid);
c480ed
-    }
c480ed
+    if (virCgroupValidatePlacement(group, pid) < 0)
c480ed
+        return -1;
c480ed
 
c480ed
     return 0;
c480ed
 }
c480ed
-- 
c480ed
2.22.0
c480ed