c313de
From 931ae6bf56044020c057716e1db59288beca2bc8 Mon Sep 17 00:00:00 2001
c313de
Message-Id: <931ae6bf56044020c057716e1db59288beca2bc8@dist-git>
c313de
From: Pavel Hrdina <phrdina@redhat.com>
c313de
Date: Mon, 1 Jul 2019 17:06:05 +0200
c313de
Subject: [PATCH] vircgroup: Extract controller detection into function
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
(cherry picked from commit bddf975c7615a30da0709b6c1509b43440d72393)
c313de
c313de
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c313de
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
Message-Id: <484f007f9f43d727b829bb18fa4ad2f116a7fae1.1561993099.git.phrdina@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/util/vircgroup.c | 48 +++++++++++++++++++++++++++++---------------
c313de
 1 file changed, 32 insertions(+), 16 deletions(-)
c313de
c313de
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c313de
index 45b854e864..6f27c50cbd 100644
c313de
--- a/src/util/vircgroup.c
c313de
+++ b/src/util/vircgroup.c
c313de
@@ -631,24 +631,11 @@ virCgroupDetectPlacement(virCgroupPtr group,
c313de
 
c313de
 
c313de
 static int
c313de
-virCgroupDetect(virCgroupPtr group,
c313de
-                pid_t pid,
c313de
-                int controllers,
c313de
-                const char *path,
c313de
-                virCgroupPtr parent)
c313de
+virCgroupDetectControllers(virCgroupPtr group,
c313de
+                           int controllers)
c313de
 {
c313de
     size_t i;
c313de
     size_t j;
c313de
-    VIR_DEBUG("group=%p controllers=%d path=%s parent=%p",
c313de
-              group, controllers, path, parent);
c313de
-
c313de
-    if (parent) {
c313de
-        if (virCgroupCopyMounts(group, parent) < 0)
c313de
-            return -1;
c313de
-    } else {
c313de
-        if (virCgroupDetectMounts(group) < 0)
c313de
-            return -1;
c313de
-    }
c313de
 
c313de
     if (controllers >= 0) {
c313de
         VIR_DEBUG("Filtering controllers %d", controllers);
c313de
@@ -703,8 +690,37 @@ virCgroupDetect(virCgroupPtr group,
c313de
         }
c313de
     }
c313de
 
c313de
+    return controllers;
c313de
+}
c313de
+
c313de
+
c313de
+static int
c313de
+virCgroupDetect(virCgroupPtr group,
c313de
+                pid_t pid,
c313de
+                int controllers,
c313de
+                const char *path,
c313de
+                virCgroupPtr parent)
c313de
+{
c313de
+    size_t i;
c313de
+    int rc;
c313de
+
c313de
+    VIR_DEBUG("group=%p controllers=%d path=%s parent=%p",
c313de
+              group, controllers, path, parent);
c313de
+
c313de
+    if (parent) {
c313de
+        if (virCgroupCopyMounts(group, parent) < 0)
c313de
+            return -1;
c313de
+    } else {
c313de
+        if (virCgroupDetectMounts(group) < 0)
c313de
+            return -1;
c313de
+    }
c313de
+
c313de
+    rc = virCgroupDetectControllers(group, controllers);
c313de
+    if (rc < 0)
c313de
+        return -1;
c313de
+
c313de
     /* Check that at least 1 controller is available */
c313de
-    if (!controllers) {
c313de
+    if (rc == 0) {
c313de
         virReportSystemError(ENXIO, "%s",
c313de
                              _("At least one cgroup controller is required"));
c313de
         return -1;
c313de
-- 
c313de
2.22.0
c313de