c480ed
From 51e0205bf57346f381143b498cfe0a77852a8da1 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <51e0205bf57346f381143b498cfe0a77852a8da1@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:07 +0200
c480ed
Subject: [PATCH] vircgroup: Split virCgroupPathOfController into two functions
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
The case where we need path of any controller is only for internal use
c480ed
so move it out to a different function.
c480ed
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit 998658bd1ebdc5fd9ec43131c381cece1a3893cf)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <7578336183563ecf49d686f6705724db25037191.1561993099.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c | 54 ++++++++++++++++++++++++++------------------
c480ed
 src/util/vircgroup.h |  2 +-
c480ed
 2 files changed, 33 insertions(+), 23 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index 2bc4febf23..8646a4a479 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -1772,28 +1772,13 @@ virCgroupHasController(virCgroupPtr cgroup, int controller)
c480ed
 
c480ed
 int
c480ed
 virCgroupPathOfController(virCgroupPtr group,
c480ed
-                          int controller,
c480ed
+                          unsigned int controller,
c480ed
                           const char *key,
c480ed
                           char **path)
c480ed
 {
c480ed
-    if (controller == -1) {
c480ed
-        size_t i;
c480ed
-        for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
c480ed
-            /* Reject any controller with a placement
c480ed
-             * of '/' to avoid doing bad stuff to the root
c480ed
-             * cgroup
c480ed
-             */
c480ed
-            if (group->controllers[i].mountPoint &&
c480ed
-                group->controllers[i].placement &&
c480ed
-                STRNEQ(group->controllers[i].placement, "/")) {
c480ed
-                controller = i;
c480ed
-                break;
c480ed
-            }
c480ed
-        }
c480ed
-    }
c480ed
-    if (controller == -1) {
c480ed
-        virReportSystemError(ENOSYS, "%s",
c480ed
-                             _("No controllers are mounted"));
c480ed
+    if (controller >= VIR_CGROUP_CONTROLLER_LAST) {
c480ed
+        virReportError(VIR_ERR_INTERNAL_ERROR,
c480ed
+                       _("Invalid controller id '%d'"), controller);
c480ed
         return -1;
c480ed
     }
c480ed
 
c480ed
@@ -3505,6 +3490,31 @@ virCgroupRemove(virCgroupPtr group)
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupPathOfAnyController(virCgroupPtr group,
c480ed
+                             const char *name,
c480ed
+                             char **keypath)
c480ed
+{
c480ed
+    size_t i;
c480ed
+
c480ed
+    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
c480ed
+        /* Reject any controller with a placement
c480ed
+         * of '/' to avoid doing bad stuff to the root
c480ed
+         * cgroup
c480ed
+         */
c480ed
+        if (group->controllers[i].mountPoint &&
c480ed
+            group->controllers[i].placement &&
c480ed
+            STRNEQ(group->controllers[i].placement, "/")) {
c480ed
+            return virCgroupPathOfController(group, i, name, keypath);
c480ed
+        }
c480ed
+    }
c480ed
+
c480ed
+    virReportSystemError(ENOSYS, "%s",
c480ed
+                         _("No controllers are mounted"));
c480ed
+    return -1;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 /*
c480ed
  * Returns 1 if some PIDs are killed, 0 if none are killed, or -1 on error
c480ed
  */
c480ed
@@ -3519,7 +3529,7 @@ virCgroupKillInternal(virCgroupPtr group, int signum, virHashTablePtr pids)
c480ed
     VIR_DEBUG("group=%p path=%s signum=%d pids=%p",
c480ed
               group, group->path, signum, pids);
c480ed
 
c480ed
-    if (virCgroupPathOfController(group, -1, "tasks", &keypath) < 0)
c480ed
+    if (virCgroupPathOfAnyController(group, "tasks", &keypath) < 0)
c480ed
         return -1;
c480ed
 
c480ed
     /* PIDs may be forking as we kill them, so loop
c480ed
@@ -3622,7 +3632,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group,
c480ed
     VIR_DEBUG("group=%p path=%s signum=%d pids=%p",
c480ed
               group, group->path, signum, pids);
c480ed
 
c480ed
-    if (virCgroupPathOfController(group, -1, "", &keypath) < 0)
c480ed
+    if (virCgroupPathOfAnyController(group, "", &keypath) < 0)
c480ed
         return -1;
c480ed
 
c480ed
     if ((rc = virCgroupKillInternal(group, signum, pids)) < 0)
c480ed
@@ -4180,7 +4190,7 @@ virCgroupHasController(virCgroupPtr cgroup ATTRIBUTE_UNUSED,
c480ed
 
c480ed
 int
c480ed
 virCgroupPathOfController(virCgroupPtr group ATTRIBUTE_UNUSED,
c480ed
-                          int controller ATTRIBUTE_UNUSED,
c480ed
+                          unsigned int controller ATTRIBUTE_UNUSED,
c480ed
                           const char *key ATTRIBUTE_UNUSED,
c480ed
                           char **path ATTRIBUTE_UNUSED)
c480ed
 {
c480ed
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
c480ed
index c7fdaaede4..ee3b7c7222 100644
c480ed
--- a/src/util/vircgroup.h
c480ed
+++ b/src/util/vircgroup.h
c480ed
@@ -114,7 +114,7 @@ void virCgroupFree(virCgroupPtr *group);
c480ed
 
c480ed
 bool virCgroupHasController(virCgroupPtr cgroup, int controller);
c480ed
 int virCgroupPathOfController(virCgroupPtr group,
c480ed
-                              int controller,
c480ed
+                              unsigned int controller,
c480ed
                               const char *key,
c480ed
                               char **path);
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed