mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
util: openvswitch: split out virNetDevOpenvswitchInterfaceSetTxQos
The virNetDevOpenvswitchInterfaceSetQos function is uneven because setting the Tx Qos is open-coded, while clearing it is sepearated in another function. Separate the setting too. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
186aa292a0
commit
be82600128
@ -745,68 +745,11 @@ virNetDevOpenvswitchInterfaceClearRxQos(const char *ifname)
|
||||
#define KIBIBYTE_TO_BITS(x) (x * 8192ULL)
|
||||
#define VIR_NETDEV_RX_TO_OVS 8
|
||||
|
||||
/**
|
||||
* virNetDevOpenvswitchInterfaceSetQos:
|
||||
* @ifname: on which interface
|
||||
* @bandwidth: rates to set (may be NULL)
|
||||
* @vmuuid: the Domain UUID that has this interface
|
||||
* @swapped: true if IN/OUT should be set contrariwise
|
||||
*
|
||||
* Update qos configuration of an OVS port.
|
||||
*
|
||||
* 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
|
||||
virNetDevOpenvswitchInterfaceSetQos(const char *ifname,
|
||||
const virNetDevBandwidth *bandwidth,
|
||||
const unsigned char *vmuuid,
|
||||
bool swapped)
|
||||
static int
|
||||
virNetDevOpenvswitchInterfaceSetTxQos(const char *ifname,
|
||||
const virNetDevBandwidthRate *tx,
|
||||
const unsigned char *vmuuid)
|
||||
{
|
||||
virNetDevBandwidthRate *rx = NULL; /* From domain POV */
|
||||
virNetDevBandwidthRate *tx = NULL; /* From domain POV */
|
||||
|
||||
if (!bandwidth) {
|
||||
/* nothing to be enabled */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (geteuid() != 0) {
|
||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||
_("Network bandwidth tuning is not available"
|
||||
" in session mode"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!ifname) {
|
||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||
_("Unable to set bandwidth for interface because "
|
||||
"device name is unknown"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (swapped) {
|
||||
rx = bandwidth->out;
|
||||
tx = bandwidth->in;
|
||||
} else {
|
||||
rx = bandwidth->in;
|
||||
tx = bandwidth->out;
|
||||
}
|
||||
|
||||
if (!bandwidth->out && !bandwidth->in) {
|
||||
if (virNetDevOpenvswitchInterfaceClearQos(ifname, vmuuid) < 0) {
|
||||
VIR_WARN("Clean qos for interface %s failed", ifname);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tx && tx->average) {
|
||||
char vmuuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
g_autoptr(virCommand) cmd = NULL;
|
||||
g_autofree char *vmid_ex_id = NULL;
|
||||
@ -889,6 +832,74 @@ virNetDevOpenvswitchInterfaceSetQos(const char *ifname,
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* virNetDevOpenvswitchInterfaceSetQos:
|
||||
* @ifname: on which interface
|
||||
* @bandwidth: rates to set (may be NULL)
|
||||
* @vmuuid: the Domain UUID that has this interface
|
||||
* @swapped: true if IN/OUT should be set contrariwise
|
||||
*
|
||||
* Update qos configuration of an OVS port.
|
||||
*
|
||||
* 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
|
||||
virNetDevOpenvswitchInterfaceSetQos(const char *ifname,
|
||||
const virNetDevBandwidth *bandwidth,
|
||||
const unsigned char *vmuuid,
|
||||
bool swapped)
|
||||
{
|
||||
virNetDevBandwidthRate *rx = NULL; /* From domain POV */
|
||||
virNetDevBandwidthRate *tx = NULL; /* From domain POV */
|
||||
|
||||
if (!bandwidth) {
|
||||
/* nothing to be enabled */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (geteuid() != 0) {
|
||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||
_("Network bandwidth tuning is not available"
|
||||
" in session mode"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!ifname) {
|
||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||
_("Unable to set bandwidth for interface because "
|
||||
"device name is unknown"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (swapped) {
|
||||
rx = bandwidth->out;
|
||||
tx = bandwidth->in;
|
||||
} else {
|
||||
rx = bandwidth->in;
|
||||
tx = bandwidth->out;
|
||||
}
|
||||
|
||||
if (!bandwidth->out && !bandwidth->in) {
|
||||
if (virNetDevOpenvswitchInterfaceClearQos(ifname, vmuuid) < 0) {
|
||||
VIR_WARN("Clean qos for interface %s failed", ifname);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tx && tx->average) {
|
||||
if (virNetDevOpenvswitchInterfaceSetTxQos(ifname, tx, vmuuid) < 0)
|
||||
return -1;
|
||||
} else {
|
||||
if (virNetDevOpenvswitchInterfaceClearTxQos(ifname, vmuuid) < 0) {
|
||||
VIR_WARN("Clean tx qos for interface %s failed", ifname);
|
||||
|
Loading…
x
Reference in New Issue
Block a user