On Tue, Sep 18, 2018 at 5:45 PM, Pavel Hrdina <phrdina@redhat.com> wrote:
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
 
---
 src/util/vircgroup.c        | 16 ++++------------
 src/util/vircgroupbackend.h |  4 ++++
 src/util/vircgroupv1.c      | 22 ++++++++++++++++++++++
 3 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 3d10ac2427..817ee8f6ca 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -3167,19 +3167,11 @@ virCgroupPathOfAnyController(virCgroupPtr group,
                              const char *name,
                              char **keypath)
 {
-    size_t i;
+    int controller;

-    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
-        /* Reject any controller with a placement
-         * of '/' to avoid doing bad stuff to the root
-         * cgroup
-         */
-        if (group->controllers[i].mountPoint &&
-            group->controllers[i].placement &&
-            STRNEQ(group->controllers[i].placement, "/")) {
-            return virCgroupPathOfController(group, i, name, keypath);
-        }
-    }
+    controller = group->backend->getAnyController(group);
+    if (controller >= 0)
+        return virCgroupPathOfController(group, controller, name, keypath);

     virReportSystemError(ENOSYS, "%s",
                          _("No controllers are mounted"));
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 8b751af355..933f59151a 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -77,6 +77,9 @@ typedef bool
 (*virCgroupHasControllerCB)(virCgroupPtr cgroup,
                             int controller);

+typedef int
+(*virCgroupGetAnyControllerCB)(virCgroupPtr group);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;

@@ -91,6 +94,7 @@ struct _virCgroupBackend {
     virCgroupGetPlacementCB getPlacement;
     virCgroupDetectControllersCB detectControllers;
     virCgroupHasControllerCB hasController;
+    virCgroupGetAnyControllerCB getAnyController;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index c040d50141..105024ddde 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -485,6 +485,27 @@ virCgroupV1HasController(virCgroupPtr group,
 }


+static int
+virCgroupV1GetAnyController(virCgroupPtr group)
+{
+    size_t i;
+
+    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+        /* Reject any controller with a placement
+         * of '/' to avoid doing bad stuff to the root
+         * cgroup
+         */
+        if (group->controllers[i].mountPoint &&
+            group->controllers[i].placement &&
+            STRNEQ(group->controllers[i].placement, "/")) {
+            return i;
+        }
+    }
+
+    return -1;
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,

@@ -498,6 +519,7 @@ virCgroupBackend virCgroupV1Backend = {
     .getPlacement = virCgroupV1GetPlacement,
     .detectControllers = virCgroupV1DetectControllers,
     .hasController = virCgroupV1HasController,
+    .getAnyController = virCgroupV1GetAnyController,
 };
 

--
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list