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

Pavel Hrdina posted 7 patches 6 years, 7 months ago
[libvirt] [PATCH v3 5/7] util: vircgroupv2: separate return values of virCgroupV2EnableController
Posted by Pavel Hrdina 6 years, 7 months ago
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@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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v3 5/7] util: vircgroupv2: separate return values of virCgroupV2EnableController
Posted by Peter Krempa 6 years, 7 months ago
On Tue, Jun 25, 2019 at 13:16:24 +0200, Pavel Hrdina wrote:
> 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@redhat.com>
> ---
> 
> Notes:
>     Introduced in v2

ACK although based on the review of the next patch you probably also
want to add a boolean to suppres the error reporting in case of a known
ignorable error.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list