Signed-off-by: Pavel Hrdina <phrdina(a)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 7557fc5576..0fcb047a0c 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -271,42 +271,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
@@ -534,7 +498,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 2882a19be2..f73f40db0e 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -182,6 +182,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,
@@ -342,6 +378,7 @@ virCgroupBackend virCgroupV1Backend = {
.available = virCgroupV1Available,
.validateMachineGroup = virCgroupV1ValidateMachineGroup,
.copyMounts = virCgroupV1CopyMounts,
+ .copyPlacement = virCgroupV1CopyPlacement,
.detectMounts = virCgroupV1DetectMounts,
.detectPlacement = virCgroupV1DetectPlacement,
};
--
2.17.1