Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/util/vircgroupv2.c | 64 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 6279072aab..88bd9fb37c 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -893,6 +893,68 @@ virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group,
}
+static int
+virCgroupV2SetBlkioDeviceReadBps(virCgroupPtr group,
+ const char *path,
+ unsigned long long rbps)
+{
+ VIR_AUTOFREE(char *) str = NULL;
+ VIR_AUTOFREE(char *) blkstr = NULL;
+
+ if (!(blkstr = virCgroupGetBlockDevString(path)))
+ return -1;
+
+ if (rbps == 0) {
+ if (virAsprintf(&str, "%srbps=max", blkstr) < 0)
+ return -1;
+ } else {
+ if (virAsprintf(&str, "%srbps=%llu", blkstr, rbps) < 0)
+ return -1;
+ }
+
+ return virCgroupSetValueStr(group,
+ VIR_CGROUP_CONTROLLER_BLKIO,
+ "io.max",
+ str);
+}
+
+
+static int
+virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group,
+ const char *path,
+ unsigned long long *rbps)
+{
+ VIR_AUTOFREE(char *) str = NULL;
+ char *tmp;
+
+ if (virCgroupGetValueForBlkDev(group,
+ VIR_CGROUP_CONTROLLER_BLKIO,
+ "io.max",
+ path,
+ &str) < 0) {
+ return -1;
+ }
+
+ if (!str) {
+ *rbps = 0;
+ } else {
+ tmp = strstr(str, "rbps=");
+ tmp += strlen("rbps=");
+
+ if (STREQLEN(tmp, "max", 3)) {
+ *rbps = 0;
+ } else if (virStrToLong_ull(tmp, NULL, 10, rbps) < 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,
@@ -925,6 +987,8 @@ virCgroupBackend virCgroupV2Backend = {
.getBlkioDeviceReadIops = virCgroupV2GetBlkioDeviceReadIops,
.setBlkioDeviceWriteIops = virCgroupV2SetBlkioDeviceWriteIops,
.getBlkioDeviceWriteIops = virCgroupV2GetBlkioDeviceWriteIops,
+ .setBlkioDeviceReadBps = virCgroupV2SetBlkioDeviceReadBps,
+ .getBlkioDeviceReadBps = virCgroupV2GetBlkioDeviceReadBps,
};
--
2.17.1