Currently virt drivers will call directly into the network driver impl to allocate domain interface devices where type=network. This introduces a callback system to allow us to decouple the virt drivers from the network driver. Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> --- src/conf/domain_conf.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 34 ++++++++++++++++++++++++++++ src/libvirt_private.syms | 4 ++++ src/libxl/libxl_domain.c | 5 ++--- src/libxl/libxl_driver.c | 7 +++--- src/lxc/lxc_driver.c | 5 ++--- src/lxc/lxc_process.c | 7 +++--- src/network/bridge_driver.c | 32 ++++++++++++++++----------- src/network/bridge_driver.h | 28 ----------------------- src/qemu/qemu_hotplug.c | 15 ++++++------- src/qemu/qemu_process.c | 6 ++--- 11 files changed, 131 insertions(+), 66 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9c9e3334f0..50c485853a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28800,3 +28800,57 @@ virDomainNetTypeSharesHostView(const virDomainNetDef *net) } return false; } + +static virDomainNetAllocateActualDeviceImpl netAllocate; +static virDomainNetNotifyActualDeviceImpl netNotify; +static virDomainNetReleaseActualDeviceImpl netRelease; + +void +virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate, + virDomainNetNotifyActualDeviceImpl notify, + virDomainNetReleaseActualDeviceImpl release) +{ + netAllocate = allocate; + netNotify = notify; + netRelease = release; +} + +int +virDomainNetAllocateActualDevice(virDomainDefPtr dom, + virDomainNetDefPtr iface) +{ + if (!netAllocate) { + virReportError(VIR_ERR_NO_SUPPORT, "%s", + _("Network device allocation not available")); + return -1; + } + + return netAllocate(dom, iface); +} + +void +virDomainNetNotifyActualDevice(virDomainDefPtr dom, + virDomainNetDefPtr iface) +{ + if (!netNotify) { + virReportError(VIR_ERR_NO_SUPPORT, "%s", + _("Network device notification not available")); + return; + } + + netNotify(dom, iface); +} + + +int +virDomainNetReleaseActualDevice(virDomainDefPtr dom, + virDomainNetDefPtr iface) +{ + if (!netRelease) { + virReportError(VIR_ERR_NO_SUPPORT, "%s", + _("Network device release not available")); + return -1; + } + + return netRelease(dom, iface); +} diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ed85260926..ccd19d6a6b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3454,4 +3454,38 @@ bool virDomainDefLifecycleActionAllowed(virDomainLifecycle type, virDomainLifecycleAction action); +typedef int +(*virDomainNetAllocateActualDeviceImpl)(virDomainDefPtr dom, + virDomainNetDefPtr iface); + +typedef void +(*virDomainNetNotifyActualDeviceImpl)(virDomainDefPtr dom, + virDomainNetDefPtr iface); + +typedef int +(*virDomainNetReleaseActualDeviceImpl)(virDomainDefPtr dom, + virDomainNetDefPtr iface); + +void +virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate, + virDomainNetNotifyActualDeviceImpl notify, + virDomainNetReleaseActualDeviceImpl release); + +int +virDomainNetAllocateActualDevice(virDomainDefPtr dom, + virDomainNetDefPtr iface) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + +void +virDomainNetNotifyActualDevice(virDomainDefPtr dom, + virDomainNetDefPtr iface) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + +int +virDomainNetReleaseActualDevice(virDomainDefPtr dom, + virDomainNetDefPtr iface) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + + + #endif /* __DOMAIN_CONF_H */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index af34745e4c..e1e1fc0c8f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -431,6 +431,7 @@ virDomainMemoryInsert; virDomainMemoryRemove; virDomainMemorySourceTypeFromString; virDomainMemorySourceTypeToString; +virDomainNetAllocateActualDevice; virDomainNetAppendIPAddress; virDomainNetDefClear; virDomainNetDefFormat; @@ -450,8 +451,11 @@ virDomainNetGetActualType; virDomainNetGetActualVirtPortProfile; virDomainNetGetActualVlan; virDomainNetInsert; +virDomainNetNotifyActualDevice; +virDomainNetReleaseActualDevice; virDomainNetRemove; virDomainNetRemoveHostdev; +virDomainNetSetDeviceImpl; virDomainNetTypeFromString; virDomainNetTypeSharesHostView; virDomainNetTypeToString; diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 395c8a921b..feb092ba48 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -38,7 +38,6 @@ #include "virtime.h" #include "locking/domain_lock.h" #include "xen_common.h" -#include "network/bridge_driver.h" #define VIR_FROM_THIS VIR_FROM_LIBXL @@ -796,7 +795,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, /* cleanup actual device */ virDomainNetRemoveHostdev(vm->def, net); - networkReleaseActualDevice(vm->def, net); + virDomainNetReleaseActualDevice(vm->def, net); } } @@ -955,7 +954,7 @@ libxlNetworkPrepareDevices(virDomainDefPtr def) * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (networkAllocateActualDevice(def, net) < 0) + if (virDomainNetAllocateActualDevice(def, net) < 0) return -1; actualType = virDomainNetGetActualType(net); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 79e29ce072..be11134fb2 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -59,7 +59,6 @@ #include "viraccessapicheck.h" #include "viratomic.h" #include "virhostdev.h" -#include "network/bridge_driver.h" #include "locking/domain_lock.h" #include "virnetdevtap.h" #include "cpu/cpu.h" @@ -3349,7 +3348,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver, * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (networkAllocateActualDevice(vm->def, net) < 0) + if (virDomainNetAllocateActualDevice(vm->def, net) < 0) goto cleanup; actualType = virDomainNetGetActualType(net); @@ -3399,7 +3398,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver, vm->def->nets[vm->def->nnets++] = net; } else { virDomainNetRemoveHostdev(vm->def, net); - networkReleaseActualDevice(vm->def, net); + virDomainNetReleaseActualDevice(vm->def, net); } virObjectUnref(cfg); return ret; @@ -3822,7 +3821,7 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver, cleanup: libxl_device_nic_dispose(&nic); if (!ret) { - networkReleaseActualDevice(vm->def, detach); + virDomainNetReleaseActualDevice(vm->def, detach); virDomainNetRemove(vm->def, detachidx); } virObjectUnref(cfg); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index b3447100fc..961baa344c 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -67,7 +67,6 @@ #include "domain_audit.h" #include "domain_nwfilter.h" #include "nwfilter_conf.h" -#include "network/bridge_driver.h" #include "virinitctl.h" #include "virnetdev.h" #include "virnetdevtap.h" @@ -3944,7 +3943,7 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn, * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (networkAllocateActualDevice(vm->def, net) < 0) + if (virDomainNetAllocateActualDevice(vm->def, net) < 0) return -1; actualType = virDomainNetGetActualType(net); @@ -4468,7 +4467,7 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm, ret = 0; cleanup: if (!ret) { - networkReleaseActualDevice(vm->def, detach); + virDomainNetReleaseActualDevice(vm->def, detach); virDomainNetRemove(vm->def, detachidx); virDomainNetDefFree(detach); } diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index efd8a69000..bc321e360d 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -40,7 +40,6 @@ #include "virnetdevopenvswitch.h" #include "virtime.h" #include "domain_nwfilter.h" -#include "network/bridge_driver.h" #include "viralloc.h" #include "domain_audit.h" #include "virerror.h" @@ -219,7 +218,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, iface->ifname)); ignore_value(virNetDevVethDelete(iface->ifname)); } - networkReleaseActualDevice(vm->def, iface); + virDomainNetReleaseActualDevice(vm->def, iface); } virDomainConfVMNWFilterTeardown(vm); @@ -553,7 +552,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn, if (virLXCProcessValidateInterface(net) < 0) return -1; - if (networkAllocateActualDevice(def, net) < 0) + if (virDomainNetAllocateActualDevice(def, net) < 0) goto cleanup; if (VIR_EXPAND_N(*veths, *nveths, 1) < 0) @@ -635,7 +634,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn, ignore_value(virNetDevOpenvswitchRemovePort( virDomainNetGetActualBridgeName(iface), iface->ifname)); - networkReleaseActualDevice(def, iface); + virDomainNetReleaseActualDevice(def, iface); } } return ret; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 334da7a85d..a492b190e4 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4275,16 +4275,6 @@ static virStateDriver networkStateDriver = { .stateReload = networkStateReload, }; -int -networkRegister(void) -{ - if (virSetSharedNetworkDriver(&networkDriver) < 0) - return -1; - if (virRegisterStateDriver(&networkStateDriver) < 0) - return -1; - return 0; -} - /* A unified function to log network connections and disconnections */ @@ -4342,7 +4332,7 @@ networkLogAllocation(virNetworkDefPtr netdef, * * Returns 0 on success, -1 on failure. */ -int +static int networkAllocateActualDevice(virDomainDefPtr dom, virDomainNetDefPtr iface) { @@ -4764,7 +4754,7 @@ networkAllocateActualDevice(virDomainDefPtr dom, * * No return value (but does log any failures) */ -void +static void networkNotifyActualDevice(virDomainDefPtr dom, virDomainNetDefPtr iface) { @@ -4981,7 +4971,7 @@ networkNotifyActualDevice(virDomainDefPtr dom, * * Returns 0 on success, -1 on failure. */ -int +static int networkReleaseActualDevice(virDomainDefPtr dom, virDomainNetDefPtr iface) { @@ -5716,3 +5706,19 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, virNetworkObjEndAPI(&obj); return ret; } + +int +networkRegister(void) +{ + if (virSetSharedNetworkDriver(&networkDriver) < 0) + return -1; + if (virRegisterStateDriver(&networkStateDriver) < 0) + return -1; + + virDomainNetSetDeviceImpl( + networkAllocateActualDevice, + networkNotifyActualDevice, + networkReleaseActualDevice); + + return 0; +} diff --git a/src/network/bridge_driver.h b/src/network/bridge_driver.h index 6d9aece656..dbb4fa8086 100644 --- a/src/network/bridge_driver.h +++ b/src/network/bridge_driver.h @@ -35,20 +35,6 @@ int networkRegister(void); # if WITH_NETWORK -int -networkAllocateActualDevice(virDomainDefPtr dom, - virDomainNetDefPtr iface) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); - -void -networkNotifyActualDevice(virDomainDefPtr dom, - virDomainNetDefPtr iface) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); - -int -networkReleaseActualDevice(virDomainDefPtr dom, - virDomainNetDefPtr iface) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int networkGetNetworkAddress(const char *netname, @@ -78,25 +64,11 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, # else /* Define no-op replacements that don't drag in any link dependencies. */ -# define networkAllocateActualDevice(dom, iface) 0 # define networkGetActualType(iface) (iface->type) # define networkGetNetworkAddress(netname, netaddr) (-2) # define networkDnsmasqConfContents(network, pidfile, configstr, \ dctx, caps) 0 -static inline void -networkNotifyActualDevice(virDomainDefPtr dom ATTRIBUTE_UNUSED, - virDomainNetDefPtr iface ATTRIBUTE_UNUSED) -{ -} - -static inline int -networkReleaseActualDevice(virDomainDefPtr dom ATTRIBUTE_UNUSED, - virDomainNetDefPtr iface ATTRIBUTE_UNUSED) -{ - return 0; -} - static inline bool networkBandwidthChangeAllowed(virDomainNetDefPtr iface ATTRIBUTE_UNUSED, virNetDevBandwidthPtr newBandwidth ATTRIBUTE_UNUSED) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 6b245bd6ac..2cf4e76ec1 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -47,7 +47,6 @@ #include "virprocess.h" #include "qemu_cgroup.h" #include "locking/domain_lock.h" -#include "network/bridge_driver.h" #include "virnetdev.h" #include "virnetdevbridge.h" #include "virnetdevtap.h" @@ -851,7 +850,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (networkAllocateActualDevice(vm->def, net) < 0) + if (virDomainNetAllocateActualDevice(vm->def, net) < 0) goto cleanup; actualType = virDomainNetGetActualType(net); @@ -1182,7 +1181,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, virDomainNetRemoveHostdev(vm->def, net); - networkReleaseActualDevice(vm->def, net); + virDomainNetReleaseActualDevice(vm->def, net); } VIR_FREE(nicstr); @@ -3229,7 +3228,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, * free it if we fail for any reason */ if (newdev->type == VIR_DOMAIN_NET_TYPE_NETWORK && - networkAllocateActualDevice(vm->def, newdev) < 0) { + virDomainNetAllocateActualDevice(vm->def, newdev) < 0) { goto cleanup; } @@ -3437,7 +3436,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, /* this function doesn't work with HOSTDEV networks yet, thus * no need to change the pointer in the hostdev structure */ - networkReleaseActualDevice(vm->def, olddev); + virDomainNetReleaseActualDevice(vm->def, olddev); virDomainNetDefFree(olddev); /* move newdev into the nets list, and NULL it out from the * virDomainDeviceDef that we were given so that the caller @@ -3469,7 +3468,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, * replace the entire device object. */ if (newdev) - networkReleaseActualDevice(vm->def, newdev); + virDomainNetReleaseActualDevice(vm->def, newdev); return ret; } @@ -4051,7 +4050,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, virDomainHostdevDefFree(hostdev); if (net) { - networkReleaseActualDevice(vm->def, net); + virDomainNetReleaseActualDevice(vm->def, net); virDomainNetDefFree(net); } @@ -4162,7 +4161,7 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver, qemuDomainNetDeviceVportRemove(net); - networkReleaseActualDevice(vm->def, net); + virDomainNetReleaseActualDevice(vm->def, net); virDomainNetDefFree(net); ret = 0; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index bcd4ac8ad6..c943407b58 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2922,7 +2922,7 @@ qemuProcessNotifyNets(virDomainDefPtr def) if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) ignore_value(virNetDevMacVLanReserveName(net->ifname, false)); - networkNotifyActualDevice(def, net); + virDomainNetNotifyActualDevice(def, net); } } @@ -4992,7 +4992,7 @@ qemuProcessNetworkPrepareDevices(virDomainDefPtr def) * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (networkAllocateActualDevice(def, net) < 0) + if (virDomainNetAllocateActualDevice(def, net) < 0) goto cleanup; actualType = virDomainNetGetActualType(net); @@ -6576,7 +6576,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, /* kick the device out of the hostdev list too */ virDomainNetRemoveHostdev(def, net); - networkReleaseActualDevice(vm->def, net); + virDomainNetReleaseActualDevice(vm->def, net); } retry: -- 2.14.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list