From patchwork Tue Jan 5 01:08:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Fehlig X-Patchwork-Id: 7952221 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 241A7BEEE5 for ; Tue, 5 Jan 2016 01:11:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2B838202EC for ; Tue, 5 Jan 2016 01:11:39 +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 07399202E9 for ; Tue, 5 Jan 2016 01:11:38 +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 1aGG78-00077k-L4; Tue, 05 Jan 2016 01:08:42 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aGG76-00077A-FL for xen-devel@lists.xen.org; Tue, 05 Jan 2016 01:08:40 +0000 Received: from [85.158.143.35] by server-2.bemta-4.messagelabs.com id 60/75-27104-7971B865; Tue, 05 Jan 2016 01:08:39 +0000 X-Env-Sender: jfehlig@suse.com X-Msg-Ref: server-14.tower-21.messagelabs.com!1451956115!8378433!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 7092 invoked from network); 5 Jan 2016 01:08:37 -0000 Received: from smtp2.provo.novell.com (HELO smtp2.provo.novell.com) (137.65.250.81) by server-14.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 5 Jan 2016 01:08:37 -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:32 -0700 From: Jim Fehlig To: libvir-list@redhat.com Date: Mon, 4 Jan 2016 18:08:14 -0700 Message-Id: <1451956095-25353-3-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 2/3] xenconfig: support vif bandwidth in xm and xl 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 Both xm and xl config have long supported specifying vif rate limiting, e.g. vif = [ 'mac=00:16:3E:74:3d:76,bridge=br0,rate=10MB/s' ] Add support for mapping rate to and from in the xenconfig parser and formatter. rate is mapped to the required 'average' attribute of the element, e.g. ... Also add a unit test to check the conversion logic. Signed-off-by: Jim Fehlig --- src/xenconfig/xen_common.c | 30 +++++++++++++++++++ tests/xlconfigdata/test-vif-rate.cfg | 26 ++++++++++++++++ tests/xlconfigdata/test-vif-rate.xml | 57 ++++++++++++++++++++++++++++++++++++ tests/xlconfigtest.c | 1 + 4 files changed, 114 insertions(+) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 54f5791..7cc8639 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -819,6 +819,7 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def) char mac[18]; char bridge[50]; char vifname[50]; + char rate[50]; char *key; bridge[0] = '\0'; @@ -827,6 +828,7 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def) model[0] = '\0'; type[0] = '\0'; vifname[0] = '\0'; + rate[0] = '\0'; if ((list->type != VIR_CONF_STRING) || (list->str == NULL)) goto skipnic; @@ -892,6 +894,13 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def) _("IP %s too big for destination"), data); goto skipnic; } + } else if (STRPREFIX(key, "rate=")) { + int len = nextkey ? (nextkey - data) : sizeof(rate) - 1; + if (virStrncpy(rate, data, len, sizeof(rate)) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("rate %s too big for destination"), data); + goto skipnic; + } } while (nextkey && (nextkey[0] == ',' || @@ -942,6 +951,24 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def) VIR_STRDUP(net->ifname, vifname) < 0) goto cleanup; + if (rate[0]) { + virNetDevBandwidthPtr bandwidth; + unsigned long long kbytes_per_sec; + + if (xenParseSxprVifRate(rate, &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; @@ -1184,6 +1211,9 @@ xenFormatNet(virConnectPtr conn, virBufferAsprintf(&buf, ",vifname=%s", net->ifname); + if (net->bandwidth && net->bandwidth->out && net->bandwidth->out->average) + virBufferAsprintf(&buf, ",rate=%lluKB/s", net->bandwidth->out->average); + if (virBufferCheckError(&buf) < 0) goto cleanup; diff --git a/tests/xlconfigdata/test-vif-rate.cfg b/tests/xlconfigdata/test-vif-rate.cfg new file mode 100644 index 0000000..c5484dc --- /dev/null +++ b/tests/xlconfigdata/test-vif-rate.cfg @@ -0,0 +1,26 @@ +name = "XenGuest2" +uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" +maxmem = 579 +memory = 394 +vcpus = 1 +pae = 1 +acpi = 1 +apic = 1 +hap = 0 +viridian = 0 +rtc_timeoffset = 0 +localtime = 0 +on_poweroff = "destroy" +on_reboot = "restart" +on_crash = "restart" +device_model = "/usr/lib/xen/bin/qemu-dm" +sdl = 0 +vnc = 1 +vncunused = 1 +vnclisten = "127.0.0.1" +vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,rate=10240KB/s" ] +parallel = "none" +serial = "none" +builder = "hvm" +boot = "d" +disk = [ "/dev/HostVG/XenGuest2,raw,hda,w,backendtype=phy", "/var/lib/libvirt/images/XenGuest2-home,qcow2,hdb,w,backendtype=qdisk", "/root/boot.iso,raw,hdc,r,backendtype=qdisk,devtype=cdrom" ] diff --git a/tests/xlconfigdata/test-vif-rate.xml b/tests/xlconfigdata/test-vif-rate.xml new file mode 100644 index 0000000..29f0f79 --- /dev/null +++ b/tests/xlconfigdata/test-vif-rate.xml @@ -0,0 +1,57 @@ + + XenGuest2 + c7a5fdb2-cdaf-9455-926a-d65c16db1809 + 592896 + 403456 + 1 + + hvm + /usr/lib/xen/boot/hvmloader + + + + + + + + + destroy + restart + restart + + /usr/lib/xen/bin/qemu-dm + + + + +
+ + + + + +
+ + + + + + +
+ + + + + + + +