From: Jinsheng Zhang <zhangjl02(a)inspur.com>
Instead of cleaning all qos rules each time new qos is set, tx and rx's qos can be set
or clean respectively.
Replace virReportError with VIR_WARN to let the cleaning process continue when error
occurs.
Add ifname into ovs querying statements, which will reduce failure of removing qos on the
other interfaces of the same vm.
Additionally, two problems is fixed.
1. Ingress rules is not clean on previous version of
virNetDevOpenvswitchInterfaceClearQos.
2. If errors occurs when removing inbound qos on multi interfaces vm, some rules may not
be delete as aspected.
Signed-off-by: zhangjl02 <zhangjl02(a)inspur.com>
---
src/libvirt_private.syms | 2 +
src/util/virnetdevopenvswitch.c | 69 +++++++++++++++++++++++++++------
src/util/virnetdevopenvswitch.h | 7 ++++
3 files changed, 67 insertions(+), 11 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6fc8239d2e..7366919d6c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2816,6 +2816,8 @@ virNetDevOpenvswitchAddPort;
virNetDevOpenvswitchGetMigrateData;
virNetDevOpenvswitchGetVhostuserIfname;
virNetDevOpenvswitchInterfaceClearQos;
+virNetDevOpenvswitchInterfaceClearRxQos;
+virNetDevOpenvswitchInterfaceClearTxQos;
virNetDevOpenvswitchInterfaceGetMaster;
virNetDevOpenvswitchInterfaceParseStats;
virNetDevOpenvswitchInterfaceSetQos;
diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c
index 7a64a8dbe6..af9c611905 100644
--- a/src/util/virnetdevopenvswitch.c
+++ b/src/util/virnetdevopenvswitch.c
@@ -778,6 +778,10 @@ virNetDevOpenvswitchInterfaceSetQos(const char *ifname,
return -1;
}
}
+ } else {
+ if (virNetDevOpenvswitchInterfaceClearTxQos(ifname, vmid) < 0) {
+ VIR_WARN("Clean tx qos for interface %s failed", ifname);
+ }
}
if (rx) {
@@ -794,17 +798,23 @@ virNetDevOpenvswitchInterfaceSetQos(const char *ifname,
_("Unable to set vlan configuration on port %s"),
ifname);
return -1;
}
+ } else {
+ if (virNetDevOpenvswitchInterfaceClearRxQos(ifname) < 0) {
+ VIR_WARN("Clean rx qos for interface %s failed", ifname);
+ }
}
return 0;
}
int
-virNetDevOpenvswitchInterfaceClearQos(const char *ifname,
- const unsigned char *vmid)
+virNetDevOpenvswitchInterfaceClearTxQos(const char *ifname,
+ const unsigned char *vmid)
{
+ int ret = 0;
char vmuuidstr[VIR_UUID_STRING_BUFLEN];
g_autoptr(virCommand) cmd = NULL;
+ g_autofree char *ifname_ex_id = NULL;
g_autofree char *vmid_ex_id = NULL;
g_autofree char *qos_uuid = NULL;
g_autofree char *queue_uuid = NULL;
@@ -815,7 +825,8 @@ virNetDevOpenvswitchInterfaceClearQos(const char *ifname,
cmd = virNetDevOpenvswitchCreateCmd();
virUUIDFormat(vmid, vmuuidstr);
vmid_ex_id = g_strdup_printf("external-ids:vm-id=\"%s\"",
vmuuidstr);
- virCommandAddArgList(cmd, "--no-heading", "--columns=_uuid",
"find", "qos", vmid_ex_id, NULL);
+ ifname_ex_id = g_strdup_printf("external-ids:ifname=\"%s\"",
ifname);
+ virCommandAddArgList(cmd, "--no-heading", "--columns=_uuid",
"find", "qos", vmid_ex_id, ifname_ex_id, NULL);
virCommandSetOutputBuffer(cmd, &qos_uuid);
if (virCommandRun(cmd, NULL) < 0) {
VIR_WARN("Unable to find qos on port %s", ifname);
@@ -825,7 +836,7 @@ virNetDevOpenvswitchInterfaceClearQos(const char *ifname,
virCommandFree(cmd);
cmd = virNetDevOpenvswitchCreateCmd();
vmid_ex_id = g_strdup_printf("external-ids:vm-id=\"%s\"",
vmuuidstr);
- virCommandAddArgList(cmd, "--no-heading", "--columns=_uuid",
"find", "queue", vmid_ex_id, NULL);
+ virCommandAddArgList(cmd, "--no-heading", "--columns=_uuid",
"find", "queue", vmid_ex_id, ifname_ex_id, NULL);
virCommandSetOutputBuffer(cmd, &queue_uuid);
if (virCommandRun(cmd, NULL) < 0) {
VIR_WARN("Unable to find queue on port %s", ifname);
@@ -843,7 +854,7 @@ virNetDevOpenvswitchInterfaceClearQos(const char *ifname,
virCommandFree(cmd);
cmd = virNetDevOpenvswitchCreateCmd();
virCommandAddArgList(cmd, "--no-heading",
"--columns=_uuid", "--if-exists",
- "list", "port", ifname, "qos", NULL);
+ "list", "port", ifname,
"qos", NULL);
virCommandSetOutputBuffer(cmd, &port_qos);
if (virCommandRun(cmd, NULL) < 0) {
VIR_WARN("Unable to remove port qos on port %s", ifname);
@@ -860,9 +871,8 @@ virNetDevOpenvswitchInterfaceClearQos(const char *ifname,
cmd = virNetDevOpenvswitchCreateCmd();
virCommandAddArgList(cmd, "destroy", "qos", line, NULL);
if (virCommandRun(cmd, NULL) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unable to destroy qos on port %s"), ifname);
- return -1;
+ VIR_WARN("Unable to destroy qos on port %s", ifname);
+ ret = -1;
}
}
}
@@ -879,12 +889,49 @@ virNetDevOpenvswitchInterfaceClearQos(const char *ifname,
cmd = virNetDevOpenvswitchCreateCmd();
virCommandAddArgList(cmd, "destroy", "queue", line,
NULL);
if (virCommandRun(cmd, NULL) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unable to destroy queue on port %s"),
ifname);
- return -1;
+ VIR_WARN("Unable to destroy queue on port %s", ifname);
+ ret = -1;
}
}
}
+ return ret;
+}
+
+int
+virNetDevOpenvswitchInterfaceClearRxQos(const char *ifname)
+{
+ g_autoptr(virCommand) cmd = NULL;
+
+ cmd = virNetDevOpenvswitchCreateCmd();
+ virCommandAddArgList(cmd, "set", "Interface", ifname, NULL);
+ virCommandAddArgFormat(cmd, "ingress_policing_rate=%llu", 0llu);
+ virCommandAddArgFormat(cmd, "ingress_policing_burst=%llu", 0llu);
+
+ if (virCommandRun(cmd, NULL) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to set vlan configuration on port %s"),
ifname);
+ return -1;
+ }
+
return 0;
}
+
+int
+virNetDevOpenvswitchInterfaceClearQos(const char *ifname,
+ const unsigned char *vmid)
+{
+ int ret = 0;
+
+ if (virNetDevOpenvswitchInterfaceClearTxQos(ifname, vmid) < 0) {
+ VIR_WARN("Clean tx qos for interface %s failed", ifname);
+ ret = -1;
+ }
+
+ if (virNetDevOpenvswitchInterfaceClearRxQos(ifname) < 0) {
+ VIR_WARN("Clean rx qos for interface %s failed", ifname);
+ ret = -1;
+ }
+
+ return ret;
+}
diff --git a/src/util/virnetdevopenvswitch.h b/src/util/virnetdevopenvswitch.h
index 2dcd1aec6b..d44072cc8c 100644
--- a/src/util/virnetdevopenvswitch.h
+++ b/src/util/virnetdevopenvswitch.h
@@ -80,3 +80,10 @@ int virNetDevOpenvswitchInterfaceSetQos(const char *ifname,
int virNetDevOpenvswitchInterfaceClearQos(const char *ifname,
const unsigned char *vmid)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
+
+int virNetDevOpenvswitchInterfaceClearRxQos(const char *ifname)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
+
+int virNetDevOpenvswitchInterfaceClearTxQos(const char *ifname,
+ const unsigned char *vmid)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
--
2.30.2.windows.1