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

219 lines
8.2 KiB
Diff
Raw Normal View History

From c5ff4dbe89d9a57da51bb92389ebd9e5af4dd8dc Mon Sep 17 00:00:00 2001
Message-Id: <c5ff4dbe89d9a57da51bb92389ebd9e5af4dd8dc@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:31 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1DetectControllers
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 d7f77dd6d5bcf91c3422a15842c2b7c2714510af)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <a066563f5d5183b6e09ae73cbfb3defb478bb693.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/util/vircgroup.c | 66 +------------------------------------
src/util/vircgroupbackend.h | 5 +++
src/util/vircgroupv1.c | 65 ++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+), 65 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 0e64ad67f4..2e74cbbff4 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -349,70 +349,6 @@ virCgroupDetectPlacement(virCgroupPtr group,
}
-static int
-virCgroupDetectControllers(virCgroupPtr group,
- int controllers)
-{
- size_t i;
- size_t j;
-
- if (controllers >= 0) {
- VIR_DEBUG("Filtering controllers %d", controllers);
- /* First mark requested but non-existing controllers to be ignored */
- for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
- if (((1 << i) & controllers)) {
- /* Remove non-existent controllers */
- if (!group->controllers[i].mountPoint) {
- VIR_DEBUG("Requested controller '%s' not mounted, ignoring",
- virCgroupControllerTypeToString(i));
- controllers &= ~(1 << i);
- }
- }
- }
- for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
- VIR_DEBUG("Controller '%s' wanted=%s, mount='%s'",
- virCgroupControllerTypeToString(i),
- (1 << i) & controllers ? "yes" : "no",
- NULLSTR(group->controllers[i].mountPoint));
- if (!((1 << i) & controllers) &&
- group->controllers[i].mountPoint) {
- /* Check whether a request to disable a controller
- * clashes with co-mounting of controllers */
- for (j = 0; j < VIR_CGROUP_CONTROLLER_LAST; j++) {
- if (j == i)
- continue;
- if (!((1 << j) & controllers))
- continue;
-
- if (STREQ_NULLABLE(group->controllers[i].mountPoint,
- group->controllers[j].mountPoint)) {
- virReportSystemError(EINVAL,
- _("Controller '%s' is not wanted, but '%s' is co-mounted"),
- virCgroupControllerTypeToString(i),
- virCgroupControllerTypeToString(j));
- return -1;
- }
- }
- VIR_FREE(group->controllers[i].mountPoint);
- }
- }
- } else {
- VIR_DEBUG("Auto-detecting controllers");
- controllers = 0;
- for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
- VIR_DEBUG("Controller '%s' present=%s",
- virCgroupControllerTypeToString(i),
- group->controllers[i].mountPoint ? "yes" : "no");
- if (group->controllers[i].mountPoint == NULL)
- continue;
- controllers |= (1 << i);
- }
- }
-
- return controllers;
-}
-
-
static int
virCgroupDetect(virCgroupPtr group,
pid_t pid,
@@ -451,7 +387,7 @@ virCgroupDetect(virCgroupPtr group,
return -1;
}
- rc = virCgroupDetectControllers(group, controllers);
+ rc = group->backend->detectControllers(group, controllers);
if (rc < 0)
return -1;
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 9c0bd89793..011d1b00da 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -69,6 +69,10 @@ typedef int
typedef char *
(*virCgroupStealPlacementCB)(virCgroupPtr group);
+typedef int
+(*virCgroupDetectControllersCB)(virCgroupPtr group,
+ int controllers);
+
struct _virCgroupBackend {
virCgroupBackendType type;
@@ -81,6 +85,7 @@ struct _virCgroupBackend {
virCgroupDetectPlacementCB detectPlacement;
virCgroupValidatePlacementCB validatePlacement;
virCgroupStealPlacementCB stealPlacement;
+ virCgroupDetectControllersCB detectControllers;
};
typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 446546fd58..11a86c061a 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -414,6 +414,70 @@ virCgroupV1StealPlacement(virCgroupPtr group)
}
+static int
+virCgroupV1DetectControllers(virCgroupPtr group,
+ int controllers)
+{
+ size_t i;
+ size_t j;
+
+ if (controllers >= 0) {
+ VIR_DEBUG("Filtering controllers %d", controllers);
+ /* First mark requested but non-existing controllers to be ignored */
+ for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+ if (((1 << i) & controllers)) {
+ /* Remove non-existent controllers */
+ if (!group->controllers[i].mountPoint) {
+ VIR_DEBUG("Requested controller '%s' not mounted, ignoring",
+ virCgroupV1ControllerTypeToString(i));
+ controllers &= ~(1 << i);
+ }
+ }
+ }
+ for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+ VIR_DEBUG("Controller '%s' wanted=%s, mount='%s'",
+ virCgroupV1ControllerTypeToString(i),
+ (1 << i) & controllers ? "yes" : "no",
+ NULLSTR(group->controllers[i].mountPoint));
+ if (!((1 << i) & controllers) &&
+ group->controllers[i].mountPoint) {
+ /* Check whether a request to disable a controller
+ * clashes with co-mounting of controllers */
+ for (j = 0; j < VIR_CGROUP_CONTROLLER_LAST; j++) {
+ if (j == i)
+ continue;
+ if (!((1 << j) & controllers))
+ continue;
+
+ if (STREQ_NULLABLE(group->controllers[i].mountPoint,
+ group->controllers[j].mountPoint)) {
+ virReportSystemError(EINVAL,
+ _("V1 controller '%s' is not wanted, but '%s' is co-mounted"),
+ virCgroupV1ControllerTypeToString(i),
+ virCgroupV1ControllerTypeToString(j));
+ return -1;
+ }
+ }
+ VIR_FREE(group->controllers[i].mountPoint);
+ }
+ }
+ } else {
+ VIR_DEBUG("Auto-detecting controllers");
+ controllers = 0;
+ for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+ VIR_DEBUG("Controller '%s' present=%s",
+ virCgroupV1ControllerTypeToString(i),
+ group->controllers[i].mountPoint ? "yes" : "no");
+ if (group->controllers[i].mountPoint == NULL)
+ continue;
+ controllers |= (1 << i);
+ }
+ }
+
+ return controllers;
+}
+
+
virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1,
@@ -425,6 +489,7 @@ virCgroupBackend virCgroupV1Backend = {
.detectPlacement = virCgroupV1DetectPlacement,
.validatePlacement = virCgroupV1ValidatePlacement,
.stealPlacement = virCgroupV1StealPlacement,
+ .detectControllers = virCgroupV1DetectControllers,
};
--
2.22.0