From eca0f75e6f67ec9e445b90685143992b6929cef0 Mon Sep 17 00:00:00 2001 Message-Id: From: Pavel Hrdina Date: Mon, 1 Jul 2019 17:07:36 +0200 Subject: [PATCH] vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceWriteIops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pavel Hrdina (cherry picked from commit 438587033bdaf714238a98703c9efc7b0dada51f) Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297 Signed-off-by: Pavel Hrdina Message-Id: <7937bd2aa5da315f8351e3f312f5aee71b682c30.1561993100.git.phrdina@redhat.com> Reviewed-by: Ján Tomko --- src/util/vircgroupv2.c | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 8cecc43f76..1d25c0ae1f 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -811,6 +811,74 @@ virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group, } +static int +virCgroupV2SetBlkioDeviceWriteIops(virCgroupPtr group, + const char *path, + unsigned int wiops) +{ + VIR_AUTOFREE(char *) str = NULL; + VIR_AUTOFREE(char *) blkstr = NULL; + + if (!(blkstr = virCgroupGetBlockDevString(path))) + return -1; + + if (wiops == 0) { + if (virAsprintf(&str, "%swiops=max", blkstr) < 0) + return -1; + } else { + if (virAsprintf(&str, "%swiops=%u", blkstr, wiops) < 0) + return -1; + } + + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + str); +} + + +static int +virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group, + const char *path, + unsigned int *wiops) +{ + VIR_AUTOFREE(char *) str = NULL; + const char *name = "wiops="; + char *tmp; + + if (virCgroupGetValueForBlkDev(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + path, + &str) < 0) { + return -1; + } + + if (!str) { + *wiops = 0; + } else { + if (!(tmp = strstr(str, name))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to find '%s' limit for block device '%s'"), + name, path); + return -1; + } + tmp += strlen(name); + + if (STREQLEN(tmp, "max", 3)) { + *wiops = 0; + } else if (virStrToLong_ui(tmp, NULL, 10, wiops) < 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, @@ -841,6 +909,8 @@ virCgroupBackend virCgroupV2Backend = { .getBlkioDeviceWeight = virCgroupV2GetBlkioDeviceWeight, .setBlkioDeviceReadIops = virCgroupV2SetBlkioDeviceReadIops, .getBlkioDeviceReadIops = virCgroupV2GetBlkioDeviceReadIops, + .setBlkioDeviceWriteIops = virCgroupV2SetBlkioDeviceWriteIops, + .getBlkioDeviceWriteIops = virCgroupV2GetBlkioDeviceWriteIops, }; -- 2.22.0