]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroup: introduce virCgroupV2(Set|Get)BlkioWeight
authorPavel Hrdina <phrdina@redhat.com>
Fri, 17 Aug 2018 14:51:28 +0000 (16:51 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 5 Oct 2018 13:53:29 +0000 (15:53 +0200)
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/util/vircgroupv2.c

index 8a3dc4901b9ef263d474318cf34fb1b1e2a1d530..9775b5bc17cae98fa3227f5b8c78e503347814fc 100644 (file)
@@ -520,6 +520,52 @@ virCgroupV2SetOwner(virCgroupPtr cgroup,
 }
 
 
+static int
+virCgroupV2SetBlkioWeight(virCgroupPtr group,
+                          unsigned int weight)
+{
+    VIR_AUTOFREE(char *) value = NULL;
+
+    if (virAsprintf(&value, "default %u", weight) < 0)
+        return -1;
+
+    return virCgroupSetValueStr(group,
+                                VIR_CGROUP_CONTROLLER_BLKIO,
+                                "io.weight",
+                                value);
+}
+
+
+static int
+virCgroupV2GetBlkioWeight(virCgroupPtr group,
+                          unsigned int *weight)
+{
+    VIR_AUTOFREE(char *) value = NULL;
+    char *tmp;
+
+    if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO,
+                             "io.weight", &value) < 0) {
+        return -1;
+    }
+
+    if (!(tmp = strstr(value, "default "))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Cannot find default io weight."));
+        return -1;
+    }
+    tmp += strlen("default ");
+
+    if (virStrToLong_ui(tmp, NULL, 10, weight) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to parse '%s' as an integer"),
+                       tmp);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 virCgroupBackend virCgroupV2Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
 
@@ -541,6 +587,9 @@ virCgroupBackend virCgroupV2Backend = {
     .hasEmptyTasks = virCgroupV2HasEmptyTasks,
     .bindMount = virCgroupV2BindMount,
     .setOwner = virCgroupV2SetOwner,
+
+    .setBlkioWeight = virCgroupV2SetBlkioWeight,
+    .getBlkioWeight = virCgroupV2GetBlkioWeight,
 };