From nobody Wed May 14 03:35:43 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=126.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153060963672978.8154276021204; Tue, 3 Jul 2018 02:20:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6372C32B684; Tue, 3 Jul 2018 09:20:35 +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 2961260A98; Tue, 3 Jul 2018 09:20:35 +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 C9D974A46C; Tue, 3 Jul 2018 09:20:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w639KJJ7015818 for ; Tue, 3 Jul 2018 05:20:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 074B11092021; Tue, 3 Jul 2018 09:20:19 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F2936109201B for ; Tue, 3 Jul 2018 09:20:18 +0000 (UTC) Received: from m50-110.126.com (m50-110.126.com [123.125.50.110]) by mx1.redhat.com (Postfix) with ESMTP id 2735C308A94F for ; Tue, 3 Jul 2018 09:20:15 +0000 (UTC) Received: from localhost.localdomain (unknown [210.13.242.135]) by smtp4 (Coremail) with SMTP id jdKowAAHaferPztbAQ+EAQ--.1051S13; Tue, 03 Jul 2018 17:20:10 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=xQNQHhb3vx5L6N9lKu PulQvVVgmb2V4+MJkycSWGwa4=; b=E9635JIsnykx65EcQqJYiMXGN4U0mQzfTH QuX0ImiguRb/Ua6200jYvSN3gDW2MzV58TUm+j0KGXY0+wS6EoZ/O/CZNMUd8FHK WUHGWcSrASJOUFjS/y+2kdKwerFJUJ7/u9dub7gyHqk7Pxdw8ywDFbQFuxWJlCLP jLmTZjBcI= From: dubo163 To: libvir-list@redhat.com Date: Tue, 3 Jul 2018 05:19:22 -0400 Message-Id: <1530609577-9195-11-git-send-email-dubo163@126.com> In-Reply-To: <1530609577-9195-1-git-send-email-dubo163@126.com> References: <1530609577-9195-1-git-send-email-dubo163@126.com> X-CM-TRANSID: jdKowAAHaferPztbAQ+EAQ--.1051S13 X-Coremail-Antispam: 1Uf129KBjvJXoWxAr45Zr1ruw45Kw13XF4xWFg_yoWrZFy3pr WkKFn8Gr10yr1xCwsakw18Wry5CryrWryrAFZ8ZF17uayUJr9avw47KFWUAw43AFWxA3Wr AF9Yv348ua4fXFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j53kZUUUUU= X-Originating-IP: [210.13.242.135] X-CM-SenderInfo: 5gxe0iiwt6ij2wof0z/1tbicgp4MFpD5bHBCgAAs2 X-Greylist: Sender passed SPF test, ACL 227 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 03 Jul 2018 09:20:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 03 Jul 2018 09:20:17 +0000 (UTC) for IP:'123.125.50.110' DOMAIN:'m50-110.126.com' HELO:'m50-110.126.com' FROM:'dubo163@126.com' RCPT:'' X-RedHat-Spam-Score: 5.305 ***** (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_ANBREP_L3, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_L3, SPF_PASS) 123.125.50.110 m50-110.126.com 123.125.50.110 m50-110.126.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH 10/25] util: new function virNetDevOpenvswitchInterfaceGetMaster() 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 03 Jul 2018 09:20:36 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Laine Stump This function retrieves the name of the OVS bridge that the given netdev is attached to. This separate function is necessary because OVS set the IFLA_MASTER attribute to "ovs-system" for all netdevs that are attached to an OVS bridge, so the standard method of retrieving the master can't be used. Signed-off-by: Laine Stump ACKed-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/util/virnetdevopenvswitch.c | 56 +++++++++++++++++++++++++++++++++++++= ++++ src/util/virnetdevopenvswitch.h | 6 +++++ 3 files changed, 63 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b87e813..ffe5dfd 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2389,6 +2389,7 @@ virNetDevMidonetUnbindPort; virNetDevOpenvswitchAddPort; virNetDevOpenvswitchGetMigrateData; virNetDevOpenvswitchGetVhostuserIfname; +virNetDevOpenvswitchInterfaceGetMaster; virNetDevOpenvswitchInterfaceStats; virNetDevOpenvswitchRemovePort; virNetDevOpenvswitchSetMigrateData; diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitc= h.c index f86f698..d1c5cf4 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -404,6 +404,62 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, return ret; } =20 + +/** + * virNetDeOpenvswitchGetMaster: + * @ifname: name of interface we're interested in + * @master: used to return a string containing the name of @ifname's "mast= er" + * (this is the bridge or bond device that this device is attache= d to) + * + * Returns 0 on success, -1 on failure (if @ifname has no master + * @master will be NULL, but return value will still be 0 (success)). + * + * NB: This function is needed because the IFLA_MASTER attribute of an + * interface in a netlink dump (see virNetDevGetMaster()) will always + * return "ovs-system" for any interface that is attached to an OVS + * switch. When that happens, virNetDevOpenvswitchInterfaceGetMaster() + * must be called to get the "real" master of the interface. + */ +int +virNetDevOpenvswitchInterfaceGetMaster(const char *ifname, char **master) +{ + virCommandPtr cmd =3D NULL; + int ret =3D -1; + int exitstatus; + + *master =3D NULL; + + cmd =3D virCommandNew(OVSVSCTL); + virNetDevOpenvswitchAddTimeout(cmd); + virCommandAddArgList(cmd, "iface-to-br", ifname, NULL); + virCommandSetOutputBuffer(cmd, master); + + if (virCommandRun(cmd, &exitstatus) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to run command to get OVS master for " + "interface %s"), ifname); + goto cleanup; + } + + /* non-0 exit code just means that the interface has no master in OVS = */ + if (exitstatus !=3D 0) + VIR_FREE(*master); + + if (*master) { + /* truncate at the first newline */ + char *nl =3D strchr(*master, '\n'); + if (nl) + *nl =3D '\0'; + } + + VIR_DEBUG("OVS master for %s is %s", ifname, *master ? *master : "(non= e)"); + + ret =3D 0; + cleanup: + return ret; +} + + /** * virNetDevOpenvswitchVhostuserGetIfname: * @path: the path of the unix socket diff --git a/src/util/virnetdevopenvswitch.h b/src/util/virnetdevopenvswitc= h.h index 6f6e620..331e483 100644 --- a/src/util/virnetdevopenvswitch.h +++ b/src/util/virnetdevopenvswitch.h @@ -47,6 +47,9 @@ int virNetDevOpenvswitchAddPort(const char *brname, int virNetDevOpenvswitchRemovePort(const char *brname, const char *ifname) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; =20 +int virNetDevOpenvswitchInterfaceGetMaster(const char *ifname, char **mast= er) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; + int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; =20 @@ -57,6 +60,9 @@ int virNetDevOpenvswitchInterfaceStats(const char *ifname, virDomainInterfaceStatsPtr stats) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; =20 +int virNetDevOpenvswitchInterfaceGetMaster(const char *ifname, char **mast= er) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; + int virNetDevOpenvswitchGetVhostuserIfname(const char *path, char **ifname) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NOINLINE; --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list