[libvirt] [PATCH v2 05/53] [ACKED] vircgroup: introduce virCgroupV2CopyPlacement

Pavel Hrdina phrdina at redhat.com
Fri Oct 5 12:43:26 UTC 2018


Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/util/vircgroupv2.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index b4c551d1d2..28f4dd6ff0 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -148,12 +148,39 @@ virCgroupV2CopyMounts(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV2CopyPlacement(virCgroupPtr group,
+                         const char *path,
+                         virCgroupPtr parent)
+{
+    if (path[0] == '/') {
+        if (VIR_STRDUP(group->unified.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->unified.placement, "%s%s%s",
+                        parent->unified.placement,
+                        (STREQ(parent->unified.placement, "/") ||
+                         STREQ(path, "") ? "" : "/"),
+                        path) < 0)
+            return -1;
+    }
+
+    return 0;
+}
+
+
 virCgroupBackend virCgroupV2Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
 
     .available = virCgroupV2Available,
     .validateMachineGroup = virCgroupV2ValidateMachineGroup,
     .copyMounts = virCgroupV2CopyMounts,
+    .copyPlacement = virCgroupV2CopyPlacement,
 };
 
 
-- 
2.17.1




More information about the libvir-list mailing list