From b246f8418526ea154fe2f0223f6f34ea86b90ea4 Mon Sep 17 00:00:00 2001
Message-Id: <b246f8418526ea154fe2f0223f6f34ea86b90ea4@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:28 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1CopyPlacement
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 229a8b5d3504efdbe8cd25bb3a127ec74ab4bbd3)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <9a9b8e24c5574e7b61e19a46d9978bf0dc1b32d3.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/util/vircgroup.c | 38 +------------------------------------
src/util/vircgroupbackend.h | 6 ++++++
src/util/vircgroupv1.c | 37 ++++++++++++++++++++++++++++++++++++
3 files changed, 44 insertions(+), 37 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 10c99a66fd..b63321ca33 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -269,42 +269,6 @@ virCgroupDetectMounts(virCgroupPtr group)
}
-static int
-virCgroupCopyPlacement(virCgroupPtr group,
- const char *path,
- virCgroupPtr parent)
-{
- size_t i;
- for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
- if (!group->controllers[i].mountPoint)
- continue;
-
- if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
- continue;
-
- if (path[0] == '/') {
- if (VIR_STRDUP(group->controllers[i].placement, path) < 0)
- return -1;
- } else {
- /*
- * parent == "/" + path="" => "/"
- * parent == "/libvirt.service" + path == "" => "/libvirt.service"
- * parent == "/libvirt.service" + path == "foo" => "/libvirt.service/foo"
- */
- if (virAsprintf(&group->controllers[i].placement,
- "%s%s%s",
- parent->controllers[i].placement,
- (STREQ(parent->controllers[i].placement, "/") ||
- STREQ(path, "") ? "" : "/"),
- path) < 0)
- return -1;
- }
- }
-
- return 0;
-}
-
-
/*
* virCgroupDetectPlacement:
* @group: the group to process
@@ -532,7 +496,7 @@ virCgroupDetect(virCgroupPtr group,
* based on the parent cgroup...
*/
if ((parent || path[0] == '/') &&
- virCgroupCopyPlacement(group, path, parent) < 0)
+ group->backend->copyPlacement(group, path, parent) < 0)
return -1;
/* ... but use /proc/cgroups to fill in the rest */
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index fadc7efdcf..85906e7191 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -45,6 +45,11 @@ typedef int
(*virCgroupCopyMountsCB)(virCgroupPtr group,
virCgroupPtr parent);
+typedef int
+(*virCgroupCopyPlacementCB)(virCgroupPtr group,
+ const char *path,
+ virCgroupPtr parent);
+
typedef int
(*virCgroupDetectMountsCB)(virCgroupPtr group,
const char *mntType,
@@ -64,6 +69,7 @@ struct _virCgroupBackend {
virCgroupAvailableCB available;
virCgroupValidateMachineGroupCB validateMachineGroup;
virCgroupCopyMountsCB copyMounts;
+ virCgroupCopyPlacementCB copyPlacement;
virCgroupDetectMountsCB detectMounts;
virCgroupDetectPlacementCB detectPlacement;
};
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index bd9f28f6e9..68bb1c6f5d 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -183,6 +183,42 @@ virCgroupV1CopyMounts(virCgroupPtr group,
}
+static int
+virCgroupV1CopyPlacement(virCgroupPtr group,
+ const char *path,
+ virCgroupPtr parent)
+{
+ size_t i;
+ for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+ if (!group->controllers[i].mountPoint)
+ continue;
+
+ if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
+ continue;
+
+ if (path[0] == '/') {
+ if (VIR_STRDUP(group->controllers[i].placement, path) < 0)
+ return -1;
+ } else {
+ /*
+ * parent == "/" + path="" => "/"
+ * parent == "/libvirt.service" + path == "" => "/libvirt.service"
+ * parent == "/libvirt.service" + path == "foo" => "/libvirt.service/foo"
+ */
+ if (virAsprintf(&group->controllers[i].placement,
+ "%s%s%s",
+ parent->controllers[i].placement,
+ (STREQ(parent->controllers[i].placement, "/") ||
+ STREQ(path, "") ? "" : "/"),
+ path) < 0)
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+
static int
virCgroupV1ResolveMountLink(const char *mntDir,
const char *typeStr,
@@ -343,6 +379,7 @@ virCgroupBackend virCgroupV1Backend = {
.available = virCgroupV1Available,
.validateMachineGroup = virCgroupV1ValidateMachineGroup,
.copyMounts = virCgroupV1CopyMounts,
+ .copyPlacement = virCgroupV1CopyPlacement,
.detectMounts = virCgroupV1DetectMounts,
.detectPlacement = virCgroupV1DetectPlacement,
};
--
2.22.0