mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
QoS: Set classes and filters in proper direction
Similarly to previous patch, for some types of interface domain and host are on the same side of RX/TX barrier. In that case, we need to set up the QoS differently. Well, swapped. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
d86fd2402e
commit
cea3715b2e
@ -3981,7 +3981,8 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn,
|
||||
actualBandwidth = virDomainNetGetActualBandwidth(net);
|
||||
if (actualBandwidth) {
|
||||
if (virNetDevSupportBandwidth(actualType)) {
|
||||
if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false) < 0)
|
||||
if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
|
||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||
goto cleanup;
|
||||
} else {
|
||||
VIR_WARN("setting bandwidth on interfaces of "
|
||||
|
@ -601,7 +601,8 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
|
||||
actualBandwidth = virDomainNetGetActualBandwidth(net);
|
||||
if (actualBandwidth) {
|
||||
if (virNetDevSupportBandwidth(type)) {
|
||||
if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false) < 0)
|
||||
if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
|
||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||
goto cleanup;
|
||||
} else {
|
||||
VIR_WARN("setting bandwidth on interfaces of "
|
||||
|
@ -2445,7 +2445,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
|
||||
VIR_FORCE_CLOSE(tapfd);
|
||||
}
|
||||
|
||||
if (virNetDevBandwidthSet(def->bridge, def->bandwidth, true) < 0)
|
||||
if (virNetDevBandwidthSet(def->bridge, def->bandwidth, true, true) < 0)
|
||||
goto err5;
|
||||
|
||||
VIR_FREE(macTapIfName);
|
||||
|
@ -8578,7 +8578,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
|
||||
actualBandwidth = virDomainNetGetActualBandwidth(net);
|
||||
if (actualBandwidth) {
|
||||
if (virNetDevSupportBandwidth(actualType)) {
|
||||
if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false) < 0)
|
||||
if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
|
||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||
goto cleanup;
|
||||
} else {
|
||||
VIR_WARN("setting bandwidth on interfaces of "
|
||||
|
@ -11182,11 +11182,13 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
|
||||
if (!networkBandwidthChangeAllowed(net, newBandwidth))
|
||||
goto endjob;
|
||||
|
||||
if (virNetDevBandwidthSet(net->ifname, newBandwidth, false) < 0 ||
|
||||
if (virNetDevBandwidthSet(net->ifname, newBandwidth, false,
|
||||
!virDomainNetTypeSharesHostView(net)) < 0 ||
|
||||
networkBandwidthUpdate(net, newBandwidth) < 0) {
|
||||
ignore_value(virNetDevBandwidthSet(net->ifname,
|
||||
net->bandwidth,
|
||||
false));
|
||||
false,
|
||||
!virDomainNetTypeSharesHostView(net)));
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
|
@ -1209,7 +1209,8 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
|
||||
actualBandwidth = virDomainNetGetActualBandwidth(net);
|
||||
if (actualBandwidth) {
|
||||
if (virNetDevSupportBandwidth(actualType)) {
|
||||
if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false) < 0)
|
||||
if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
|
||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||
goto cleanup;
|
||||
} else {
|
||||
VIR_WARN("setting bandwidth on interfaces of "
|
||||
@ -3362,7 +3363,8 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
|
||||
if (needBandwidthSet) {
|
||||
if (virNetDevBandwidthSet(newdev->ifname,
|
||||
virDomainNetGetActualBandwidth(newdev),
|
||||
false) < 0)
|
||||
false,
|
||||
!virDomainNetTypeSharesHostView(newdev)) < 0)
|
||||
goto cleanup;
|
||||
needReplaceDevDef = true;
|
||||
}
|
||||
|
@ -174,6 +174,7 @@ virNetDevBandwidthManipulateFilter(const char *ifname,
|
||||
* @ifname: on which interface
|
||||
* @bandwidth: rates to set (may be NULL)
|
||||
* @hierarchical_class: whether to create hierarchical class
|
||||
* @swapped: true if IN/OUT should be set contrariwise
|
||||
*
|
||||
* This function enables QoS on specified interface
|
||||
* and set given traffic limits for both, incoming
|
||||
@ -182,14 +183,23 @@ virNetDevBandwidthManipulateFilter(const char *ifname,
|
||||
* hierarchical class. It is used to guarantee minimal
|
||||
* throughput ('floor' attribute in NIC).
|
||||
*
|
||||
* If @swapped is set, the IN part of @bandwidth is set on
|
||||
* @ifname's TX, and vice versa. If it is not set, IN is set on
|
||||
* RX and OUT on TX. This is because for some types of interfaces
|
||||
* domain and the host live on the same side of the interface (so
|
||||
* domain's RX/TX is host's RX/TX), and for some it's swapped
|
||||
* (domain's RX/TX is hosts's TX/RX).
|
||||
*
|
||||
* Return 0 on success, -1 otherwise.
|
||||
*/
|
||||
int
|
||||
virNetDevBandwidthSet(const char *ifname,
|
||||
virNetDevBandwidthPtr bandwidth,
|
||||
bool hierarchical_class)
|
||||
bool hierarchical_class,
|
||||
bool swapped)
|
||||
{
|
||||
int ret = -1;
|
||||
virNetDevBandwidthRatePtr rx = NULL, tx = NULL; /* From domain POV */
|
||||
virCommandPtr cmd = NULL;
|
||||
char *average = NULL;
|
||||
char *peak = NULL;
|
||||
@ -215,16 +225,24 @@ virNetDevBandwidthSet(const char *ifname,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (swapped) {
|
||||
rx = bandwidth->out;
|
||||
tx = bandwidth->in;
|
||||
} else {
|
||||
rx = bandwidth->in;
|
||||
tx = bandwidth->out;
|
||||
}
|
||||
|
||||
virNetDevBandwidthClear(ifname);
|
||||
|
||||
if (bandwidth->in && bandwidth->in->average) {
|
||||
if (virAsprintf(&average, "%llukbps", bandwidth->in->average) < 0)
|
||||
if (tx && tx->average) {
|
||||
if (virAsprintf(&average, "%llukbps", tx->average) < 0)
|
||||
goto cleanup;
|
||||
if (bandwidth->in->peak &&
|
||||
(virAsprintf(&peak, "%llukbps", bandwidth->in->peak) < 0))
|
||||
if (tx->peak &&
|
||||
(virAsprintf(&peak, "%llukbps", tx->peak) < 0))
|
||||
goto cleanup;
|
||||
if (bandwidth->in->burst &&
|
||||
(virAsprintf(&burst, "%llukb", bandwidth->in->burst) < 0))
|
||||
if (tx->burst &&
|
||||
(virAsprintf(&burst, "%llukb", tx->burst) < 0))
|
||||
goto cleanup;
|
||||
|
||||
cmd = virCommandNew(TC);
|
||||
@ -303,7 +321,7 @@ virNetDevBandwidthSet(const char *ifname,
|
||||
virCommandAddArgList(cmd, "class", "add", "dev", ifname, "parent",
|
||||
"1:", "classid", "1:1", "htb", "rate", average,
|
||||
"ceil", peak ? peak : average, NULL);
|
||||
virNetDevBandwidthCmdAddOptimalQuantum(cmd, bandwidth->in);
|
||||
virNetDevBandwidthCmdAddOptimalQuantum(cmd, tx);
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
@ -319,7 +337,7 @@ virNetDevBandwidthSet(const char *ifname,
|
||||
if (burst)
|
||||
virCommandAddArgList(cmd, "burst", burst, NULL);
|
||||
|
||||
virNetDevBandwidthCmdAddOptimalQuantum(cmd, bandwidth->in);
|
||||
virNetDevBandwidthCmdAddOptimalQuantum(cmd, tx);
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
@ -347,11 +365,10 @@ virNetDevBandwidthSet(const char *ifname,
|
||||
VIR_FREE(burst);
|
||||
}
|
||||
|
||||
if (bandwidth->out) {
|
||||
if (virAsprintf(&average, "%llukbps", bandwidth->out->average) < 0)
|
||||
if (rx) {
|
||||
if (virAsprintf(&average, "%llukbps", rx->average) < 0)
|
||||
goto cleanup;
|
||||
if (virAsprintf(&burst, "%llukb", bandwidth->out->burst ?
|
||||
bandwidth->out->burst : bandwidth->out->average) < 0)
|
||||
if (virAsprintf(&burst, "%llukb", rx->burst ? rx->burst : rx->average) < 0)
|
||||
goto cleanup;
|
||||
|
||||
virCommandFree(cmd);
|
||||
|
@ -45,7 +45,8 @@ void virNetDevBandwidthFree(virNetDevBandwidthPtr def);
|
||||
|
||||
int virNetDevBandwidthSet(const char *ifname,
|
||||
virNetDevBandwidthPtr bandwidth,
|
||||
bool hierarchical_class)
|
||||
bool hierarchical_class,
|
||||
bool swapped)
|
||||
ATTRIBUTE_RETURN_CHECK;
|
||||
int virNetDevBandwidthClear(const char *ifname);
|
||||
int virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest,
|
||||
|
@ -81,7 +81,7 @@ testVirNetDevBandwidthSet(const void *data)
|
||||
|
||||
virCommandSetDryRun(&buf, NULL, NULL);
|
||||
|
||||
if (virNetDevBandwidthSet(iface, band, info->hierarchical_class) < 0)
|
||||
if (virNetDevBandwidthSet(iface, band, info->hierarchical_class, true) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(actual_cmd = virBufferContentAndReset(&buf))) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user