diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 34aae82f15..53c33df0dd 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28817,3 +28817,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 091f2ee71a..a0f2af4a7a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3456,4 +3456,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 bbe97b161f..ecb90febc0 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -433,6 +433,7 @@ virDomainMemoryModelTypeToString; virDomainMemoryRemove; virDomainMemorySourceTypeFromString; virDomainMemorySourceTypeToString; +virDomainNetAllocateActualDevice; virDomainNetAppendIPAddress; virDomainNetDefClear; virDomainNetDefFormat; @@ -452,8 +453,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 b9da0569f1..4113217882 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4374,7 +4374,7 @@ networkLogAllocation(virNetworkDefPtr netdef, * * Returns 0 on success, -1 on failure. */ -int +static int networkAllocateActualDevice(virDomainDefPtr dom, virDomainNetDefPtr iface) { @@ -4796,7 +4796,7 @@ networkAllocateActualDevice(virDomainDefPtr dom, * * No return value (but does log any failures) */ -void +static void networkNotifyActualDevice(virDomainDefPtr dom, virDomainNetDefPtr iface) { @@ -5013,7 +5013,7 @@ networkNotifyActualDevice(virDomainDefPtr dom, * * Returns 0 on success, -1 on failure. */ -int +static int networkReleaseActualDevice(virDomainDefPtr dom, virDomainNetDefPtr iface) { @@ -5810,5 +5810,11 @@ networkRegister(void) 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 53bfe47d08..1a406b6d26 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" @@ -855,7 +854,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); @@ -1186,7 +1185,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, virDomainNetRemoveHostdev(vm->def, net); - networkReleaseActualDevice(vm->def, net); + virDomainNetReleaseActualDevice(vm->def, net); } VIR_FREE(nicstr); @@ -3233,7 +3232,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; } @@ -3441,7 +3440,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 @@ -3473,7 +3472,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, * replace the entire device object. */ if (newdev) - networkReleaseActualDevice(vm->def, newdev); + virDomainNetReleaseActualDevice(vm->def, newdev); return ret; } @@ -4059,7 +4058,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, virDomainHostdevDefFree(hostdev); if (net) { - networkReleaseActualDevice(vm->def, net); + virDomainNetReleaseActualDevice(vm->def, net); virDomainNetDefFree(net); } @@ -4170,7 +4169,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 c1da3bb7c8..265ffc9304 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2954,7 +2954,7 @@ qemuProcessNotifyNets(virDomainDefPtr def) if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) ignore_value(virNetDevMacVLanReserveName(net->ifname, false)); - networkNotifyActualDevice(def, net); + virDomainNetNotifyActualDevice(def, net); } } @@ -5050,7 +5050,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); @@ -6637,7 +6637,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: