Separate network port deletion code from the domain driver network callback implementation.
Reivewed-by: Laine Stump <la...@laine.org> Signed-off-by: Daniel P. Berrangé <berra...@redhat.com> --- src/network/bridge_driver.c | 90 ++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 31 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 6c2dc36efa..41934762d0 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4948,9 +4948,9 @@ networkNotifyActualDevice(virNetworkPtr net, } -/* networkReleaseActualDevice: - * @dom: domain definition that @iface belongs to - * @iface: a domain's NetDef (interface definition) +/* networkReleasePort: + * @obj: the network to release from + * @port: the port definition to release * * Given a domain <interface> element that previously had its <actual> * element filled in (and possibly a physical device allocated to it), @@ -4960,40 +4960,15 @@ networkNotifyActualDevice(virNetworkPtr net, * Returns 0 on success, -1 on failure. */ static int -networkReleaseActualDevice(virNetworkPtr net, - virDomainDefPtr dom, - virDomainNetDefPtr iface) +networkReleasePort(virNetworkObjPtr obj, + virNetworkPortDefPtr port) { virNetworkDriverStatePtr driver = networkGetDriver(); - virNetworkObjPtr obj; virNetworkDefPtr netdef; virNetworkForwardIfDefPtr dev = NULL; - virNetworkPortDefPtr port = NULL; size_t i; int ret = -1; - obj = virNetworkObjFindByName(driver->networks, net->name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - net->name); - goto cleanup; - } - - if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expected an interface for a virtual network")); - goto cleanup; - } - - if (iface->data.network.actual == NULL) { - ret = 0; - goto cleanup; - } - - if (!(port = virDomainNetDefActualToNetworkPort(dom, iface))) - goto cleanup; - netdef = virNetworkObjGetDef(obj); switch ((virNetworkPortPlugType)port->plugtype) { @@ -5073,7 +5048,7 @@ networkReleaseActualDevice(virNetworkPtr net, goto cleanup; } - virNetworkObjMacMgrDel(obj, driver->dnsmasqStateDir, dom->name, &port->mac); + virNetworkObjMacMgrDel(obj, driver->dnsmasqStateDir, port->ownername, &port->mac); netdef->connections--; if (dev) @@ -5083,6 +5058,59 @@ networkReleaseActualDevice(virNetworkPtr net, VIR_HOOK_SUBOP_BEGIN); networkLogAllocation(netdef, dev, &port->mac, false); + ret = 0; + cleanup: + return ret; +} + + +/* networkReleaseActualDevice: + * @dom: domain definition that @iface belongs to + * @iface: a domain's NetDef (interface definition) + * + * Given a domain <interface> element that previously had its <actual> + * element filled in (and possibly a physical device allocated to it), + * free up the physical device for use by someone else, and free the + * virDomainActualNetDef. + * + * Returns 0 on success, -1 on failure. + */ +static int +networkReleaseActualDevice(virNetworkPtr net, + virDomainDefPtr dom, + virDomainNetDefPtr iface) +{ + virNetworkDriverStatePtr driver = networkGetDriver(); + virNetworkObjPtr obj; + virNetworkPortDefPtr port = NULL; + int ret = -1; + + obj = virNetworkObjFindByName(driver->networks, net->name); + if (!obj) { + virReportError(VIR_ERR_NO_NETWORK, + _("no network with matching name '%s'"), + net->name); + goto cleanup; + } + + + if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected an interface for a virtual network")); + goto cleanup; + } + + if (iface->data.network.actual == NULL) { + ret = 0; + goto cleanup; + } + + if (!(port = virDomainNetDefActualToNetworkPort(dom, iface))) + goto cleanup; + + if (networkReleasePort(obj, port) < 0) + goto cleanup; + ret = 0; cleanup: virNetworkObjEndAPI(&obj); -- 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list