libvirt/SOURCES/libvirt-vircgroup-extract-virCgroupV1GetAnyController.patch

119 lines
3.9 KiB
Diff
Raw Normal View History

From 98be75680dd7026b7156b3f9a0bd220f00714387 Mon Sep 17 00:00:00 2001
Message-Id: <98be75680dd7026b7156b3f9a0bd220f00714387@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:33 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1GetAnyController
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit d6564037e8161bbdd270a822f5a2aafd90c7df10)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <fc1d1ba80e734d7cdbdf6300e0199b48ede77bd1.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@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 5bbe42b699..a6f529accd 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -3173,19 +3173,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 29b2fd119f..b4eaa89021 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 {
virCgroupStealPlacementCB stealPlacement;
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 0638f48d50..bae16b8294 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -486,6 +486,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,
@@ -499,6 +520,7 @@ virCgroupBackend virCgroupV1Backend = {
.stealPlacement = virCgroupV1StealPlacement,
.detectControllers = virCgroupV1DetectControllers,
.hasController = virCgroupV1HasController,
+ .getAnyController = virCgroupV1GetAnyController,
};
--
2.22.0