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