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.
---
src/Makefile.am | 11 ++++--
src/vbox/vbox_driver.c | 9 +++--
src/vbox/vbox_get_driver.h | 1 +
src/vbox/vbox_network.c | 83 +++++++++++++++++++++++++++++++++--------
src/vbox/vbox_tmpl.c | 18 ---------
src/vbox/vbox_uniformed_api.h | 16 --------
6 files changed, 82 insertions(+), 56 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 34eb9f8..5e8cd4a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -519,6 +519,7 @@ DRIVER_SOURCE_FILES = \
$(TEST_DRIVER_SOURCES) \
$(UML_DRIVER_SOURCES) \
$(VBOX_DRIVER_SOURCES) \
+ $(VBOX_NETWORK_DRIVER_SOURCES) \
vbox/vbox_tmpl.c \
$(VMWARE_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_4.c vbox/vbox_CAPI_v4_3_4.h \
vbox/vbox_common.c vbox/vbox_common.h \
- vbox/vbox_network.c \
vbox/vbox_uniformed_api.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/vbox_tmpl.c vbox/README \
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_LIBADD = $(DLOPEN_LIBS) \
$(MSCOM_LIBS) \
- $(LIBXML_LIBS)
-libvirt_driver_vbox_network_impl_la_SOURCES = $(VBOX_DRIVER_SOURCES)
+ $(LIBXML_LIBS) \
+ libvirt_driver_vbox_impl.la
+libvirt_driver_vbox_network_impl_la_SOURCES = $(VBOX_NETWORK_DRIVER_SOURCES)
libvirt_driver_vbox_storage_impl_la_CFLAGS = \
-I$(top_srcdir)/src/conf \
diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c
index 89d49be..7d7214a 100644
--- a/src/vbox/vbox_driver.c
+++ b/src/vbox/vbox_driver.c
@@ -71,7 +71,7 @@ extern virStorageDriver vbox43_4StorageDriver;
#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
vboxGetDrivers(virDriverPtr *driver_ret,
virNetworkDriverPtr *networkDriver_ret,
@@ -161,9 +161,12 @@ vboxGetDrivers(virDriverPtr *driver_ret,
#if !defined(WITH_DRIVER_MODULES) || defined(VBOX_NETWORK_DRIVER)
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)
return -1;
return 0;
diff --git a/src/vbox/vbox_get_driver.h b/src/vbox/vbox_get_driver.h
index cfc8b93..a31f10c 100644
--- a/src/vbox/vbox_get_driver.h
+++ b/src/vbox/vbox_get_driver.h
@@ -22,5 +22,6 @@
# include "internal.h"
virDriverPtr vboxGetDriver(uint32_t uVersion);
+virNetworkDriverPtr vboxGetNetworkDriver(uint32_t uVersion);
#endif /* VBOX_GET_DRIVER_H */
diff --git a/src/vbox/vbox_network.c b/src/vbox/vbox_network.c
index b4453a6..35bf833 100644
--- a/src/vbox/vbox_network.c
+++ b/src/vbox/vbox_network.c
@@ -29,6 +29,7 @@
#include "vbox_common.h"
#include "vbox_uniformed_api.h"
+#include "vbox_get_driver.h"
#define VIR_FROM_THIS VIR_FROM_VBOX
@@ -83,9 +84,10 @@ static vboxUniformedAPI gVBoxAPI;
* The Network Functions here on
*/
-virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn,
- virConnectAuthPtr auth ATTRIBUTE_UNUSED,
- unsigned int flags)
+static virDrvOpenStatus
+vboxNetworkOpen(virConnectPtr conn,
+ virConnectAuthPtr auth ATTRIBUTE_UNUSED,
+ unsigned int flags)
{
vboxGlobalData *data = conn->privateData;
@@ -105,14 +107,14 @@ virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn,
return VIR_DRV_OPEN_DECLINED;
}
-int vboxNetworkClose(virConnectPtr conn)
+static int vboxNetworkClose(virConnectPtr conn)
{
VIR_DEBUG("network uninitialized");
conn->networkPrivateData = NULL;
return 0;
}
-int vboxConnectNumOfNetworks(virConnectPtr conn)
+static int vboxConnectNumOfNetworks(virConnectPtr conn)
{
vboxGlobalData *data = conn->privateData;
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
@@ -157,7 +159,7 @@ int vboxConnectNumOfNetworks(virConnectPtr conn)
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;
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
@@ -214,7 +216,7 @@ int vboxConnectListNetworks(virConnectPtr conn, char **const names,
int nnames)
return ret;
}
-int vboxConnectNumOfDefinedNetworks(virConnectPtr conn)
+static int vboxConnectNumOfDefinedNetworks(virConnectPtr conn)
{
vboxGlobalData *data = conn->privateData;
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
@@ -259,7 +261,7 @@ int vboxConnectNumOfDefinedNetworks(virConnectPtr conn)
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;
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
@@ -316,7 +318,7 @@ int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const
names, int n
return ret;
}
-virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
+static virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char
*uuid)
{
vboxGlobalData *data = conn->privateData;
PRUint32 interfaceType = 0;
@@ -368,7 +370,7 @@ virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const
unsigned char *u
return ret;
}
-virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name)
+static virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name)
{
vboxGlobalData *data = conn->privateData;
PRUnichar *nameUtf16 = NULL;
@@ -619,12 +621,12 @@ vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool
start)
return ret;
}
-virNetworkPtr vboxNetworkCreateXML(virConnectPtr conn, const char *xml)
+static virNetworkPtr vboxNetworkCreateXML(virConnectPtr conn, const char *xml)
{
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);
}
@@ -725,17 +727,17 @@ vboxNetworkUndefineDestroy(virNetworkPtr network, bool
removeinterface)
return ret;
}
-int vboxNetworkUndefine(virNetworkPtr network)
+static int vboxNetworkUndefine(virNetworkPtr network)
{
return vboxNetworkUndefineDestroy(network, true);
}
-int vboxNetworkDestroy(virNetworkPtr network)
+static int vboxNetworkDestroy(virNetworkPtr network)
{
return vboxNetworkUndefineDestroy(network, false);
}
-int vboxNetworkCreate(virNetworkPtr network)
+static int vboxNetworkCreate(virNetworkPtr network)
{
vboxGlobalData *data = network->conn->privateData;
char *networkNameUtf8 = NULL;
@@ -828,7 +830,7 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar
*utf16,
return result;
}
-char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags)
+static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags)
{
vboxGlobalData *data = network->conn->privateData;
virNetworkDefPtr def = NULL;
@@ -997,3 +999,52 @@ char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int
flags)
VBOX_RELEASE(dhcpServer);
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;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 9231fab..a062428 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -5894,24 +5894,6 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
* 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) = {
.name = "VBOX",
.storageOpen = vboxStorageOpen, /* 0.7.1 */
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index da754e8..b92c932 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -586,22 +586,6 @@ typedef struct {
virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
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 */
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
--
1.7.9.5