From: John Ferlan <jferlan@redhat.com>
To: Jim Fehlig <jfehlig@suse.com>, libvir-list@redhat.com
Cc: xen-devel@lists.xen.org
Subject: Re: [libvirt] [PATCH V2 1/3] xenconfig: support vif bandwidth in sexpr parser and formatter
Date: Tue, 12 Jan 2016 08:41:19 -0500 [thread overview]
Message-ID: <5695027F.4030401@redhat.com> (raw)
In-Reply-To: <1451956095-25353-2-git-send-email-jfehlig@suse.com>
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@suse.com>
> ---
>
> 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;
> +}
> +
> +
<...>
prev parent reply other threads:[~2016-01-12 13:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1451956095-25353-1-git-send-email-jfehlig@suse.com>
2016-01-05 1:08 ` [PATCH V2 1/3] xenconfig: support vif bandwidth in sexpr parser and formatter Jim Fehlig
2016-01-05 1:08 ` [PATCH V2 2/3] xenconfig: support vif bandwidth in xm and xl " Jim Fehlig
2016-01-05 1:08 ` [PATCH V2 3/3] libxl: support vif outgoing bandwidth QoS Jim Fehlig
2016-01-08 16:45 ` [libvirt] [PATCH V2 0/3] Xen: Support vif outging " Michal Privoznik
[not found] ` <568FE7AC.9050004@redhat.com>
2016-01-09 1:59 ` Jim Fehlig
[not found] ` <1451956095-25353-2-git-send-email-jfehlig@suse.com>
2016-01-12 13:41 ` John Ferlan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5695027F.4030401@redhat.com \
--to=jferlan@redhat.com \
--cc=jfehlig@suse.com \
--cc=libvir-list@redhat.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).