]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: vircgroupv1: add support for BFQ blkio files
authorPavel Hrdina <phrdina@redhat.com>
Tue, 18 Jun 2019 13:15:43 +0000 (15:15 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 21 Jun 2019 12:35:59 +0000 (14:35 +0200)
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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/vircgroupv1.c

index 064b99dceb9dc9c4f173f22ba8fb8c1ba62b46cb..97258917bc20c2ce0a8fe91b088b60fa186f3302 100644 (file)
@@ -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) {