vbox: New network driver

This patch seperate the domain driver and the network driver.

libvirt_driver_vbox_impl.la has been linked in the network driver.
So that the version specified codes in vbox_V*.c would only be
compiled once.

The vboxGetNetworkDriver provides a simple interface to get vbox
network driver.
This commit is contained in:
Taowei 2014-10-02 11:30:38 +08:00 committed by Michal Privoznik
parent bde0cb511d
commit 87dea4fcff
6 changed files with 82 additions and 56 deletions

View File

@ -519,6 +519,7 @@ DRIVER_SOURCE_FILES = \
$(TEST_DRIVER_SOURCES) \ $(TEST_DRIVER_SOURCES) \
$(UML_DRIVER_SOURCES) \ $(UML_DRIVER_SOURCES) \
$(VBOX_DRIVER_SOURCES) \ $(VBOX_DRIVER_SOURCES) \
$(VBOX_NETWORK_DRIVER_SOURCES) \
vbox/vbox_tmpl.c \ vbox/vbox_tmpl.c \
$(VMWARE_DRIVER_SOURCES) \ $(VMWARE_DRIVER_SOURCES) \
$(XEN_DRIVER_SOURCES) \ $(XEN_DRIVER_SOURCES) \
@ -678,10 +679,13 @@ VBOX_DRIVER_SOURCES = \
vbox/vbox_V4_3.c vbox/vbox_CAPI_v4_3.h \ vbox/vbox_V4_3.c vbox/vbox_CAPI_v4_3.h \
vbox/vbox_V4_3_4.c vbox/vbox_CAPI_v4_3_4.h \ vbox/vbox_V4_3_4.c vbox/vbox_CAPI_v4_3_4.h \
vbox/vbox_common.c vbox/vbox_common.h \ vbox/vbox_common.c vbox/vbox_common.h \
vbox/vbox_network.c \
vbox/vbox_uniformed_api.h \ vbox/vbox_uniformed_api.h \
vbox/vbox_get_driver.h vbox/vbox_get_driver.h
VBOX_NETWORK_DRIVER_SOURCES = \
vbox/vbox_driver.c vbox/vbox_driver.h \
vbox/vbox_network.c vbox/vbox_get_driver.h
VBOX_DRIVER_EXTRA_DIST = \ VBOX_DRIVER_EXTRA_DIST = \
vbox/vbox_tmpl.c vbox/README \ vbox/vbox_tmpl.c vbox/README \
vbox/vbox_MSCOMGlue.c vbox/vbox_MSCOMGlue.h \ vbox/vbox_MSCOMGlue.c vbox/vbox_MSCOMGlue.h \
@ -1186,8 +1190,9 @@ libvirt_driver_vbox_network_impl_la_CFLAGS = \
libvirt_driver_vbox_network_impl_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_vbox_network_impl_la_LDFLAGS = $(AM_LDFLAGS)
libvirt_driver_vbox_network_impl_la_LIBADD = $(DLOPEN_LIBS) \ libvirt_driver_vbox_network_impl_la_LIBADD = $(DLOPEN_LIBS) \
$(MSCOM_LIBS) \ $(MSCOM_LIBS) \
$(LIBXML_LIBS) $(LIBXML_LIBS) \
libvirt_driver_vbox_network_impl_la_SOURCES = $(VBOX_DRIVER_SOURCES) libvirt_driver_vbox_impl.la
libvirt_driver_vbox_network_impl_la_SOURCES = $(VBOX_NETWORK_DRIVER_SOURCES)
libvirt_driver_vbox_storage_impl_la_CFLAGS = \ libvirt_driver_vbox_storage_impl_la_CFLAGS = \
-I$(top_srcdir)/src/conf \ -I$(top_srcdir)/src/conf \

View File

@ -71,7 +71,7 @@ extern virStorageDriver vbox43_4StorageDriver;
#define VIR_FROM_THIS VIR_FROM_VBOX #define VIR_FROM_THIS VIR_FROM_VBOX
#if !defined(WITH_DRIVER_MODULES) || defined(VBOX_NETWORK_DRIVER) || defined(VBOX_STORAGE_DRIVER) #if !defined(WITH_DRIVER_MODULES) || defined(VBOX_STORAGE_DRIVER)
static void static void
vboxGetDrivers(virDriverPtr *driver_ret, vboxGetDrivers(virDriverPtr *driver_ret,
virNetworkDriverPtr *networkDriver_ret, virNetworkDriverPtr *networkDriver_ret,
@ -161,9 +161,12 @@ vboxGetDrivers(virDriverPtr *driver_ret,
#if !defined(WITH_DRIVER_MODULES) || defined(VBOX_NETWORK_DRIVER) #if !defined(WITH_DRIVER_MODULES) || defined(VBOX_NETWORK_DRIVER)
int vboxNetworkRegister(void) int vboxNetworkRegister(void)
{ {
virNetworkDriverPtr networkDriver; virNetworkDriverPtr networkDriver = NULL;
uint32_t uVersion;
if (VBoxCGlueInit(&uVersion) == 0)
networkDriver = vboxGetNetworkDriver(uVersion);
vboxGetDrivers(NULL, &networkDriver, NULL);
if (virRegisterNetworkDriver(networkDriver) < 0) if (virRegisterNetworkDriver(networkDriver) < 0)
return -1; return -1;
return 0; return 0;

View File

@ -22,5 +22,6 @@
# include "internal.h" # include "internal.h"
virDriverPtr vboxGetDriver(uint32_t uVersion); virDriverPtr vboxGetDriver(uint32_t uVersion);
virNetworkDriverPtr vboxGetNetworkDriver(uint32_t uVersion);
#endif /* VBOX_GET_DRIVER_H */ #endif /* VBOX_GET_DRIVER_H */

View File

@ -31,6 +31,7 @@
#include "vbox_common.h" #include "vbox_common.h"
#include "vbox_uniformed_api.h" #include "vbox_uniformed_api.h"
#include "vbox_get_driver.h"
#define VIR_FROM_THIS VIR_FROM_VBOX #define VIR_FROM_THIS VIR_FROM_VBOX
@ -85,7 +86,8 @@ static vboxUniformedAPI gVBoxAPI;
* The Network Functions here on * The Network Functions here on
*/ */
virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, static virDrvOpenStatus
vboxNetworkOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED, virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags) unsigned int flags)
{ {
@ -107,14 +109,14 @@ virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn,
return VIR_DRV_OPEN_DECLINED; return VIR_DRV_OPEN_DECLINED;
} }
int vboxNetworkClose(virConnectPtr conn) static int vboxNetworkClose(virConnectPtr conn)
{ {
VIR_DEBUG("network uninitialized"); VIR_DEBUG("network uninitialized");
conn->networkPrivateData = NULL; conn->networkPrivateData = NULL;
return 0; return 0;
} }
int vboxConnectNumOfNetworks(virConnectPtr conn) static int vboxConnectNumOfNetworks(virConnectPtr conn)
{ {
vboxGlobalData *data = conn->privateData; vboxGlobalData *data = conn->privateData;
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
@ -159,7 +161,7 @@ int vboxConnectNumOfNetworks(virConnectPtr conn)
return ret; return ret;
} }
int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames) static int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames)
{ {
vboxGlobalData *data = conn->privateData; vboxGlobalData *data = conn->privateData;
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
@ -216,7 +218,7 @@ int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames)
return ret; return ret;
} }
int vboxConnectNumOfDefinedNetworks(virConnectPtr conn) static int vboxConnectNumOfDefinedNetworks(virConnectPtr conn)
{ {
vboxGlobalData *data = conn->privateData; vboxGlobalData *data = conn->privateData;
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
@ -261,7 +263,7 @@ int vboxConnectNumOfDefinedNetworks(virConnectPtr conn)
return ret; return ret;
} }
int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames) static int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames)
{ {
vboxGlobalData *data = conn->privateData; vboxGlobalData *data = conn->privateData;
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
@ -318,7 +320,7 @@ int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int n
return ret; return ret;
} }
virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid) static virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
{ {
vboxGlobalData *data = conn->privateData; vboxGlobalData *data = conn->privateData;
PRUint32 interfaceType = 0; PRUint32 interfaceType = 0;
@ -370,7 +372,7 @@ virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *u
return ret; return ret;
} }
virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name) static virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name)
{ {
vboxGlobalData *data = conn->privateData; vboxGlobalData *data = conn->privateData;
PRUnichar *nameUtf16 = NULL; PRUnichar *nameUtf16 = NULL;
@ -621,12 +623,12 @@ vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool start)
return ret; return ret;
} }
virNetworkPtr vboxNetworkCreateXML(virConnectPtr conn, const char *xml) static virNetworkPtr vboxNetworkCreateXML(virConnectPtr conn, const char *xml)
{ {
return vboxNetworkDefineCreateXML(conn, xml, true); return vboxNetworkDefineCreateXML(conn, xml, true);
} }
virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml) static virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml)
{ {
return vboxNetworkDefineCreateXML(conn, xml, false); return vboxNetworkDefineCreateXML(conn, xml, false);
} }
@ -727,17 +729,17 @@ vboxNetworkUndefineDestroy(virNetworkPtr network, bool removeinterface)
return ret; return ret;
} }
int vboxNetworkUndefine(virNetworkPtr network) static int vboxNetworkUndefine(virNetworkPtr network)
{ {
return vboxNetworkUndefineDestroy(network, true); return vboxNetworkUndefineDestroy(network, true);
} }
int vboxNetworkDestroy(virNetworkPtr network) static int vboxNetworkDestroy(virNetworkPtr network)
{ {
return vboxNetworkUndefineDestroy(network, false); return vboxNetworkUndefineDestroy(network, false);
} }
int vboxNetworkCreate(virNetworkPtr network) static int vboxNetworkCreate(virNetworkPtr network)
{ {
vboxGlobalData *data = network->conn->privateData; vboxGlobalData *data = network->conn->privateData;
char *networkNameUtf8 = NULL; char *networkNameUtf8 = NULL;
@ -830,7 +832,7 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16,
return result; return result;
} }
char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags)
{ {
vboxGlobalData *data = network->conn->privateData; vboxGlobalData *data = network->conn->privateData;
virNetworkDefPtr def = NULL; virNetworkDefPtr def = NULL;
@ -999,3 +1001,52 @@ char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags)
VBOX_RELEASE(dhcpServer); VBOX_RELEASE(dhcpServer);
return ret; return ret;
} }
virNetworkDriver vboxNetworkDriver = {
"VBOX",
.networkOpen = vboxNetworkOpen, /* 0.6.4 */
.networkClose = vboxNetworkClose, /* 0.6.4 */
.connectNumOfNetworks = vboxConnectNumOfNetworks, /* 0.6.4 */
.connectListNetworks = vboxConnectListNetworks, /* 0.6.4 */
.connectNumOfDefinedNetworks = vboxConnectNumOfDefinedNetworks, /* 0.6.4 */
.connectListDefinedNetworks = vboxConnectListDefinedNetworks, /* 0.6.4 */
.networkLookupByUUID = vboxNetworkLookupByUUID, /* 0.6.4 */
.networkLookupByName = vboxNetworkLookupByName, /* 0.6.4 */
.networkCreateXML = vboxNetworkCreateXML, /* 0.6.4 */
.networkDefineXML = vboxNetworkDefineXML, /* 0.6.4 */
.networkUndefine = vboxNetworkUndefine, /* 0.6.4 */
.networkCreate = vboxNetworkCreate, /* 0.6.4 */
.networkDestroy = vboxNetworkDestroy, /* 0.6.4 */
.networkGetXMLDesc = vboxNetworkGetXMLDesc, /* 0.6.4 */
};
virNetworkDriverPtr vboxGetNetworkDriver(uint32_t uVersion)
{
/* Install gVBoxAPI according to the vbox API version.
* Return -1 for unsupported version.
*/
if (uVersion >= 2001052 && uVersion < 2002051) {
vbox22InstallUniformedAPI(&gVBoxAPI);
} else if (uVersion >= 2002051 && uVersion < 3000051) {
vbox30InstallUniformedAPI(&gVBoxAPI);
} else if (uVersion >= 3000051 && uVersion < 3001051) {
vbox31InstallUniformedAPI(&gVBoxAPI);
} else if (uVersion >= 3001051 && uVersion < 3002051) {
vbox32InstallUniformedAPI(&gVBoxAPI);
} else if (uVersion >= 3002051 && uVersion < 4000051) {
vbox40InstallUniformedAPI(&gVBoxAPI);
} else if (uVersion >= 4000051 && uVersion < 4001051) {
vbox41InstallUniformedAPI(&gVBoxAPI);
} else if (uVersion >= 4001051 && uVersion < 4002020) {
vbox42InstallUniformedAPI(&gVBoxAPI);
} else if (uVersion >= 4002020 && uVersion < 4002051) {
vbox42_20InstallUniformedAPI(&gVBoxAPI);
} else if (uVersion >= 4002051 && uVersion < 4003004) {
vbox43InstallUniformedAPI(&gVBoxAPI);
} else if (uVersion >= 4003004 && uVersion < 4003051) {
vbox43_4InstallUniformedAPI(&gVBoxAPI);
} else {
return NULL;
}
return &vboxNetworkDriver;
}

View File

@ -5894,24 +5894,6 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
* Function Tables * Function Tables
*/ */
virNetworkDriver NAME(NetworkDriver) = {
"VBOX",
.networkOpen = vboxNetworkOpen, /* 0.6.4 */
.networkClose = vboxNetworkClose, /* 0.6.4 */
.connectNumOfNetworks = vboxConnectNumOfNetworks, /* 0.6.4 */
.connectListNetworks = vboxConnectListNetworks, /* 0.6.4 */
.connectNumOfDefinedNetworks = vboxConnectNumOfDefinedNetworks, /* 0.6.4 */
.connectListDefinedNetworks = vboxConnectListDefinedNetworks, /* 0.6.4 */
.networkLookupByUUID = vboxNetworkLookupByUUID, /* 0.6.4 */
.networkLookupByName = vboxNetworkLookupByName, /* 0.6.4 */
.networkCreateXML = vboxNetworkCreateXML, /* 0.6.4 */
.networkDefineXML = vboxNetworkDefineXML, /* 0.6.4 */
.networkUndefine = vboxNetworkUndefine, /* 0.6.4 */
.networkCreate = vboxNetworkCreate, /* 0.6.4 */
.networkDestroy = vboxNetworkDestroy, /* 0.6.4 */
.networkGetXMLDesc = vboxNetworkGetXMLDesc, /* 0.6.4 */
};
virStorageDriver NAME(StorageDriver) = { virStorageDriver NAME(StorageDriver) = {
.name = "VBOX", .name = "VBOX",
.storageOpen = vboxStorageOpen, /* 0.7.1 */ .storageOpen = vboxStorageOpen, /* 0.7.1 */

View File

@ -586,22 +586,6 @@ typedef struct {
virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn, virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
const unsigned char *uuid); const unsigned char *uuid);
virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn,
virConnectAuthPtr auth,
unsigned int flags);
int vboxNetworkClose(virConnectPtr conn);
int vboxConnectNumOfNetworks(virConnectPtr conn);
int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames);
int vboxConnectNumOfDefinedNetworks(virConnectPtr conn);
int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames);
virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid);
virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name);
virNetworkPtr vboxNetworkCreateXML(virConnectPtr conn, const char *xml);
virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml);
int vboxNetworkUndefine(virNetworkPtr network);
int vboxNetworkDestroy(virNetworkPtr network);
int vboxNetworkCreate(virNetworkPtr network);
char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags);
/* Version specified functions for installing uniformed API */ /* Version specified functions for installing uniformed API */
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);