提交 a455d41e 编写于 作者: D Daniel P. Berrangé

conf: expand network device callbacks to cover resolving NIC type

Currently the QEMU driver will call directly into the network driver
impl to modify resolve the atual type of NICs with type=network. It
has todo this before it has allocated the actual NIC. This introduces
a callback system to allow us to decouple the QEMU driver from the
network driver.

This is a short term step, as it ought to be possible to achieve the
same end goal by simply querying XML via the public network API. The
QEMU code in question though, has no virConnectPtr conveniently
available at this time.
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 9069331b
...@@ -28823,6 +28823,7 @@ static virDomainNetNotifyActualDeviceImpl netNotify; ...@@ -28823,6 +28823,7 @@ static virDomainNetNotifyActualDeviceImpl netNotify;
static virDomainNetReleaseActualDeviceImpl netRelease; static virDomainNetReleaseActualDeviceImpl netRelease;
static virDomainNetBandwidthChangeAllowedImpl netBandwidthChangeAllowed; static virDomainNetBandwidthChangeAllowedImpl netBandwidthChangeAllowed;
static virDomainNetBandwidthUpdateImpl netBandwidthUpdate; static virDomainNetBandwidthUpdateImpl netBandwidthUpdate;
static virDomainNetResolveActualTypeImpl netResolveActualType;
void void
...@@ -28830,13 +28831,15 @@ virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate, ...@@ -28830,13 +28831,15 @@ virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate,
virDomainNetNotifyActualDeviceImpl notify, virDomainNetNotifyActualDeviceImpl notify,
virDomainNetReleaseActualDeviceImpl release, virDomainNetReleaseActualDeviceImpl release,
virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed, virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed,
virDomainNetBandwidthUpdateImpl bandwidthUpdate) virDomainNetBandwidthUpdateImpl bandwidthUpdate,
virDomainNetResolveActualTypeImpl resolveActualType)
{ {
netAllocate = allocate; netAllocate = allocate;
netNotify = notify; netNotify = notify;
netRelease = release; netRelease = release;
netBandwidthChangeAllowed = bandwidthChangeAllowed; netBandwidthChangeAllowed = bandwidthChangeAllowed;
netBandwidthUpdate = bandwidthUpdate; netBandwidthUpdate = bandwidthUpdate;
netResolveActualType = resolveActualType;
} }
int int
...@@ -28904,3 +28907,15 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface, ...@@ -28904,3 +28907,15 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
return netBandwidthUpdate(iface, newBandwidth); return netBandwidthUpdate(iface, newBandwidth);
} }
int
virDomainNetResolveActualType(virDomainNetDefPtr iface)
{
if (!netResolveActualType) {
virReportError(VIR_ERR_NO_SUPPORT, "%s",
_("Network device resolve type not available"));
return -1;
}
return netResolveActualType(iface);
}
...@@ -3476,13 +3476,17 @@ typedef int ...@@ -3476,13 +3476,17 @@ typedef int
(*virDomainNetBandwidthUpdateImpl)(virDomainNetDefPtr iface, (*virDomainNetBandwidthUpdateImpl)(virDomainNetDefPtr iface,
virNetDevBandwidthPtr newBandwidth); virNetDevBandwidthPtr newBandwidth);
typedef int
(*virDomainNetResolveActualTypeImpl)(virDomainNetDefPtr iface);
void void
virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate, virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate,
virDomainNetNotifyActualDeviceImpl notify, virDomainNetNotifyActualDeviceImpl notify,
virDomainNetReleaseActualDeviceImpl release, virDomainNetReleaseActualDeviceImpl release,
virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed, virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed,
virDomainNetBandwidthUpdateImpl bandwidthUpdate); virDomainNetBandwidthUpdateImpl bandwidthUpdate,
virDomainNetResolveActualTypeImpl resolveActualType);
int int
virDomainNetAllocateActualDevice(virDomainDefPtr dom, virDomainNetAllocateActualDevice(virDomainDefPtr dom,
...@@ -3509,5 +3513,14 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface, ...@@ -3509,5 +3513,14 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
virNetDevBandwidthPtr newBandwidth) virNetDevBandwidthPtr newBandwidth)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
/* XXX this is a nasty hack and should be removed. It should
* be by via public API by fetching XML and parsing it. Not
* easy right now as code paths in QEMU reying on this don't
* have a virConnectPtr handy.
*/
int
virDomainNetResolveActualType(virDomainNetDefPtr iface)
ATTRIBUTE_NONNULL(1);
#endif /* __DOMAIN_CONF_H */ #endif /* __DOMAIN_CONF_H */
...@@ -459,6 +459,7 @@ virDomainNetNotifyActualDevice; ...@@ -459,6 +459,7 @@ virDomainNetNotifyActualDevice;
virDomainNetReleaseActualDevice; virDomainNetReleaseActualDevice;
virDomainNetRemove; virDomainNetRemove;
virDomainNetRemoveHostdev; virDomainNetRemoveHostdev;
virDomainNetResolveActualType;
virDomainNetSetDeviceImpl; virDomainNetSetDeviceImpl;
virDomainNetTypeFromString; virDomainNetTypeFromString;
virDomainNetTypeSharesHostView; virDomainNetTypeSharesHostView;
......
...@@ -5147,8 +5147,7 @@ networkReleaseActualDevice(virDomainDefPtr dom, ...@@ -5147,8 +5147,7 @@ networkReleaseActualDevice(virDomainDefPtr dom,
/* networkGetActualType: /* networkResolveActualType:
* @dom: domain definition that @iface belongs to
* @iface: the original NetDef from the domain * @iface: the original NetDef from the domain
* *
* Looks up the network reference by iface, and returns the actual * Looks up the network reference by iface, and returns the actual
...@@ -5156,8 +5155,8 @@ networkReleaseActualDevice(virDomainDefPtr dom, ...@@ -5156,8 +5155,8 @@ networkReleaseActualDevice(virDomainDefPtr dom,
* *
* Returns 0 on success, -1 on failure. * Returns 0 on success, -1 on failure.
*/ */
int static int
networkGetActualType(virDomainNetDefPtr iface) networkResolveActualType(virDomainNetDefPtr iface)
{ {
virNetworkDriverStatePtr driver = networkGetDriver(); virNetworkDriverStatePtr driver = networkGetDriver();
virNetworkObjPtr obj = NULL; virNetworkObjPtr obj = NULL;
...@@ -5718,7 +5717,8 @@ networkRegister(void) ...@@ -5718,7 +5717,8 @@ networkRegister(void)
networkNotifyActualDevice, networkNotifyActualDevice,
networkReleaseActualDevice, networkReleaseActualDevice,
networkBandwidthChangeAllowed, networkBandwidthChangeAllowed,
networkBandwidthUpdate); networkBandwidthUpdate,
networkResolveActualType);
return 0; return 0;
} }
...@@ -36,10 +36,6 @@ networkRegister(void); ...@@ -36,10 +36,6 @@ networkRegister(void);
# if WITH_NETWORK # if WITH_NETWORK
int
networkGetActualType(virDomainNetDefPtr iface)
ATTRIBUTE_NONNULL(1);
int int
networkDnsmasqConfContents(virNetworkObjPtr obj, networkDnsmasqConfContents(virNetworkObjPtr obj,
const char *pidfile, const char *pidfile,
...@@ -49,7 +45,6 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, ...@@ -49,7 +45,6 @@ networkDnsmasqConfContents(virNetworkObjPtr obj,
# else # else
/* Define no-op replacements that don't drag in any link dependencies. */ /* Define no-op replacements that don't drag in any link dependencies. */
# define networkGetActualType(iface) (iface->type)
# define networkDnsmasqConfContents(network, pidfile, configstr, \ # define networkDnsmasqConfContents(network, pidfile, configstr, \
dctx, caps) 0 dctx, caps) 0
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include "viralloc.h" #include "viralloc.h"
#include "virlog.h" #include "virlog.h"
#include "virstring.h" #include "virstring.h"
#include "network/bridge_driver.h"
#define QEMU_DRIVE_HOST_PREFIX "drive-" #define QEMU_DRIVE_HOST_PREFIX "drive-"
...@@ -271,7 +270,7 @@ qemuAssignDeviceNetAlias(virDomainDefPtr def, ...@@ -271,7 +270,7 @@ qemuAssignDeviceNetAlias(virDomainDefPtr def,
* We must use "-1" as the index because the caller doesn't know * We must use "-1" as the index because the caller doesn't know
* that we're now looking for a unique hostdevN rather than netN * that we're now looking for a unique hostdevN rather than netN
*/ */
if (networkGetActualType(net) == VIR_DOMAIN_NET_TYPE_HOSTDEV) if (virDomainNetResolveActualType(net) == VIR_DOMAIN_NET_TYPE_HOSTDEV)
return qemuAssignDeviceHostdevAlias(def, &net->info.alias, -1); return qemuAssignDeviceHostdevAlias(def, &net->info.alias, -1);
if (idx == -1) { if (idx == -1) {
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "qemu_domain_address.h" #include "qemu_domain_address.h"
#include "qemu_domain.h" #include "qemu_domain.h"
#include "network/bridge_driver.h"
#include "viralloc.h" #include "viralloc.h"
#include "virerror.h" #include "virerror.h"
#include "virlog.h" #include "virlog.h"
...@@ -1064,7 +1063,7 @@ qemuDomainFillDeviceIsolationGroup(virDomainDefPtr def, ...@@ -1064,7 +1063,7 @@ qemuDomainFillDeviceIsolationGroup(virDomainDefPtr def,
* to is of type hostdev. All other kinds of network interfaces don't * to is of type hostdev. All other kinds of network interfaces don't
* require us to isolate the guest device, so we can skip them */ * require us to isolate the guest device, so we can skip them */
if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK || if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK ||
networkGetActualType(iface) != VIR_DOMAIN_NET_TYPE_HOSTDEV) { virDomainNetResolveActualType(iface) != VIR_DOMAIN_NET_TYPE_HOSTDEV) {
goto skip; goto skip;
} }
......
...@@ -280,7 +280,7 @@ test_libraries += virmocklibxl.la ...@@ -280,7 +280,7 @@ test_libraries += virmocklibxl.la
endif WITH_LIBXL endif WITH_LIBXL
if WITH_QEMU if WITH_QEMU
test_programs += qemuxml2argvtest qemuxml2xmltest \ test_programs += qemuxml2xmltest \
qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest \ qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest \
qemumonitortest qemumonitorjsontest qemuhotplugtest \ qemumonitortest qemumonitorjsontest qemuhotplugtest \
qemuagenttest qemucapabilitiestest qemucaps2xmltest \ qemuagenttest qemucapabilitiestest qemucaps2xmltest \
...@@ -288,6 +288,11 @@ test_programs += qemuxml2argvtest qemuxml2xmltest \ ...@@ -288,6 +288,11 @@ test_programs += qemuxml2argvtest qemuxml2xmltest \
qemucommandutiltest \ qemucommandutiltest \
qemublocktest \ qemublocktest \
$(NULL) $(NULL)
if WITH_NETWORK
# Dep on the network driver callback for resolving NIC
# actual type. XXX remove this dep.
test_programs += qemuxml2xmltest
endif WITH_NETWORK
test_helpers += qemucapsprobe test_helpers += qemucapsprobe
test_libraries += libqemumonitortestutils.la \ test_libraries += libqemumonitortestutils.la \
libqemutestdriver.la \ libqemutestdriver.la \
...@@ -582,7 +587,9 @@ qemucpumock_la_LIBADD = $(MOCKLIBS_LIBS) ...@@ -582,7 +587,9 @@ qemucpumock_la_LIBADD = $(MOCKLIBS_LIBS)
qemuxml2argvtest_SOURCES = \ qemuxml2argvtest_SOURCES = \
qemuxml2argvtest.c testutilsqemu.c testutilsqemu.h \ qemuxml2argvtest.c testutilsqemu.c testutilsqemu.h \
testutils.c testutils.h testutils.c testutils.h
qemuxml2argvtest_LDADD = libqemutestdriver.la $(LDADDS) $(LIBXML_LIBS) qemuxml2argvtest_LDADD = libqemutestdriver.la \
../src/libvirt_driver_network_impl.la \
$(LDADDS) $(LIBXML_LIBS)
qemuxml2argvmock_la_SOURCES = \ qemuxml2argvmock_la_SOURCES = \
qemuxml2argvmock.c qemuxml2argvmock.c
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
# include "cpu/cpu_map.h" # include "cpu/cpu_map.h"
# include "virstring.h" # include "virstring.h"
# include "storage/storage_driver.h" # include "storage/storage_driver.h"
# include "network/bridge_driver.h"
# include "virmock.h" # include "virmock.h"
# define __QEMU_CAPSPRIV_H_ALLOW__ # define __QEMU_CAPSPRIV_H_ALLOW__
...@@ -580,6 +581,9 @@ mymain(void) ...@@ -580,6 +581,9 @@ mymain(void)
if (qemuTestDriverInit(&driver) < 0) if (qemuTestDriverInit(&driver) < 0)
return EXIT_FAILURE; return EXIT_FAILURE;
if (networkRegister() < 0)
return EXIT_FAILURE;
driver.privileged = true; driver.privileged = true;
VIR_FREE(driver.config->defaultTLSx509certdir); VIR_FREE(driver.config->defaultTLSx509certdir);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册