This patch provides the new stroage driver for vbox. The work
is similar with patch 87dea4fc and the next b4022de33.
---
src/Makefile.am | 12 +++--
src/vbox/vbox_driver.c | 99 ++--------------------------------------
src/vbox/vbox_get_driver.h | 1 +
src/vbox/vbox_storage.c | 101 +++++++++++++++++++++++++++++++++--------
src/vbox/vbox_tmpl.c | 24 ----------
src/vbox/vbox_uniformed_api.h | 17 -------
6 files changed, 96 insertions(+), 158 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index b245dd1..1379478 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -520,6 +520,7 @@ DRIVER_SOURCE_FILES = \
$(UML_DRIVER_SOURCES) \
$(VBOX_DRIVER_SOURCES) \
$(VBOX_NETWORK_DRIVER_SOURCES) \
+ $(VBOX_STORAGE_DRIVER_SOURCES) \
vbox/vbox_tmpl.c \
$(VMWARE_DRIVER_SOURCES) \
$(XEN_DRIVER_SOURCES) \
@@ -679,7 +680,6 @@ 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_storage.c \
vbox/vbox_uniformed_api.h \
vbox/vbox_get_driver.h
@@ -687,6 +687,10 @@ VBOX_NETWORK_DRIVER_SOURCES = \
vbox/vbox_driver.c vbox/vbox_driver.h \
vbox/vbox_network.c vbox/vbox_get_driver.h
+VBOX_STORAGE_DRIVER_SOURCES = \
+ vbox/vbox_driver.c vbox/vbox_driver.h \
+ vbox/vbox_storage.c vbox/vbox_get_driver.h
+
VBOX_DRIVER_EXTRA_DIST = \
vbox/vbox_tmpl.c vbox/README \
vbox/vbox_MSCOMGlue.c vbox/vbox_MSCOMGlue.h \
@@ -1173,7 +1177,8 @@ noinst_LTLIBRARIES += libvirt_driver_vbox.la
# GPLv2-only license requries that it be linked into
# libvirtd and *not* libvirt.so
#libvirt_la_BUILT_LIBADD += libvirt_driver_vbox.la
-libvirt_driver_vbox_la_LIBADD += libvirt_driver_vbox_network_impl.la
+libvirt_driver_vbox_la_LIBADD += libvirt_driver_vbox_network_impl.la \
+ libvirt_driver_vbox_storage_impl.la
endif ! WITH_DRIVER_MODULES
libvirt_driver_vbox_impl_la_CFLAGS = \
@@ -1205,7 +1210,8 @@ libvirt_driver_vbox_storage_impl_la_LDFLAGS = $(AM_LDFLAGS)
libvirt_driver_vbox_storage_impl_la_LIBADD = $(DLOPEN_LIBS) \
$(MSCOM_LIBS) \
$(LIBXML_LIBS)
-libvirt_driver_vbox_storage_impl_la_SOURCES = $(VBOX_DRIVER_SOURCES)
+ libvirt_driver_vbox_impl.la
+libvirt_driver_vbox_storage_impl_la_SOURCES = $(VBOX_STORAGE_DRIVER_SOURCES)
endif WITH_VBOX
if WITH_XENAPI
diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c
index 743a488..f8d1f07 100644
--- a/src/vbox/vbox_driver.c
+++ b/src/vbox/vbox_driver.c
@@ -48,101 +48,8 @@
VIR_LOG_INIT("vbox.vbox_driver");
-extern virNetworkDriver vbox22NetworkDriver;
-extern virStorageDriver vbox22StorageDriver;
-extern virNetworkDriver vbox30NetworkDriver;
-extern virStorageDriver vbox30StorageDriver;
-extern virNetworkDriver vbox31NetworkDriver;
-extern virStorageDriver vbox31StorageDriver;
-extern virNetworkDriver vbox32NetworkDriver;
-extern virStorageDriver vbox32StorageDriver;
-extern virNetworkDriver vbox40NetworkDriver;
-extern virStorageDriver vbox40StorageDriver;
-extern virNetworkDriver vbox41NetworkDriver;
-extern virStorageDriver vbox41StorageDriver;
-extern virNetworkDriver vbox42NetworkDriver;
-extern virStorageDriver vbox42StorageDriver;
-extern virNetworkDriver vbox42_20NetworkDriver;
-extern virStorageDriver vbox42_20StorageDriver;
-extern virNetworkDriver vbox43NetworkDriver;
-extern virStorageDriver vbox43StorageDriver;
-extern virNetworkDriver vbox43_4NetworkDriver;
-extern virStorageDriver vbox43_4StorageDriver;
-
#define VIR_FROM_THIS VIR_FROM_VBOX
-#if !defined(WITH_DRIVER_MODULES) || defined(VBOX_STORAGE_DRIVER)
-static void
-vboxGetDrivers(virHypervisorDriverPtr *hypervisorDriver_ret,
- virStorageDriverPtr *storageDriver_ret)
-{
- virStorageDriverPtr storageDriver;
- uint32_t uVersion;
-
- /*
- * If the glue layer does not initialize, we register a driver
- * with a dummy open method, so we can report nicer errors
- * if the user requests a vbox:// URI which we know will
- * never work
- */
- storageDriver = &vbox22StorageDriver;
-
- /* Init the glue and get the API version. */
- if (VBoxCGlueInit(&uVersion) == 0) {
- VIR_DEBUG("VBoxCGlueInit found API version: %d.%d.%d (%u)",
- uVersion / 1000000,
- uVersion % 1000000 / 1000,
- uVersion % 1000,
- uVersion);
-
- /* Select driver implementation based on version.
- * Note that the VirtualBox development usually happens at build
- * number 51, thus the version ranges in the if statements below.
- */
- if (uVersion >= 2001052 && uVersion < 2002051) {
- VIR_DEBUG("VirtualBox API version: 2.2");
- storageDriver = &vbox22StorageDriver;
- } else if (uVersion >= 2002051 && uVersion < 3000051) {
- VIR_DEBUG("VirtualBox API version: 3.0");
- storageDriver = &vbox30StorageDriver;
- } else if (uVersion >= 3000051 && uVersion < 3001051) {
- VIR_DEBUG("VirtualBox API version: 3.1");
- storageDriver = &vbox31StorageDriver;
- } else if (uVersion >= 3001051 && uVersion < 3002051) {
- VIR_DEBUG("VirtualBox API version: 3.2");
- storageDriver = &vbox32StorageDriver;
- } else if (uVersion >= 3002051 && uVersion < 4000051) {
- VIR_DEBUG("VirtualBox API version: 4.0");
- storageDriver = &vbox40StorageDriver;
- } else if (uVersion >= 4000051 && uVersion < 4001051) {
- VIR_DEBUG("VirtualBox API version: 4.1");
- storageDriver = &vbox41StorageDriver;
- } else if (uVersion >= 4001051 && uVersion < 4002020) {
- VIR_DEBUG("VirtualBox API version: 4.2");
- storageDriver = &vbox42StorageDriver;
- } else if (uVersion >= 4002020 && uVersion < 4002051) {
- VIR_DEBUG("VirtualBox API version: 4.2.20 or higher");
- storageDriver = &vbox42_20StorageDriver;
- } else if (uVersion >= 4002051 && uVersion < 4003004) {
- VIR_DEBUG("VirtualBox API version: 4.3");
- storageDriver = &vbox43StorageDriver;
- } else if (uVersion >= 4003004 && uVersion < 4003051) {
- VIR_DEBUG("VirtualBox API version: 4.3.4 or higher");
- storageDriver = &vbox43_4StorageDriver;
- } else {
- VIR_DEBUG("Unsupported VirtualBox API version: %u", uVersion);
- }
- } else {
- VIR_DEBUG("VBoxCGlueInit failed, using dummy driver");
- }
-
- if (hypervisorDriver_ret)
- *hypervisorDriver_ret = NULL;
- if (storageDriver_ret)
- *storageDriver_ret = storageDriver;
-}
-#endif
-
#if !defined(WITH_DRIVER_MODULES) || defined(VBOX_NETWORK_DRIVER)
int vboxNetworkRegister(void)
{
@@ -161,9 +68,11 @@ int vboxNetworkRegister(void)
#if !defined(WITH_DRIVER_MODULES) || defined(VBOX_STORAGE_DRIVER)
int vboxStorageRegister(void)
{
- virStorageDriverPtr storageDriver;
+ virStorageDriverPtr storageDriver = NULL;
+ uint32_t uVersion;
- vboxGetDrivers(NULL, &storageDriver);
+ if (VBoxCGlueInit(&uVersion) == 0)
+ storageDriver = vboxGetStorageDriver(uVersion);
if (virRegisterStorageDriver(storageDriver) < 0)
return -1;
diff --git a/src/vbox/vbox_get_driver.h b/src/vbox/vbox_get_driver.h
index 025236f..84a1f8a 100644
--- a/src/vbox/vbox_get_driver.h
+++ b/src/vbox/vbox_get_driver.h
@@ -23,5 +23,6 @@
virHypervisorDriverPtr vboxGetHypervisorDriver(uint32_t uVersion);
virNetworkDriverPtr vboxGetNetworkDriver(uint32_t uVersion);
+virStorageDriverPtr vboxGetStorageDriver(uint32_t uVersion);
#endif /* VBOX_GET_DRIVER_H */
diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c
index 2211630..3610a35 100644
--- a/src/vbox/vbox_storage.c
+++ b/src/vbox/vbox_storage.c
@@ -30,6 +30,7 @@
#include "vbox_common.h"
#include "vbox_uniformed_api.h"
+#include "vbox_get_driver.h"
#define VIR_FROM_THIS VIR_FROM_VBOX
@@ -41,9 +42,10 @@ static vboxUniformedAPI gVBoxAPI;
* The Storage Functions here on
*/
-virDrvOpenStatus vboxStorageOpen(virConnectPtr conn,
- virConnectAuthPtr auth ATTRIBUTE_UNUSED,
- unsigned int flags)
+static virDrvOpenStatus
+vboxStorageOpen(virConnectPtr conn,
+ virConnectAuthPtr auth ATTRIBUTE_UNUSED,
+ unsigned int flags)
{
vboxGlobalData *data = conn->privateData;
@@ -60,14 +62,14 @@ virDrvOpenStatus vboxStorageOpen(virConnectPtr conn,
return VIR_DRV_OPEN_SUCCESS;
}
-int vboxStorageClose(virConnectPtr conn)
+static int vboxStorageClose(virConnectPtr conn)
{
VIR_DEBUG("vbox storage uninitialized");
conn->storagePrivateData = NULL;
return 0;
}
-int vboxConnectNumOfStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED)
+static int vboxConnectNumOfStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED)
{
/** Currently only one pool supported, the default one
@@ -77,8 +79,8 @@ int vboxConnectNumOfStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED)
return 1;
}
-int vboxConnectListStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED,
- char **const names, int nnames)
+static int vboxConnectListStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED,
+ char **const names, int nnames)
{
int numActive = 0;
@@ -88,7 +90,8 @@ int vboxConnectListStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED,
return numActive;
}
-virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *name)
+static virStoragePoolPtr
+vboxStoragePoolLookupByName(virConnectPtr conn, const char *name)
{
virStoragePoolPtr ret = NULL;
@@ -108,7 +111,7 @@ virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn,
const char *na
return ret;
}
-int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool)
+static int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool)
{
vboxGlobalData *data = pool->conn->privateData;
vboxArray hardDisks = VBOX_ARRAY_INITIALIZER;
@@ -149,7 +152,8 @@ int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool)
return ret;
}
-int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int nnames)
+static int
+vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int nnames)
{
vboxGlobalData *data = pool->conn->privateData;
vboxArray hardDisks = VBOX_ARRAY_INITIALIZER;
@@ -205,7 +209,8 @@ int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const
names, int n
return ret;
}
-virStorageVolPtr vboxStorageVolLookupByName(virStoragePoolPtr pool, const char *name)
+static virStorageVolPtr
+vboxStorageVolLookupByName(virStoragePoolPtr pool, const char *name)
{
vboxGlobalData *data = pool->conn->privateData;
vboxArray hardDisks = VBOX_ARRAY_INITIALIZER;
@@ -278,7 +283,8 @@ virStorageVolPtr vboxStorageVolLookupByName(virStoragePoolPtr pool,
const char *
return ret;
}
-virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char *key)
+static virStorageVolPtr
+vboxStorageVolLookupByKey(virConnectPtr conn, const char *key)
{
vboxGlobalData *data = conn->privateData;
vboxIIDUnion hddIID;
@@ -345,7 +351,8 @@ virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const
char *key)
return ret;
}
-virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const char *path)
+static virStorageVolPtr
+vboxStorageVolLookupByPath(virConnectPtr conn, const char *path)
{
vboxGlobalData *data = conn->privateData;
PRUnichar *hddPathUtf16 = NULL;
@@ -422,8 +429,9 @@ virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const
char *path
return ret;
}
-virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool,
- const char *xml, unsigned int flags)
+static virStorageVolPtr
+vboxStorageVolCreateXML(virStoragePoolPtr pool,
+ const char *xml, unsigned int flags)
{
vboxGlobalData *data = pool->conn->privateData;
virStorageVolDefPtr def = NULL;
@@ -531,7 +539,7 @@ virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool,
return ret;
}
-int vboxStorageVolDelete(virStorageVolPtr vol, unsigned int flags)
+static int vboxStorageVolDelete(virStorageVolPtr vol, unsigned int flags)
{
vboxGlobalData *data = vol->conn->privateData;
unsigned char uuid[VIR_UUID_BUFLEN];
@@ -691,7 +699,7 @@ int vboxStorageVolDelete(virStorageVolPtr vol, unsigned int flags)
return ret;
}
-int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info)
+static int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info)
{
vboxGlobalData *data = vol->conn->privateData;
IHardDisk *hardDisk = NULL;
@@ -747,7 +755,7 @@ int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr
info)
return ret;
}
-char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
+static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
{
vboxGlobalData *data = vol->conn->privateData;
IHardDisk *hardDisk = NULL;
@@ -840,7 +848,7 @@ char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int
flags)
return ret;
}
-char *vboxStorageVolGetPath(virStorageVolPtr vol)
+static char *vboxStorageVolGetPath(virStorageVolPtr vol)
{
vboxGlobalData *data = vol->conn->privateData;
IHardDisk *hardDisk = NULL;
@@ -894,3 +902,58 @@ char *vboxStorageVolGetPath(virStorageVolPtr vol)
vboxIIDUnalloc(&hddIID);
return ret;
}
+
+/**
+ * Function Tables
+ */
+
+virStorageDriver vboxStorageDriver = {
+ .name = "VBOX",
+ .storageOpen = vboxStorageOpen, /* 0.7.1 */
+ .storageClose = vboxStorageClose, /* 0.7.1 */
+ .connectNumOfStoragePools = vboxConnectNumOfStoragePools, /* 0.7.1 */
+ .connectListStoragePools = vboxConnectListStoragePools, /* 0.7.1 */
+ .storagePoolLookupByName = vboxStoragePoolLookupByName, /* 0.7.1 */
+ .storagePoolNumOfVolumes = vboxStoragePoolNumOfVolumes, /* 0.7.1 */
+ .storagePoolListVolumes = vboxStoragePoolListVolumes, /* 0.7.1 */
+
+ .storageVolLookupByName = vboxStorageVolLookupByName, /* 0.7.1 */
+ .storageVolLookupByKey = vboxStorageVolLookupByKey, /* 0.7.1 */
+ .storageVolLookupByPath = vboxStorageVolLookupByPath, /* 0.7.1 */
+ .storageVolCreateXML = vboxStorageVolCreateXML, /* 0.7.1 */
+ .storageVolDelete = vboxStorageVolDelete, /* 0.7.1 */
+ .storageVolGetInfo = vboxStorageVolGetInfo, /* 0.7.1 */
+ .storageVolGetXMLDesc = vboxStorageVolGetXMLDesc, /* 0.7.1 */
+ .storageVolGetPath = vboxStorageVolGetPath /* 0.7.1 */
+};
+
+virStorageDriverPtr vboxGetStorageDriver(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 &vboxStorageDriver;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index e74c3c4..b4d67c3 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -5129,27 +5129,3 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
pVBoxAPI->networkRemoveInterface = 1;
#endif /* VBOX_API_VERSION > 2002000 */
}
-
-/**
- * Function Tables
- */
-
-virStorageDriver NAME(StorageDriver) = {
- .name = "VBOX",
- .storageOpen = vboxStorageOpen, /* 0.7.1 */
- .storageClose = vboxStorageClose, /* 0.7.1 */
- .connectNumOfStoragePools = vboxConnectNumOfStoragePools, /* 0.7.1 */
- .connectListStoragePools = vboxConnectListStoragePools, /* 0.7.1 */
- .storagePoolLookupByName = vboxStoragePoolLookupByName, /* 0.7.1 */
- .storagePoolNumOfVolumes = vboxStoragePoolNumOfVolumes, /* 0.7.1 */
- .storagePoolListVolumes = vboxStoragePoolListVolumes, /* 0.7.1 */
-
- .storageVolLookupByName = vboxStorageVolLookupByName, /* 0.7.1 */
- .storageVolLookupByKey = vboxStorageVolLookupByKey, /* 0.7.1 */
- .storageVolLookupByPath = vboxStorageVolLookupByPath, /* 0.7.1 */
- .storageVolCreateXML = vboxStorageVolCreateXML, /* 0.7.1 */
- .storageVolDelete = vboxStorageVolDelete, /* 0.7.1 */
- .storageVolGetInfo = vboxStorageVolGetInfo, /* 0.7.1 */
- .storageVolGetXMLDesc = vboxStorageVolGetXMLDesc, /* 0.7.1 */
- .storageVolGetPath = vboxStorageVolGetPath /* 0.7.1 */
-};
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index c426f8a..babc1e6 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -608,23 +608,6 @@ typedef struct {
virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
const unsigned char *uuid);
-virDrvOpenStatus vboxStorageOpen(virConnectPtr conn, virConnectAuthPtr auth,
- unsigned int flags);
-int vboxStorageClose(virConnectPtr conn);
-int vboxConnectNumOfStoragePools(virConnectPtr conn);
-int vboxConnectListStoragePools(virConnectPtr conn, char **const names, int nnames);
-virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *name);
-int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool);
-int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int nnames);
-virStorageVolPtr vboxStorageVolLookupByName(virStoragePoolPtr pool, const char *name);
-virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char *key);
-virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const char *path);
-virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool,
- const char *xml, unsigned int flags);
-int vboxStorageVolDelete(virStorageVolPtr vol, unsigned int flags);
-int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info);
-char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags);
-char *vboxStorageVolGetPath(virStorageVolPtr vol);
/* Version specified functions for installing uniformed API */
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
--
1.7.9.5