[libvirt PATCH 20/25] vircgroup: introduce virCgroupSetPlacement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently this task is done by virCgroupCopyPlacement when the @path
starts with "/".

virCgroupNew is always called with @path starting with "/" and there is
no parent to copy path from. To make it obvious what the code is doing
introduce new helper.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/util/vircgroup.c        | 19 ++++++++++++++++++-
 src/util/vircgroupbackend.h |  5 +++++
 src/util/vircgroupv1.c      | 21 +++++++++++++++++++++
 src/util/vircgroupv2.c      | 11 +++++++++++
 4 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 6a34eb4037..00967ea5fa 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -393,6 +393,23 @@ virCgroupDetectPlacement(virCgroupPtr group,
 }
 
 
+static int
+virCgroupSetPlacement(virCgroupPtr group,
+                      const char *path)
+{
+    size_t i;
+
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
+        if (group->backends[i] &&
+            group->backends[i]->setPlacement(group, path) < 0) {
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+
 static int
 virCgroupValidatePlacement(virCgroupPtr group,
                            pid_t pid)
@@ -689,7 +706,7 @@ virCgroupNew(const char *path,
     if (virCgroupDetectMounts(newGroup) < 0)
         return -1;
 
-    if (virCgroupCopyPlacement(newGroup, path, NULL) < 0)
+    if (virCgroupSetPlacement(newGroup, path) < 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 f677157a91..4ca2e38af2 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -88,6 +88,10 @@ typedef int
                               const char *controllers,
                               const char *selfpath);
 
+typedef int
+(*virCgroupSetPlacementCB)(virCgroupPtr group,
+                           const char *path);
+
 typedef int
 (*virCgroupValidatePlacementCB)(virCgroupPtr group,
                                 pid_t pid);
@@ -369,6 +373,7 @@ struct _virCgroupBackend {
     virCgroupCopyPlacementCB copyPlacement;
     virCgroupDetectMountsCB detectMounts;
     virCgroupDetectPlacementCB detectPlacement;
+    virCgroupSetPlacementCB setPlacement;
     virCgroupValidatePlacementCB validatePlacement;
     virCgroupStealPlacementCB stealPlacement;
     virCgroupDetectControllersCB detectControllers;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 98b5aa047d..ed4b0813f2 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -364,6 +364,26 @@ virCgroupV1DetectPlacement(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV1SetPlacement(virCgroupPtr group,
+                        const char *path)
+{
+    size_t i;
+
+    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+        if (!group->legacy[i].mountPoint)
+            continue;
+
+        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
+            continue;
+
+        group->legacy[i].placement = g_strdup(path);
+    }
+
+    return 0;
+}
+
+
 static int
 virCgroupV1ValidatePlacement(virCgroupPtr group,
                              pid_t pid)
@@ -2101,6 +2121,7 @@ virCgroupBackend virCgroupV1Backend = {
     .copyPlacement = virCgroupV1CopyPlacement,
     .detectMounts = virCgroupV1DetectMounts,
     .detectPlacement = virCgroupV1DetectPlacement,
+    .setPlacement = virCgroupV1SetPlacement,
     .validatePlacement = virCgroupV1ValidatePlacement,
     .stealPlacement = virCgroupV1StealPlacement,
     .detectControllers = virCgroupV1DetectControllers,
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 0467a72566..8e058ca9c6 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -223,6 +223,16 @@ virCgroupV2DetectPlacement(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV2SetPlacement(virCgroupPtr group,
+                        const char *path)
+{
+    group->unified.placement = g_strdup(path);
+
+    return 0;
+}
+
+
 static int
 virCgroupV2ValidatePlacement(virCgroupPtr group,
                              pid_t pid G_GNUC_UNUSED)
@@ -1845,6 +1855,7 @@ virCgroupBackend virCgroupV2Backend = {
     .copyPlacement = virCgroupV2CopyPlacement,
     .detectMounts = virCgroupV2DetectMounts,
     .detectPlacement = virCgroupV2DetectPlacement,
+    .setPlacement = virCgroupV2SetPlacement,
     .validatePlacement = virCgroupV2ValidatePlacement,
     .stealPlacement = virCgroupV2StealPlacement,
     .detectControllers = virCgroupV2DetectControllers,
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux