[PATCH 24/53] vircgroup: introduce virCgroupV2SetBlkioDeviceWeight

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

 



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

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index eff410258c..b7e4db9f41 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -720,6 +720,55 @@ virCgroupV2GetBlkioIoDeviceServiced(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV2SetBlkioDeviceWeight(virCgroupPtr group,
+                                const char *path,
+                                unsigned int weight)
+{
+    VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) blkstr = NULL;
+
+    if (!(blkstr = virCgroupGetBlockDevString(path)))
+        return -1;
+
+    if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
+        return -1;
+
+    return virCgroupSetValueStr(group,
+                                VIR_CGROUP_CONTROLLER_BLKIO,
+                                "io.weight",
+                                str);
+}
+
+
+static int
+virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group,
+                                const char *path,
+                                unsigned int *weight)
+{
+    VIR_AUTOFREE(char *) str = NULL;
+
+    if (virCgroupGetValueForBlkDev(group,
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
+                                   "io.weight",
+                                   path,
+                                   &str) < 0) {
+        return -1;
+    }
+
+    if (!str) {
+        *weight = 0;
+    } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to parse '%s' as an integer"),
+                       str);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 virCgroupBackend virCgroupV2Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
 
@@ -746,6 +795,8 @@ virCgroupBackend virCgroupV2Backend = {
     .getBlkioWeight = virCgroupV2GetBlkioWeight,
     .getBlkioIoServiced = virCgroupV2GetBlkioIoServiced,
     .getBlkioIoDeviceServiced = virCgroupV2GetBlkioIoDeviceServiced,
+    .setBlkioDeviceWeight = virCgroupV2SetBlkioDeviceWeight,
+    .getBlkioDeviceWeight = virCgroupV2GetBlkioDeviceWeight,
 };
 
 
-- 
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