mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 21:34:54 +03:00
conf: introduce callback registration for domain net device allocation
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@redhat.com>
This commit is contained in:
parent
5cbe0b1085
commit
5b13570ab8
@ -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);
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user