render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 66611194a3195560a9aea899b9da724154a03609 Mon Sep 17 00:00:00 2001
Message-Id: <66611194a3195560a9aea899b9da724154a03609@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:34 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1PathOfController
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 57890b2ab49b27ca9dc8a3922fe61e586aca8f77)

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <0867ff8a5f46a8909e621bfb730942cfac3b2cdb.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroup.c        | 22 +---------------------
 src/util/vircgroupbackend.h |  7 +++++++
 src/util/vircgroupv1.c      | 31 +++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index a6f529accd..438d9b4e70 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1460,27 +1460,7 @@ virCgroupPathOfController(virCgroupPtr group,
         return -1;
     }
 
-    if (group->controllers[controller].mountPoint == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Controller '%s' is not mounted"),
-                       virCgroupControllerTypeToString(controller));
-        return -1;
-    }
-
-    if (group->controllers[controller].placement == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Controller '%s' is not enabled for group"),
-                       virCgroupControllerTypeToString(controller));
-        return -1;
-    }
-
-    if (virAsprintf(path, "%s%s/%s",
-                    group->controllers[controller].mountPoint,
-                    group->controllers[controller].placement,
-                    key ? key : "") < 0)
-        return -1;
-
-    return 0;
+    return group->backend->pathOfController(group, controller, key, path);
 }
 
 
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index b4eaa89021..916227ba6a 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -80,6 +80,12 @@ typedef bool
 typedef int
 (*virCgroupGetAnyControllerCB)(virCgroupPtr group);
 
+typedef int
+(*virCgroupPathOfControllerCB)(virCgroupPtr group,
+                               int controller,
+                               const char *key,
+                               char **path);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -95,6 +101,7 @@ struct _virCgroupBackend {
     virCgroupDetectControllersCB detectControllers;
     virCgroupHasControllerCB hasController;
     virCgroupGetAnyControllerCB getAnyController;
+    virCgroupPathOfControllerCB pathOfController;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index bae16b8294..a6302d71b1 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -507,6 +507,36 @@ virCgroupV1GetAnyController(virCgroupPtr group)
 }
 
 
+static int
+virCgroupV1PathOfController(virCgroupPtr group,
+                            int controller,
+                            const char *key,
+                            char **path)
+{
+    if (group->controllers[controller].mountPoint == NULL) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("v1 controller '%s' is not mounted"),
+                       virCgroupV1ControllerTypeToString(controller));
+        return -1;
+    }
+
+    if (group->controllers[controller].placement == NULL) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("v1 controller '%s' is not enabled for group"),
+                       virCgroupV1ControllerTypeToString(controller));
+        return -1;
+    }
+
+    if (virAsprintf(path, "%s%s/%s",
+                    group->controllers[controller].mountPoint,
+                    group->controllers[controller].placement,
+                    key ? key : "") < 0)
+        return -1;
+
+    return 0;
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -521,6 +551,7 @@ virCgroupBackend virCgroupV1Backend = {
     .detectControllers = virCgroupV1DetectControllers,
     .hasController = virCgroupV1HasController,
     .getAnyController = virCgroupV1GetAnyController,
+    .pathOfController = virCgroupV1PathOfController,
 };
 
 
-- 
2.22.0