render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From a4fad1d74b1af03d7bd89d4ef1bc1be4d7c9feca Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <a4fad1d74b1af03d7bd89d4ef1bc1be4d7c9feca@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:29 +0200
c480ed
Subject: [PATCH] vircgroup: extract virCgroupV1ValidatePlacement
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit b549a66edf46ced7c2b922408f3c7cdad2539e0b)
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: <0fac794a48f75788ccfab8614ac8e7f051df2719.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c        | 32 +-------------------------------
c480ed
 src/util/vircgroupbackend.h |  5 +++++
c480ed
 src/util/vircgroupv1.c      | 31 +++++++++++++++++++++++++++++++
c480ed
 3 files changed, 37 insertions(+), 31 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index b63321ca33..b17a1dcbb7 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -349,36 +349,6 @@ 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
@@ -504,7 +474,7 @@ virCgroupDetect(virCgroupPtr group,
c480ed
         return -1;
c480ed
 
c480ed
     /* Check that for every mounted controller, we found our placement */
c480ed
-    if (virCgroupValidatePlacement(group, pid) < 0)
c480ed
+    if (group->backend->validatePlacement(group, pid) < 0)
c480ed
         return -1;
c480ed
 
c480ed
     return 0;
c480ed
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c480ed
index 85906e7191..086cfb8090 100644
c480ed
--- a/src/util/vircgroupbackend.h
c480ed
+++ b/src/util/vircgroupbackend.h
c480ed
@@ -62,6 +62,10 @@ typedef int
c480ed
                               const char *controllers,
c480ed
                               const char *selfpath);
c480ed
 
c480ed
+typedef int
c480ed
+(*virCgroupValidatePlacementCB)(virCgroupPtr group,
c480ed
+                                pid_t pid);
c480ed
+
c480ed
 struct _virCgroupBackend {
c480ed
     virCgroupBackendType type;
c480ed
 
c480ed
@@ -72,6 +76,7 @@ struct _virCgroupBackend {
c480ed
     virCgroupCopyPlacementCB copyPlacement;
c480ed
     virCgroupDetectMountsCB detectMounts;
c480ed
     virCgroupDetectPlacementCB detectPlacement;
c480ed
+    virCgroupValidatePlacementCB validatePlacement;
c480ed
 };
c480ed
 typedef struct _virCgroupBackend virCgroupBackend;
c480ed
 typedef virCgroupBackend *virCgroupBackendPtr;
c480ed
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c480ed
index 68bb1c6f5d..2c905a832a 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -373,6 +373,36 @@ virCgroupV1DetectPlacement(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV1ValidatePlacement(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 v1 controller %s at %s"),
c480ed
+                           virCgroupV1ControllerTypeToString(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
+                  virCgroupV1ControllerTypeToString(i),
c480ed
+                  group->controllers[i].mountPoint,
c480ed
+                  group->controllers[i].placement,
c480ed
+                  (long long) pid);
c480ed
+    }
c480ed
+
c480ed
+    return 0;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV1Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
c480ed
 
c480ed
@@ -382,6 +412,7 @@ virCgroupBackend virCgroupV1Backend = {
c480ed
     .copyPlacement = virCgroupV1CopyPlacement,
c480ed
     .detectMounts = virCgroupV1DetectMounts,
c480ed
     .detectPlacement = virCgroupV1DetectPlacement,
c480ed
+    .validatePlacement = virCgroupV1ValidatePlacement,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed