[libvirt] [PATCH 3/4] util: vircgroupv1: add support for BFQ blkio files

Pavel Hrdina phrdina at redhat.com
Wed Jun 19 14:16:49 UTC 2019


In kernel 4.12 there was introduced new BFQ scheduler and in kernel
5.0 the old CFQ scheduler was removed.  This has an implication on
the cgroups file names.

If the CFQ controller is enabled we use these two files:

    blkio.weight
    blkio.weight_device

The new BFQ controller expose only one file with different name:

    blkio.bfq.weight

The reason is that BFQ controller doesn't support per-device weight.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/util/vircgroupv1.c | 114 ++++++++++++++++++++++++++++++++---------
 1 file changed, 90 insertions(+), 24 deletions(-)

diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 064b99dceb..97258917bc 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -949,10 +949,33 @@ static int
 virCgroupV1SetBlkioWeight(virCgroupPtr group,
                           unsigned int weight)
 {
-    return virCgroupSetValueU64(group,
-                                VIR_CGROUP_CONTROLLER_BLKIO,
-                                "blkio.weight",
-                                weight);
+    VIR_AUTOFREE(char *) path = NULL;
+    VIR_AUTOFREE(char *) value = NULL;
+
+    if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
+                                    "blkio.bfq.weight", &path) < 0) {
+        return -1;
+    }
+
+    if (!virFileExists(path)) {
+        VIR_FREE(path);
+
+        if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
+                                        "blkio.weight", &path) < 0) {
+            return -1;
+        }
+    }
+
+    if (!virFileExists(path)) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("blkio device weight is valid only for bfq or cfq scheduler"));
+        return -1;
+    }
+
+    if (virAsprintf(&value, "%u", weight) < 0)
+        return -1;
+
+    return virCgroupSetValueRaw(path, value);
 }
 
 
@@ -960,14 +983,40 @@ static int
 virCgroupV1GetBlkioWeight(virCgroupPtr group,
                           unsigned int *weight)
 {
-    unsigned long long tmp;
-    int ret;
-    ret = virCgroupGetValueU64(group,
-                               VIR_CGROUP_CONTROLLER_BLKIO,
-                               "blkio.weight", &tmp);
-    if (ret == 0)
-        *weight = tmp;
-    return ret;
+    VIR_AUTOFREE(char *) path = NULL;
+    VIR_AUTOFREE(char *) value = NULL;
+
+    if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
+                                    "blkio.bfq.weight", &path) < 0) {
+        return -1;
+    }
+
+    if (!virFileExists(path)) {
+        VIR_FREE(path);
+
+        if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
+                                        "blkio.weight", &path) < 0) {
+            return -1;
+        }
+    }
+
+    if (!virFileExists(path)) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("blkio device weight is valid only for bfq or cfq scheduler"));
+        return -1;
+    }
+
+    if (virCgroupGetValueRaw(path, &value) < 0)
+        return -1;
+
+    if (virStrToLong_ui(value, NULL, 10, weight) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to parse '%s' as an integer"),
+                       value);
+        return -1;
+    }
+
+    return 0;
 }
 
 
@@ -1156,41 +1205,58 @@ virCgroupV1GetBlkioIoDeviceServiced(virCgroupPtr group,
 
 static int
 virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group,
-                                const char *path,
+                                const char *devPath,
                                 unsigned int weight)
 {
     VIR_AUTOFREE(char *) str = NULL;
     VIR_AUTOFREE(char *) blkstr = NULL;
+    VIR_AUTOFREE(char *) path = NULL;
 
-    if (!(blkstr = virCgroupGetBlockDevString(path)))
+    if (!(blkstr = virCgroupGetBlockDevString(devPath)))
         return -1;
 
     if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
         return -1;
 
-    return virCgroupSetValueStr(group,
-                                VIR_CGROUP_CONTROLLER_BLKIO,
-                                "blkio.weight_device",
-                                str);
+    if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
+                                    "blkio.weight_device", &path) < 0) {
+        return -1;
+    }
+
+    if (!virFileExists(path)) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("blkio device weight is valid only for cfq scheduler"));
+        return -1;
+    }
+
+    return virCgroupSetValueRaw(path, str);
 }
 
 
 static int
 virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group,
-                                const char *path,
+                                const char *devPath,
                                 unsigned int *weight)
 {
     VIR_AUTOFREE(char *) str = NULL;
     VIR_AUTOFREE(char *) value = NULL;
+    VIR_AUTOFREE(char *) path = NULL;
 
-    if (virCgroupGetValueStr(group,
-                             VIR_CGROUP_CONTROLLER_BLKIO,
-                             "blkio.weight_device",
-                             &value) < 0) {
+    if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
+                                    "blkio.weight_device", &path) < 0) {
         return -1;
     }
 
-    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
+    if (!virFileExists(path)) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("blkio device weight is valid only for cfq scheduler"));
+        return -1;
+    }
+
+    if (virCgroupGetValueRaw(path, &value) < 0)
+        return -1;
+
+    if (virCgroupGetValueForBlkDev(value, devPath, &str) < 0)
         return -1;
 
     if (!str) {
-- 
2.21.0




More information about the libvir-list mailing list