From nobody Wed Dec 17 00:02:13 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530488833150411.52286633953815; Sun, 1 Jul 2018 16:47:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89D123082A3E; Sun, 1 Jul 2018 23:47:11 +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 2F5AE308BDA5; Sun, 1 Jul 2018 23:47:11 +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 15C5F1800B6B; Sun, 1 Jul 2018 23:47:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w61Nl449024658 for ; Sun, 1 Jul 2018 19:47:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id D5E432156889; Sun, 1 Jul 2018 23:47:04 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-116.phx2.redhat.com [10.3.116.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6703A2156880 for ; Sun, 1 Jul 2018 23:47:04 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Sun, 1 Jul 2018 19:46:56 -0400 Message-Id: <20180701234658.667147-2-laine@laine.org> In-Reply-To: <20180701234658.667147-1-laine@laine.org> References: <20180701234658.667147-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sun, 01 Jul 2018 23:47:12 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 --- src/libvirt_private.syms | 1 + src/util/virnetdevopenvswitch.c | 55 +++++++++++++++++++++++++++++++++++++= ++++ src/util/virnetdevopenvswitch.h | 6 +++++ 3 files changed, 62 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 98913a577a..386f53eeb9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2364,6 +2364,7 @@ virNetDevMidonetUnbindPort; virNetDevOpenvswitchAddPort; virNetDevOpenvswitchGetMigrateData; virNetDevOpenvswitchGetVhostuserIfname; +virNetDevOpenvswitchInterfaceGetMaster; virNetDevOpenvswitchInterfaceStats; virNetDevOpenvswitchRemovePort; virNetDevOpenvswitchSetMigrateData; diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitc= h.c index f86f698430..af3f2a773d 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -404,6 +404,61 @@ 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 6f6e620c22..331e483018 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 2.14.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list