[libvirt] [PATCH 21/47] vircgroup: extract virCgroupV1(Set|Get)BlkioWeight

Fabiano Fidêncio fidencio at redhat.com
Thu Sep 20 06:29:59 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        | 14 ++------------
>  src/util/vircgroupbackend.h | 20 ++++++++++++++++++++
>  src/util/vircgroupv1.c      | 29 +++++++++++++++++++++++++++++
>  3 files changed, 51 insertions(+), 12 deletions(-)
>
> diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
> index 479a2bf664..cb9f03d488 100644
> --- a/src/util/vircgroup.c
> +++ b/src/util/vircgroup.c
> @@ -1512,10 +1512,7 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr
> group,
>  int
>  virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
>  {
> -    return virCgroupSetValueU64(group,
> -                                VIR_CGROUP_CONTROLLER_BLKIO,
> -                                "blkio.weight",
> -                                weight);
> +    VIR_CGROUP_BACKEND_CALL(group, setBlkioWeight, -1, weight);
>  }
>
>
> @@ -1530,14 +1527,7 @@ virCgroupSetBlkioWeight(virCgroupPtr group,
> unsigned int weight)
>  int
>  virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight)
>  {
> -    unsigned long long tmp;
> -    int ret;
> -    ret = virCgroupGetValueU64(group,
> -                               VIR_CGROUP_CONTROLLER_BLKIO,
> -                               "blkio.weight", &tmp);
> -    if (ret == 0)
> -        *weight = tmp;
> -    return ret;
> +    VIR_CGROUP_BACKEND_CALL(group, getBlkioWeight, -1, weight);
>  }
>
>  /**
> diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
> index 4538654068..2c42227297 100644
> --- a/src/util/vircgroupbackend.h
> +++ b/src/util/vircgroupbackend.h
> @@ -129,6 +129,14 @@ typedef int
>                         gid_t gid,
>                         int controllers);
>
> +typedef int
> +(*virCgroupSetBlkioWeightCB)(virCgroupPtr group,
> +                             unsigned int weight);
> +
> +typedef int
> +(*virCgroupGetBlkioWeightCB)(virCgroupPtr group,
> +                             unsigned int *weight);
> +
>  struct _virCgroupBackend {
>      virCgroupBackendType type;
>
> @@ -151,6 +159,10 @@ struct _virCgroupBackend {
>      virCgroupHasEmptyTasksCB hasEmptyTasks;
>      virCgroupBindMountCB bindMount;
>      virCgroupSetOwnerCB setOwner;
> +
> +    /* Optional cgroup controller specific callbacks. */
> +    virCgroupSetBlkioWeightCB setBlkioWeight;
> +    virCgroupGetBlkioWeightCB getBlkioWeight;
>  };
>  typedef struct _virCgroupBackend virCgroupBackend;
>  typedef virCgroupBackend *virCgroupBackendPtr;
> @@ -161,4 +173,12 @@ virCgroupBackendRegister(virCgroupBackendPtr
> backend);
>  virCgroupBackendPtr *
>  virCgroupBackendGetAll(void);
>
> +# define VIR_CGROUP_BACKEND_CALL(group, func, ret, ...) \
> +    if (!group->backend->func) { \
> +        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", \
> +                       _("operation '" #func "' not supported")); \
> +        return ret; \
> +    } \
> +    return group->backend->func(group, ##__VA_ARGS__);
> +
>  #endif /* __VIR_CGROUP_BACKEND_H__ */
> diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
> index d74fc8ff96..380a310589 100644
> --- a/src/util/vircgroupv1.c
> +++ b/src/util/vircgroupv1.c
> @@ -930,6 +930,32 @@ virCgroupV1SetOwner(virCgroupPtr cgroup,
>  }
>
>
> +static int
> +virCgroupV1SetBlkioWeight(virCgroupPtr group,
> +                          unsigned int weight)
> +{
> +    return virCgroupSetValueU64(group,
> +                                VIR_CGROUP_CONTROLLER_BLKIO,
> +                                "blkio.weight",
> +                                weight);
> +}
> +
> +
> +static int
> +virCgroupV1GetBlkioWeight(virCgroupPtr group,
> +                          unsigned int *weight)
> +{
> +    unsigned long long tmp;
> +    int ret;
> +    ret = virCgroupGetValueU64(group,
> +                               VIR_CGROUP_CONTROLLER_BLKIO,
> +                               "blkio.weight", &tmp);
> +    if (ret == 0)
> +        *weight = tmp;
> +    return ret;
> +}
> +
> +
>  virCgroupBackend virCgroupV1Backend = {
>      .type = VIR_CGROUP_BACKEND_TYPE_V1,
>
> @@ -951,6 +977,9 @@ virCgroupBackend virCgroupV1Backend = {
>      .hasEmptyTasks = virCgroupV1HasEmptyTasks,
>      .bindMount = virCgroupV1BindMount,
>      .setOwner = virCgroupV1SetOwner,
> +
> +    .setBlkioWeight = virCgroupV1SetBlkioWeight,
> +    .getBlkioWeight = virCgroupV1GetBlkioWeight,
>  };
>
>
> --
> 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/8f8c8e99/attachment-0001.htm>


More information about the libvir-list mailing list