From 149733821d4a9cfc6c4ec55cfd90ddab163a1cfe Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 18 Mar 2014 10:50:02 +0100 Subject: [PATCH] qemuDomainSetInterfaceParameters: Allow bandwidth clear out We allow translation from no_bandwidth to has_bandwidth for a vnic. However, going in the opposite direction is not implemented. It's not limitation of the API rather than internal implementation. The problem is, we correctly detect that user hasn't specified any outbound (say he wants to clear out outbound). However, this gets overwritten by current vnic outbound settings. Then, virNetDevBandwidthSet doesn't change anything. We need to stop overwriting the outbound if users don't want us to. Same applies for inbound. Signed-off-by: Michal Privoznik --- src/qemu/qemu_driver.c | 15 +++++++++++---- tools/virsh-domain.c | 4 ++-- tools/virsh.pod | 3 +++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c83021e6f5..6b96c1673a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9739,6 +9739,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, virNetDevBandwidthPtr bandwidth = NULL, newBandwidth = NULL; virQEMUDriverConfigPtr cfg = NULL; virCapsPtr caps = NULL; + bool inboundSpecified = false, outboundSpecified = false; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); @@ -9800,12 +9801,14 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_IN_AVERAGE)) { bandwidth->in->average = params[i].value.ui; + inboundSpecified = true; } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_IN_PEAK)) { bandwidth->in->peak = params[i].value.ui; } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_IN_BURST)) { bandwidth->in->burst = params[i].value.ui; } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_OUT_AVERAGE)) { bandwidth->out->average = params[i].value.ui; + outboundSpecified = true; } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_OUT_PEAK)) { bandwidth->out->peak = params[i].value.ui; } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_OUT_BURST)) { @@ -9831,7 +9834,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, * bandwidth parameters, so merge with old bandwidth parameters * here to prevent them from being lost. */ if (bandwidth->in || - (net->bandwidth && net->bandwidth->in)) { + (!inboundSpecified && net->bandwidth && net->bandwidth->in)) { if (VIR_ALLOC(newBandwidth->in) < 0) goto cleanup; @@ -9840,7 +9843,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, sizeof(*newBandwidth->in)); } if (bandwidth->out || - (net->bandwidth && net->bandwidth->out)) { + (!outboundSpecified && net->bandwidth && net->bandwidth->out)) { if (VIR_ALLOC(newBandwidth->out) < 0) goto cleanup; @@ -9857,8 +9860,12 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, } virNetDevBandwidthFree(net->bandwidth); - net->bandwidth = newBandwidth; - newBandwidth = NULL; + if (newBandwidth->in || newBandwidth->out) { + net->bandwidth = newBandwidth; + newBandwidth = NULL; + } else { + net->bandwidth = NULL; + } } if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (!persistentNet->bandwidth) { diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index fbde3da0db..cb6bf63da1 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2615,7 +2615,7 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("inbound format is incorrect")); goto cleanup; } - if (inbound.average == 0) { + if (inbound.average == 0 && (inbound.burst || inbound.peak)) { vshError(ctl, _("inbound average is mandatory")); goto cleanup; } @@ -2643,7 +2643,7 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("outbound format is incorrect")); goto cleanup; } - if (outbound.average == 0) { + if (outbound.average == 0 && (outbound.burst || outbound.peak)) { vshError(ctl, _("outbound average is mandatory")); goto cleanup; } diff --git a/tools/virsh.pod b/tools/virsh.pod index 5c74bb328c..3e721e0fe5 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -698,6 +698,9 @@ expressed in kilobytes per second, while I is expressed in kilobytes in a single burst at -I speed as described in the Network XML documentation at L. +To clear inbound or outbound settings, use I<--inbound> or I<--outbound> +respectfully with average of value zero. + If I<--live> is specified, affect a running guest. If I<--config> is specified, affect the next boot of a persistent guest. If I<--current> is specified, affect the current guest state.