render / rpms / libvirt

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