[libvirt] [PATCH 25/47] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceReadIops
Fabiano Fidêncio
fidencio at redhat.com
Thu Sep 20 06:30:11 UTC 2018
On Tue, Sep 18, 2018 at 5:45 PM, Pavel Hrdina <phrdina at redhat.com> wrote:
> Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
>
Reviewed-by: Fabiano Fidêncio <fidencio at redhat.com>
> ---
> src/util/vircgroup.c | 34 ++-----------------------
> src/util/vircgroupbackend.h | 12 +++++++++
> src/util/vircgroupv1.c | 50 +++++++++++++++++++++++++++++++++++++
> 3 files changed, 64 insertions(+), 32 deletions(-)
>
> diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
> index 465d540bb2..5fbad25d5c 100644
> --- a/src/util/vircgroup.c
> +++ b/src/util/vircgroup.c
> @@ -1387,19 +1387,7 @@ virCgroupSetBlkioDeviceReadIops(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 (virAsprintf(&str, "%s%u", blkstr, riops) < 0)
> - return -1;
> -
> - return virCgroupSetValueStr(group,
> - VIR_CGROUP_CONTROLLER_BLKIO,
> - "blkio.throttle.read_iops_device",
> - str);
> + VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceReadIops, -1, path,
> riops);
> }
>
>
> @@ -1519,25 +1507,7 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group,
> const char *path,
> unsigned int *riops)
> {
> - VIR_AUTOFREE(char *) str = NULL;
> -
> - if (virCgroupGetValueForBlkDev(group,
> - VIR_CGROUP_CONTROLLER_BLKIO,
> - "blkio.throttle.read_iops_device",
> - path,
> - &str) < 0)
> - return -1;
> -
> - if (!str) {
> - *riops = 0;
> - } else if (virStrToLong_ui(str, NULL, 10, riops) < 0) {
> - virReportError(VIR_ERR_INTERNAL_ERROR,
> - _("Unable to parse '%s' as an integer"),
> - str);
> - return -1;
> - }
> -
> - return 0;
> + VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceReadIops, -1, path,
> riops);
> }
>
> /**
> diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
> index a84417ddb7..813ed61b6a 100644
> --- a/src/util/vircgroupbackend.h
> +++ b/src/util/vircgroupbackend.h
> @@ -162,6 +162,16 @@ typedef int
> const char *path,
> unsigned int *weight);
>
> +typedef int
> +(*virCgroupSetBlkioDeviceReadIopsCB)(virCgroupPtr group,
> + const char *path,
> + unsigned int riops);
> +
> +typedef int
> +(*virCgroupGetBlkioDeviceReadIopsCB)(virCgroupPtr group,
> + const char *path,
> + unsigned int *riops);
> +
> struct _virCgroupBackend {
> virCgroupBackendType type;
>
> @@ -192,6 +202,8 @@ struct _virCgroupBackend {
> virCgroupGetBlkioIoDeviceServicedCB getBlkioIoDeviceServiced;
> virCgroupSetBlkioDeviceWeightCB setBlkioDeviceWeight;
> virCgroupGetBlkioDeviceWeightCB getBlkioDeviceWeight;
> + virCgroupSetBlkioDeviceReadIopsCB setBlkioDeviceReadIops;
> + virCgroupGetBlkioDeviceReadIopsCB getBlkioDeviceReadIops;
> };
> typedef struct _virCgroupBackend virCgroupBackend;
> typedef virCgroupBackend *virCgroupBackendPtr;
> diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
> index b627a9d516..d418ef41df 100644
> --- a/src/util/vircgroupv1.c
> +++ b/src/util/vircgroupv1.c
> @@ -1185,6 +1185,54 @@ virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group,
> }
>
>
> +static int
> +virCgroupV1SetBlkioDeviceReadIops(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 (virAsprintf(&str, "%s%u", blkstr, riops) < 0)
> + return -1;
> +
> + return virCgroupSetValueStr(group,
> + VIR_CGROUP_CONTROLLER_BLKIO,
> + "blkio.throttle.read_iops_device",
> + str);
> +}
> +
> +
> +static int
> +virCgroupV1GetBlkioDeviceReadIops(virCgroupPtr group,
> + const char *path,
> + unsigned int *riops)
> +{
> + VIR_AUTOFREE(char *) str = NULL;
> +
> + if (virCgroupGetValueForBlkDev(group,
> + VIR_CGROUP_CONTROLLER_BLKIO,
> + "blkio.throttle.read_iops_device",
> + path,
> + &str) < 0)
> + return -1;
> +
> + if (!str) {
> + *riops = 0;
> + } else if (virStrToLong_ui(str, NULL, 10, riops) < 0) {
> + virReportError(VIR_ERR_INTERNAL_ERROR,
> + _("Unable to parse '%s' as an integer"),
> + str);
> + return -1;
> + }
> +
> + return 0;
> +}
> +
> +
> virCgroupBackend virCgroupV1Backend = {
> .type = VIR_CGROUP_BACKEND_TYPE_V1,
>
> @@ -1213,6 +1261,8 @@ virCgroupBackend virCgroupV1Backend = {
> .getBlkioIoDeviceServiced = virCgroupV1GetBlkioIoDeviceServiced,
> .setBlkioDeviceWeight = virCgroupV1SetBlkioDeviceWeight,
> .getBlkioDeviceWeight = virCgroupV1GetBlkioDeviceWeight,
> + .setBlkioDeviceReadIops = virCgroupV1SetBlkioDeviceReadIops,
> + .getBlkioDeviceReadIops = virCgroupV1GetBlkioDeviceReadIops,
> };
>
>
> --
> 2.17.1
>
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180920/20f47df5/attachment-0001.htm>
More information about the libvir-list
mailing list