render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 931ae6bf56044020c057716e1db59288beca2bc8 Mon Sep 17 00:00:00 2001
Message-Id: <931ae6bf56044020c057716e1db59288beca2bc8@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:05 +0200
Subject: [PATCH] vircgroup: Extract controller detection into function
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit bddf975c7615a30da0709b6c1509b43440d72393)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <484f007f9f43d727b829bb18fa4ad2f116a7fae1.1561993099.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroup.c | 48 +++++++++++++++++++++++++++++---------------
 1 file changed, 32 insertions(+), 16 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 45b854e864..6f27c50cbd 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -631,24 +631,11 @@ virCgroupDetectPlacement(virCgroupPtr group,
 
 
 static int
-virCgroupDetect(virCgroupPtr group,
-                pid_t pid,
-                int controllers,
-                const char *path,
-                virCgroupPtr parent)
+virCgroupDetectControllers(virCgroupPtr group,
+                           int controllers)
 {
     size_t i;
     size_t j;
-    VIR_DEBUG("group=%p controllers=%d path=%s parent=%p",
-              group, controllers, path, parent);
-
-    if (parent) {
-        if (virCgroupCopyMounts(group, parent) < 0)
-            return -1;
-    } else {
-        if (virCgroupDetectMounts(group) < 0)
-            return -1;
-    }
 
     if (controllers >= 0) {
         VIR_DEBUG("Filtering controllers %d", controllers);
@@ -703,8 +690,37 @@ virCgroupDetect(virCgroupPtr group,
         }
     }
 
+    return controllers;
+}
+
+
+static int
+virCgroupDetect(virCgroupPtr group,
+                pid_t pid,
+                int controllers,
+                const char *path,
+                virCgroupPtr parent)
+{
+    size_t i;
+    int rc;
+
+    VIR_DEBUG("group=%p controllers=%d path=%s parent=%p",
+              group, controllers, path, parent);
+
+    if (parent) {
+        if (virCgroupCopyMounts(group, parent) < 0)
+            return -1;
+    } else {
+        if (virCgroupDetectMounts(group) < 0)
+            return -1;
+    }
+
+    rc = virCgroupDetectControllers(group, controllers);
+    if (rc < 0)
+        return -1;
+
     /* Check that at least 1 controller is available */
-    if (!controllers) {
+    if (rc == 0) {
         virReportSystemError(ENXIO, "%s",
                              _("At least one cgroup controller is required"));
         return -1;
-- 
2.22.0