[libvirt] [PATCH v3 5/7] util: vircgroupv2: separate return values of virCgroupV2EnableController

Pavel Hrdina phrdina at redhat.com
Tue Jun 25 11:16:24 UTC 2019


In order to skip controllers that we are not able to activate we need
to return different return value so the caller can decide what to do.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---

Notes:
    Introduced in v2

 src/util/vircgroupv2.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 3f4548b532..133a8e0e66 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -353,22 +353,37 @@ virCgroupV2PathOfController(virCgroupPtr group,
 }
 
 
+/**
+ * virCgroupV2EnableController:
+ *
+ * Returns: -1 on fatal error
+ *          -2 if we failed to write into cgroup.subtree_control
+ *          0 on success
+ */
 static int
 virCgroupV2EnableController(virCgroupPtr parent,
                             int controller)
 {
     VIR_AUTOFREE(char *) val = NULL;
+    VIR_AUTOFREE(char *) path = NULL;
 
     if (virAsprintf(&val, "+%s",
                     virCgroupV2ControllerTypeToString(controller)) < 0) {
         return -1;
     }
 
-    if (virCgroupSetValueStr(parent, controller,
-                             "cgroup.subtree_control", val) < 0) {
+    if (virCgroupPathOfController(parent, controller,
+                                  "cgroup.subtree_control", &path) < 0) {
         return -1;
     }
 
+    if (virFileWriteStr(path, val, 0) < 0) {
+        virReportSystemError(errno,
+                             _("Failed to enable controller '%s' for '%s'"),
+                             val, path);
+        return -2;
+    }
+
     return 0;
 }
 
-- 
2.21.0




More information about the libvir-list mailing list