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