Pablo Greco 40546a
From 66611194a3195560a9aea899b9da724154a03609 Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <66611194a3195560a9aea899b9da724154a03609@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:06:34 +0200
Pablo Greco 40546a
Subject: [PATCH] vircgroup: extract virCgroupV1PathOfController
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 57890b2ab49b27ca9dc8a3922fe61e586aca8f77)
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: <0867ff8a5f46a8909e621bfb730942cfac3b2cdb.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        | 22 +---------------------
Pablo Greco 40546a
 src/util/vircgroupbackend.h |  7 +++++++
Pablo Greco 40546a
 src/util/vircgroupv1.c      | 31 +++++++++++++++++++++++++++++++
Pablo Greco 40546a
 3 files changed, 39 insertions(+), 21 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
Pablo Greco 40546a
index a6f529accd..438d9b4e70 100644
Pablo Greco 40546a
--- a/src/util/vircgroup.c
Pablo Greco 40546a
+++ b/src/util/vircgroup.c
Pablo Greco 40546a
@@ -1460,27 +1460,7 @@ virCgroupPathOfController(virCgroupPtr group,
Pablo Greco 40546a
         return -1;
Pablo Greco 40546a
     }
Pablo Greco 40546a
 
Pablo Greco 40546a
-    if (group->controllers[controller].mountPoint == NULL) {
Pablo Greco 40546a
-        virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
-                       _("Controller '%s' is not mounted"),
Pablo Greco 40546a
-                       virCgroupControllerTypeToString(controller));
Pablo Greco 40546a
-        return -1;
Pablo Greco 40546a
-    }
Pablo Greco 40546a
-
Pablo Greco 40546a
-    if (group->controllers[controller].placement == NULL) {
Pablo Greco 40546a
-        virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
-                       _("Controller '%s' is not enabled for group"),
Pablo Greco 40546a
-                       virCgroupControllerTypeToString(controller));
Pablo Greco 40546a
-        return -1;
Pablo Greco 40546a
-    }
Pablo Greco 40546a
-
Pablo Greco 40546a
-    if (virAsprintf(path, "%s%s/%s",
Pablo Greco 40546a
-                    group->controllers[controller].mountPoint,
Pablo Greco 40546a
-                    group->controllers[controller].placement,
Pablo Greco 40546a
-                    key ? key : "") < 0)
Pablo Greco 40546a
-        return -1;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    return 0;
Pablo Greco 40546a
+    return group->backend->pathOfController(group, controller, key, path);
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
Pablo Greco 40546a
index b4eaa89021..916227ba6a 100644
Pablo Greco 40546a
--- a/src/util/vircgroupbackend.h
Pablo Greco 40546a
+++ b/src/util/vircgroupbackend.h
Pablo Greco 40546a
@@ -80,6 +80,12 @@ typedef bool
Pablo Greco 40546a
 typedef int
Pablo Greco 40546a
 (*virCgroupGetAnyControllerCB)(virCgroupPtr group);
Pablo Greco 40546a
 
Pablo Greco 40546a
+typedef int
Pablo Greco 40546a
+(*virCgroupPathOfControllerCB)(virCgroupPtr group,
Pablo Greco 40546a
+                               int controller,
Pablo Greco 40546a
+                               const char *key,
Pablo Greco 40546a
+                               char **path);
Pablo Greco 40546a
+
Pablo Greco 40546a
 struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupBackendType type;
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -95,6 +101,7 @@ struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupDetectControllersCB detectControllers;
Pablo Greco 40546a
     virCgroupHasControllerCB hasController;
Pablo Greco 40546a
     virCgroupGetAnyControllerCB getAnyController;
Pablo Greco 40546a
+    virCgroupPathOfControllerCB pathOfController;
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 bae16b8294..a6302d71b1 100644
Pablo Greco 40546a
--- a/src/util/vircgroupv1.c
Pablo Greco 40546a
+++ b/src/util/vircgroupv1.c
Pablo Greco 40546a
@@ -507,6 +507,36 @@ virCgroupV1GetAnyController(virCgroupPtr group)
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1PathOfController(virCgroupPtr group,
Pablo Greco 40546a
+                            int controller,
Pablo Greco 40546a
+                            const char *key,
Pablo Greco 40546a
+                            char **path)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    if (group->controllers[controller].mountPoint == NULL) {
Pablo Greco 40546a
+        virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
+                       _("v1 controller '%s' is not mounted"),
Pablo Greco 40546a
+                       virCgroupV1ControllerTypeToString(controller));
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (group->controllers[controller].placement == NULL) {
Pablo Greco 40546a
+        virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
+                       _("v1 controller '%s' is not enabled for group"),
Pablo Greco 40546a
+                       virCgroupV1ControllerTypeToString(controller));
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (virAsprintf(path, "%s%s/%s",
Pablo Greco 40546a
+                    group->controllers[controller].mountPoint,
Pablo Greco 40546a
+                    group->controllers[controller].placement,
Pablo Greco 40546a
+                    key ? key : "") < 0)
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return 0;
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
@@ -521,6 +551,7 @@ virCgroupBackend virCgroupV1Backend = {
Pablo Greco 40546a
     .detectControllers = virCgroupV1DetectControllers,
Pablo Greco 40546a
     .hasController = virCgroupV1HasController,
Pablo Greco 40546a
     .getAnyController = virCgroupV1GetAnyController,
Pablo Greco 40546a
+    .pathOfController = virCgroupV1PathOfController,
Pablo Greco 40546a
 };
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a