[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 3/6] virsh: blockjob: Support --bytes and scaled integers as bandwidth




On 03/18/2016 04:57 AM, Peter Krempa wrote:
> Allow specifying sizes in bytes or as scaled integers for user
> convenience.
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1288000
> ---
>  tools/virsh-domain.c | 17 ++++++++++-------
>  tools/virsh.pod      | 11 ++++++++---
>  tools/vsh.c          | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  tools/vsh.h          |  4 ++++
>  4 files changed, 74 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c

[...]

> diff --git a/tools/vsh.c b/tools/vsh.c
> index cbe8189..f90619d 100644
> --- a/tools/vsh.c
> +++ b/tools/vsh.c
> @@ -1201,6 +1201,58 @@ vshCommandOptArgv(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd,
>  }
> 
> 
> +/**
> + * vshBlockJobOptionBandwidth
> + * @ctl: virsh control data
> + * @cmd: virsh command description
> + * @bytes: return bandwidth in bytes/s instead of MiB/s
> + * @bandwidth: return value
> + *
> + * Extracts the value of --bandwidth either as a wrappable number without scale

wrappable is not a word... but wrap-able works

> + * or as a scaled integer. The returned value is checked to fit into a unsigned
> + * long data type. This is a legacy compatibility function and it should not
> + * be used for things other the block job APIs.
> + *
> + * Returns 0 on success, -1 on error.
> + */
> +int
> +vshBlockJobOptionBandwidth(vshControl *ctl,
> +                           const vshCmd *cmd,
> +                           bool bytes,
> +                           unsigned long *bandwidth)
> +{
> +    vshCmdOpt *arg;
> +    char *end;
> +    unsigned long long bw;
> +    int ret;
> +
> +    if ((ret = vshCommandOpt(cmd, "bandwidth", &arg, true)) <= 0)
> +        return ret;
> +
> +    /* due to historical reasons we declare to parse negative numbers and wrap
> +     * them to the unsigned data type. */
> +    if (virStrToLong_ul(arg->data, NULL, 10, bandwidth) < 0) {
> +        /* try to parse the number as scaled size in this cas we don't accept

s/this cas/this case/

> +         * wrapping since it would be ridiculous. In case of a 32 bit host,
> +         * limit the value to ULONG_MAX */
> +        if (virStrToLong_ullp(arg->data, &end, 10, &bw) < 0 ||
> +            virScaleInteger(&bw, end, 1, ULONG_MAX) < 0) {
> +            vshError(ctl,
> +                     _("Scaled numeric value '%s' for <--bandwidth> option is "
> +                       "malformed or out of range"), arg->data);
> +            return -1;
> +        }
> +
> +        if (!bytes)
> +            bw >>= 20;
> +
> +        *bandwidth = bw;
> +    }
> +
> +    return 0;
> +}
> +
> +
>  /*
>   * Executes command(s) and returns return code from last command
>   */
[...]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]