The case where we need path of any controller is only for internal use so move it out to a different function. Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx> --- src/util/vircgroup.c | 54 ++++++++++++++++++++++++++------------------ src/util/vircgroup.h | 2 +- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 2bc4febf23..8646a4a479 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1772,28 +1772,13 @@ virCgroupHasController(virCgroupPtr cgroup, int controller) int virCgroupPathOfController(virCgroupPtr group, - int controller, + unsigned int controller, const char *key, char **path) { - if (controller == -1) { - 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, "/")) { - controller = i; - break; - } - } - } - if (controller == -1) { - virReportSystemError(ENOSYS, "%s", - _("No controllers are mounted")); + if (controller >= VIR_CGROUP_CONTROLLER_LAST) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid controller id '%d'"), controller); return -1; } @@ -3505,6 +3490,31 @@ virCgroupRemove(virCgroupPtr group) } +static int +virCgroupPathOfAnyController(virCgroupPtr group, + const char *name, + char **keypath) +{ + 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 virCgroupPathOfController(group, i, name, keypath); + } + } + + virReportSystemError(ENOSYS, "%s", + _("No controllers are mounted")); + return -1; +} + + /* * Returns 1 if some PIDs are killed, 0 if none are killed, or -1 on error */ @@ -3519,7 +3529,7 @@ virCgroupKillInternal(virCgroupPtr group, int signum, virHashTablePtr pids) VIR_DEBUG("group=%p path=%s signum=%d pids=%p", group, group->path, signum, pids); - if (virCgroupPathOfController(group, -1, "tasks", &keypath) < 0) + if (virCgroupPathOfAnyController(group, "tasks", &keypath) < 0) return -1; /* PIDs may be forking as we kill them, so loop @@ -3622,7 +3632,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, VIR_DEBUG("group=%p path=%s signum=%d pids=%p", group, group->path, signum, pids); - if (virCgroupPathOfController(group, -1, "", &keypath) < 0) + if (virCgroupPathOfAnyController(group, "", &keypath) < 0) return -1; if ((rc = virCgroupKillInternal(group, signum, pids)) < 0) @@ -4180,7 +4190,7 @@ virCgroupHasController(virCgroupPtr cgroup ATTRIBUTE_UNUSED, int virCgroupPathOfController(virCgroupPtr group ATTRIBUTE_UNUSED, - int controller ATTRIBUTE_UNUSED, + unsigned int controller ATTRIBUTE_UNUSED, const char *key ATTRIBUTE_UNUSED, char **path ATTRIBUTE_UNUSED) { diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index c7fdaaede4..ee3b7c7222 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -114,7 +114,7 @@ void virCgroupFree(virCgroupPtr *group); bool virCgroupHasController(virCgroupPtr cgroup, int controller); int virCgroupPathOfController(virCgroupPtr group, - int controller, + unsigned int controller, const char *key, char **path); -- 2.17.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list