render / rpms / libvirt

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

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit b549a66edf46ced7c2b922408f3c7cdad2539e0b)

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <0fac794a48f75788ccfab8614ac8e7f051df2719.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroup.c        | 32 +-------------------------------
 src/util/vircgroupbackend.h |  5 +++++
 src/util/vircgroupv1.c      | 31 +++++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index b63321ca33..b17a1dcbb7 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -349,36 +349,6 @@ virCgroupDetectPlacement(virCgroupPtr group,
 }
 
 
-static int
-virCgroupValidatePlacement(virCgroupPtr group,
-                           pid_t pid)
-{
-    size_t i;
-
-    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
-        if (!group->controllers[i].mountPoint)
-            continue;
-
-        if (!group->controllers[i].placement) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Could not find placement for controller %s at %s"),
-                           virCgroupControllerTypeToString(i),
-                           group->controllers[i].placement);
-            return -1;
-        }
-
-        VIR_DEBUG("Detected mount/mapping %zu:%s at %s in %s for pid %lld",
-                  i,
-                  virCgroupControllerTypeToString(i),
-                  group->controllers[i].mountPoint,
-                  group->controllers[i].placement,
-                  (long long) pid);
-    }
-
-    return 0;
-}
-
-
 static int
 virCgroupDetectControllers(virCgroupPtr group,
                            int controllers)
@@ -504,7 +474,7 @@ virCgroupDetect(virCgroupPtr group,
         return -1;
 
     /* Check that for every mounted controller, we found our placement */
-    if (virCgroupValidatePlacement(group, pid) < 0)
+    if (group->backend->validatePlacement(group, pid) < 0)
         return -1;
 
     return 0;
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 85906e7191..086cfb8090 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -62,6 +62,10 @@ typedef int
                               const char *controllers,
                               const char *selfpath);
 
+typedef int
+(*virCgroupValidatePlacementCB)(virCgroupPtr group,
+                                pid_t pid);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -72,6 +76,7 @@ struct _virCgroupBackend {
     virCgroupCopyPlacementCB copyPlacement;
     virCgroupDetectMountsCB detectMounts;
     virCgroupDetectPlacementCB detectPlacement;
+    virCgroupValidatePlacementCB validatePlacement;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 68bb1c6f5d..2c905a832a 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -373,6 +373,36 @@ virCgroupV1DetectPlacement(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV1ValidatePlacement(virCgroupPtr group,
+                             pid_t pid)
+{
+    size_t i;
+
+    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+        if (!group->controllers[i].mountPoint)
+            continue;
+
+        if (!group->controllers[i].placement) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Could not find placement for v1 controller %s at %s"),
+                           virCgroupV1ControllerTypeToString(i),
+                           group->controllers[i].placement);
+            return -1;
+        }
+
+        VIR_DEBUG("Detected mount/mapping %zu:%s at %s in %s for pid %lld",
+                  i,
+                  virCgroupV1ControllerTypeToString(i),
+                  group->controllers[i].mountPoint,
+                  group->controllers[i].placement,
+                  (long long) pid);
+    }
+
+    return 0;
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -382,6 +412,7 @@ virCgroupBackend virCgroupV1Backend = {
     .copyPlacement = virCgroupV1CopyPlacement,
     .detectMounts = virCgroupV1DetectMounts,
     .detectPlacement = virCgroupV1DetectPlacement,
+    .validatePlacement = virCgroupV1ValidatePlacement,
 };
 
 
-- 
2.22.0