From d05aa66db308b9f6c24d7c060809cd5b3a869be9 Mon Sep 17 00:00:00 2001 From: Jinsheng Zhang Date: Tue, 17 Aug 2021 12:38:12 +0800 Subject: [PATCH] virnetdevopenvswitch: Extract conversion parameters between virNetDevBandwidth and ovs Signed-off-by: zhangjl02 Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- src/util/virnetdevopenvswitch.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index d86ad0eafd..a3eb720063 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -620,6 +620,14 @@ int virNetDevOpenvswitchUpdateVlan(const char *ifname, } +/* + * Average, peak, floor and burst in virNetDevBandwidth are in kbytes. + * However other_config in ovs qos is in bit. + * ingress_policing_rate in ovs interface is in kbit. + */ +#define VIR_NETDEV_TX_TO_OVS 8192 +#define VIR_NETDEV_RX_TO_OVS 8 + /** * virNetDevOpenvswitchInterfaceSetQos: * @ifname: on which interface @@ -692,11 +700,11 @@ virNetDevOpenvswitchInterfaceSetQos(const char *ifname, g_autofree char *qos_uuid = NULL; g_autofree char *queue_uuid = NULL; - average = g_strdup_printf("%llu", tx->average * 8192); + average = g_strdup_printf("%llu", tx->average * VIR_NETDEV_TX_TO_OVS); if (tx->burst) - burst = g_strdup_printf("%llu", tx->burst * 8192); + burst = g_strdup_printf("%llu", tx->burst * VIR_NETDEV_TX_TO_OVS); if (tx->peak) - peak = g_strdup_printf("%llu", tx->peak * 8192); + peak = g_strdup_printf("%llu", tx->peak * VIR_NETDEV_TX_TO_OVS); /* find queue */ cmd = virNetDevOpenvswitchCreateCmd(); @@ -786,9 +794,11 @@ virNetDevOpenvswitchInterfaceSetQos(const char *ifname, cmd = virNetDevOpenvswitchCreateCmd(); virCommandAddArgList(cmd, "set", "Interface", ifname, NULL); - virCommandAddArgFormat(cmd, "ingress_policing_rate=%llu", rx->average * 8); + virCommandAddArgFormat(cmd, "ingress_policing_rate=%llu", + rx->average * VIR_NETDEV_RX_TO_OVS); if (rx->burst) - virCommandAddArgFormat(cmd, "ingress_policing_burst=%llu", rx->burst * 8); + virCommandAddArgFormat(cmd, "ingress_policing_burst=%llu", + rx->burst * VIR_NETDEV_RX_TO_OVS); if (virCommandRun(cmd, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR,