From nobody Sun May 5 11:58:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=126.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1628474870343282.1469380853381; Sun, 8 Aug 2021 19:07:50 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-100-lQygrzJKNO-cxdF3jFNezg-1; Sun, 08 Aug 2021 22:07:47 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D54AD1084F4B; Mon, 9 Aug 2021 02:07:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ADD7E66FFF; Mon, 9 Aug 2021 02:07:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4F6C4180BAB1; Mon, 9 Aug 2021 02:07:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17926GRZ010527 for ; Sun, 8 Aug 2021 22:06:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7051B568E6; Mon, 9 Aug 2021 02:06:16 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6B257568E4 for ; Mon, 9 Aug 2021 02:06:12 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A68B78CA942 for ; Mon, 9 Aug 2021 02:06:12 +0000 (UTC) Received: from m15113.mail.126.com (m15113.mail.126.com [220.181.15.113]) by relay.mimecast.com with ESMTP id us-mta-548-0v7o_nFYMzuW2NnZQ9HDbg-1; Sun, 08 Aug 2021 22:06:10 -0400 Received: from zhangjl0200.home.langchao.com (unknown [223.104.194.187]) by smtp3 (Coremail) with SMTP id DcmowAAnd8OMjRBhXsB1Tw--.2037S3; Mon, 09 Aug 2021 10:06:06 +0800 (CST) X-MC-Unique: lQygrzJKNO-cxdF3jFNezg-1 X-MC-Unique: 0v7o_nFYMzuW2NnZQ9HDbg-1 From: zhangjl02 To: libvir-list@redhat.com Subject: [PATCH 1/2] virDomain: interface: add virNetDevOpenvswitchInterfaceClearTxQos and virNetDevOpenvswitchInterfaceClearRxQos. Date: Mon, 9 Aug 2021 10:05:59 +0800 Message-Id: <20210809020600.647-2-jx8zjs@126.com> In-Reply-To: <20210809020600.647-1-jx8zjs@126.com> References: <20210809020600.647-1-jx8zjs@126.com> MIME-Version: 1.0 X-CM-TRANSID: DcmowAAnd8OMjRBhXsB1Tw--.2037S3 X-Coremail-Antispam: 1Uf129KBjvJXoW3Gr45Xry7tFWfAw1UWw17Jrb_yoWxKrW5pF y8Gr1DJw10vrsrGwsrCa10gryUtrZ5Wr1fAas8u3WUXw4DG34Svw47K3y7Aay5Cr4xJ3W5 AFZ5XFy8Aa4xJaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UlFAXUUUUU= X-Originating-IP: [223.104.194.187] X-CM-SenderInfo: dm0y6ybv6rjloofrz/1tbi1w7pSF53WygArAABsP X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: shenjiatong@inspur.com, zhangjl02@inspur.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1628474872093100001 Content-Type: text/plain; charset="utf-8" From: Jinsheng Zhang 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 w= hen error occurs. Add ifname into ovs querying statements, which will reduce failure of remov= ing qos on the other interfaces of the same vm. Additionally, two problems is fixed. 1. Ingress rules is not clean on previous version of virNetDevOpenvswitchIn= terfaceClearQos. 2. If errors occurs when removing inbound qos on multi interfaces vm, some = rules may not be delete as aspected. Signed-off-by: zhangjl02 --- 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/virnetdevopenvswitc= h.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); + } } =20 if (rx) { @@ -794,17 +798,23 @@ virNetDevOpenvswitchInterfaceSetQos(const char *ifnam= e, _("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); + } } =20 return 0; } =20 int -virNetDevOpenvswitchInterfaceClearQos(const char *ifname, - const unsigned char *vmid) +virNetDevOpenvswitchInterfaceClearTxQos(const char *ifname, + const unsigned char *vmid) { + int ret =3D 0; char vmuuidstr[VIR_UUID_STRING_BUFLEN]; g_autoptr(virCommand) cmd =3D NULL; + g_autofree char *ifname_ex_id =3D NULL; g_autofree char *vmid_ex_id =3D NULL; g_autofree char *qos_uuid =3D NULL; g_autofree char *queue_uuid =3D NULL; @@ -815,7 +825,8 @@ virNetDevOpenvswitchInterfaceClearQos(const char *ifnam= e, cmd =3D virNetDevOpenvswitchCreateCmd(); virUUIDFormat(vmid, vmuuidstr); vmid_ex_id =3D g_strdup_printf("external-ids:vm-id=3D\"%s\"", vmuuidst= r); - virCommandAddArgList(cmd, "--no-heading", "--columns=3D_uuid", "find",= "qos", vmid_ex_id, NULL); + ifname_ex_id =3D g_strdup_printf("external-ids:ifname=3D\"%s\"", ifnam= e); + virCommandAddArgList(cmd, "--no-heading", "--columns=3D_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 *ifnam= e, virCommandFree(cmd); cmd =3D virNetDevOpenvswitchCreateCmd(); vmid_ex_id =3D g_strdup_printf("external-ids:vm-id=3D\"%s\"", vmuuidst= r); - virCommandAddArgList(cmd, "--no-heading", "--columns=3D_uuid", "find",= "queue", vmid_ex_id, NULL); + virCommandAddArgList(cmd, "--no-heading", "--columns=3D_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 *ifnam= e, virCommandFree(cmd); cmd =3D virNetDevOpenvswitchCreateCmd(); virCommandAddArgList(cmd, "--no-heading", "--columns=3D_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 *ifnam= e, cmd =3D virNetDevOpenvswitchCreateCmd(); virCommandAddArgList(cmd, "destroy", "qos", line, NULL); if (virCommandRun(cmd, NULL) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to destroy qos on port %s"), ifna= me); - return -1; + VIR_WARN("Unable to destroy qos on port %s", ifname); + ret =3D -1; } } } @@ -879,12 +889,49 @@ virNetDevOpenvswitchInterfaceClearQos(const char *ifn= ame, cmd =3D virNetDevOpenvswitchCreateCmd(); virCommandAddArgList(cmd, "destroy", "queue", line, NULL); if (virCommandRun(cmd, NULL) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to destroy queue on port %s"), if= name); - return -1; + VIR_WARN("Unable to destroy queue on port %s", ifname); + ret =3D -1; } } } =20 + return ret; +} + +int +virNetDevOpenvswitchInterfaceClearRxQos(const char *ifname) +{ + g_autoptr(virCommand) cmd =3D NULL; + + cmd =3D virNetDevOpenvswitchCreateCmd(); + virCommandAddArgList(cmd, "set", "Interface", ifname, NULL); + virCommandAddArgFormat(cmd, "ingress_policing_rate=3D%llu", 0llu); + virCommandAddArgFormat(cmd, "ingress_policing_burst=3D%llu", 0llu); + + if (virCommandRun(cmd, NULL) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to set vlan configuration on port %s"), i= fname); + return -1; + } + return 0; } + +int +virNetDevOpenvswitchInterfaceClearQos(const char *ifname, + const unsigned char *vmid) +{ + int ret =3D 0; + + if (virNetDevOpenvswitchInterfaceClearTxQos(ifname, vmid) < 0) { + VIR_WARN("Clean tx qos for interface %s failed", ifname); + ret =3D -1; + } + + if (virNetDevOpenvswitchInterfaceClearRxQos(ifname) < 0) { + VIR_WARN("Clean rx qos for interface %s failed", ifname); + ret =3D -1; + } + + return ret; +} diff --git a/src/util/virnetdevopenvswitch.h b/src/util/virnetdevopenvswitc= h.h index 2dcd1aec6b..d44072cc8c 100644 --- a/src/util/virnetdevopenvswitch.h +++ b/src/util/virnetdevopenvswitch.h @@ -80,3 +80,10 @@ int virNetDevOpenvswitchInterfaceSetQos(const char *ifna= me, 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; --=20 2.30.2.windows.1 From nobody Sun May 5 11:58:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=126.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1628474838907794.0410833456081; Sun, 8 Aug 2021 19:07:18 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-66-ufzqtmEKOtChO_2CXu7saw-1; Sun, 08 Aug 2021 22:07:15 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 80226801FCD; Mon, 9 Aug 2021 02:07:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4025460C81; Mon, 9 Aug 2021 02:07:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3840B4A7CA; Mon, 9 Aug 2021 02:07:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17926E9T010514 for ; Sun, 8 Aug 2021 22:06:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9765E10087DD; Mon, 9 Aug 2021 02:06:14 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92A59110FBFC for ; Mon, 9 Aug 2021 02:06:13 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 90D43800260 for ; Mon, 9 Aug 2021 02:06:13 +0000 (UTC) Received: from m15113.mail.126.com (m15113.mail.126.com [220.181.15.113]) by relay.mimecast.com with ESMTP id us-mta-43-CpS2JtKLOGOBjRb7Nu2xTA-1; Sun, 08 Aug 2021 22:06:10 -0400 Received: from zhangjl0200.home.langchao.com (unknown [223.104.194.187]) by smtp3 (Coremail) with SMTP id DcmowAAnd8OMjRBhXsB1Tw--.2037S4; Mon, 09 Aug 2021 10:06:07 +0800 (CST) X-MC-Unique: ufzqtmEKOtChO_2CXu7saw-1 X-MC-Unique: CpS2JtKLOGOBjRb7Nu2xTA-1 From: zhangjl02 To: libvir-list@redhat.com Subject: [PATCH 2/2] tests: add test on virNetDevOpenvswitchInterfaceSetQos and virNetDevOpenvswitchInterfaceClearQos Date: Mon, 9 Aug 2021 10:06:00 +0800 Message-Id: <20210809020600.647-3-jx8zjs@126.com> In-Reply-To: <20210809020600.647-1-jx8zjs@126.com> References: <20210809020600.647-1-jx8zjs@126.com> MIME-Version: 1.0 X-CM-TRANSID: DcmowAAnd8OMjRBhXsB1Tw--.2037S4 X-Coremail-Antispam: 1Uf129KBjvJXoW3Jr4kuFW3JF43KF1rXrW5Jrb_yoW3Ww1DpF sxG3Z0kr48Jr1xK3y7ur1rGrWUGr10kF48Ga4xW3y5trn8Jryaqw17Ka1IkanIyr4fX3s5 Xa15JFWqkw17taDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2FALUUUUU= X-Originating-IP: [223.104.194.187] X-CM-SenderInfo: dm0y6ybv6rjloofrz/1tbiIQ-pSFpECDD+VAAAsD X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: shenjiatong@inspur.com, zhangjl02@inspur.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1628474841630100002 Content-Type: text/plain; charset="utf-8" From: Jinsheng Zhang Test virNetDevOpenvswitchInterfaceSetQos and virNetDevOpenvswitchInterfaceC= learQos with dryrun method. Signed-off-by: zhangjl02 --- tests/virnetdevopenvswitchtest.c | 196 ++++++++++++++++++++++++++++++- 1 file changed, 195 insertions(+), 1 deletion(-) diff --git a/tests/virnetdevopenvswitchtest.c b/tests/virnetdevopenvswitcht= est.c index 46172dae90..d1bcca637a 100644 --- a/tests/virnetdevopenvswitchtest.c +++ b/tests/virnetdevopenvswitchtest.c @@ -19,7 +19,11 @@ #include =20 #include "testutils.h" +#define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW +#include "vircommandpriv.h" +#include "virnetdevbandwidth.h" #include "virnetdevopenvswitch.h" +#include "netdev_bandwidth_conf.c" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -29,6 +33,43 @@ struct _InterfaceParseStatsData { const virDomainInterfaceStatsStruct stats; }; =20 +struct testSetQosStruct { + const char *band; + const char *exp_cmd; + const char *iface; +}; + +struct testClearQosStruct { + const char *exp_cmd; + const char *iface; + const unsigned char *vmid; +}; + +#define PARSE(xml, var) \ + do { \ + int rc; \ + xmlDocPtr doc; \ + xmlXPathContextPtr ctxt =3D NULL; \ + \ + if (!xml) \ + break; \ + \ + if (!(doc =3D virXMLParseStringCtxt((xml), \ + "bandwidth definition", \ + &ctxt))) \ + goto cleanup; \ + \ + rc =3D virNetDevBandwidthParse(&(var), \ + NULL, \ + ctxt->node, \ + true); \ + xmlFreeDoc(doc); \ + xmlXPathFreeContext(ctxt); \ + if (rc < 0) \ + goto cleanup; \ + } while (0) + +static const unsigned char vm_id[VIR_UUID_BUFLEN] =3D "fakeuuid"; =20 static int testInterfaceParseStats(const void *opaque) @@ -111,6 +152,80 @@ testNameEscape(const void *opaque) } =20 =20 +static int +testVirNetDevOpenvswitchInterfaceSetQos(const void *data) +{ + int ret =3D -1; + const struct testSetQosStruct *info =3D data; + const char *iface =3D info->iface; + g_autoptr(virNetDevBandwidth) band =3D NULL; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + char *actual_cmd =3D NULL; + g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); + + PARSE(info->band, band); + + if (!iface) + iface =3D "tap-fake"; + + virCommandSetDryRun(dryRunToken, &buf, false, false, NULL, NULL); + + if (virNetDevOpenvswitchInterfaceSetQos(iface, band, vm_id, true) < 0) + goto cleanup; + + if (!(actual_cmd =3D virBufferContentAndReset(&buf))) { + /* This is interesting, no command has been executed. + * Maybe that's expected, actually. */ + } + + if (STRNEQ_NULLABLE(info->exp_cmd, actual_cmd)) { + virTestDifference(stderr, + NULLSTR(info->exp_cmd), + NULLSTR(actual_cmd)); + goto cleanup; + } + + ret =3D 0; + cleanup: + VIR_FREE(actual_cmd); + return ret; +} + + +static int +testVirNetDevOpenvswitchInterfaceClearQos(const void *data) +{ + int ret =3D -1; + const struct testClearQosStruct *info =3D data; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + char *actual_cmd =3D NULL; + const char *iface =3D info->iface; + const unsigned char *vmid =3D info->vmid; + g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); + + virCommandSetDryRun(dryRunToken, &buf, false, false, NULL, NULL); + + if (virNetDevOpenvswitchInterfaceClearQos(iface, vmid) < 0) + goto cleanup; + + if (!(actual_cmd =3D virBufferContentAndReset(&buf))) { + /* This is interesting, no command has been executed. + * Maybe that's expected, actually. */ + } + + if (STRNEQ_NULLABLE(info->exp_cmd, actual_cmd)) { + virTestDifference(stderr, + NULLSTR(info->exp_cmd), + NULLSTR(actual_cmd)); + goto cleanup; + } + + ret =3D 0; + cleanup: + VIR_FREE(actual_cmd); + return ret; +} + static int mymain(void) { @@ -146,7 +261,86 @@ mymain(void) TEST_NAME_ESCAPE("\"vhost\"user1\"", NULL); TEST_NAME_ESCAPE("\"\\\\", NULL); =20 +#define DO_TEST_SET(Band, Exp_cmd, ...) \ + do { \ + struct testSetQosStruct data =3D {.band =3D Band, \ + .exp_cmd =3D Exp_cmd, \ + __VA_ARGS__}; \ + if (virTestRun("virNetDevOpenvswitchInterfaceSetQos", \ + testVirNetDevOpenvswitchInterfaceSetQos, \ + &data) < 0) \ + ret =3D -1; \ + } while (0) + + DO_TEST_SET(("" + " " + ""), + (OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D_uuid = find queue" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D_uuid = find qos" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 set port tap-fake qos=3D@qos1" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'" + " -- --id=3D@qos1 create qos type=3Dlinux-htb o= ther_config:min-rate=3D163840000" + " queues:0=3D@queue0 'external-ids:vm-id=3D\"66= 616b65-7575-6964-0000-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'" + " -- --id=3D@queue0 create queue other_config:m= in-rate=3D163840000 " + "'external-ids:vm-id=3D\"66616b65-7575-6964-000= 0-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 set Interface tap-fake ingress_= policing_rate=3D0 ingress_policing_burst=3D0\n")); + + DO_TEST_SET(NULL, NULL); + + DO_TEST_SET("", NULL); + + DO_TEST_SET(("" + " " + ""), + (OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D_uuid = find qos" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D_uuid = find queue" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 set Interface tap-fake ingress_= policing_rate=3D0 ingress_policing_burst=3D0\n")); + + DO_TEST_SET(("" + " " + " " + ""), + (OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D_uuid = find qos" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D_uuid = find queue" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 set Interface tap-fake ingress_= policing_rate=3D40000\n")); + +#define DO_TEST_CLEAR_QOS(Iface, Vmid, Exp_cmd, ...) \ + do { \ + struct testClearQosStruct data =3D {.iface =3D Iface, \ + .vmid =3D Vmid, \ + .exp_cmd =3D Exp_cmd, \ + __VA_ARGS__}; \ + if (virTestRun("virNetDevOpenvswitchInterfaceClearQos", \ + testVirNetDevOpenvswitchInterfaceClearQos, \ + &data) < 0) \ + ret =3D -1; \ + } while (0) + + DO_TEST_CLEAR_QOS(("fake-iface"), vm_id, + (OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D= _uuid find qos" + " 'external-ids:vm-id=3D\"66616b65-7575-6= 964-0000-000000000000\"'" + " 'external-ids:ifname=3D\"fake-iface\"'\= n" + OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D= _uuid find queue" + " 'external-ids:vm-id=3D\"66616b65-7575-6= 964-0000-000000000000\"'" + " 'external-ids:ifname=3D\"fake-iface\"'\= n" + OVS_VSCTL " --timeout=3D5 set Interface fake-iface = ingress_policing_rate=3D0 ingress_policing_burst=3D0\n")); + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 -VIR_TEST_MAIN(mymain); +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virnetdevbandwidth")) --=20 2.30.2.windows.1