From: Laine Stump Date: Tue, 17 Sep 2024 17:28:04 +0000 (-0400) Subject: util: don't return early from virNetDevTapReattachBridge() if "force" is true X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=e3f8bccea698e5e985f109800c4f1d21194000b8;p=libvirt.git util: don't return early from virNetDevTapReattachBridge() if "force" is true It can be useful to force an interface to be detached/reattached from its bridge even if it's the same bridge - possibly something like the virtualport profileID has changed, and a detach/attach cycle will get it connected with the new profileID. The one and only current use of virNetDevTapReattachBridge() sets force to false, to preserve current behavior. An upcoming patch will use it with force set to true. Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7f6a91c427..6d7dee7956 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30625,7 +30625,7 @@ virDomainNetNotifyActualDevice(virConnectPtr conn, virDomainNetGetActualVirtPortProfile(iface), virDomainNetGetActualVlan(iface), virDomainNetGetActualPortOptionsIsolated(iface), - iface->mtu, NULL)); + iface->mtu, NULL, false)); } } diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 3d7f680599..2701ba6dfc 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -510,6 +510,9 @@ virNetDevTapAttachBridge(const char *tapname, * @virtVlan: vlan tag info * @mtu: requested MTU for port (or 0 for "default") * @actualMTU: MTU actually set for port (after accounting for bridge's MTU) + * @force: set true to force detach/reattach even if the bridge name is unchanged + * (this can be useful if, for example, the profileid of the + * changes) * * Ensures that the tap device (@tapname) is connected to the bridge * (@brname), potentially removing it from any existing bridge that @@ -526,7 +529,8 @@ virNetDevTapReattachBridge(const char *tapname, const virNetDevVlan *virtVlan, virTristateBool isolatedPort, unsigned int mtu, - unsigned int *actualMTU) + unsigned int *actualMTU, + bool force) { bool useOVS = false; g_autofree char *master = NULL; @@ -542,7 +546,7 @@ virNetDevTapReattachBridge(const char *tapname, } /* Nothing more todo if we're on the right bridge already */ - if (STREQ_NULLABLE(brname, master)) + if (STREQ_NULLABLE(brname, master) && !force) return 0; /* disconnect from current (incorrect) bridge, if any */ diff --git a/src/util/virnetdevtap.h b/src/util/virnetdevtap.h index c9d29c0384..9ebe0ee9ed 100644 --- a/src/util/virnetdevtap.h +++ b/src/util/virnetdevtap.h @@ -82,7 +82,8 @@ virNetDevTapReattachBridge(const char *tapname, const virNetDevVlan *virtVlan, virTristateBool isolatedPort, unsigned int mtu, - unsigned int *actualMTU) + unsigned int *actualMTU, + bool force) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) G_GNUC_WARN_UNUSED_RESULT;