render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
Pablo Greco 40546a
From c5ff4dbe89d9a57da51bb92389ebd9e5af4dd8dc Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <c5ff4dbe89d9a57da51bb92389ebd9e5af4dd8dc@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:06:31 +0200
Pablo Greco 40546a
Subject: [PATCH] vircgroup: extract virCgroupV1DetectControllers
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: Fabiano Fidêncio <fidencio@redhat.com>
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 d7f77dd6d5bcf91c3422a15842c2b7c2714510af)
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: <a066563f5d5183b6e09ae73cbfb3defb478bb693.1561993100.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        | 66 +------------------------------------
Pablo Greco 40546a
 src/util/vircgroupbackend.h |  5 +++
Pablo Greco 40546a
 src/util/vircgroupv1.c      | 65 ++++++++++++++++++++++++++++++++++++
Pablo Greco 40546a
 3 files changed, 71 insertions(+), 65 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
Pablo Greco 40546a
index 0e64ad67f4..2e74cbbff4 100644
Pablo Greco 40546a
--- a/src/util/vircgroup.c
Pablo Greco 40546a
+++ b/src/util/vircgroup.c
Pablo Greco 40546a
@@ -349,70 +349,6 @@ virCgroupDetectPlacement(virCgroupPtr group,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-static int
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
-
Pablo Greco 40546a
-    if (controllers >= 0) {
Pablo Greco 40546a
-        VIR_DEBUG("Filtering controllers %d", controllers);
Pablo Greco 40546a
-        /* First mark requested but non-existing controllers to be ignored */
Pablo Greco 40546a
-        for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
Pablo Greco 40546a
-            if (((1 << i) & controllers)) {
Pablo Greco 40546a
-                /* Remove non-existent controllers  */
Pablo Greco 40546a
-                if (!group->controllers[i].mountPoint) {
Pablo Greco 40546a
-                    VIR_DEBUG("Requested controller '%s' not mounted, ignoring",
Pablo Greco 40546a
-                              virCgroupControllerTypeToString(i));
Pablo Greco 40546a
-                    controllers &= ~(1 << i);
Pablo Greco 40546a
-                }
Pablo Greco 40546a
-            }
Pablo Greco 40546a
-        }
Pablo Greco 40546a
-        for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
Pablo Greco 40546a
-            VIR_DEBUG("Controller '%s' wanted=%s, mount='%s'",
Pablo Greco 40546a
-                      virCgroupControllerTypeToString(i),
Pablo Greco 40546a
-                      (1 << i) & controllers ? "yes" : "no",
Pablo Greco 40546a
-                      NULLSTR(group->controllers[i].mountPoint));
Pablo Greco 40546a
-            if (!((1 << i) & controllers) &&
Pablo Greco 40546a
-                group->controllers[i].mountPoint) {
Pablo Greco 40546a
-                /* Check whether a request to disable a controller
Pablo Greco 40546a
-                 * clashes with co-mounting of controllers */
Pablo Greco 40546a
-                for (j = 0; j < VIR_CGROUP_CONTROLLER_LAST; j++) {
Pablo Greco 40546a
-                    if (j == i)
Pablo Greco 40546a
-                        continue;
Pablo Greco 40546a
-                    if (!((1 << j) & controllers))
Pablo Greco 40546a
-                        continue;
Pablo Greco 40546a
-
Pablo Greco 40546a
-                    if (STREQ_NULLABLE(group->controllers[i].mountPoint,
Pablo Greco 40546a
-                                       group->controllers[j].mountPoint)) {
Pablo Greco 40546a
-                        virReportSystemError(EINVAL,
Pablo Greco 40546a
-                                             _("Controller '%s' is not wanted, but '%s' is co-mounted"),
Pablo Greco 40546a
-                                             virCgroupControllerTypeToString(i),
Pablo Greco 40546a
-                                             virCgroupControllerTypeToString(j));
Pablo Greco 40546a
-                        return -1;
Pablo Greco 40546a
-                    }
Pablo Greco 40546a
-                }
Pablo Greco 40546a
-                VIR_FREE(group->controllers[i].mountPoint);
Pablo Greco 40546a
-            }
Pablo Greco 40546a
-        }
Pablo Greco 40546a
-    } else {
Pablo Greco 40546a
-        VIR_DEBUG("Auto-detecting controllers");
Pablo Greco 40546a
-        controllers = 0;
Pablo Greco 40546a
-        for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
Pablo Greco 40546a
-            VIR_DEBUG("Controller '%s' present=%s",
Pablo Greco 40546a
-                      virCgroupControllerTypeToString(i),
Pablo Greco 40546a
-                      group->controllers[i].mountPoint ? "yes" : "no");
Pablo Greco 40546a
-            if (group->controllers[i].mountPoint == NULL)
Pablo Greco 40546a
-                continue;
Pablo Greco 40546a
-            controllers |= (1 << i);
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
@@ -451,7 +387,7 @@ virCgroupDetect(virCgroupPtr group,
Pablo Greco 40546a
             return -1;
Pablo Greco 40546a
     }
Pablo Greco 40546a
 
Pablo Greco 40546a
-    rc = virCgroupDetectControllers(group, controllers);
Pablo Greco 40546a
+    rc = group->backend->detectControllers(group, controllers);
Pablo Greco 40546a
     if (rc < 0)
Pablo Greco 40546a
         return -1;
Pablo Greco 40546a
 
Pablo Greco 40546a
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
Pablo Greco 40546a
index 9c0bd89793..011d1b00da 100644
Pablo Greco 40546a
--- a/src/util/vircgroupbackend.h
Pablo Greco 40546a
+++ b/src/util/vircgroupbackend.h
Pablo Greco 40546a
@@ -69,6 +69,10 @@ typedef int
Pablo Greco 40546a
 typedef char *
Pablo Greco 40546a
 (*virCgroupStealPlacementCB)(virCgroupPtr group);
Pablo Greco 40546a
 
Pablo Greco 40546a
+typedef int
Pablo Greco 40546a
+(*virCgroupDetectControllersCB)(virCgroupPtr group,
Pablo Greco 40546a
+                                int controllers);
Pablo Greco 40546a
+
Pablo Greco 40546a
 struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupBackendType type;
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -81,6 +85,7 @@ struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupDetectPlacementCB detectPlacement;
Pablo Greco 40546a
     virCgroupValidatePlacementCB validatePlacement;
Pablo Greco 40546a
     virCgroupStealPlacementCB stealPlacement;
Pablo Greco 40546a
+    virCgroupDetectControllersCB detectControllers;
Pablo Greco 40546a
 };
Pablo Greco 40546a
 typedef struct _virCgroupBackend virCgroupBackend;
Pablo Greco 40546a
 typedef virCgroupBackend *virCgroupBackendPtr;
Pablo Greco 40546a
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
Pablo Greco 40546a
index 446546fd58..11a86c061a 100644
Pablo Greco 40546a
--- a/src/util/vircgroupv1.c
Pablo Greco 40546a
+++ b/src/util/vircgroupv1.c
Pablo Greco 40546a
@@ -414,6 +414,70 @@ virCgroupV1StealPlacement(virCgroupPtr group)
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1DetectControllers(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
+
Pablo Greco 40546a
+    if (controllers >= 0) {
Pablo Greco 40546a
+        VIR_DEBUG("Filtering controllers %d", controllers);
Pablo Greco 40546a
+        /* First mark requested but non-existing controllers to be ignored */
Pablo Greco 40546a
+        for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
Pablo Greco 40546a
+            if (((1 << i) & controllers)) {
Pablo Greco 40546a
+                /* Remove non-existent controllers  */
Pablo Greco 40546a
+                if (!group->controllers[i].mountPoint) {
Pablo Greco 40546a
+                    VIR_DEBUG("Requested controller '%s' not mounted, ignoring",
Pablo Greco 40546a
+                              virCgroupV1ControllerTypeToString(i));
Pablo Greco 40546a
+                    controllers &= ~(1 << i);
Pablo Greco 40546a
+                }
Pablo Greco 40546a
+            }
Pablo Greco 40546a
+        }
Pablo Greco 40546a
+        for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
Pablo Greco 40546a
+            VIR_DEBUG("Controller '%s' wanted=%s, mount='%s'",
Pablo Greco 40546a
+                      virCgroupV1ControllerTypeToString(i),
Pablo Greco 40546a
+                      (1 << i) & controllers ? "yes" : "no",
Pablo Greco 40546a
+                      NULLSTR(group->controllers[i].mountPoint));
Pablo Greco 40546a
+            if (!((1 << i) & controllers) &&
Pablo Greco 40546a
+                group->controllers[i].mountPoint) {
Pablo Greco 40546a
+                /* Check whether a request to disable a controller
Pablo Greco 40546a
+                 * clashes with co-mounting of controllers */
Pablo Greco 40546a
+                for (j = 0; j < VIR_CGROUP_CONTROLLER_LAST; j++) {
Pablo Greco 40546a
+                    if (j == i)
Pablo Greco 40546a
+                        continue;
Pablo Greco 40546a
+                    if (!((1 << j) & controllers))
Pablo Greco 40546a
+                        continue;
Pablo Greco 40546a
+
Pablo Greco 40546a
+                    if (STREQ_NULLABLE(group->controllers[i].mountPoint,
Pablo Greco 40546a
+                                       group->controllers[j].mountPoint)) {
Pablo Greco 40546a
+                        virReportSystemError(EINVAL,
Pablo Greco 40546a
+                                             _("V1 controller '%s' is not wanted, but '%s' is co-mounted"),
Pablo Greco 40546a
+                                             virCgroupV1ControllerTypeToString(i),
Pablo Greco 40546a
+                                             virCgroupV1ControllerTypeToString(j));
Pablo Greco 40546a
+                        return -1;
Pablo Greco 40546a
+                    }
Pablo Greco 40546a
+                }
Pablo Greco 40546a
+                VIR_FREE(group->controllers[i].mountPoint);
Pablo Greco 40546a
+            }
Pablo Greco 40546a
+        }
Pablo Greco 40546a
+    } else {
Pablo Greco 40546a
+        VIR_DEBUG("Auto-detecting controllers");
Pablo Greco 40546a
+        controllers = 0;
Pablo Greco 40546a
+        for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
Pablo Greco 40546a
+            VIR_DEBUG("Controller '%s' present=%s",
Pablo Greco 40546a
+                      virCgroupV1ControllerTypeToString(i),
Pablo Greco 40546a
+                      group->controllers[i].mountPoint ? "yes" : "no");
Pablo Greco 40546a
+            if (group->controllers[i].mountPoint == NULL)
Pablo Greco 40546a
+                continue;
Pablo Greco 40546a
+            controllers |= (1 << i);
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
 virCgroupBackend virCgroupV1Backend = {
Pablo Greco 40546a
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -425,6 +489,7 @@ virCgroupBackend virCgroupV1Backend = {
Pablo Greco 40546a
     .detectPlacement = virCgroupV1DetectPlacement,
Pablo Greco 40546a
     .validatePlacement = virCgroupV1ValidatePlacement,
Pablo Greco 40546a
     .stealPlacement = virCgroupV1StealPlacement,
Pablo Greco 40546a
+    .detectControllers = virCgroupV1DetectControllers,
Pablo Greco 40546a
 };
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a