render / rpms / libvirt

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