[PATCH 21/53] vircgroup: introduce virCgroupV2SetBlkioWeight

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/util/vircgroupv2.c | 49 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index fec5d28835..3e2cd16335 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -546,6 +546,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,
 
@@ -567,6 +613,9 @@ virCgroupBackend virCgroupV2Backend = {
     .hasEmptyTasks = virCgroupV2HasEmptyTasks,
     .bindMount = virCgroupV2BindMount,
     .setOwner = virCgroupV2SetOwner,
+
+    .setBlkioWeight = virCgroupV2SetBlkioWeight,
+    .getBlkioWeight = virCgroupV2GetBlkioWeight,
 };
 
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux