diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 54f5791905..7cc8639977 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 0000000000..c5484dc50f --- /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 0000000000..29f0f79e26 --- /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 + + + + +
+ + + + + +
+ + + + + + +
+ + + + + + + +