[libvirt] [PATCH 25/53] vircgroup: introduce virCgroupV2SetBlkioDeviceReadIops

Pavel Hrdina posted 53 patches 6 years, 7 months ago
There is a newer version of this series
[libvirt] [PATCH 25/53] vircgroup: introduce virCgroupV2SetBlkioDeviceReadIops
Posted by Pavel Hrdina 6 years, 7 months ago
Signed-off-by: Pavel Hrdina <phrdina@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 b7e4db9f41..408f7e3eeb 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -769,6 +769,68 @@ virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV2SetBlkioDeviceReadIops(virCgroupPtr group,
+                                  const char *path,
+                                  unsigned int riops)
+{
+    VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) blkstr = NULL;
+
+    if (!(blkstr = virCgroupGetBlockDevString(path)))
+        return -1;
+
+    if (riops == 0) {
+        if (virAsprintf(&str, "%sriops=max", blkstr) < 0)
+            return -1;
+    } else {
+        if (virAsprintf(&str, "%sriops=%u", blkstr, riops) < 0)
+            return -1;
+    }
+
+    return virCgroupSetValueStr(group,
+                                VIR_CGROUP_CONTROLLER_BLKIO,
+                                "io.max",
+                                str);
+}
+
+
+static int
+virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group,
+                                  const char *path,
+                                  unsigned int *riops)
+{
+    VIR_AUTOFREE(char *) str = NULL;
+    char *tmp;
+
+    if (virCgroupGetValueForBlkDev(group,
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
+                                   "io.max",
+                                   path,
+                                   &str) < 0) {
+        return -1;
+    }
+
+    if (!str) {
+        *riops = 0;
+    } else {
+        tmp = strstr(str, "riops=");
+        tmp += strlen("riops=");
+
+        if (STREQLEN(tmp, "max", 3)) {
+            *riops = 0;
+        } else if (virStrToLong_ui(tmp, NULL, 10, riops) < 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,
 
@@ -797,6 +859,8 @@ virCgroupBackend virCgroupV2Backend = {
     .getBlkioIoDeviceServiced = virCgroupV2GetBlkioIoDeviceServiced,
     .setBlkioDeviceWeight = virCgroupV2SetBlkioDeviceWeight,
     .getBlkioDeviceWeight = virCgroupV2GetBlkioDeviceWeight,
+    .setBlkioDeviceReadIops = virCgroupV2SetBlkioDeviceReadIops,
+    .getBlkioDeviceReadIops = virCgroupV2GetBlkioDeviceReadIops,
 };
 
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 25/53] vircgroup: introduce virCgroupV2SetBlkioDeviceReadIops
Posted by Michal Privoznik 6 years, 7 months ago
On 10/02/2018 10:44 AM, Pavel Hrdina wrote:
> Signed-off-by: Pavel Hrdina <phrdina@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 b7e4db9f41..408f7e3eeb 100644
> --- a/src/util/vircgroupv2.c
> +++ b/src/util/vircgroupv2.c
> @@ -769,6 +769,68 @@ virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group,
>  }
>  
>  
> +static int
> +virCgroupV2SetBlkioDeviceReadIops(virCgroupPtr group,
> +                                  const char *path,
> +                                  unsigned int riops)
> +{
> +    VIR_AUTOFREE(char *) str = NULL;
> +    VIR_AUTOFREE(char *) blkstr = NULL;
> +
> +    if (!(blkstr = virCgroupGetBlockDevString(path)))
> +        return -1;
> +
> +    if (riops == 0) {
> +        if (virAsprintf(&str, "%sriops=max", blkstr) < 0)
> +            return -1;
> +    } else {
> +        if (virAsprintf(&str, "%sriops=%u", blkstr, riops) < 0)
> +            return -1;
> +    }
> +
> +    return virCgroupSetValueStr(group,
> +                                VIR_CGROUP_CONTROLLER_BLKIO,
> +                                "io.max",
> +                                str);
> +}
> +
> +
> +static int
> +virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group,
> +                                  const char *path,
> +                                  unsigned int *riops)
> +{
> +    VIR_AUTOFREE(char *) str = NULL;
> +    char *tmp;
> +
> +    if (virCgroupGetValueForBlkDev(group,
> +                                   VIR_CGROUP_CONTROLLER_BLKIO,
> +                                   "io.max",
> +                                   path,
> +                                   &str) < 0) {
> +        return -1;
> +    }
> +
> +    if (!str) {
> +        *riops = 0;
> +    } else {
> +        tmp = strstr(str, "riops=");
> +        tmp += strlen("riops=");

I bet coverity won't be happy about this. Please check the retval of
strstr().

> +
> +        if (STREQLEN(tmp, "max", 3)) {
> +            *riops = 0;
> +        } else if (virStrToLong_ui(tmp, NULL, 10, riops) < 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,
>  
> @@ -797,6 +859,8 @@ virCgroupBackend virCgroupV2Backend = {
>      .getBlkioIoDeviceServiced = virCgroupV2GetBlkioIoDeviceServiced,
>      .setBlkioDeviceWeight = virCgroupV2SetBlkioDeviceWeight,
>      .getBlkioDeviceWeight = virCgroupV2GetBlkioDeviceWeight,
> +    .setBlkioDeviceReadIops = virCgroupV2SetBlkioDeviceReadIops,
> +    .getBlkioDeviceReadIops = virCgroupV2GetBlkioDeviceReadIops,
>  };
>  
>  
> 


ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 25/53] vircgroup: introduce virCgroupV2SetBlkioDeviceReadIops
Posted by Fabiano Fidêncio 6 years, 7 months ago
On Tue, 2018-10-02 at 10:44 +0200, Pavel Hrdina wrote:
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>

Here, again, I'd just adjust the commit log to show that you're adding
the Get/Set instead of just the Set function.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 25/53] vircgroup: introduce virCgroupV2SetBlkioDeviceReadIops
Posted by Fabiano Fidêncio 6 years, 7 months ago
On Fri, 2018-10-05 at 09:54 +0200, Fabiano Fidêncio wrote:
> On Tue, 2018-10-02 at 10:44 +0200, Pavel Hrdina wrote:
> > Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> 
> Here, again, I'd just adjust the commit log to show that you're
> adding
> the Get/Set instead of just the Set function.

And the same comment applies for a few other patches after this one.

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