From: Daniel P. Berrangé Date: Fri, 1 Feb 2019 14:53:12 +0000 (+0000) Subject: network: move re-attach of bridge device out of network driver X-Git-Tag: v5.3.0-rc1~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b806a60eaff1da0fee7a029206b757c5e6df48b0;p=thirdparty%2Flibvirt.git network: move re-attach of bridge device out of network driver During initial NIC setup the hypervisor drivers are responsible for attaching the TAP device to the bridge device. Any fixup after libvirtd restarts should thus also be their responsibility. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrangé --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2df26cc6a9..d6494257df 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -54,6 +54,7 @@ #include "virsecret.h" #include "virstring.h" #include "virnetdev.h" +#include "virnetdevtap.h" #include "virnetdevmacvlan.h" #include "virhostdev.h" #include "virmdev.h" @@ -30449,8 +30450,25 @@ virDomainNetNotifyActualDevice(virConnectPtr conn, if (!(net = virNetworkLookupByName(conn, iface->data.network.name))) return; - netNotify(net, dom, iface); + if (netNotify(net, dom, iface) < 0) + goto cleanup; + + if (virDomainNetGetActualType(iface) == VIR_DOMAIN_NET_TYPE_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 virNetDevTapReattachBridge()) + */ + if (virNetDevTapReattachBridge(iface->ifname, + iface->data.network.actual->data.bridge.brname, + &iface->mac, dom->uuid, + virDomainNetGetActualVirtPortProfile(iface), + virDomainNetGetActualVlan(iface), + iface->mtu, NULL) < 0) + goto cleanup; + } + cleanup: virObjectUnref(net); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5910ed0beb..fb053a7ca3 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3552,7 +3552,7 @@ typedef int virDomainDefPtr dom, virDomainNetDefPtr iface); -typedef void +typedef int (*virDomainNetNotifyActualDeviceImpl)(virNetworkPtr net, virDomainDefPtr dom, virDomainNetDefPtr iface); diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 4055939ade..8b36376761 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4793,12 +4793,11 @@ networkAllocateActualDevice(virNetworkPtr net, * 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, or re-attach the interface's tap device to the network's - * bridge. + * order. * - * No return value (but does log any failures) + * Returns 0 on success, -1 on failure. */ -static void +static int networkNotifyActualDevice(virNetworkPtr net, virDomainDefPtr dom, virDomainNetDefPtr iface) @@ -4809,6 +4808,7 @@ networkNotifyActualDevice(virNetworkPtr net, virNetworkDefPtr netdef; virNetworkForwardIfDefPtr dev = NULL; size_t i; + int ret = -1; obj = virNetworkObjFindByName(driver->networks, net->name); if (!obj) { @@ -4833,22 +4833,6 @@ networkNotifyActualDevice(virNetworkPtr net, goto error; } - /* see if we're connected to the correct bridge */ - if (netdef->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 virNetDevTapReattachBridge()) - */ - if (virNetDevTapReattachBridge(iface->ifname, netdef->bridge, - &iface->mac, dom->uuid, - virDomainNetGetActualVirtPortProfile(iface), - virDomainNetGetActualVlan(iface), - iface->mtu, NULL) < 0) { - goto error; - } - } - if (!iface->data.network.actual || (actualType != VIR_DOMAIN_NET_TYPE_DIRECT && actualType != VIR_DOMAIN_NET_TYPE_HOSTDEV)) { @@ -4977,10 +4961,11 @@ networkNotifyActualDevice(virNetworkPtr net, goto error; } networkLogAllocation(netdef, actualType, dev, iface, true); + ret = 0; cleanup: virNetworkObjEndAPI(&obj); - return; + return ret; error: goto cleanup;