From patchwork Tue Jan 5 01:08:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Fehlig X-Patchwork-Id: 7952201 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 69C49BEEE5 for ; Tue, 5 Jan 2016 01:11:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2EDA52034A for ; Tue, 5 Jan 2016 01:11:34 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E3D7D202E9 for ; Tue, 5 Jan 2016 01:11:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aGG79-00078C-Hc; Tue, 05 Jan 2016 01:08:43 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aGG76-00077C-RJ for xen-devel@lists.xen.org; Tue, 05 Jan 2016 01:08:41 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 47/8D-23747-8971B865; Tue, 05 Jan 2016 01:08:40 +0000 X-Env-Sender: jfehlig@suse.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1451956115!13371461!1 X-Originating-IP: [137.65.250.81] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 14564 invoked from network); 5 Jan 2016 01:08:36 -0000 Received: from smtp2.provo.novell.com (HELO smtp2.provo.novell.com) (137.65.250.81) by server-13.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 5 Jan 2016 01:08:36 -0000 Received: from linux-m42f.gns.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Mon, 04 Jan 2016 18:08:31 -0700 From: Jim Fehlig To: libvir-list@redhat.com Date: Mon, 4 Jan 2016 18:08:13 -0700 Message-Id: <1451956095-25353-2-git-send-email-jfehlig@suse.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1451956095-25353-1-git-send-email-jfehlig@suse.com> References: <1451956095-25353-1-git-send-email-jfehlig@suse.com> Cc: Jim Fehlig , xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH V2 1/3] xenconfig: support vif bandwidth in sexpr parser and formatter X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 in the xenconfig sexpr parser and formatter. rate is mapped to the required 'average' attribute of the element, e.g. ... 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 --- 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(+) 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 +#include + #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); + 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; +} + + /** * xenParseSxprDisks: * @def: the domain config @@ -594,6 +646,25 @@ xenParseSxprNets(virDomainDefPtr def, VIR_STRDUP(net->model, "netfront") < 0) goto cleanup; + tmp = sexpr_node(node, "device/vif/rate"); + if (tmp) { + virNetDevBandwidthPtr bandwidth; + unsigned long long kbytes_per_sec; + + if (xenParseSxprVifRate(tmp, &kbytes_per_sec) < 0) + goto cleanup; + + if (VIR_ALLOC(bandwidth) < 0) + goto cleanup; + if (VIR_ALLOC(bandwidth->out) < 0) { + VIR_FREE(bandwidth); + goto cleanup; + } + + bandwidth->out->average = kbytes_per_sec; + net->bandwidth = bandwidth; + } + if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0) goto cleanup; @@ -1784,6 +1855,9 @@ xenFormatSxprNet(virConnectPtr conn, virBufferAsprintf(buf, "(mac '%s')", virMacAddrFormat(&def->mac, macaddr)); + if (def->bandwidth && def->bandwidth->out && def->bandwidth->out->average) + virBufferAsprintf(buf, "(rate '%lluKB/s')", def->bandwidth->out->average); + switch (def->type) { case VIR_DOMAIN_NET_TYPE_BRIDGE: virBufferEscapeSexpr(buf, "(bridge '%s')", def->data.bridge.brname); diff --git a/src/xenconfig/xen_sxpr.h b/src/xenconfig/xen_sxpr.h index a4f4c44..76ff943 100644 --- a/src/xenconfig/xen_sxpr.h +++ b/src/xenconfig/xen_sxpr.h @@ -49,6 +49,8 @@ int xenParseSxprSound(virDomainDefPtr def, const char *str); virDomainChrDefPtr xenParseSxprChar(const char *value, const char *tty); +int xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec); + int xenFormatSxprDisk(virDomainDiskDefPtr def, virBufferPtr buf, int hvm, int isAttach); diff --git a/tests/sexpr2xmldata/sexpr2xml-vif-rate.sexpr b/tests/sexpr2xmldata/sexpr2xml-vif-rate.sexpr new file mode 100644 index 0000000..c3ed8e8 --- /dev/null +++ b/tests/sexpr2xmldata/sexpr2xml-vif-rate.sexpr @@ -0,0 +1,11 @@ +(domain (domid 3)(name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)\ +(uuid 'b5d70dd275cdaca517769660b059d8bc')(on_poweroff 'destroy')\ +(on_reboot 'restart')(on_crash 'restart')\ +(image (hvm (kernel '/usr/lib/xen/boot/hvmloader')\ +(device_model '/usr/lib64/xen/bin/qemu-dm')(boot c)\ +(acpi 1)(vnc 1)(keymap ja)))(device (vbd (dev 'ioemu:hda')\ +(uname 'file:/root/foo.img')(mode 'w')))\ +(device (vbd (dev 'hdc:cdrom')\ +(uname 'file:/root/boot.iso')(mode 'r')))\ +(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')\ +(script 'vif-bridge')(type 'netfront')(rate '10240KB/s')))) diff --git a/tests/sexpr2xmldata/sexpr2xml-vif-rate.xml b/tests/sexpr2xmldata/sexpr2xml-vif-rate.xml new file mode 100644 index 0000000..0531817 --- /dev/null +++ b/tests/sexpr2xmldata/sexpr2xml-vif-rate.xml @@ -0,0 +1,51 @@ + + fvtest + b5d70dd2-75cd-aca5-1776-9660b059d8bc + 409600 + 409600 + 1 + + hvm + /usr/lib/xen/boot/hvmloader + + + + + + + destroy + restart + restart + + /usr/lib64/xen/bin/qemu-dm + + + + + +
+ + + + + + + +
+ + + + + + + +