Currently the QEMU driver will call directly into the network driver
impl to modify network device bandwidth for interfaces with
type=network. This introduces a callback system to allow us to decouple
the QEMU driver from the network driver.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/conf/domain_conf.c | 35 ++++++++++++++++++++++++++++++++++-
src/conf/domain_conf.h | 22 +++++++++++++++++++++-
src/libvirt_private.syms | 2 ++
src/network/bridge_driver.c | 8 +++++---
src/network/bridge_driver.h | 24 ------------------------
src/qemu/qemu_driver.c | 4 ++--
6 files changed, 64 insertions(+), 31 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a3719164ae..5cae6f51cf 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -28446,15 +28446,22 @@ virDomainNetTypeSharesHostView(const virDomainNetDef *net)
static virDomainNetAllocateActualDeviceImpl netAllocate;
static virDomainNetNotifyActualDeviceImpl netNotify;
static virDomainNetReleaseActualDeviceImpl netRelease;
+static virDomainNetBandwidthChangeAllowedImpl netBandwidthChangeAllowed;
+static virDomainNetBandwidthUpdateImpl netBandwidthUpdate;
+
void
virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate,
virDomainNetNotifyActualDeviceImpl notify,
- virDomainNetReleaseActualDeviceImpl release)
+ virDomainNetReleaseActualDeviceImpl release,
+ virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed,
+ virDomainNetBandwidthUpdateImpl bandwidthUpdate)
{
netAllocate = allocate;
netNotify = notify;
netRelease = release;
+ netBandwidthChangeAllowed = bandwidthChangeAllowed;
+ netBandwidthUpdate = bandwidthUpdate;
}
int
@@ -28496,3 +28503,29 @@ virDomainNetReleaseActualDevice(virDomainDefPtr dom,
return netRelease(dom, iface);
}
+
+bool
+virDomainNetBandwidthChangeAllowed(virDomainNetDefPtr iface,
+ virNetDevBandwidthPtr newBandwidth)
+{
+ if (!netBandwidthChangeAllowed) {
+ virReportError(VIR_ERR_NO_SUPPORT, "%s",
+ _("Network device release not available"));
+ return -1;
+ }
+
+ return netBandwidthChangeAllowed(iface, newBandwidth);
+}
+
+int
+virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
+ virNetDevBandwidthPtr newBandwidth)
+{
+ if (!netBandwidthUpdate) {
+ virReportError(VIR_ERR_NO_SUPPORT, "%s",
+ _("Network device release not available"));
+ return -1;
+ }
+
+ return netBandwidthUpdate(iface, newBandwidth);
+}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 1d1e3ac1a4..e876fe953d 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3453,10 +3453,21 @@ typedef int
(*virDomainNetReleaseActualDeviceImpl)(virDomainDefPtr dom,
virDomainNetDefPtr iface);
+typedef bool
+(*virDomainNetBandwidthChangeAllowedImpl)(virDomainNetDefPtr iface,
+ virNetDevBandwidthPtr newBandwidth);
+
+typedef int
+(*virDomainNetBandwidthUpdateImpl)(virDomainNetDefPtr iface,
+ virNetDevBandwidthPtr newBandwidth);
+
+
void
virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate,
virDomainNetNotifyActualDeviceImpl notify,
- virDomainNetReleaseActualDeviceImpl release);
+ virDomainNetReleaseActualDeviceImpl release,
+ virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed,
+ virDomainNetBandwidthUpdateImpl bandwidthUpdate);
int
virDomainNetAllocateActualDevice(virDomainDefPtr dom,
@@ -3473,6 +3484,15 @@ virDomainNetReleaseActualDevice(virDomainDefPtr dom,
virDomainNetDefPtr iface)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+bool
+virDomainNetBandwidthChangeAllowed(virDomainNetDefPtr iface,
+ virNetDevBandwidthPtr newBandwidth)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
+int
+virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
+ virNetDevBandwidthPtr newBandwidth)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
#endif /* __DOMAIN_CONF_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 831b030b8c..10d8e65b62 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -432,6 +432,8 @@ virDomainMemorySourceTypeFromString;
virDomainMemorySourceTypeToString;
virDomainNetAllocateActualDevice;
virDomainNetAppendIPAddress;
+virDomainNetBandwidthChangeAllowed;
+virDomainNetBandwidthUpdate;
virDomainNetDefClear;
virDomainNetDefFormat;
virDomainNetDefFree;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index a492b190e4..a0e45d1f65 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -5589,7 +5589,7 @@ networkBandwidthGenericChecks(virDomainNetDefPtr iface,
}
-bool
+static bool
networkBandwidthChangeAllowed(virDomainNetDefPtr iface,
virNetDevBandwidthPtr newBandwidth)
{
@@ -5620,7 +5620,7 @@ networkBandwidthChangeAllowed(virDomainNetDefPtr iface,
}
-int
+static int
networkBandwidthUpdate(virDomainNetDefPtr iface,
virNetDevBandwidthPtr newBandwidth)
{
@@ -5718,7 +5718,9 @@ networkRegister(void)
virDomainNetSetDeviceImpl(
networkAllocateActualDevice,
networkNotifyActualDevice,
- networkReleaseActualDevice);
+ networkReleaseActualDevice,
+ networkBandwidthChangeAllowed,
+ networkBandwidthUpdate);
return 0;
}
diff --git a/src/network/bridge_driver.h b/src/network/bridge_driver.h
index dbb4fa8086..098f9e5c5b 100644
--- a/src/network/bridge_driver.h
+++ b/src/network/bridge_driver.h
@@ -52,16 +52,6 @@ networkDnsmasqConfContents(virNetworkObjPtr obj,
dnsmasqContext *dctx,
dnsmasqCapsPtr caps);
-bool
-networkBandwidthChangeAllowed(virDomainNetDefPtr iface,
- virNetDevBandwidthPtr newBandwidth)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-
-int
-networkBandwidthUpdate(virDomainNetDefPtr iface,
- virNetDevBandwidthPtr newBandwidth)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-
# else
/* Define no-op replacements that don't drag in any link dependencies. */
# define networkGetActualType(iface) (iface->type)
@@ -69,20 +59,6 @@ networkBandwidthUpdate(virDomainNetDefPtr iface,
# define networkDnsmasqConfContents(network, pidfile, configstr, \
dctx, caps) 0
-static inline bool
-networkBandwidthChangeAllowed(virDomainNetDefPtr iface ATTRIBUTE_UNUSED,
- virNetDevBandwidthPtr newBandwidth ATTRIBUTE_UNUSED)
-{
- return true;
-}
-
-static inline int
-networkBandwidthUpdate(virDomainNetDefPtr iface ATTRIBUTE_UNUSED,
- virNetDevBandwidthPtr newBandwidth ATTRIBUTE_UNUSED)
-{
- return 0;
-}
-
# endif
#endif /* __VIR_NETWORK__DRIVER_H */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 28ca4c09cc..a2a4c984df 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11264,12 +11264,12 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
sizeof(*newBandwidth->out));
}
- if (!networkBandwidthChangeAllowed(net, newBandwidth))
+ if (!virDomainNetBandwidthChangeAllowed(net, newBandwidth))
goto endjob;
if (virNetDevBandwidthSet(net->ifname, newBandwidth, false,
!virDomainNetTypeSharesHostView(net)) < 0 ||
- networkBandwidthUpdate(net, newBandwidth) < 0) {
+ virDomainNetBandwidthUpdate(net, newBandwidth) < 0) {
ignore_value(virNetDevBandwidthSet(net->ifname,
net->bandwidth,
false,
--
2.14.3