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(a)redhat.com>
---
src/conf/domain_conf.c | 54 +++++++++++++++++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 34 ++++++++++++++++++++++++++++
src/libvirt_private.syms | 4 ++++
src/libxl/libxl_domain.c | 4 ++--
src/libxl/libxl_driver.c | 6 ++---
src/lxc/lxc_driver.c | 4 ++--
src/lxc/lxc_process.c | 6 ++---
src/network/bridge_driver.c | 32 ++++++++++++++++-----------
src/network/bridge_driver.h | 28 -----------------------
src/qemu/qemu_hotplug.c | 14 ++++++------
src/qemu/qemu_process.c | 6 ++---
11 files changed, 131 insertions(+), 61 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a1c25060f9..a3719164ae 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -28442,3 +28442,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 6f7f96b3dd..1d1e3ac1a4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3441,4 +3441,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 3d8ed0b9de..831b030b8c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -430,6 +430,7 @@ virDomainMemoryInsert;
virDomainMemoryRemove;
virDomainMemorySourceTypeFromString;
virDomainMemorySourceTypeToString;
+virDomainNetAllocateActualDevice;
virDomainNetAppendIPAddress;
virDomainNetDefClear;
virDomainNetDefFormat;
@@ -449,8 +450,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..8cc931a32f 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -796,7 +796,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
/* cleanup actual device */
virDomainNetRemoveHostdev(vm->def, net);
- networkReleaseActualDevice(vm->def, net);
+ virDomainNetReleaseActualDevice(vm->def, net);
}
}
@@ -955,7 +955,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..36aa840936 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3349,7 +3349,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 +3399,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 +3822,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..cc2f97205a 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -3944,7 +3944,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 +4468,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..06bedfe73b 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -219,7 +219,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 +553,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 +635,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..2ab60919bb 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -851,7 +851,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 +1182,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
virDomainNetRemoveHostdev(vm->def, net);
- networkReleaseActualDevice(vm->def, net);
+ virDomainNetReleaseActualDevice(vm->def, net);
}
VIR_FREE(nicstr);
@@ -3229,7 +3229,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 +3437,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 +3469,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
* replace the entire device object.
*/
if (newdev)
- networkReleaseActualDevice(vm->def, newdev);
+ virDomainNetReleaseActualDevice(vm->def, newdev);
return ret;
}
@@ -4051,7 +4051,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
virDomainHostdevDefFree(hostdev);
if (net) {
- networkReleaseActualDevice(vm->def, net);
+ virDomainNetReleaseActualDevice(vm->def, net);
virDomainNetDefFree(net);
}
@@ -4162,7 +4162,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 25ec464d3e..29af643160 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2895,7 +2895,7 @@ qemuProcessNotifyNets(virDomainDefPtr def)
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT)
ignore_value(virNetDevMacVLanReserveName(net->ifname, false));
- networkNotifyActualDevice(def, net);
+ virDomainNetNotifyActualDevice(def, net);
}
}
@@ -4965,7 +4965,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);
@@ -6531,7 +6531,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