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