From nobody Tue Feb 10 04:53:53 2026 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.zoho.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 1490108719295490.9599977400628; Tue, 21 Mar 2017 08:05:19 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 329D181235; Tue, 21 Mar 2017 15:05:18 +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 03ACB1712D; Tue, 21 Mar 2017 15:05:18 +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 A412718523CD; Tue, 21 Mar 2017 15:05:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2LF49H9011468 for ; Tue, 21 Mar 2017 11:04:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id B2A665DD65; Tue, 21 Mar 2017 15:04:09 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-242.phx2.redhat.com [10.3.116.242]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71B6C5DD6E for ; Tue, 21 Mar 2017 15:04:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 329D181235 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=laine.org Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 329D181235 From: Laine Stump To: libvir-list@redhat.com Date: Tue, 21 Mar 2017 11:04:00 -0400 Message-Id: <20170321150400.13422-4-laine@laine.org> In-Reply-To: <20170321150400.13422-1-laine@laine.org> References: <20170321150400.13422-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] network: reconnect tap devices during networkNotifyActualDevice 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 21 Mar 2017 15:05:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: root If a network is destroyed and restarted, or its bridge is changed, any tap devices that had previously been connected to the bridge will no longer be connected. As a first step in automating a reconnection of all tap devices when this happens, this patch modifies networkNotifyActualDevice() (which is called once for every of every active domain whenever libvirtd is restarted) to reconnect any tap devices that it finds disconnected. With this patch in place, you will need to restart libvirtd to reconnect all the taps to their proper bridges. A future patch will add a callback that hypervisor drivers can register with the network driver to that the network driver can trigger this behavior automatically whenever a network is started. --- src/network/bridge_driver.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 32c5ab7..6f2d03a 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4605,7 +4605,8 @@ networkAllocateActualDevice(virDomainDefPtr dom, * Called to notify the network driver when libvirtd is restarted and * finds an already running domain. If appropriate it will force an * allocation of the actual->direct.linkdev to get everything back in - * order. + * order, or re-attach the interface's tap device to the network's + * bridge. * * Returns 0 on success, -1 on failure. */ @@ -4620,6 +4621,7 @@ networkNotifyActualDevice(virDomainDefPtr dom, virNetworkForwardIfDefPtr dev =3D NULL; size_t i; int ret =3D -1; + char *master =3D NULL; =20 if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) return 0; @@ -4644,6 +4646,31 @@ networkNotifyActualDevice(virDomainDefPtr dom, netdef->bridge) < 0)) goto error; =20 + /* see if we're connected to the correct bridge */ + if (netdef->bridge) { + if (virNetDevGetMaster(iface->ifname, &master) < 0) + goto error; + + if (STRNEQ_NULLABLE(netdef->bridge, master)) { + /* disconnect from current (incorrect) bridge */ + if (master) + ignore_value(virNetDevBridgeRemovePort(master, iface->ifna= me)); + + /* attach/reattach to correct bridge. + * NB: we can't notify the guest of any MTU change anyway, + * so there is no point in trying to learn the actualMTU + * (final arg to virNetDevTapAttachBridge()) + */ + if (virNetDevTapAttachBridge(iface->ifname, netdef->bridge, + &iface->mac, dom->uuid, + virDomainNetGetActualVirtPortProf= ile(iface), + virDomainNetGetActualVlan(iface), + iface->mtu, NULL) < 0) { + goto error; + } + } + } + if (!iface->data.network.actual || (actualType !=3D VIR_DOMAIN_NET_TYPE_DIRECT && actualType !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV)) { @@ -4776,6 +4803,7 @@ networkNotifyActualDevice(virDomainDefPtr dom, ret =3D 0; cleanup: virNetworkObjEndAPI(&network); + VIR_FREE(master); return ret; =20 error: --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list