From nobody Sun Feb 8 11:39:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1726673264074939.4927407090385; Wed, 18 Sep 2024 08:27:44 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 073D514C5; Wed, 18 Sep 2024 11:27:43 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4087619BE; Wed, 18 Sep 2024 11:26:42 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 85BE71462; Wed, 18 Sep 2024 11:26:38 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0DBE71462 for ; Wed, 18 Sep 2024 11:26:38 -0400 (EDT) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-179-vzL7F0gbMRmJWgSwFsYLxQ-1; Wed, 18 Sep 2024 11:26:35 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 77EAB1953943 for ; Wed, 18 Sep 2024 15:26:34 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.17.190]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DC14F30001A1 for ; Wed, 18 Sep 2024 15:26:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726673197; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kwIr/TCEjfm7Rifz+nakqjL0js37Npjtj2Rq/Qwyphg=; b=YXE5rwQ2e+zE/BUhzxZIGuj4go51dPO5LccDRqSVSaa/4g6hCLA5YdTl3o8A996bLPXxyK 4B1eRT8o47eHc3xyRh4e+Z0MjxgzqZTDrTfyU2MopR1bNzKRxIupdarfhBrqdHDINnHoi2 OTjrtVeovve0d3Vqnq3iuGigxlQ62F0= X-MC-Unique: vzL7F0gbMRmJWgSwFsYLxQ-1 From: Laine Stump To: devel@lists.libvirt.org Subject: [PATCH 3/4] qemu: replace open-coded remove/attach bridge with virNetDevTapReattachBridge() Date: Wed, 18 Sep 2024 11:26:29 -0400 Message-ID: <20240918152630.875195-4-laine@redhat.com> In-Reply-To: <20240918152630.875195-1-laine@redhat.com> References: <20240918152630.875195-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: Y6WBWSAAT7OFTLRNBGBCBWYI4B2BA3RI X-Message-ID-Hash: Y6WBWSAAT7OFTLRNBGBCBWYI4B2BA3RI X-MailFrom: laine@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1726673266130116600 Content-Type: text/plain; charset="utf-8"; x-default="true" The new function does what the old qemuDomainChangeNetbridge() did manually, except that: 1) the new function supports changing from a bridge of one type to another, e.g. from a Linux host bridge to an OVS bridge. (previously that wasn't handled) 2) the new function doesn't emit audit log messages. This is actually a good thing, because the old code would just log a "detach" followed immediately by "attach" for the same MAC address, so it's essentially a NOP. (the audit logs don't have any more detailed info about the connection - just the VM name and MAC address, so it makes no sense to log the detach/attach pair as it's not providing any information). Signed-off-by: Laine Stump --- src/qemu/qemu_hotplug.c | 55 ++++++++++------------------------------- 1 file changed, 13 insertions(+), 42 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index a187466c5b..4291feba29 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -55,6 +55,7 @@ #include "virnetdevbridge.h" #include "virnetdevopenvswitch.h" #include "virnetdevmidonet.h" +#include "virnetdevtap.h" #include "device_conf.h" #include "storage_source.h" #include "storage_source_conf.h" @@ -3484,7 +3485,6 @@ qemuDomainChangeNetBridge(virDomainObj *vm, virDomainNetDef *olddev, virDomainNetDef *newdev) { - int ret =3D -1; const char *oldbridge =3D virDomainNetGetActualBridgeName(olddev); const char *newbridge =3D virDomainNetGetActualBridgeName(newdev); =20 @@ -3498,50 +3498,21 @@ qemuDomainChangeNetBridge(virDomainObj *vm, =20 if (virNetDevExists(newbridge) !=3D 1) { virReportError(VIR_ERR_OPERATION_FAILED, - _("bridge %1$s doesn't exist"), newbridge); + _("cannot add domain %1$s device %2$s to nonexisten= t bridge %3$s"), + vm->def->name, newdev->ifname, newbridge); return -1; } =20 - ret =3D virNetDevBridgeRemovePort(oldbridge, olddev->ifname); - virDomainAuditNet(vm, olddev, NULL, "detach", ret =3D=3D 0); - if (ret < 0) { - /* warn but continue - possibly the old network - * had been destroyed and reconstructed, leaving the - * tap device orphaned. - */ - VIR_WARN("Unable to detach device %s from bridge %s", - olddev->ifname, oldbridge); - } - - ret =3D virNetDevBridgeAddPort(newbridge, olddev->ifname); - if (ret =3D=3D 0 && - virDomainNetGetActualPortOptionsIsolated(newdev) =3D=3D VIR_TRISTA= TE_BOOL_YES) { - - ret =3D virNetDevBridgePortSetIsolated(newbridge, olddev->ifname, = true); - if (ret < 0) { - virErrorPtr err; - - virErrorPreserveLast(&err); - ignore_value(virNetDevBridgeRemovePort(newbridge, olddev->ifna= me)); - virErrorRestore(&err); - } - } - virDomainAuditNet(vm, NULL, newdev, "attach", ret =3D=3D 0); - if (ret < 0) { - virErrorPtr err; - - virErrorPreserveLast(&err); - ret =3D virNetDevBridgeAddPort(oldbridge, olddev->ifname); - if (ret =3D=3D 0 && - virDomainNetGetActualPortOptionsIsolated(olddev) =3D=3D VIR_TR= ISTATE_BOOL_YES) { - ignore_value(virNetDevBridgePortSetIsolated(newbridge, olddev-= >ifname, true)); - } - virDomainAuditNet(vm, NULL, olddev, "attach", ret =3D=3D 0); - virErrorRestore(&err); - return -1; - } - /* caller will replace entire olddev with newdev in domain nets list */ - return 0; + /* force the detach/reattach (final arg) to make sure we pick up virtu= alport changes + * even if the bridge name hasn't changed + */ + return virNetDevTapReattachBridge(newdev->ifname, + virDomainNetGetActualBridgeName(newd= ev), + &newdev->mac, vm->def->uuid, + virDomainNetGetActualVirtPortProfile= (newdev), + virDomainNetGetActualVlan(newdev), + virDomainNetGetActualPortOptionsIsol= ated(newdev), + newdev->mtu, NULL, true); } =20 static int --=20 2.46.0