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

Re: [Xen-devel] [libvirt] [PATCH V2 1/3] xenconfig: support vif bandwidth in sexpr parser and formatter




On 01/04/2016 08:08 PM, Jim Fehlig wrote:
> The xen sexpr config format has long supported specifying vif rate
> limiting, e.g.
> 
>   (device
>     (vif
>       (mac '00:16:3e:1b:b1:47')
>       (rate '10240KB/s')
>       ...
>     )
>   )
> 
> Add support for mapping rate to and from <bandwidth> in the xenconfig
> sexpr parser and formatter. rate is mapped to the required 'average'
> attribute of the <outbound> element, e.g.
> 
>   <interface type='bridge'>
>     ...
>     <bandwidth>
>       <outbound average='10240'/>
>     </bandwidth>
>   </interface>
> 
> Also add unit tests to check the conversion logic.
> 
> This patch benefits both the old xen driver and the libxl driver.
> Both drivers gain support for vif bandwidth when converting to/from
> domXML and xen-sxpr. In addition, the old xen driver will now be
> able to handle vif 'rate' setting when communicating with xend.
> 
> Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx>
> ---
> 
> I used a bit of code from libxlu_vif.c to implement xenParseSxprVifRate()
> instead of using the libxlutil lib directly, since rate limiting applies
> to the old xen driver (no libxl) as well.
> 
>  src/libvirt_xenconfig.syms                      |  1 +
>  src/xenconfig/xen_sxpr.c                        | 74 
> +++++++++++++++++++++++++
>  src/xenconfig/xen_sxpr.h                        |  2 +
>  tests/sexpr2xmldata/sexpr2xml-vif-rate.sexpr    | 11 ++++
>  tests/sexpr2xmldata/sexpr2xml-vif-rate.xml      | 51 +++++++++++++++++
>  tests/sexpr2xmltest.c                           |  2 +
>  tests/xml2sexprdata/xml2sexpr-fv-net-rate.sexpr | 10 ++++
>  tests/xml2sexprdata/xml2sexpr-fv-net-rate.xml   | 34 ++++++++++++
>  tests/xml2sexprtest.c                           |  1 +
>  9 files changed, 186 insertions(+)
> 

Coverity found an 'issue'...

> diff --git a/src/libvirt_xenconfig.syms b/src/libvirt_xenconfig.syms
> index 6541685..b69f2ab 100644
> --- a/src/libvirt_xenconfig.syms
> +++ b/src/libvirt_xenconfig.syms
> @@ -15,6 +15,7 @@ xenParseSxpr;
>  xenParseSxprChar;
>  xenParseSxprSound;
>  xenParseSxprString;
> +xenParseSxprVifRate;
>  
>  # xenconfig/xen_xm.h
>  xenFormatXM;
> diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
> index d99bac0..9ae50b0 100644
> --- a/src/xenconfig/xen_sxpr.c
> +++ b/src/xenconfig/xen_sxpr.c
> @@ -26,6 +26,8 @@
>  
>  #include <config.h>
>  
> +#include <regex.h>
> +
>  #include "internal.h"
>  #include "virerror.h"
>  #include "virconf.h"
> @@ -315,6 +317,56 @@ xenParseSxprChar(const char *value,
>  }
>  
>  
> +static const char *vif_bytes_per_sec_re = "^[0-9]+[GMK]?[Bb]/s$";
> +
> +int
> +xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec)
> +{
> +    char *trate = NULL;
> +    char *p;
> +    regex_t rec;
> +    char *suffix;
> +    unsigned long long tmp;
> +    int ret = -1;
> +
> +    if (VIR_STRDUP(trate, rate) < 0)
> +        return -1;
> +
> +    p = strchr(trate, '@');
> +    if (p != NULL)
> +        *p = 0;
> +
> +    regcomp(&rec, vif_bytes_per_sec_re, REG_EXTENDED|REG_NOSUB);

5) Event check_return:  Calling "regcomp" without checking return value
(as is done elsewhere 14 out of 15 times).

IOW: What if regcomp fails...

John
> +    if (regexec(&rec, trate, 0, NULL, 0)) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("Invalid rate '%s' specified"), rate);
> +        goto cleanup;
> +    }
> +
> +    if (virStrToLong_ull(rate, &suffix, 10, &tmp)) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("Failed to parse rate '%s'"), rate);
> +        goto cleanup;
> +    }
> +
> +    if (*suffix == 'G')
> +       tmp *= 1024 * 1024;
> +    else if (*suffix == 'M')
> +       tmp *= 1024;
> +
> +    if (*suffix == 'b' || *(suffix + 1) == 'b')
> +       tmp /= 8;
> +
> +    *kbytes_per_sec = tmp;
> +    ret = 0;
> +
> + cleanup:
> +    regfree(&rec);
> +    VIR_FREE(trate);
> +    return ret;
> +}
> +
> +

<...>

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.