[libvirt] [PATCH 00/20] vbox: Rewrite StorageDriver

The last part of rewriting vbox driver. This series of patch is based on the patches rewriting network driver: https://www.redhat.com/archives/libvir-list/2014-August/msg00842.html Taowei (20): vbox: Rewrite vboxStorageOpen vbox: Rewrite vboxStorageClose vbox: Rewrite vboxConnectNumOfStoragePools vbox: Rewrite vboxConnectListStoragePools vbox: Rewrite vboxStoragePoolLookupByName vbox: Rewrite vboxStoragePoolNumOfVolumes vbox: Rewrite vboxStoragePoolListVolumes vbox: Rewrite vboxStorageVolLookupByName vbox: Rewrite vboxStorageVolLookupByKey vbox: Make FindMedium support old vbox versions vbox: Rewrite vboxStorageVolLookupByPath vbox: Make CreateHardDisk support all vbox versions vbox: Rewrite vboxStorageVolCreateXML vbox: Make IMediumAttachment work with vbox2.2 and 3.0 vbox: Rewrite vboxStorageVolDelete vbox: Rewrite vboxStorageVolGetInfo vbox: Rewrite vboxStorageVolGetXMLDesc vbox: Rewrite vboxStorageVolGetPath vbox: Introducing vboxCommonStorageDriver vbox: Remove unused things in vbox_tmpl.c src/vbox/vbox_common.c | 858 ++++++++++++++++++++++++++++++- src/vbox/vbox_common.h | 22 + src/vbox/vbox_driver.c | 52 +- src/vbox/vbox_tmpl.c | 1142 +++++------------------------------------ src/vbox/vbox_uniformed_api.h | 28 +- 5 files changed, 1039 insertions(+), 1063 deletions(-) -- 1.7.9.5

--- src/vbox/vbox_common.c | 25 +++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 21 --------------------- src/vbox/vbox_uniformed_api.h | 2 ++ 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 4bb01b0..15a331e 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8289,6 +8289,31 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) } /** + * The Storage Functions here on + */ + +virDrvOpenStatus vboxStorageOpen(virConnectPtr conn, + virConnectAuthPtr auth ATTRIBUTE_UNUSED, + unsigned int flags) +{ + vboxGlobalData *data = conn->privateData; + + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + + if (STRNEQ(conn->driver->name, "VBOX")) + return VIR_DRV_OPEN_DECLINED; + + if ((data->pFuncs == NULL) || + (data->vboxObj == NULL) || + (data->vboxSession == NULL)) + return VIR_DRV_OPEN_ERROR; + + VIR_DEBUG("vbox storage initialized"); + /* conn->storagePrivateData = some storage specific data */ + return VIR_DRV_OPEN_SUCCESS; +} + +/** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 67bd408..d6d4dd7 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2021,27 +2021,6 @@ _registerDomainEvent(virDriverPtr driver) * The Storage Functions here on */ -static virDrvOpenStatus vboxStorageOpen(virConnectPtr conn, - virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags) -{ - vboxGlobalData *data = conn->privateData; - - virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - - if (STRNEQ(conn->driver->name, "VBOX")) - return VIR_DRV_OPEN_DECLINED; - - if ((data->pFuncs == NULL) || - (data->vboxObj == NULL) || - (data->vboxSession == NULL)) - return VIR_DRV_OPEN_ERROR; - - VIR_DEBUG("vbox storage initialized"); - /* conn->storagePrivateData = some storage specific data */ - return VIR_DRV_OPEN_SUCCESS; -} - static int vboxStorageClose(virConnectPtr conn) { VIR_DEBUG("vbox storage uninitialized"); diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index b92c932..696a86d 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -586,6 +586,8 @@ typedef struct { virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid); +virDrvOpenStatus vboxStorageOpen(virConnectPtr conn, virConnectAuthPtr auth, + unsigned int flags); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 7 +++++++ src/vbox/vbox_tmpl.c | 7 ------- src/vbox/vbox_uniformed_api.h | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 15a331e..d144a65 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8313,6 +8313,13 @@ virDrvOpenStatus vboxStorageOpen(virConnectPtr conn, return VIR_DRV_OPEN_SUCCESS; } +int vboxStorageClose(virConnectPtr conn) +{ + VIR_DEBUG("vbox storage uninitialized"); + conn->storagePrivateData = NULL; + return 0; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index d6d4dd7..e0cd5c4 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2021,13 +2021,6 @@ _registerDomainEvent(virDriverPtr driver) * The Storage Functions here on */ -static int vboxStorageClose(virConnectPtr conn) -{ - VIR_DEBUG("vbox storage uninitialized"); - conn->storagePrivateData = NULL; - return 0; -} - static int vboxConnectNumOfStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED) { diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 696a86d..d19e65d 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -588,6 +588,7 @@ virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid); virDrvOpenStatus vboxStorageOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags); +int vboxStorageClose(virConnectPtr conn); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 10 ++++++++++ src/vbox/vbox_tmpl.c | 10 ---------- src/vbox/vbox_uniformed_api.h | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index d144a65..d9a5db6 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8320,6 +8320,16 @@ int vboxStorageClose(virConnectPtr conn) return 0; } +int vboxConnectNumOfStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + + /** Currently only one pool supported, the default one + * given by ISystemProperties::defaultHardDiskFolder() + */ + + return 1; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index e0cd5c4..c18ce4d 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2021,16 +2021,6 @@ _registerDomainEvent(virDriverPtr driver) * The Storage Functions here on */ -static int vboxConnectNumOfStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED) -{ - - /** Currently only one pool supported, the default one - * given by ISystemProperties::defaultHardDiskFolder() - */ - - return 1; -} - static int vboxConnectListStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED, char **const names, int nnames) { int numActive = 0; diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index d19e65d..1426222 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -589,6 +589,7 @@ virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn, virDrvOpenStatus vboxStorageOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags); int vboxStorageClose(virConnectPtr conn); +int vboxConnectNumOfStoragePools(virConnectPtr conn); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

Change the if condition nnames == 1 to nnames > 0. So if we put more than one slot to get active storage pools, the new function will return exactly one, while the old would return 0. --- src/vbox/vbox_common.c | 11 +++++++++++ src/vbox/vbox_tmpl.c | 10 ---------- src/vbox/vbox_uniformed_api.h | 1 + 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index d9a5db6..e245fd0 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8330,6 +8330,17 @@ int vboxConnectNumOfStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED) return 1; } +int vboxConnectListStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED, + char **const names, int nnames) +{ + int numActive = 0; + + if (nnames > 0 && + VIR_STRDUP(names[numActive], "default-pool") > 0) + numActive++; + return numActive; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index c18ce4d..37108cf 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2021,16 +2021,6 @@ _registerDomainEvent(virDriverPtr driver) * The Storage Functions here on */ -static int vboxConnectListStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED, - char **const names, int nnames) { - int numActive = 0; - - if (nnames == 1 && - VIR_STRDUP(names[numActive], "default-pool") > 0) - numActive++; - return numActive; -} - static virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *name) { diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 1426222..aa7d4af 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -590,6 +590,7 @@ 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); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 20 ++++++++++++++++++++ src/vbox/vbox_tmpl.c | 21 --------------------- src/vbox/vbox_uniformed_api.h | 1 + 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index e245fd0..6996e7a 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8341,6 +8341,26 @@ int vboxConnectListStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED, return numActive; } +virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *name) +{ + virStoragePoolPtr ret = NULL; + + /** Current limitation of the function: since + * the default pool doesn't have UUID just assign + * one till vbox can handle pools + */ + if (STREQ("default-pool", name)) { + unsigned char uuid[VIR_UUID_BUFLEN]; + const char *uuidstr = "1deff1ff-1481-464f-967f-a50fe8936cc4"; + + ignore_value(virUUIDParse(uuidstr, uuid)); + + ret = virGetStoragePool(conn, name, uuid, NULL, NULL); + } + + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 37108cf..3cca406 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2021,27 +2021,6 @@ _registerDomainEvent(virDriverPtr driver) * The Storage Functions here on */ -static virStoragePoolPtr -vboxStoragePoolLookupByName(virConnectPtr conn, const char *name) -{ - virStoragePoolPtr ret = NULL; - - /** Current limitation of the function: since - * the default pool doesn't have UUID just assign - * one till vbox can handle pools - */ - if (STREQ("default-pool", name)) { - unsigned char uuid[VIR_UUID_BUFLEN]; - const char *uuidstr = "1deff1ff-1481-464f-967f-a50fe8936cc4"; - - ignore_value(virUUIDParse(uuidstr, uuid)); - - ret = virGetStoragePool(conn, name, uuid, NULL, NULL); - } - - return ret; -} - static int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool) { VBOX_OBJECT_CHECK(pool->conn, int, -1); diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index aa7d4af..cffb7f7 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -591,6 +591,7 @@ virDrvOpenStatus vboxStorageOpen(virConnectPtr conn, virConnectAuthPtr auth, int vboxStorageClose(virConnectPtr conn); int vboxConnectNumOfStoragePools(virConnectPtr conn); int vboxConnectListStoragePools(virConnectPtr conn, char **const names, int nnames); +virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *name); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

We use typedef IMedium IHardDisk to make IHardDisk hierachy from IMedium (Actually it did on vbox 2.2 and 3.0's C++ API). So when calling VBOX_MEDIUM_FUNC_ARG*(IHardDisk, func, args) we can directly replace it to gVBoxAPI.UIMedium.func(IHardDisk, args) The vbox CAPI is generate from vbox's C++ version. In which the IHardDisk is hierachy from IMedium in vbox2.2 and 3.0 and since 3.1 IHardDisk is merged into IMedium. Here we assume IHardDisk always hierachy from IMedium. When dealing with this two types, we get some rules from it's hierachy relationship. When using IHardDisk and IMedium as input, we can't transfer a IMedium to IHardDisk. Like: gVBoxAPI.UIHardDisk.func(IHardDisk *hardDisk, args) Here, we can't put a *IMedium as a argument. When using IHardDisk and IMedium as output, we can't transfer a IHardDisk to IMedium. Like: gVBoxAPI.UIMachine.GetMedium(IMedium **out) Here, we can't put a **IHardDisk as a argument. If this case do happen, we either change the API to GetHardDisk or write a new one. --- src/vbox/vbox_common.c | 36 ++++++++++++++++++++++++++++++++ src/vbox/vbox_common.h | 12 +++++++++++ src/vbox/vbox_tmpl.c | 46 +++++++++++------------------------------ src/vbox/vbox_uniformed_api.h | 3 +++ 4 files changed, 63 insertions(+), 34 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 6996e7a..4ca0a10 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8361,6 +8361,42 @@ virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *na return ret; } +int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool) +{ + VBOX_OBJECT_CHECK(pool->conn, int, -1); + vboxArray hardDisks = VBOX_ARRAY_INITIALIZER; + PRUint32 hardDiskAccessible = 0; + nsresult rc; + size_t i; + + rc = gVBoxAPI.UArray.vboxArrayGet(&hardDisks, data->vboxObj, + gVBoxAPI.UArray.handleGetHardDisks(data->vboxObj)); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("could not get number of volumes in the pool: %s, rc=%08x"), + pool->name, (unsigned)rc); + return ret; + } + + for (i = 0; i < hardDisks.count; ++i) { + IHardDisk *hardDisk = hardDisks.items[i]; + PRUint32 hddstate; + + if (!hardDisk) + continue; + + gVBoxAPI.UIMedium.GetState(hardDisk, &hddstate); + if (hddstate != MediaState_Inaccessible) + hardDiskAccessible++; + } + + gVBoxAPI.UArray.vboxArrayRelease(&hardDisks); + + ret = hardDiskAccessible; + + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h index 76288d4..71592c9 100644 --- a/src/vbox/vbox_common.h +++ b/src/vbox/vbox_common.h @@ -278,6 +278,17 @@ enum HostNetworkInterfaceType HostNetworkInterfaceType_HostOnly = 2 }; +enum MediaState +{ + MediaState_NotCreated = 0, + MediaState_Created = 1, + MediaState_LockedRead = 2, + MediaState_LockedWrite = 3, + MediaState_Inaccessible = 4, + MediaState_Creating = 5, + MediaState_Deleting = 6 +}; + # define VBOX_E_OBJECT_NOT_FOUND 0x80BB0001 # define VBOX_E_INVALID_VM_STATE 0x80BB0002 # define VBOX_E_VM_ERROR 0x80BB0003 @@ -318,5 +329,6 @@ typedef nsISupports IDisplay; typedef nsISupports IHost; typedef nsISupports IHostNetworkInterface; typedef nsISupports IDHCPServer; +typedef IMedium IHardDisk; #endif /* VBOX_COMMON_H */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 3cca406..75eb73d 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2021,40 +2021,6 @@ _registerDomainEvent(virDriverPtr driver) * The Storage Functions here on */ -static int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool) -{ - VBOX_OBJECT_CHECK(pool->conn, int, -1); - vboxArray hardDisks = VBOX_ARRAY_INITIALIZER; - PRUint32 hardDiskAccessible = 0; - nsresult rc; - size_t i; - - rc = vboxArrayGet(&hardDisks, data->vboxObj, data->vboxObj->vtbl->GetHardDisks); - if (NS_SUCCEEDED(rc)) { - for (i = 0; i < hardDisks.count; ++i) { - IHardDisk *hardDisk = hardDisks.items[i]; - if (hardDisk) { - PRUint32 hddstate; - - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetState, &hddstate); - if (hddstate != MediaState_Inaccessible) - hardDiskAccessible++; - } - } - - vboxArrayRelease(&hardDisks); - - ret = hardDiskAccessible; - } else { - ret = -1; - virReportError(VIR_ERR_INTERNAL_ERROR, - _("could not get number of volumes in the pool: %s, rc=%08x"), - pool->name, (unsigned)rc); - } - - return ret; -} - static int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int nnames) { VBOX_OBJECT_CHECK(pool->conn, int, -1); vboxArray hardDisks = VBOX_ARRAY_INITIALIZER; @@ -3566,6 +3532,11 @@ static void* _handleGetMachines(IVirtualBox *vboxObj) return vboxObj->vtbl->GetMachines; } +static void* _handleGetHardDisks(IVirtualBox *vboxObj) +{ + return vboxObj->vtbl->GetHardDisks; +} + static void* _handleUSBGetDeviceFilters(IUSBCommon *USBCommon) { return USBCommon->vtbl->GetDeviceFilters; @@ -4915,6 +4886,11 @@ static nsresult _mediumGetLocation(IMedium *medium, PRUnichar **location) return medium->vtbl->GetLocation(medium, location); } +static nsresult _mediumGetState(IMedium *medium, PRUint32 *state) +{ + return medium->vtbl->GetState(medium, state); +} + static nsresult _mediumGetReadOnly(IMedium *medium ATTRIBUTE_UNUSED, PRBool *readOnly ATTRIBUTE_UNUSED) { @@ -5432,6 +5408,7 @@ static vboxUniformedArray _UArray = { .vboxArrayGetWithIIDArg = _vboxArrayGetWithIIDArg, .vboxArrayRelease = vboxArrayRelease, .handleGetMachines = _handleGetMachines, + .handleGetHardDisks = _handleGetHardDisks, .handleUSBGetDeviceFilters = _handleUSBGetDeviceFilters, .handleMachineGetMediumAttachments = _handleMachineGetMediumAttachments, .handleMachineGetSharedFolders = _handleMachineGetSharedFolders, @@ -5634,6 +5611,7 @@ static vboxUniformedIUSBDeviceFilter _UIUSBDeviceFilter = { static vboxUniformedIMedium _UIMedium = { .GetId = _mediumGetId, .GetLocation = _mediumGetLocation, + .GetState = _mediumGetState, .GetReadOnly = _mediumGetReadOnly, .GetParent = _mediumGetParent, .GetChildren = _mediumGetChildren, diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index cffb7f7..9709934 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -170,6 +170,7 @@ typedef struct { void (*vboxArrayRelease)(vboxArray *array); /* Generate function pointers for vboxArrayGet */ void* (*handleGetMachines)(IVirtualBox *vboxObj); + void* (*handleGetHardDisks)(IVirtualBox *vboxObj); void* (*handleUSBGetDeviceFilters)(IUSBCommon *USBCommon); void* (*handleMachineGetMediumAttachments)(IMachine *machine); void* (*handleMachineGetSharedFolders)(IMachine *machine); @@ -407,6 +408,7 @@ typedef struct { typedef struct { nsresult (*GetId)(IMedium *medium, vboxIIDUnion *iidu); nsresult (*GetLocation)(IMedium *medium, PRUnichar **location); + nsresult (*GetState)(IMedium *medium, PRUint32 *state); nsresult (*GetReadOnly)(IMedium *medium, PRBool *readOnly); nsresult (*GetParent)(IMedium *medium, IMedium **parent); nsresult (*GetChildren)(IMedium *medium, PRUint32 *childrenSize, IMedium ***children); @@ -592,6 +594,7 @@ 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); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 51 ++++++++++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 54 +++++------------------------------------ src/vbox/vbox_uniformed_api.h | 2 ++ 3 files changed, 59 insertions(+), 48 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 4ca0a10..85c4dd0 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8397,6 +8397,57 @@ int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool) return ret; } +int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int nnames) +{ + VBOX_OBJECT_CHECK(pool->conn, int, -1); + vboxArray hardDisks = VBOX_ARRAY_INITIALIZER; + PRUint32 numActive = 0; + nsresult rc; + size_t i; + + rc = gVBoxAPI.UArray.vboxArrayGet(&hardDisks, data->vboxObj, + gVBoxAPI.UArray.handleGetHardDisks(data->vboxObj)); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("could not get the volume list in the pool: %s, rc=%08x"), + pool->name, (unsigned)rc); + return ret; + } + + for (i = 0; i < hardDisks.count && numActive < nnames; ++i) { + IHardDisk *hardDisk = hardDisks.items[i]; + PRUint32 hddstate; + char *nameUtf8 = NULL; + PRUnichar *nameUtf16 = NULL; + + if (!hardDisk) + continue; + + gVBoxAPI.UIMedium.GetState(hardDisk, &hddstate); + if (hddstate == MediaState_Inaccessible) + continue; + + gVBoxAPI.UIMedium.GetName(hardDisk, &nameUtf16); + + VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8); + VBOX_UTF16_FREE(nameUtf16); + + if (!nameUtf8) + continue; + + VIR_DEBUG("nnames[%d]: %s", numActive, nameUtf8); + if (VIR_STRDUP(names[numActive], nameUtf8) > 0) + numActive++; + + VBOX_UTF8_FREE(nameUtf8); + } + + gVBoxAPI.UArray.vboxArrayRelease(&hardDisks); + ret = numActive; + + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 75eb73d..eac0e9c 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2021,54 +2021,6 @@ _registerDomainEvent(virDriverPtr driver) * The Storage Functions here on */ -static int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int nnames) { - VBOX_OBJECT_CHECK(pool->conn, int, -1); - vboxArray hardDisks = VBOX_ARRAY_INITIALIZER; - PRUint32 numActive = 0; - nsresult rc; - size_t i; - - rc = vboxArrayGet(&hardDisks, data->vboxObj, data->vboxObj->vtbl->GetHardDisks); - if (NS_SUCCEEDED(rc)) { - for (i = 0; i < hardDisks.count && numActive < nnames; ++i) { - IHardDisk *hardDisk = hardDisks.items[i]; - - if (hardDisk) { - PRUint32 hddstate; - char *nameUtf8 = NULL; - PRUnichar *nameUtf16 = NULL; - - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetState, &hddstate); - if (hddstate != MediaState_Inaccessible) { - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetName, &nameUtf16); - - VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8); - VBOX_UTF16_FREE(nameUtf16); - - if (nameUtf8) { - VIR_DEBUG("nnames[%d]: %s", numActive, nameUtf8); - if (VIR_STRDUP(names[numActive], nameUtf8) > 0) - numActive++; - - VBOX_UTF8_FREE(nameUtf8); - } - } - } - } - - vboxArrayRelease(&hardDisks); - - ret = numActive; - } else { - ret = -1; - virReportError(VIR_ERR_INTERNAL_ERROR, - _("could not get the volume list in the pool: %s, rc=%08x"), - pool->name, (unsigned)rc); - } - - return ret; -} - static virStorageVolPtr vboxStorageVolLookupByName(virStoragePoolPtr pool, const char *name) { @@ -4891,6 +4843,11 @@ static nsresult _mediumGetState(IMedium *medium, PRUint32 *state) return medium->vtbl->GetState(medium, state); } +static nsresult _mediumGetName(IMedium *medium, PRUnichar **name) +{ + return medium->vtbl->GetName(medium, name); +} + static nsresult _mediumGetReadOnly(IMedium *medium ATTRIBUTE_UNUSED, PRBool *readOnly ATTRIBUTE_UNUSED) { @@ -5612,6 +5569,7 @@ static vboxUniformedIMedium _UIMedium = { .GetId = _mediumGetId, .GetLocation = _mediumGetLocation, .GetState = _mediumGetState, + .GetName = _mediumGetName, .GetReadOnly = _mediumGetReadOnly, .GetParent = _mediumGetParent, .GetChildren = _mediumGetChildren, diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 9709934..ed72447 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -409,6 +409,7 @@ typedef struct { nsresult (*GetId)(IMedium *medium, vboxIIDUnion *iidu); nsresult (*GetLocation)(IMedium *medium, PRUnichar **location); nsresult (*GetState)(IMedium *medium, PRUint32 *state); + nsresult (*GetName)(IMedium *medium, PRUnichar **name); nsresult (*GetReadOnly)(IMedium *medium, PRBool *readOnly); nsresult (*GetParent)(IMedium *medium, IMedium **parent); nsresult (*GetChildren)(IMedium *medium, PRUint32 *childrenSize, IMedium ***children); @@ -595,6 +596,7 @@ 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); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 68 +++++++++++++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 65 --------------------------------------- src/vbox/vbox_uniformed_api.h | 2 ++ 3 files changed, 70 insertions(+), 65 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 85c4dd0..88ace96 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8448,6 +8448,74 @@ int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int n return ret; } +virStorageVolPtr vboxStorageVolLookupByName(virStoragePoolPtr pool, const char *name) +{ + VBOX_OBJECT_CHECK(pool->conn, virStorageVolPtr, NULL); + vboxArray hardDisks = VBOX_ARRAY_INITIALIZER; + nsresult rc; + size_t i; + + if (!name) + return ret; + + rc = gVBoxAPI.UArray.vboxArrayGet(&hardDisks, data->vboxObj, + gVBoxAPI.UArray.handleGetHardDisks(data->vboxObj)); + if (NS_FAILED(rc)) + return ret; + + for (i = 0; i < hardDisks.count; ++i) { + IHardDisk *hardDisk = hardDisks.items[i]; + PRUint32 hddstate; + char *nameUtf8 = NULL; + PRUnichar *nameUtf16 = NULL; + + if (!hardDisk) + continue; + + gVBoxAPI.UIMedium.GetState(hardDisk, &hddstate); + if (hddstate == MediaState_Inaccessible) + continue; + + gVBoxAPI.UIMedium.GetName(hardDisk, &nameUtf16); + + if (nameUtf16) { + VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8); + VBOX_UTF16_FREE(nameUtf16); + } + + if (nameUtf8 && STREQ(nameUtf8, name)) { + vboxIIDUnion hddIID; + unsigned char uuid[VIR_UUID_BUFLEN]; + char key[VIR_UUID_STRING_BUFLEN] = ""; + + VBOX_IID_INITIALIZE(&hddIID); + rc = gVBoxAPI.UIMedium.GetId(hardDisk, &hddIID); + if (NS_SUCCEEDED(rc)) { + vboxIIDToUUID(&hddIID, uuid); + virUUIDFormat(uuid, key); + + ret = virGetStorageVol(pool->conn, pool->name, name, key, + NULL, NULL); + + VIR_DEBUG("virStorageVolPtr: %p", ret); + VIR_DEBUG("Storage Volume Name: %s", name); + VIR_DEBUG("Storage Volume key : %s", key); + VIR_DEBUG("Storage Volume Pool: %s", pool->name); + } + + vboxIIDUnalloc(&hddIID); + VBOX_UTF8_FREE(nameUtf8); + break; + } + + VBOX_UTF8_FREE(nameUtf8); + } + + gVBoxAPI.UArray.vboxArrayRelease(&hardDisks); + + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index eac0e9c..a6278e2 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2022,71 +2022,6 @@ _registerDomainEvent(virDriverPtr driver) */ static virStorageVolPtr -vboxStorageVolLookupByName(virStoragePoolPtr pool, const char *name) -{ - VBOX_OBJECT_CHECK(pool->conn, virStorageVolPtr, NULL); - vboxArray hardDisks = VBOX_ARRAY_INITIALIZER; - nsresult rc; - size_t i; - - if (!name) - return ret; - - rc = vboxArrayGet(&hardDisks, data->vboxObj, data->vboxObj->vtbl->GetHardDisks); - if (NS_SUCCEEDED(rc)) { - for (i = 0; i < hardDisks.count; ++i) { - IHardDisk *hardDisk = hardDisks.items[i]; - - if (hardDisk) { - PRUint32 hddstate; - char *nameUtf8 = NULL; - PRUnichar *nameUtf16 = NULL; - - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetState, &hddstate); - if (hddstate != MediaState_Inaccessible) { - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetName, &nameUtf16); - - if (nameUtf16) { - VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8); - VBOX_UTF16_FREE(nameUtf16); - } - - if (nameUtf8 && STREQ(nameUtf8, name)) { - vboxIID hddIID = VBOX_IID_INITIALIZER; - unsigned char uuid[VIR_UUID_BUFLEN]; - char key[VIR_UUID_STRING_BUFLEN] = ""; - - rc = VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetId, &hddIID.value); - if (NS_SUCCEEDED(rc)) { - vboxIIDToUUID(&hddIID, uuid); - virUUIDFormat(uuid, key); - - ret = virGetStorageVol(pool->conn, pool->name, name, key, - NULL, NULL); - - VIR_DEBUG("virStorageVolPtr: %p", ret); - VIR_DEBUG("Storage Volume Name: %s", name); - VIR_DEBUG("Storage Volume key : %s", key); - VIR_DEBUG("Storage Volume Pool: %s", pool->name); - } - - vboxIIDUnalloc(&hddIID); - VBOX_UTF8_FREE(nameUtf8); - break; - } - - VBOX_UTF8_FREE(nameUtf8); - } - } - } - - vboxArrayRelease(&hardDisks); - } - - return ret; -} - -static virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char *key) { VBOX_OBJECT_CHECK(conn, virStorageVolPtr, NULL); diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index ed72447..595a544 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -597,6 +597,8 @@ int vboxConnectListStoragePools(virConnectPtr conn, char **const names, int nnam 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); + /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 62 +++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 88 +++++++++-------------------------------- src/vbox/vbox_uniformed_api.h | 3 +- 3 files changed, 83 insertions(+), 70 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 88ace96..befd192 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8516,6 +8516,68 @@ virStorageVolPtr vboxStorageVolLookupByName(virStoragePoolPtr pool, const char * return ret; } +virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char *key) +{ + VBOX_OBJECT_CHECK(conn, virStorageVolPtr, NULL); + vboxIIDUnion hddIID; + unsigned char uuid[VIR_UUID_BUFLEN]; + IHardDisk *hardDisk = NULL; + PRUnichar *hddNameUtf16 = NULL; + char *hddNameUtf8 = NULL; + PRUint32 hddstate; + nsresult rc; + + VBOX_IID_INITIALIZE(&hddIID); + if (!key) + return ret; + + if (virUUIDParse(key, uuid) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("Could not parse UUID from '%s'"), key); + return NULL; + } + + vboxIIDFromUUID(&hddIID, uuid); + rc = gVBoxAPI.UIVirtualBox.GetHardDiskByIID(data->vboxObj, &hddIID, &hardDisk); + if (NS_FAILED(rc)) + goto cleanup; + + gVBoxAPI.UIMedium.GetState(hardDisk, &hddstate); + if (hddstate == MediaState_Inaccessible) + goto cleanup; + + gVBoxAPI.UIMedium.GetName(hardDisk, &hddNameUtf16); + if (!hddNameUtf16) + goto cleanup; + + VBOX_UTF16_TO_UTF8(hddNameUtf16, &hddNameUtf8); + if (!hddNameUtf8) { + VBOX_UTF16_FREE(hddNameUtf16); + goto cleanup; + } + + if (vboxConnectNumOfStoragePools(conn) == 1) { + ret = virGetStorageVol(conn, "default-pool", hddNameUtf8, key, + NULL, NULL); + VIR_DEBUG("Storage Volume Pool: %s", "default-pool"); + } else { + /* TODO: currently only one default pool and thus + * nothing here, change it when pools are supported + */ + } + + VIR_DEBUG("Storage Volume Name: %s", key); + VIR_DEBUG("Storage Volume key : %s", hddNameUtf8); + + VBOX_UTF8_FREE(hddNameUtf8); + VBOX_UTF16_FREE(hddNameUtf16); + + cleanup: + VBOX_MEDIUM_RELEASE(hardDisk); + vboxIIDUnalloc(&hddIID); + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index a6278e2..e239517 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -104,7 +104,10 @@ typedef IUSBDeviceFilters IUSBCommon; #if VBOX_API_VERSION < 3001000 typedef IHardDiskAttachment IMediumAttachment; -#endif /* VBOX_API_VERSION < 3001000 */ +#else /* VBOX_API_VERSION >= 3001000 */ +typedef IMedium IHardDisk; +typedef IMediumAttachment IHardDiskAttachment; +#endif /* VBOX_API_VERSION >= 3001000 */ #include "vbox_uniformed_api.h" @@ -183,8 +186,6 @@ if (arg)\ #else /* VBOX_API_VERSION >= 3001000 */ -typedef IMedium IHardDisk; -typedef IMediumAttachment IHardDiskAttachment; # define MediaState_Inaccessible MediumState_Inaccessible # define HardDiskVariant_Standard MediumVariant_Standard # define HardDiskVariant_Fixed MediumVariant_Fixed @@ -2022,72 +2023,6 @@ _registerDomainEvent(virDriverPtr driver) */ static virStorageVolPtr -vboxStorageVolLookupByKey(virConnectPtr conn, const char *key) -{ - VBOX_OBJECT_CHECK(conn, virStorageVolPtr, NULL); - vboxIID hddIID = VBOX_IID_INITIALIZER; - unsigned char uuid[VIR_UUID_BUFLEN]; - IHardDisk *hardDisk = NULL; - nsresult rc; - - if (!key) - return ret; - - if (virUUIDParse(key, uuid) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("Could not parse UUID from '%s'"), key); - return NULL; - } - - vboxIIDFromUUID(&hddIID, uuid); -#if VBOX_API_VERSION < 4000000 - rc = data->vboxObj->vtbl->GetHardDisk(data->vboxObj, hddIID.value, &hardDisk); -#elif VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000 - rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddIID.value, - DeviceType_HardDisk, &hardDisk); -#else - rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddIID.value, - DeviceType_HardDisk, AccessMode_ReadWrite, - PR_FALSE, &hardDisk); -#endif /* VBOX_API_VERSION >= 4000000 */ - if (NS_SUCCEEDED(rc)) { - PRUint32 hddstate; - - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetState, &hddstate); - if (hddstate != MediaState_Inaccessible) { - PRUnichar *hddNameUtf16 = NULL; - char *hddNameUtf8 = NULL; - - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetName, &hddNameUtf16); - VBOX_UTF16_TO_UTF8(hddNameUtf16, &hddNameUtf8); - - if (hddNameUtf8) { - if (vboxConnectNumOfStoragePools(conn) == 1) { - ret = virGetStorageVol(conn, "default-pool", hddNameUtf8, key, - NULL, NULL); - VIR_DEBUG("Storage Volume Pool: %s", "default-pool"); - } else { - /* TODO: currently only one default pool and thus - * nothing here, change it when pools are supported - */ - } - - VIR_DEBUG("Storage Volume Name: %s", key); - VIR_DEBUG("Storage Volume key : %s", hddNameUtf8); - - VBOX_UTF8_FREE(hddNameUtf8); - VBOX_UTF16_FREE(hddNameUtf16); - } - } - - VBOX_MEDIUM_RELEASE(hardDisk); - } - - vboxIIDUnalloc(&hddIID); - return ret; -} - -static virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const char *path) { VBOX_OBJECT_CHECK(conn, virStorageVolPtr, NULL); @@ -3648,6 +3583,20 @@ _virtualboxOpenMedium(IVirtualBox *vboxObj ATTRIBUTE_UNUSED, } static nsresult +_virtualboxGetHardDiskByIID(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IHardDisk **hardDisk) +{ +#if VBOX_API_VERSION < 4000000 + return vboxObj->vtbl->GetHardDisk(vboxObj, IID_MEMBER(value), hardDisk); +#elif VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000 + return vboxObj->vtbl->FindMedium(vboxObj, IID_MEMBER(value), DeviceType_HardDisk, + hardDisk); +#else /* VBOX_API_VERSION >= 4002000 */ + return vboxObj->vtbl->OpenMedium(vboxObj, IID_MEMBER(value), DeviceType_HardDisk, + AccessMode_ReadWrite, PR_FALSE, hardDisk); +#endif /* VBOX_API_VERSION >= 4002000 */ +} + +static nsresult _virtualboxFindDHCPServerByNetworkName(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server) { return vboxObj->vtbl->FindDHCPServerByNetworkName(vboxObj, name, server); @@ -5326,6 +5275,7 @@ static vboxUniformedIVirtualBox _UIVirtualBox = { .RegisterMachine = _virtualboxRegisterMachine, .FindMedium = _virtualboxFindMedium, .OpenMedium = _virtualboxOpenMedium, + .GetHardDiskByIID = _virtualboxGetHardDiskByIID, .FindDHCPServerByNetworkName = _virtualboxFindDHCPServerByNetworkName, .CreateDHCPServer = _virtualboxCreateDHCPServer, .RemoveDHCPServer = _virtualboxRemoveDHCPServer, diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 595a544..a275d6a 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -198,6 +198,7 @@ typedef struct { nsresult (*RegisterMachine)(IVirtualBox *vboxObj, IMachine *machine); nsresult (*FindMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium); nsresult (*OpenMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium); + nsresult (*GetHardDiskByIID)(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IHardDisk **hardDisk); nsresult (*FindDHCPServerByNetworkName)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server); nsresult (*CreateDHCPServer)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server); nsresult (*RemoveDHCPServer)(IVirtualBox *vboxObj, IDHCPServer *server); @@ -598,7 +599,7 @@ virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *na 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); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

In old version, function FindMedium in UIVirtualBox doesn't work for vbox2.2 and 3.0. We assume it will not be used when vbox in these versions. But when rewriting vboxStorageVolLookupByPath, we found it was compatibe to use FindMedium to get a IHardDisk object, even in vbox old versions. To achieve this, first make FindMedium call FindHardDisk when VBOX_API_VERSION < 4000000. Then change the argument type **IMedium to **IHardDisk. (As the rules in heriachy, we can't transfer a IHardDisk to match IMedium in output) In vbox 2.2 and 3.0, the caller must be aware that they will get a IHardDisk object in return. --- src/vbox/vbox_common.c | 4 ++-- src/vbox/vbox_tmpl.c | 29 +++++++++++++++-------------- src/vbox/vbox_uniformed_api.h | 3 ++- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index befd192..a5dcf83 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -1138,8 +1138,8 @@ vboxAttachDrivesNew(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine continue; } - gVBoxAPI.UIVirtualBox.FindMedium(data->vboxObj, mediumFileUtf16, - deviceType, accessMode, &medium); + gVBoxAPI.UIVirtualBox.FindHardDisk(data->vboxObj, mediumFileUtf16, + deviceType, accessMode, &medium); if (!medium) { PRUnichar *mediumEmpty = NULL; diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index e239517..7c04ba8 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -3540,22 +3540,23 @@ _virtualboxRegisterMachine(IVirtualBox *vboxObj, IMachine *machine) } static nsresult -_virtualboxFindMedium(IVirtualBox *vboxObj ATTRIBUTE_UNUSED, - PRUnichar *location ATTRIBUTE_UNUSED, - PRUint32 deviceType ATTRIBUTE_UNUSED, - PRUint32 accessMode ATTRIBUTE_UNUSED, - IMedium **medium ATTRIBUTE_UNUSED) +_virtualboxFindHardDisk(IVirtualBox *vboxObj, PRUnichar *location, + PRUint32 deviceType ATTRIBUTE_UNUSED, + PRUint32 accessMode ATTRIBUTE_UNUSED, + IHardDisk **hardDisk) { -#if VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000 + /* In vbox 2.2 and 3.0, this function will create a IHardDisk object. + * In vbox 3.1 and later, this function will create a IMedium object. + */ +#if VBOX_API_VERSION < 4000000 + return vboxObj->vtbl->FindHardDisk(vboxObj, location, hardDisk); +#elif VBOX_API_VERSION < 4002000 return vboxObj->vtbl->FindMedium(vboxObj, location, - deviceType, medium); -#elif VBOX_API_VERSION >= 4002000 + deviceType, hardDisk); +#else /* VBOX_API_VERSION >= 4002000 */ return vboxObj->vtbl->OpenMedium(vboxObj, location, - deviceType, accessMode, PR_FALSE, medium); -#else - vboxUnsupported(); - return 0; -#endif + deviceType, accessMode, PR_FALSE, hardDisk); +#endif /* VBOX_API_VERSION >= 4002000 */ } static nsresult @@ -5273,7 +5274,7 @@ static vboxUniformedIVirtualBox _UIVirtualBox = { .CreateMachine = _virtualboxCreateMachine, .CreateHardDiskMedium = _virtualboxCreateHardDiskMedium, .RegisterMachine = _virtualboxRegisterMachine, - .FindMedium = _virtualboxFindMedium, + .FindHardDisk = _virtualboxFindHardDisk, .OpenMedium = _virtualboxOpenMedium, .GetHardDiskByIID = _virtualboxGetHardDiskByIID, .FindDHCPServerByNetworkName = _virtualboxFindDHCPServerByNetworkName, diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index a275d6a..2a9c3b2 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -196,7 +196,8 @@ typedef struct { nsresult (*CreateMachine)(vboxGlobalData *data, virDomainDefPtr def, IMachine **machine, char *uuidstr); nsresult (*CreateHardDiskMedium)(IVirtualBox *vboxObj, PRUnichar *format, PRUnichar *location, IMedium **medium); nsresult (*RegisterMachine)(IVirtualBox *vboxObj, IMachine *machine); - nsresult (*FindMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium); + nsresult (*FindHardDisk)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, + PRUint32 accessMode, IHardDisk **hardDisk); nsresult (*OpenMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium); nsresult (*GetHardDiskByIID)(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IHardDisk **hardDisk); nsresult (*FindDHCPServerByNetworkName)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server); -- 1.7.9.5

--- src/vbox/vbox_common.c | 72 ++++++++++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 77 ----------------------------------------- src/vbox/vbox_uniformed_api.h | 1 + 3 files changed, 73 insertions(+), 77 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index a5dcf83..cfc73d8 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8578,6 +8578,78 @@ virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char *key) return ret; } +virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const char *path) +{ + VBOX_OBJECT_CHECK(conn, virStorageVolPtr, NULL); + PRUnichar *hddPathUtf16 = NULL; + IHardDisk *hardDisk = NULL; + PRUnichar *hddNameUtf16 = NULL; + char *hddNameUtf8 = NULL; + unsigned char uuid[VIR_UUID_BUFLEN]; + char key[VIR_UUID_STRING_BUFLEN] = ""; + vboxIIDUnion hddIID; + PRUint32 hddstate; + nsresult rc; + + VBOX_IID_INITIALIZE(&hddIID); + + if (!path) + return ret; + + VBOX_UTF8_TO_UTF16(path, &hddPathUtf16); + + if (!hddPathUtf16) + return ret; + + rc = gVBoxAPI.UIVirtualBox.FindHardDisk(data->vboxObj, hddPathUtf16, + DeviceType_HardDisk, AccessMode_ReadWrite, &hardDisk); + if (NS_FAILED(rc)) + goto cleanup; + + gVBoxAPI.UIMedium.GetState(hardDisk, &hddstate); + if (hddstate == MediaState_Inaccessible) + goto cleanup; + + gVBoxAPI.UIMedium.GetName(hardDisk, &hddNameUtf16); + + if (!hddNameUtf16) + goto cleanup; + + VBOX_UTF16_TO_UTF8(hddNameUtf16, &hddNameUtf8); + VBOX_UTF16_FREE(hddNameUtf16); + + if (!hddNameUtf8) + goto cleanup; + + rc = gVBoxAPI.UIMedium.GetId(hardDisk, &hddIID); + if (NS_FAILED(rc)) { + VBOX_UTF8_FREE(hddNameUtf8); + goto cleanup; + } + + vboxIIDToUUID(&hddIID, uuid); + virUUIDFormat(uuid, key); + + /* TODO: currently only one default pool and thus + * the check below, change it when pools are supported + */ + if (vboxConnectNumOfStoragePools(conn) == 1) + ret = virGetStorageVol(conn, "default-pool", hddNameUtf8, key, + NULL, NULL); + + VIR_DEBUG("Storage Volume Pool: %s", "default-pool"); + VIR_DEBUG("Storage Volume Name: %s", hddNameUtf8); + VIR_DEBUG("Storage Volume key : %s", key); + + vboxIIDUnalloc(&hddIID); + VBOX_UTF8_FREE(hddNameUtf8); + + cleanup: + VBOX_MEDIUM_RELEASE(hardDisk); + VBOX_UTF16_FREE(hddPathUtf16); + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 7c04ba8..03d194b 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2022,83 +2022,6 @@ _registerDomainEvent(virDriverPtr driver) * The Storage Functions here on */ -static virStorageVolPtr -vboxStorageVolLookupByPath(virConnectPtr conn, const char *path) -{ - VBOX_OBJECT_CHECK(conn, virStorageVolPtr, NULL); - PRUnichar *hddPathUtf16 = NULL; - IHardDisk *hardDisk = NULL; - nsresult rc; - - if (!path) - return ret; - - VBOX_UTF8_TO_UTF16(path, &hddPathUtf16); - - if (!hddPathUtf16) - return ret; - -#if VBOX_API_VERSION < 4000000 - rc = data->vboxObj->vtbl->FindHardDisk(data->vboxObj, hddPathUtf16, &hardDisk); -#elif VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000 - rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddPathUtf16, - DeviceType_HardDisk, &hardDisk); -#else - rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddPathUtf16, - DeviceType_HardDisk, AccessMode_ReadWrite, - PR_FALSE, &hardDisk); -#endif /* VBOX_API_VERSION >= 4000000 */ - if (NS_SUCCEEDED(rc)) { - PRUint32 hddstate; - - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetState, &hddstate); - if (hddstate != MediaState_Inaccessible) { - PRUnichar *hddNameUtf16 = NULL; - char *hddNameUtf8 = NULL; - - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetName, &hddNameUtf16); - - if (hddNameUtf16) { - VBOX_UTF16_TO_UTF8(hddNameUtf16, &hddNameUtf8); - VBOX_UTF16_FREE(hddNameUtf16); - } - - if (hddNameUtf8) { - vboxIID hddIID = VBOX_IID_INITIALIZER; - unsigned char uuid[VIR_UUID_BUFLEN]; - char key[VIR_UUID_STRING_BUFLEN] = ""; - - rc = VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetId, &hddIID.value); - if (NS_SUCCEEDED(rc)) { - vboxIIDToUUID(&hddIID, uuid); - virUUIDFormat(uuid, key); - - /* TODO: currently only one default pool and thus - * the check below, change it when pools are supported - */ - if (vboxConnectNumOfStoragePools(conn) == 1) - ret = virGetStorageVol(conn, "default-pool", hddNameUtf8, key, - NULL, NULL); - - VIR_DEBUG("Storage Volume Pool: %s", "default-pool"); - VIR_DEBUG("Storage Volume Name: %s", hddNameUtf8); - VIR_DEBUG("Storage Volume key : %s", key); - } - - vboxIIDUnalloc(&hddIID); - } - - VBOX_UTF8_FREE(hddNameUtf8); - } - - VBOX_MEDIUM_RELEASE(hardDisk); - } - - VBOX_UTF16_FREE(hddPathUtf16); - - return ret; -} - static virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool, const char *xml, unsigned int flags) diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 2a9c3b2..4843824 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -601,6 +601,7 @@ 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); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

The CreateHardDiskMedium only support create HardDisk for medium type, and it only works when vbox version >= 3.1. This patch make the function workable with all vbox versions and rename it as CreateHardDisk. In vbox 2.2 and 3.0 this function will create a IHardDisk object. In vbox later than 3.0, this function will create a IMedium object. --- src/vbox/vbox_common.c | 16 ++++++++-------- src/vbox/vbox_tmpl.c | 18 +++++++----------- src/vbox/vbox_uniformed_api.h | 2 +- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index cfc73d8..f1ec7f4 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -5071,10 +5071,10 @@ vboxSnapshotRedefine(virDomainPtr dom, if (virAsprintf(&newLocationUtf8, "%sfakedisk-%d.vdi", machineLocationPath, it) < 0) goto cleanup; VBOX_UTF8_TO_UTF16(newLocationUtf8, &newLocation); - rc = gVBoxAPI.UIVirtualBox.CreateHardDiskMedium(data->vboxObj, - formatUtf16, - newLocation, - &newMedium); + rc = gVBoxAPI.UIVirtualBox.CreateHardDisk(data->vboxObj, + formatUtf16, + newLocation, + &newMedium); VBOX_UTF16_FREE(newLocation); VBOX_UTF16_FREE(formatUtf16); if (NS_FAILED(rc)) { @@ -6776,10 +6776,10 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot) machineLocationPath, def->parent, it) < 0) goto cleanup; VBOX_UTF8_TO_UTF16(newLocationUtf8, &newLocation); - rc = gVBoxAPI.UIVirtualBox.CreateHardDiskMedium(data->vboxObj, - formatUtf16, - newLocation, - &newMedium); + rc = gVBoxAPI.UIVirtualBox.CreateHardDisk(data->vboxObj, + formatUtf16, + newLocation, + &newMedium); if (NS_FAILED(rc)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to create HardDisk, rc=%08x"), diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 03d194b..5aa1677 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -3443,17 +3443,13 @@ _virtualboxCreateMachine(vboxGlobalData *data, virDomainDefPtr def, IMachine **m } static nsresult -_virtualboxCreateHardDiskMedium(IVirtualBox *vboxObj ATTRIBUTE_UNUSED, - PRUnichar *format ATTRIBUTE_UNUSED, - PRUnichar *location ATTRIBUTE_UNUSED, - IMedium **medium ATTRIBUTE_UNUSED) +_virtualboxCreateHardDisk(IVirtualBox *vboxObj, PRUnichar *format, + PRUnichar *location, IHardDisk **hardDisk) { -#if VBOX_API_VERSION < 3001000 - vboxUnsupported(); - return 0; -#else /* VBOX_API_VERSION >= 3001000 */ - return vboxObj->vtbl->CreateHardDisk(vboxObj, format, location, medium); -#endif /* VBOX_API_VERSION >= 3001000 */ + /* In vbox 2.2 and 3.0, this function will create a IHardDisk object. + * In vbox 3.1 and later, this function will create a IMedium object. + */ + return vboxObj->vtbl->CreateHardDisk(vboxObj, format, location, hardDisk); } static nsresult @@ -5195,7 +5191,7 @@ static vboxUniformedIVirtualBox _UIVirtualBox = { .GetSystemProperties = _virtualboxGetSystemProperties, .GetHost = _virtualboxGetHost, .CreateMachine = _virtualboxCreateMachine, - .CreateHardDiskMedium = _virtualboxCreateHardDiskMedium, + .CreateHardDisk = _virtualboxCreateHardDisk, .RegisterMachine = _virtualboxRegisterMachine, .FindHardDisk = _virtualboxFindHardDisk, .OpenMedium = _virtualboxOpenMedium, diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 4843824..8a2a96b 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -194,7 +194,7 @@ typedef struct { nsresult (*GetSystemProperties)(IVirtualBox *vboxObj, ISystemProperties **systemProperties); nsresult (*GetHost)(IVirtualBox *vboxObj, IHost **host); nsresult (*CreateMachine)(vboxGlobalData *data, virDomainDefPtr def, IMachine **machine, char *uuidstr); - nsresult (*CreateHardDiskMedium)(IVirtualBox *vboxObj, PRUnichar *format, PRUnichar *location, IMedium **medium); + nsresult (*CreateHardDisk)(IVirtualBox *vboxObj, PRUnichar *format, PRUnichar *location, IHardDisk **hardDisk); nsresult (*RegisterMachine)(IVirtualBox *vboxObj, IMachine *machine); nsresult (*FindHardDisk)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IHardDisk **hardDisk); -- 1.7.9.5

If the <path> in target is not given, the volume will be put in ~/.VirtualBox by default. --- src/vbox/vbox_common.c | 105 +++++++++++++++++++++++++++++++++++++ src/vbox/vbox_common.h | 10 ++++ src/vbox/vbox_tmpl.c | 114 ++++++----------------------------------- src/vbox/vbox_uniformed_api.h | 11 ++++ 4 files changed, 142 insertions(+), 98 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index f1ec7f4..75e41fb 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -36,6 +36,7 @@ #include "fdstream.h" #include "configmake.h" #include "network_conf.h" +#include "storage_conf.h" #include "vbox_common.h" #include "vbox_uniformed_api.h" @@ -8650,6 +8651,110 @@ virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const char *path return ret; } +virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool, + const char *xml, unsigned int flags) +{ + VBOX_OBJECT_CHECK(pool->conn, virStorageVolPtr, NULL); + virStorageVolDefPtr def = NULL; + PRUnichar *hddFormatUtf16 = NULL; + PRUnichar *hddNameUtf16 = NULL; + virStoragePoolDef poolDef; + nsresult rc; + vboxIIDUnion hddIID; + unsigned char uuid[VIR_UUID_BUFLEN]; + char key[VIR_UUID_STRING_BUFLEN] = ""; + IHardDisk *hardDisk = NULL; + IProgress *progress = NULL; + PRUint64 logicalSize = 0; + PRUint32 variant = HardDiskVariant_Standard; + resultCodeUnion resultCode; + + virCheckFlags(0, NULL); + + /* since there is currently one default pool now + * and virStorageVolDefFormat() just checks it type + * so just assign it for now, change the behaviour + * when vbox supports pools. + */ + memset(&poolDef, 0, sizeof(poolDef)); + poolDef.type = VIR_STORAGE_POOL_DIR; + + if ((def = virStorageVolDefParseString(&poolDef, xml)) == NULL) + goto cleanup; + + if (!def->name || + (def->type != VIR_STORAGE_VOL_FILE)) + goto cleanup; + + /* For now only the vmdk, vpc and vdi type harddisk + * variants can be created. For historical reason, we default to vdi */ + if (def->target.format == VIR_STORAGE_FILE_VMDK) { + VBOX_UTF8_TO_UTF16("VMDK", &hddFormatUtf16); + } else if (def->target.format == VIR_STORAGE_FILE_VPC) { + VBOX_UTF8_TO_UTF16("VHD", &hddFormatUtf16); + } else { + VBOX_UTF8_TO_UTF16("VDI", &hddFormatUtf16); + } + + /* If target.path isn't given, use default path ~/.VirtualBox/image_name */ + if (def->target.path == NULL && + virAsprintf(&def->target.path, "%s/.VirtualBox/%s", virGetUserDirectory(), def->name) < 0) + goto cleanup; + VBOX_UTF8_TO_UTF16(def->target.path, &hddNameUtf16); + + if (!hddFormatUtf16 || !hddNameUtf16) + goto cleanup; + + rc = gVBoxAPI.UIVirtualBox.CreateHardDisk(data->vboxObj, hddFormatUtf16, hddNameUtf16, &hardDisk); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not create harddisk, rc=%08x"), + (unsigned)rc); + goto cleanup; + } + + logicalSize = VIR_DIV_UP(def->target.capacity, 1024 * 1024); + + if (def->target.capacity == def->target.allocation) + variant = HardDiskVariant_Fixed; + + rc = gVBoxAPI.UIHardDisk.CreateBaseStorage(hardDisk, logicalSize, variant, &progress); + if (NS_FAILED(rc) || !progress) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not create base storage, rc=%08x"), + (unsigned)rc); + goto cleanup; + } + + gVBoxAPI.UIProgress.WaitForCompletion(progress, -1); + gVBoxAPI.UIProgress.GetResultCode(progress, &resultCode); + if (RC_FAILED(resultCode)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not create base storage, rc=%08x"), + (unsigned)resultCode.uResultCode); + goto cleanup; + } + + VBOX_IID_INITIALIZE(&hddIID); + rc = gVBoxAPI.UIMedium.GetId(hardDisk, &hddIID); + if (NS_FAILED(rc)) + goto cleanup; + + vboxIIDToUUID(&hddIID, uuid); + virUUIDFormat(uuid, key); + + ret = virGetStorageVol(pool->conn, pool->name, def->name, key, + NULL, NULL); + + cleanup: + vboxIIDUnalloc(&hddIID); + VBOX_RELEASE(progress); + VBOX_UTF16_FREE(hddFormatUtf16); + VBOX_UTF16_FREE(hddNameUtf16); + virStorageVolDefFree(def); + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h index 71592c9..ce3a5d1 100644 --- a/src/vbox/vbox_common.h +++ b/src/vbox/vbox_common.h @@ -289,6 +289,16 @@ enum MediaState MediaState_Deleting = 6 }; +enum HardDiskVariant +{ + HardDiskVariant_Standard = 0, + HardDiskVariant_VmdkSplit2G = 0x01, + HardDiskVariant_VmdkStreamOptimized = 0x04, + HardDiskVariant_VmdkESX = 0x08, + HardDiskVariant_Fixed = 0x10000, + HardDiskVariant_Diff = 0x20000 +}; + # define VBOX_E_OBJECT_NOT_FOUND 0x80BB0001 # define VBOX_E_INVALID_VM_STATE 0x80BB0002 # define VBOX_E_VM_ERROR 0x80BB0003 diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 5aa1677..6bb12ef 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2022,104 +2022,6 @@ _registerDomainEvent(virDriverPtr driver) * The Storage Functions here on */ -static virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool, - const char *xml, - unsigned int flags) -{ - VBOX_OBJECT_CHECK(pool->conn, virStorageVolPtr, NULL); - virStorageVolDefPtr def = NULL; - PRUnichar *hddFormatUtf16 = NULL; - PRUnichar *hddNameUtf16 = NULL; - virStoragePoolDef poolDef; - nsresult rc; - - virCheckFlags(0, NULL); - - /* since there is currently one default pool now - * and virStorageVolDefFormat() just checks it type - * so just assign it for now, change the behaviour - * when vbox supports pools. - */ - memset(&poolDef, 0, sizeof(poolDef)); - poolDef.type = VIR_STORAGE_POOL_DIR; - - if ((def = virStorageVolDefParseString(&poolDef, xml)) == NULL) - goto cleanup; - - if (!def->name || - (def->type != VIR_STORAGE_VOL_FILE)) - goto cleanup; - - /* For now only the vmdk, vpc and vdi type harddisk - * variants can be created. For historical reason, we default to vdi */ - if (def->target.format == VIR_STORAGE_FILE_VMDK) { - VBOX_UTF8_TO_UTF16("VMDK", &hddFormatUtf16); - } else if (def->target.format == VIR_STORAGE_FILE_VPC) { - VBOX_UTF8_TO_UTF16("VHD", &hddFormatUtf16); - } else { - VBOX_UTF8_TO_UTF16("VDI", &hddFormatUtf16); - } - - VBOX_UTF8_TO_UTF16(def->name, &hddNameUtf16); - - if (hddFormatUtf16 && hddNameUtf16) { - IHardDisk *hardDisk = NULL; - - rc = data->vboxObj->vtbl->CreateHardDisk(data->vboxObj, hddFormatUtf16, hddNameUtf16, &hardDisk); - if (NS_SUCCEEDED(rc)) { - IProgress *progress = NULL; - PRUint64 logicalSize = VIR_DIV_UP(def->target.capacity, - 1024 * 1024); - PRUint32 variant = HardDiskVariant_Standard; - - if (def->target.capacity == def->target.allocation) - variant = HardDiskVariant_Fixed; - -#if VBOX_API_VERSION < 4003000 - rc = hardDisk->vtbl->CreateBaseStorage(hardDisk, logicalSize, variant, &progress); -#else - rc = hardDisk->vtbl->CreateBaseStorage(hardDisk, logicalSize, 1, &variant, &progress); -#endif - if (NS_SUCCEEDED(rc) && progress) { -#if VBOX_API_VERSION == 2002000 - nsresult resultCode; -#else - PRInt32 resultCode; -#endif - - progress->vtbl->WaitForCompletion(progress, -1); - progress->vtbl->GetResultCode(progress, &resultCode); - - if (NS_SUCCEEDED(resultCode)) { - vboxIID hddIID = VBOX_IID_INITIALIZER; - unsigned char uuid[VIR_UUID_BUFLEN]; - char key[VIR_UUID_STRING_BUFLEN] = ""; - - rc = VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetId, &hddIID.value); - if (NS_SUCCEEDED(rc)) { - vboxIIDToUUID(&hddIID, uuid); - virUUIDFormat(uuid, key); - - ret = virGetStorageVol(pool->conn, pool->name, def->name, key, - NULL, NULL); - } - - vboxIIDUnalloc(&hddIID); - } - - VBOX_RELEASE(progress); - } - } - } - - VBOX_UTF16_FREE(hddFormatUtf16); - VBOX_UTF16_FREE(hddNameUtf16); - - cleanup: - virStorageVolDefFree(def); - return ret; -} - static int vboxStorageVolDelete(virStorageVolPtr vol, unsigned int flags) { @@ -5109,6 +5011,17 @@ _dhcpServerStop(IDHCPServer *dhcpServer) return dhcpServer->vtbl->Stop(dhcpServer); } +static nsresult +_hardDiskCreateBaseStorage(IHardDisk *hardDisk, PRUint64 logicalSize, + PRUint32 variant, IProgress **progress) +{ +#if VBOX_API_VERSION < 4003000 + return hardDisk->vtbl->CreateBaseStorage(hardDisk, logicalSize, variant, progress); +#else + return hardDisk->vtbl->CreateBaseStorage(hardDisk, logicalSize, 1, &variant, progress); +#endif +} + static bool _machineStateOnline(PRUint32 state) { return ((state >= MachineState_FirstOnline) && @@ -5450,6 +5363,10 @@ static vboxUniformedIDHCPServer _UIDHCPServer = { .Stop = _dhcpServerStop, }; +static vboxUniformedIHardDisk _UIHardDisk = { + .CreateBaseStorage = _hardDiskCreateBaseStorage, +}; + static uniformedMachineStateChecker _machineStateChecker = { .Online = _machineStateOnline, .Inactive = _machineStateInactive, @@ -5506,6 +5423,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI) pVBoxAPI->UIHost = _UIHost; pVBoxAPI->UIHNInterface = _UIHNInterface; pVBoxAPI->UIDHCPServer = _UIDHCPServer; + pVBoxAPI->UIHardDisk = _UIHardDisk; pVBoxAPI->machineStateChecker = _machineStateChecker; #if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000 diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 8a2a96b..781c312 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -517,6 +517,14 @@ typedef struct { nsresult (*Stop)(IDHCPServer *dhcpServer); } vboxUniformedIDHCPServer; +/* Functions for IHardDisk, in vbox3.1 and later, it will call the + * corresponding functions in IMedium as IHardDisk does't exist in + * these versions. */ +typedef struct { + nsresult (*CreateBaseStorage)(IHardDisk *hardDisk, PRUint64 logicalSize, + PRUint32 variant, IProgress **progress); +} vboxUniformedIHardDisk; + typedef struct { bool (*Online)(PRUint32 state); bool (*Inactive)(PRUint32 state); @@ -574,6 +582,7 @@ typedef struct { vboxUniformedIHost UIHost; vboxUniformedIHNInterface UIHNInterface; vboxUniformedIDHCPServer UIDHCPServer; + vboxUniformedIHardDisk UIHardDisk; uniformedMachineStateChecker machineStateChecker; /* vbox API features */ bool domainEventCallbacks; @@ -602,6 +611,8 @@ int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int n 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); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

The GetMedium will always return a IHardDisk object them. In 2.2 and 3.0, it is what GetHardDisk exactly do. In 3.1 and later, The IMedium is same as IHardDisk. --- src/vbox/vbox_tmpl.c | 9 ++++----- src/vbox/vbox_uniformed_api.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 6bb12ef..5af6de1 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -4667,14 +4667,13 @@ _mediumCreateDiffStorage(IMedium *medium ATTRIBUTE_UNUSED, } static nsresult -_mediumAttachmentGetMedium(IMediumAttachment *mediumAttachment ATTRIBUTE_UNUSED, - IMedium **medium ATTRIBUTE_UNUSED) +_mediumAttachmentGetMedium(IMediumAttachment *mediumAttachment, + IHardDisk **hardDisk) { #if VBOX_API_VERSION < 3001000 - vboxUnsupported(); - return 0; + return mediumAttachment->vtbl->GetHardDisk(mediumAttachment, hardDisk); #else /* VBOX_API_VERSION >= 3001000 */ - return mediumAttachment->vtbl->GetMedium(mediumAttachment, medium); + return mediumAttachment->vtbl->GetMedium(mediumAttachment, hardDisk); #endif /* VBOX_API_VERSION >= 3001000 */ } diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 781c312..bd59dc4 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -426,7 +426,7 @@ typedef struct { /* Functions for IMediumAttachment */ typedef struct { - nsresult (*GetMedium)(IMediumAttachment *mediumAttachment, IMedium **medium); + nsresult (*GetMedium)(IMediumAttachment *mediumAttachment, IHardDisk **hardDisk); nsresult (*GetController)(IMediumAttachment *mediumAttachment, PRUnichar **controller); nsresult (*GetType)(IMediumAttachment *mediumAttachment, PRUint32 *type); nsresult (*GetPort)(IMediumAttachment *mediumAttachment, PRInt32 *port); -- 1.7.9.5

The API on IHardDiskAttachment is merged into IMediumAttachment. So, we don't need it anymore. --- src/vbox/vbox_common.c | 155 +++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 202 ++++++----------------------------------- src/vbox/vbox_uniformed_api.h | 6 ++ 3 files changed, 187 insertions(+), 176 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 75e41fb..5d283fa 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8755,6 +8755,161 @@ virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool, return ret; } +int vboxStorageVolDelete(virStorageVolPtr vol, unsigned int flags) +{ + VBOX_OBJECT_CHECK(vol->conn, int, -1); + unsigned char uuid[VIR_UUID_BUFLEN]; + IHardDisk *hardDisk = NULL; + int deregister = 0; + PRUint32 hddstate = 0; + size_t i = 0; + size_t j = 0; + PRUint32 machineIdsSize = 0; + vboxArray machineIds = VBOX_ARRAY_INITIALIZER; + vboxIIDUnion hddIID; + nsresult rc; + + VBOX_IID_INITIALIZE(&hddIID); + virCheckFlags(0, -1); + + if (virUUIDParse(vol->key, uuid) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("Could not parse UUID from '%s'"), vol->key); + return -1; + } + + vboxIIDFromUUID(&hddIID, uuid); + rc = gVBoxAPI.UIVirtualBox.GetHardDiskByIID(data->vboxObj, &hddIID, &hardDisk); + if (NS_FAILED(rc)) + goto cleanup; + + gVBoxAPI.UIMedium.GetState(hardDisk, &hddstate); + if (hddstate == MediaState_Inaccessible) + goto cleanup; + + gVBoxAPI.UArray.vboxArrayGet(&machineIds, hardDisk, + gVBoxAPI.UArray.handleMediumGetMachineIds(hardDisk)); + +#if defined WIN32 + /* VirtualBox 2.2 on Windows represents IIDs as GUIDs and the + * machineIds array contains direct instances of the GUID struct + * instead of pointers to the actual struct instances. But there + * is no 128bit width simple item type for a SafeArray to fit a + * GUID in. The largest simple type it 64bit width and VirtualBox + * uses two of this 64bit items to represents one GUID. Therefore, + * we divide the size of the SafeArray by two, to compensate for + * this workaround in VirtualBox */ + if (gVBoxAPI.uVersion >= 2001052 && gVBoxAPI.uVersion < 2002051) + machineIds.count /= 2; +#endif /* !defined WIN32 */ + + machineIdsSize = machineIds.count; + + for (i = 0; i < machineIds.count; i++) { + IMachine *machine = NULL; + vboxIIDUnion machineId; + vboxArray hddAttachments = VBOX_ARRAY_INITIALIZER; + + VBOX_IID_INITIALIZE(&machineId); + vboxIIDFromArrayItem(&machineId, &machineIds, i); + + if (gVBoxAPI.getMachineForSession) { + rc = gVBoxAPI.UIVirtualBox.GetMachine(data->vboxObj, &machineId, &machine); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_NO_DOMAIN, "%s", + _("no domain with matching uuid")); + break; + } + } + + rc = gVBoxAPI.UISession.Open(data, &machineId, machine); + + if (NS_FAILED(rc)) { + vboxIIDUnalloc(&machineId); + continue; + } + + rc = gVBoxAPI.UISession.GetMachine(data->vboxSession, &machine); + if (NS_FAILED(rc)) + goto cleanupLoop; + + gVBoxAPI.UArray.vboxArrayGet(&hddAttachments, machine, + gVBoxAPI.UArray.handleMachineGetMediumAttachments(machine)); + + for (j = 0; j < hddAttachments.count; j++) { + IMediumAttachment *hddAttachment = hddAttachments.items[j]; + IHardDisk *hdd = NULL; + vboxIIDUnion iid; + + if (!hddAttachment) + continue; + + rc = gVBoxAPI.UIMediumAttachment.GetMedium(hddAttachment, &hdd); + if (NS_FAILED(rc) || !hdd) + continue; + + VBOX_IID_INITIALIZE(&iid); + rc = gVBoxAPI.UIMedium.GetId(hdd, &iid); + if (NS_FAILED(rc)) { + VBOX_MEDIUM_RELEASE(hdd); + continue; + } + + DEBUGIID("HardDisk (to delete) UUID", &hddIID); + DEBUGIID("HardDisk (currently processing) UUID", &iid); + + if (vboxIIDIsEqual(&hddIID, &iid)) { + PRUnichar *controller = NULL; + PRInt32 port = 0; + PRInt32 device = 0; + + DEBUGIID("Found HardDisk to delete, UUID", &hddIID); + + gVBoxAPI.UIMediumAttachment.GetController(hddAttachment, &controller); + gVBoxAPI.UIMediumAttachment.GetPort(hddAttachment, &port); + gVBoxAPI.UIMediumAttachment.GetDevice(hddAttachment, &device); + + rc = gVBoxAPI.UIMachine.DetachDevice(machine, controller, port, device); + if (NS_SUCCEEDED(rc)) { + rc = gVBoxAPI.UIMachine.SaveSettings(machine); + VIR_DEBUG("saving machine settings"); + deregister++; + VIR_DEBUG("deregistering hdd:%d", deregister); + } + + VBOX_UTF16_FREE(controller); + } + vboxIIDUnalloc(&iid); + VBOX_MEDIUM_RELEASE(hdd); + } + + cleanupLoop: + gVBoxAPI.UArray.vboxArrayRelease(&hddAttachments); + VBOX_RELEASE(machine); + gVBoxAPI.UISession.Close(data->vboxSession); + vboxIIDUnalloc(&machineId); + } + + gVBoxAPI.UArray.vboxArrayUnalloc(&machineIds); + + if (machineIdsSize == 0 || machineIdsSize == deregister) { + IProgress *progress = NULL; + rc = gVBoxAPI.UIHardDisk.DeleteStorage(hardDisk, &progress); + + if (NS_SUCCEEDED(rc) && progress) { + gVBoxAPI.UIProgress.WaitForCompletion(progress, -1); + VBOX_RELEASE(progress); + DEBUGIID("HardDisk deleted, UUID", &hddIID); + ret = 0; + } + } + + cleanup: + VBOX_MEDIUM_RELEASE(hardDisk); + vboxIIDUnalloc(&hddIID); + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 5af6de1..67e0e35 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -106,7 +106,6 @@ typedef IUSBDeviceFilters IUSBCommon; typedef IHardDiskAttachment IMediumAttachment; #else /* VBOX_API_VERSION >= 3001000 */ typedef IMedium IHardDisk; -typedef IMediumAttachment IHardDiskAttachment; #endif /* VBOX_API_VERSION >= 3001000 */ #include "vbox_uniformed_api.h" @@ -2022,181 +2021,6 @@ _registerDomainEvent(virDriverPtr driver) * The Storage Functions here on */ -static int vboxStorageVolDelete(virStorageVolPtr vol, - unsigned int flags) -{ - VBOX_OBJECT_CHECK(vol->conn, int, -1); - vboxIID hddIID = VBOX_IID_INITIALIZER; - unsigned char uuid[VIR_UUID_BUFLEN]; - IHardDisk *hardDisk = NULL; - int deregister = 0; - nsresult rc; - size_t i = 0; - size_t j = 0; - - virCheckFlags(0, -1); - - if (virUUIDParse(vol->key, uuid) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("Could not parse UUID from '%s'"), vol->key); - return -1; - } - - vboxIIDFromUUID(&hddIID, uuid); -#if VBOX_API_VERSION < 4000000 - rc = data->vboxObj->vtbl->GetHardDisk(data->vboxObj, hddIID.value, &hardDisk); -#elif VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000 - rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddIID.value, - DeviceType_HardDisk, &hardDisk); -#else - rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddIID.value, - DeviceType_HardDisk, AccessMode_ReadWrite, - PR_FALSE, &hardDisk); -#endif /* VBOX_API_VERSION >= 4000000 */ - if (NS_SUCCEEDED(rc)) { - PRUint32 hddstate; - - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetState, &hddstate); - if (hddstate != MediaState_Inaccessible) { - PRUint32 machineIdsSize = 0; - vboxArray machineIds = VBOX_ARRAY_INITIALIZER; - -#if VBOX_API_VERSION < 3001000 - vboxArrayGet(&machineIds, hardDisk, hardDisk->vtbl->imedium.GetMachineIds); -#else /* VBOX_API_VERSION >= 3001000 */ - vboxArrayGet(&machineIds, hardDisk, hardDisk->vtbl->GetMachineIds); -#endif /* VBOX_API_VERSION >= 3001000 */ - -#if VBOX_API_VERSION == 2002000 && defined WIN32 - /* VirtualBox 2.2 on Windows represents IIDs as GUIDs and the - * machineIds array contains direct instances of the GUID struct - * instead of pointers to the actual struct instances. But there - * is no 128bit width simple item type for a SafeArray to fit a - * GUID in. The largest simple type it 64bit width and VirtualBox - * uses two of this 64bit items to represents one GUID. Therefore, - * we divide the size of the SafeArray by two, to compensate for - * this workaround in VirtualBox */ - machineIds.count /= 2; -#endif /* VBOX_API_VERSION >= 2002000 */ - - machineIdsSize = machineIds.count; - - for (i = 0; i < machineIds.count; i++) { - IMachine *machine = NULL; - vboxIID machineId = VBOX_IID_INITIALIZER; - - vboxIIDFromArrayItem(&machineId, &machineIds, i); - -#if VBOX_API_VERSION >= 4000000 - rc = VBOX_OBJECT_GET_MACHINE(machineId.value, &machine); - if (NS_FAILED(rc)) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching uuid")); - break; - } -#endif - - rc = VBOX_SESSION_OPEN(machineId.value, machine); - - if (NS_SUCCEEDED(rc)) { - - rc = data->vboxSession->vtbl->GetMachine(data->vboxSession, &machine); - if (NS_SUCCEEDED(rc)) { - vboxArray hddAttachments = VBOX_ARRAY_INITIALIZER; - -#if VBOX_API_VERSION < 3001000 - vboxArrayGet(&hddAttachments, machine, - machine->vtbl->GetHardDiskAttachments); -#else /* VBOX_API_VERSION >= 3001000 */ - vboxArrayGet(&hddAttachments, machine, - machine->vtbl->GetMediumAttachments); -#endif /* VBOX_API_VERSION >= 3001000 */ - for (j = 0; j < hddAttachments.count; j++) { - IHardDiskAttachment *hddAttachment = hddAttachments.items[j]; - - if (hddAttachment) { - IHardDisk *hdd = NULL; - -#if VBOX_API_VERSION < 3001000 - rc = hddAttachment->vtbl->GetHardDisk(hddAttachment, &hdd); -#else /* VBOX_API_VERSION >= 3001000 */ - rc = hddAttachment->vtbl->GetMedium(hddAttachment, &hdd); -#endif /* VBOX_API_VERSION >= 3001000 */ - if (NS_SUCCEEDED(rc) && hdd) { - vboxIID iid = VBOX_IID_INITIALIZER; - - rc = VBOX_MEDIUM_FUNC_ARG1(hdd, GetId, &iid.value); - if (NS_SUCCEEDED(rc)) { - - DEBUGIID("HardDisk (to delete) UUID", hddIID.value); - DEBUGIID("HardDisk (currently processing) UUID", iid.value); - - if (vboxIIDIsEqual(&hddIID, &iid)) { - PRUnichar *controller = NULL; - PRInt32 port = 0; - PRInt32 device = 0; - - DEBUGIID("Found HardDisk to delete, UUID", hddIID.value); - - hddAttachment->vtbl->GetController(hddAttachment, &controller); - hddAttachment->vtbl->GetPort(hddAttachment, &port); - hddAttachment->vtbl->GetDevice(hddAttachment, &device); - -#if VBOX_API_VERSION < 3001000 - rc = machine->vtbl->DetachHardDisk(machine, controller, port, device); -#else /* VBOX_API_VERSION >= 3001000 */ - rc = machine->vtbl->DetachDevice(machine, controller, port, device); -#endif /* VBOX_API_VERSION >= 3001000 */ - if (NS_SUCCEEDED(rc)) { - rc = machine->vtbl->SaveSettings(machine); - VIR_DEBUG("saving machine settings"); - } - - if (NS_SUCCEEDED(rc)) { - deregister++; - VIR_DEBUG("deregistering hdd:%d", deregister); - } - - VBOX_UTF16_FREE(controller); - } - vboxIIDUnalloc(&iid); - } - VBOX_MEDIUM_RELEASE(hdd); - } - } - } - vboxArrayRelease(&hddAttachments); - VBOX_RELEASE(machine); - } - VBOX_SESSION_CLOSE(); - } - - vboxIIDUnalloc(&machineId); - } - - vboxArrayUnalloc(&machineIds); - - if (machineIdsSize == 0 || machineIdsSize == deregister) { - IProgress *progress = NULL; - rc = hardDisk->vtbl->DeleteStorage(hardDisk, &progress); - - if (NS_SUCCEEDED(rc) && progress) { - progress->vtbl->WaitForCompletion(progress, -1); - VBOX_RELEASE(progress); - DEBUGIID("HardDisk deleted, UUID", hddIID.value); - ret = 0; - } - } - } - - VBOX_MEDIUM_RELEASE(hardDisk); - } - - vboxIIDUnalloc(&hddIID); - - return ret; -} - static int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info) { @@ -3223,6 +3047,11 @@ static void* _handleMediumGetSnapshotIds(IMedium *medium) return medium->vtbl->GetSnapshotIds; } +static void* _handleMediumGetMachineIds(IMedium *medium) +{ + return medium->vtbl->GetMachineIds; +} + static void* _handleHostGetNetworkInterfaces(IHost *host) { return host->vtbl->GetNetworkInterfaces; @@ -3535,6 +3364,17 @@ _machineFindSnapshot(IMachine *machine, vboxIIDUnion *iidu, ISnapshot **snapshot } static nsresult +_machineDetachDevice(IMachine *machine, PRUnichar *name, + PRInt32 controllerPort, PRInt32 device) +{ +#if VBOX_API_VERSION < 3001000 + return machine->vtbl->DetachHardDisk(machine, name, controllerPort, device); +#else /* VBOX_API_VERSION >= 3001000 */ + return machine->vtbl->DetachDevice(machine, name, controllerPort, device); +#endif /* VBOX_API_VERSION >= 3001000 */ +} + +static nsresult _machineGetAccessible(IMachine *machine, PRBool *isAccessible) { return machine->vtbl->GetAccessible(machine, isAccessible); @@ -5021,6 +4861,12 @@ _hardDiskCreateBaseStorage(IHardDisk *hardDisk, PRUint64 logicalSize, #endif } +static nsresult +_hardDiskDeleteStorage(IHardDisk *hardDisk, IProgress **progress) +{ + return hardDisk->vtbl->DeleteStorage(hardDisk, progress); +} + static bool _machineStateOnline(PRUint32 state) { return ((state >= MachineState_FirstOnline) && @@ -5080,6 +4926,7 @@ static vboxUniformedArray _UArray = { .vboxArrayGet = vboxArrayGet, .vboxArrayGetWithIIDArg = _vboxArrayGetWithIIDArg, .vboxArrayRelease = vboxArrayRelease, + .vboxArrayUnalloc = vboxArrayUnalloc, .handleGetMachines = _handleGetMachines, .handleGetHardDisks = _handleGetHardDisks, .handleUSBGetDeviceFilters = _handleUSBGetDeviceFilters, @@ -5088,6 +4935,7 @@ static vboxUniformedArray _UArray = { .handleSnapshotGetChildren = _handleSnapshotGetChildren, .handleMediumGetChildren = _handleMediumGetChildren, .handleMediumGetSnapshotIds = _handleMediumGetSnapshotIds, + .handleMediumGetMachineIds = _handleMediumGetMachineIds, .handleHostGetNetworkInterfaces = _handleHostGetNetworkInterfaces, }; @@ -5122,6 +4970,7 @@ static vboxUniformedIMachine _UIMachine = { .LaunchVMProcess = _machineLaunchVMProcess, .Unregister = _machineUnregister, .FindSnapshot = _machineFindSnapshot, + .DetachDevice = _machineDetachDevice, .GetAccessible = _machineGetAccessible, .GetState = _machineGetState, .GetName = _machineGetName, @@ -5364,6 +5213,7 @@ static vboxUniformedIDHCPServer _UIDHCPServer = { static vboxUniformedIHardDisk _UIHardDisk = { .CreateBaseStorage = _hardDiskCreateBaseStorage, + .DeleteStorage = _hardDiskDeleteStorage, }; static uniformedMachineStateChecker _machineStateChecker = { diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index bd59dc4..7c6e856 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -168,6 +168,7 @@ typedef struct { nsresult (*vboxArrayGet)(vboxArray *array, void *self, void *getter); nsresult (*vboxArrayGetWithIIDArg)(vboxArray *array, void *self, void *getter, vboxIIDUnion *iidu); void (*vboxArrayRelease)(vboxArray *array); + void (*vboxArrayUnalloc)(vboxArray *array); /* Generate function pointers for vboxArrayGet */ void* (*handleGetMachines)(IVirtualBox *vboxObj); void* (*handleGetHardDisks)(IVirtualBox *vboxObj); @@ -177,6 +178,7 @@ typedef struct { void* (*handleSnapshotGetChildren)(ISnapshot *snapshot); void* (*handleMediumGetChildren)(IMedium *medium); void* (*handleMediumGetSnapshotIds)(IMedium *medium); + void* (*handleMediumGetMachineIds)(IMedium *medium); void* (*handleHostGetNetworkInterfaces)(IHost *host); } vboxUniformedArray; @@ -225,6 +227,8 @@ typedef struct { nsresult (*Unregister)(IMachine *machine, PRUint32 cleanupMode, PRUint32 *aMediaSize, IMedium ***aMedia); nsresult (*FindSnapshot)(IMachine *machine, vboxIIDUnion *iidu, ISnapshot **snapshot); + nsresult (*DetachDevice)(IMachine *machine, PRUnichar *name, + PRInt32 controllerPort, PRInt32 device); nsresult (*GetAccessible)(IMachine *machine, PRBool *isAccessible); nsresult (*GetState)(IMachine *machine, PRUint32 *state); nsresult (*GetName)(IMachine *machine, PRUnichar **name); @@ -523,6 +527,7 @@ typedef struct { typedef struct { nsresult (*CreateBaseStorage)(IHardDisk *hardDisk, PRUint64 logicalSize, PRUint32 variant, IProgress **progress); + nsresult (*DeleteStorage)(IHardDisk *hardDisk, IProgress **progress); } vboxUniformedIHardDisk; typedef struct { @@ -613,6 +618,7 @@ 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); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 51 +++++++++++++++++++++ src/vbox/vbox_tmpl.c | 100 +++++++++++++---------------------------- src/vbox/vbox_uniformed_api.h | 3 ++ 3 files changed, 84 insertions(+), 70 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 5d283fa..8b16c0d 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8910,6 +8910,57 @@ int vboxStorageVolDelete(virStorageVolPtr vol, unsigned int flags) return ret; } +int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info) +{ + VBOX_OBJECT_CHECK(vol->conn, int, -1); + IHardDisk *hardDisk = NULL; + unsigned char uuid[VIR_UUID_BUFLEN]; + PRUint32 hddstate; + PRUint64 hddLogicalSize = 0; + PRUint64 hddActualSize = 0; + vboxIIDUnion hddIID; + nsresult rc; + + if (!info) + return ret; + + if (virUUIDParse(vol->key, uuid) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("Could not parse UUID from '%s'"), vol->key); + return ret; + } + + VBOX_IID_INITIALIZE(&hddIID); + vboxIIDFromUUID(&hddIID, uuid); + rc = gVBoxAPI.UIVirtualBox.GetHardDiskByIID(data->vboxObj, &hddIID, &hardDisk); + if (NS_FAILED(rc)) + goto cleanup; + + gVBoxAPI.UIMedium.GetState(hardDisk, &hddstate); + if (hddstate == MediaState_Inaccessible) + goto cleanup; + + info->type = VIR_STORAGE_VOL_FILE; + + gVBoxAPI.UIHardDisk.GetLogicalSizeInByte(hardDisk, &hddLogicalSize); + info->capacity = hddLogicalSize; + + gVBoxAPI.UIMedium.GetSize(hardDisk, &hddActualSize); + info->allocation = hddActualSize; + + ret = 0; + + VIR_DEBUG("Storage Volume Name: %s", vol->name); + VIR_DEBUG("Storage Volume Type: %s", info->type == VIR_STORAGE_VOL_BLOCK ? "Block" : "File"); + VIR_DEBUG("Storage Volume Capacity: %llu", info->capacity); + VIR_DEBUG("Storage Volume Allocation: %llu", info->allocation); + + cleanup: + VBOX_MEDIUM_RELEASE(hardDisk); + vboxIIDUnalloc(&hddIID); + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 67e0e35..198f689 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2021,76 +2021,6 @@ _registerDomainEvent(virDriverPtr driver) * The Storage Functions here on */ -static int -vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info) -{ - VBOX_OBJECT_CHECK(vol->conn, int, -1); - IHardDisk *hardDisk = NULL; - unsigned char uuid[VIR_UUID_BUFLEN]; - vboxIID hddIID = VBOX_IID_INITIALIZER; - nsresult rc; - - if (!info) - return ret; - - if (virUUIDParse(vol->key, uuid) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("Could not parse UUID from '%s'"), vol->key); - return ret; - } - - vboxIIDFromUUID(&hddIID, uuid); -#if VBOX_API_VERSION < 4000000 - rc = data->vboxObj->vtbl->GetHardDisk(data->vboxObj, hddIID.value, &hardDisk); -#elif VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000 - rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddIID.value, - DeviceType_HardDisk, &hardDisk); -#else - rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddIID.value, - DeviceType_HardDisk, AccessMode_ReadWrite, - PR_FALSE, &hardDisk); -#endif /* VBOX_API_VERSION >= 4000000 */ - if (NS_SUCCEEDED(rc)) { - PRUint32 hddstate; - - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetState, &hddstate); - if (hddstate != MediaState_Inaccessible) { -#if VBOX_API_VERSION < 4000000 - PRUint64 hddLogicalSize; - PRUint64 hddActualSize; -#else /* VBOX_API_VERSION >= 4000000 */ - PRInt64 hddLogicalSize; - PRInt64 hddActualSize; -#endif /* VBOX_API_VERSION >= 4000000 */ - - info->type = VIR_STORAGE_VOL_FILE; - - hardDisk->vtbl->GetLogicalSize(hardDisk, &hddLogicalSize); -#if VBOX_API_VERSION < 4000000 - info->capacity = hddLogicalSize * 1024 * 1024; /* MB => Bytes */ -#else /* VBOX_API_VERSION >= 4000000 */ - info->capacity = hddLogicalSize; -#endif /* VBOX_API_VERSION >= 4000000 */ - - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetSize, &hddActualSize); - info->allocation = hddActualSize; - - ret = 0; - - VIR_DEBUG("Storage Volume Name: %s", vol->name); - VIR_DEBUG("Storage Volume Type: %s", info->type == VIR_STORAGE_VOL_BLOCK ? "Block" : "File"); - VIR_DEBUG("Storage Volume Capacity: %llu", info->capacity); - VIR_DEBUG("Storage Volume Allocation: %llu", info->allocation); - } - - VBOX_MEDIUM_RELEASE(hardDisk); - } - - vboxIIDUnalloc(&hddIID); - - return ret; -} - static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) { VBOX_OBJECT_CHECK(vol->conn, char *, NULL); @@ -4394,6 +4324,19 @@ static nsresult _mediumGetName(IMedium *medium, PRUnichar **name) return medium->vtbl->GetName(medium, name); } +static nsresult _mediumGetSize(IMedium *medium, PRUint64 *uSize) +{ +#if VBOX_API_VERSION < 4000000 + return medium->vtbl->GetSize(medium, uSize); +#else /* VBOX_API_VERSION >= 4000000 */ + nsresult rc; + PRInt64 Size; + rc = medium->vtbl->GetSize(medium, &Size); + *uSize = Size; + return rc; +#endif /* VBOX_API_VERSION >= 4000000 */ +} + static nsresult _mediumGetReadOnly(IMedium *medium ATTRIBUTE_UNUSED, PRBool *readOnly ATTRIBUTE_UNUSED) { @@ -4867,6 +4810,21 @@ _hardDiskDeleteStorage(IHardDisk *hardDisk, IProgress **progress) return hardDisk->vtbl->DeleteStorage(hardDisk, progress); } +static nsresult +_hardDiskGetLogicalSizeInByte(IHardDisk *hardDisk, PRUint64 *uLogicalSize) +{ + nsresult rc; +#if VBOX_API_VERSION < 4000000 + rc = hardDisk->vtbl->GetLogicalSize(hardDisk, uLogicalSize); + *uLogicalSize *= 1024 * 1024; /* MB => Bytes */ +#else /* VBOX_API_VERSION >= 4000000 */ + PRInt64 logicalSize; + rc = hardDisk->vtbl->GetLogicalSize(hardDisk, &logicalSize); + *uLogicalSize = logicalSize; +#endif /* VBOX_API_VERSION >= 4000000 */ + return rc; +} + static bool _machineStateOnline(PRUint32 state) { return ((state >= MachineState_FirstOnline) && @@ -5136,6 +5094,7 @@ static vboxUniformedIMedium _UIMedium = { .GetLocation = _mediumGetLocation, .GetState = _mediumGetState, .GetName = _mediumGetName, + .GetSize = _mediumGetSize, .GetReadOnly = _mediumGetReadOnly, .GetParent = _mediumGetParent, .GetChildren = _mediumGetChildren, @@ -5214,6 +5173,7 @@ static vboxUniformedIDHCPServer _UIDHCPServer = { static vboxUniformedIHardDisk _UIHardDisk = { .CreateBaseStorage = _hardDiskCreateBaseStorage, .DeleteStorage = _hardDiskDeleteStorage, + .GetLogicalSizeInByte = _hardDiskGetLogicalSizeInByte, }; static uniformedMachineStateChecker _machineStateChecker = { diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 7c6e856..0f6ee07 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -416,6 +416,7 @@ typedef struct { nsresult (*GetLocation)(IMedium *medium, PRUnichar **location); nsresult (*GetState)(IMedium *medium, PRUint32 *state); nsresult (*GetName)(IMedium *medium, PRUnichar **name); + nsresult (*GetSize)(IMedium *medium, PRUint64 *uSize); nsresult (*GetReadOnly)(IMedium *medium, PRBool *readOnly); nsresult (*GetParent)(IMedium *medium, IMedium **parent); nsresult (*GetChildren)(IMedium *medium, PRUint32 *childrenSize, IMedium ***children); @@ -528,6 +529,7 @@ typedef struct { nsresult (*CreateBaseStorage)(IHardDisk *hardDisk, PRUint64 logicalSize, PRUint32 variant, IProgress **progress); nsresult (*DeleteStorage)(IHardDisk *hardDisk, IProgress **progress); + nsresult (*GetLogicalSizeInByte)(IHardDisk *hardDisk, PRUint64 *uLogicalSize); } vboxUniformedIHardDisk; typedef struct { @@ -619,6 +621,7 @@ 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); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 88 +++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 123 +++-------------------------------------- src/vbox/vbox_uniformed_api.h | 2 + 3 files changed, 97 insertions(+), 116 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 8b16c0d..8f981f3 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8961,6 +8961,94 @@ int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info) return ret; } +char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) +{ + VBOX_OBJECT_CHECK(vol->conn, char *, NULL); + IHardDisk *hardDisk = NULL; + unsigned char uuid[VIR_UUID_BUFLEN]; + PRUnichar *hddFormatUtf16 = NULL; + char *hddFormatUtf8 = NULL; + PRUint64 hddLogicalSize = 0; + PRUint64 hddActualSize = 0; + virStoragePoolDef pool; + virStorageVolDef def; + vboxIIDUnion hddIID; + PRUint32 hddstate; + nsresult rc; + + virCheckFlags(0, NULL); + + memset(&pool, 0, sizeof(pool)); + memset(&def, 0, sizeof(def)); + + if (virUUIDParse(vol->key, uuid) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("Could not parse UUID from '%s'"), vol->key); + return ret; + } + + VBOX_IID_INITIALIZE(&hddIID); + vboxIIDFromUUID(&hddIID, uuid); + rc = gVBoxAPI.UIVirtualBox.GetHardDiskByIID(data->vboxObj, &hddIID, &hardDisk); + if (NS_FAILED(rc)) + goto cleanup; + + gVBoxAPI.UIMedium.GetState(hardDisk, &hddstate); + if (hddstate == MediaState_Inaccessible) + goto cleanup; + + /* since there is currently one default pool now + * and virStorageVolDefFormat() just checks it type + * so just assign it for now, change the behaviour + * when vbox supports pools. + */ + pool.type = VIR_STORAGE_POOL_DIR; + def.type = VIR_STORAGE_VOL_FILE; + + rc = gVBoxAPI.UIHardDisk.GetLogicalSizeInByte(hardDisk, &hddLogicalSize); + if (NS_FAILED(rc)) + goto cleanup; + + def.target.capacity = hddLogicalSize; + + rc = gVBoxAPI.UIMedium.GetSize(hardDisk, &hddActualSize); + if (NS_FAILED(rc)) + goto cleanup; + + if (VIR_STRDUP(def.name, vol->name) < 0) + goto cleanup; + + if (VIR_STRDUP(def.key, vol->key) < 0) + goto cleanup; + + rc = gVBoxAPI.UIHardDisk.GetFormat(hardDisk, &hddFormatUtf16); + if (NS_FAILED(rc)) + goto cleanup; + + VBOX_UTF16_TO_UTF8(hddFormatUtf16, &hddFormatUtf8); + if (!hddFormatUtf8) + goto cleanup; + + VIR_DEBUG("Storage Volume Format: %s", hddFormatUtf8); + + if (STRCASEEQ("vmdk", hddFormatUtf8)) + def.target.format = VIR_STORAGE_FILE_VMDK; + else if (STRCASEEQ("vhd", hddFormatUtf8)) + def.target.format = VIR_STORAGE_FILE_VPC; + else if (STRCASEEQ("vdi", hddFormatUtf8)) + def.target.format = VIR_STORAGE_FILE_VDI; + else + def.target.format = VIR_STORAGE_FILE_RAW; + ret = virStorageVolDefFormat(&pool, &def); + + cleanup: + VBOX_UTF16_FREE(hddFormatUtf16); + VBOX_UTF8_FREE(hddFormatUtf8); + VBOX_MEDIUM_RELEASE(hardDisk); + vboxIIDUnalloc(&hddIID); + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 198f689..9ce1ddb 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2021,122 +2021,6 @@ _registerDomainEvent(virDriverPtr driver) * The Storage Functions here on */ -static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) -{ - VBOX_OBJECT_CHECK(vol->conn, char *, NULL); - IHardDisk *hardDisk = NULL; - unsigned char uuid[VIR_UUID_BUFLEN]; - vboxIID hddIID = VBOX_IID_INITIALIZER; - virStoragePoolDef pool; - virStorageVolDef def; - int defOk = 0; - nsresult rc; - - virCheckFlags(0, NULL); - - memset(&pool, 0, sizeof(pool)); - memset(&def, 0, sizeof(def)); - - if (virUUIDParse(vol->key, uuid) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("Could not parse UUID from '%s'"), vol->key); - return ret; - } - - vboxIIDFromUUID(&hddIID, uuid); -#if VBOX_API_VERSION < 4000000 - rc = data->vboxObj->vtbl->GetHardDisk(data->vboxObj, hddIID.value, &hardDisk); -#elif VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000 - rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddIID.value, - DeviceType_HardDisk, &hardDisk); -#else - rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddIID.value, - DeviceType_HardDisk, AccessMode_ReadWrite, - PR_FALSE, &hardDisk); -#endif /* VBOX_API_VERSION >= 4000000 */ - if (NS_SUCCEEDED(rc)) { - PRUint32 hddstate; - - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetState, &hddstate); - if (NS_SUCCEEDED(rc) && hddstate != MediaState_Inaccessible) { - PRUnichar *hddFormatUtf16 = NULL; -#if VBOX_API_VERSION < 4000000 - PRUint64 hddLogicalSize; - PRUint64 hddActualSize; -#else /* VBOX_API_VERSION >= 4000000 */ - PRInt64 hddLogicalSize; - PRInt64 hddActualSize; -#endif /* VBOX_API_VERSION >= 4000000 */ - - /* since there is currently one default pool now - * and virStorageVolDefFormat() just checks it type - * so just assign it for now, change the behaviour - * when vbox supports pools. - */ - pool.type = VIR_STORAGE_POOL_DIR; - def.type = VIR_STORAGE_VOL_FILE; - defOk = 1; - - rc = hardDisk->vtbl->GetLogicalSize(hardDisk, &hddLogicalSize); - if (NS_SUCCEEDED(rc) && defOk) { -#if VBOX_API_VERSION < 4000000 - def.target.capacity = hddLogicalSize * 1024 * 1024; /* MB => Bytes */ -#else /* VBOX_API_VERSION >= 4000000 */ - def.target.capacity = hddLogicalSize; -#endif /* VBOX_API_VERSION >= 4000000 */ - } else - defOk = 0; - - rc = VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetSize, &hddActualSize); - if (NS_SUCCEEDED(rc) && defOk) - def.target.allocation = hddActualSize; - else - defOk = 0; - - if (VIR_STRDUP(def.name, vol->name) < 0) - defOk = 0; - - if (VIR_STRDUP(def.key, vol->key) < 0) - defOk = 0; - - rc = hardDisk->vtbl->GetFormat(hardDisk, &hddFormatUtf16); - if (NS_SUCCEEDED(rc) && defOk) { - char *hddFormatUtf8 = NULL; - - VBOX_UTF16_TO_UTF8(hddFormatUtf16, &hddFormatUtf8); - if (hddFormatUtf8) { - - VIR_DEBUG("Storage Volume Format: %s", hddFormatUtf8); - - if (STRCASEEQ("vmdk", hddFormatUtf8)) - def.target.format = VIR_STORAGE_FILE_VMDK; - else if (STRCASEEQ("vhd", hddFormatUtf8)) - def.target.format = VIR_STORAGE_FILE_VPC; - else if (STRCASEEQ("vdi", hddFormatUtf8)) - def.target.format = VIR_STORAGE_FILE_VDI; - else - def.target.format = VIR_STORAGE_FILE_RAW; - - VBOX_UTF8_FREE(hddFormatUtf8); - } - - VBOX_UTF16_FREE(hddFormatUtf16); - } else { - defOk = 0; - } - } - - VBOX_MEDIUM_RELEASE(hardDisk); - } - - vboxIIDUnalloc(&hddIID); - - if (defOk) - ret = virStorageVolDefFormat(&pool, &def); - - return ret; -} - static char *vboxStorageVolGetPath(virStorageVolPtr vol) { VBOX_OBJECT_CHECK(vol->conn, char *, NULL); IHardDisk *hardDisk = NULL; @@ -4825,6 +4709,12 @@ _hardDiskGetLogicalSizeInByte(IHardDisk *hardDisk, PRUint64 *uLogicalSize) return rc; } +static nsresult +_hardDiskGetFormat(IHardDisk *hardDisk, PRUnichar **format) +{ + return hardDisk->vtbl->GetFormat(hardDisk, format); +} + static bool _machineStateOnline(PRUint32 state) { return ((state >= MachineState_FirstOnline) && @@ -5174,6 +5064,7 @@ static vboxUniformedIHardDisk _UIHardDisk = { .CreateBaseStorage = _hardDiskCreateBaseStorage, .DeleteStorage = _hardDiskDeleteStorage, .GetLogicalSizeInByte = _hardDiskGetLogicalSizeInByte, + .GetFormat = _hardDiskGetFormat, }; static uniformedMachineStateChecker _machineStateChecker = { diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 0f6ee07..46c64e7 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -530,6 +530,7 @@ typedef struct { PRUint32 variant, IProgress **progress); nsresult (*DeleteStorage)(IHardDisk *hardDisk, IProgress **progress); nsresult (*GetLogicalSizeInByte)(IHardDisk *hardDisk, PRUint64 *uLogicalSize); + nsresult (*GetFormat)(IHardDisk *hardDisk, PRUnichar **format); } vboxUniformedIHardDisk; typedef struct { @@ -622,6 +623,7 @@ 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); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 50 +++++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 61 ----------------------------------------- src/vbox/vbox_uniformed_api.h | 1 + 3 files changed, 51 insertions(+), 61 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 8f981f3..e32bee5 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -9049,6 +9049,56 @@ char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) return ret; } +char *vboxStorageVolGetPath(virStorageVolPtr vol) +{ + VBOX_OBJECT_CHECK(vol->conn, char *, NULL); + IHardDisk *hardDisk = NULL; + PRUnichar *hddLocationUtf16 = NULL; + char *hddLocationUtf8 = NULL; + unsigned char uuid[VIR_UUID_BUFLEN]; + vboxIIDUnion hddIID; + PRUint32 hddstate; + nsresult rc; + + if (virUUIDParse(vol->key, uuid) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("Could not parse UUID from '%s'"), vol->key); + return ret; + } + + VBOX_IID_INITIALIZE(&hddIID); + vboxIIDFromUUID(&hddIID, uuid); + rc = gVBoxAPI.UIVirtualBox.GetHardDiskByIID(data->vboxObj, &hddIID, &hardDisk); + if (NS_FAILED(rc)) + goto cleanup; + + gVBoxAPI.UIMedium.GetState(hardDisk, &hddstate); + if (hddstate == MediaState_Inaccessible) + goto cleanup; + + gVBoxAPI.UIMedium.GetLocation(hardDisk, &hddLocationUtf16); + if (!hddLocationUtf16) + goto cleanup; + + VBOX_UTF16_TO_UTF8(hddLocationUtf16, &hddLocationUtf8); + if (!hddLocationUtf8) + goto cleanup; + + ignore_value(VIR_STRDUP(ret, hddLocationUtf8)); + + VIR_DEBUG("Storage Volume Name: %s", vol->name); + VIR_DEBUG("Storage Volume Path: %s", hddLocationUtf8); + VIR_DEBUG("Storage Volume Pool: %s", vol->pool); + + VBOX_UTF8_FREE(hddLocationUtf8); + + cleanup: + VBOX_UTF16_FREE(hddLocationUtf16); + VBOX_MEDIUM_RELEASE(hardDisk); + vboxIIDUnalloc(&hddIID); + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 9ce1ddb..73a72c7 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2017,67 +2017,6 @@ _registerDomainEvent(virDriverPtr driver) #endif /* !(VBOX_API_VERSION == 2002000 || VBOX_API_VERSION >= 4000000) */ -/** - * The Storage Functions here on - */ - -static char *vboxStorageVolGetPath(virStorageVolPtr vol) { - VBOX_OBJECT_CHECK(vol->conn, char *, NULL); - IHardDisk *hardDisk = NULL; - unsigned char uuid[VIR_UUID_BUFLEN]; - vboxIID hddIID = VBOX_IID_INITIALIZER; - nsresult rc; - - if (virUUIDParse(vol->key, uuid) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("Could not parse UUID from '%s'"), vol->key); - return ret; - } - - vboxIIDFromUUID(&hddIID, uuid); -#if VBOX_API_VERSION < 4000000 - rc = data->vboxObj->vtbl->GetHardDisk(data->vboxObj, hddIID.value, &hardDisk); -#elif VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000 - rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddIID.value, - DeviceType_HardDisk, &hardDisk); -#else - rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddIID.value, - DeviceType_HardDisk, AccessMode_ReadWrite, - PR_FALSE, &hardDisk); -#endif /* VBOX_API_VERSION >= 4000000 */ - if (NS_SUCCEEDED(rc)) { - PRUint32 hddstate; - - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetState, &hddstate); - if (hddstate != MediaState_Inaccessible) { - PRUnichar *hddLocationUtf16 = NULL; - char *hddLocationUtf8 = NULL; - - VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetLocation, &hddLocationUtf16); - - VBOX_UTF16_TO_UTF8(hddLocationUtf16, &hddLocationUtf8); - if (hddLocationUtf8) { - - ignore_value(VIR_STRDUP(ret, hddLocationUtf8)); - - VIR_DEBUG("Storage Volume Name: %s", vol->name); - VIR_DEBUG("Storage Volume Path: %s", hddLocationUtf8); - VIR_DEBUG("Storage Volume Pool: %s", vol->pool); - - VBOX_UTF8_FREE(hddLocationUtf8); - } - - VBOX_UTF16_FREE(hddLocationUtf16); - } - - VBOX_MEDIUM_RELEASE(hardDisk); - } - - vboxIIDUnalloc(&hddIID); - - return ret; -} - static int _pfnInitialize(vboxGlobalData *data) { data->pFuncs = g_pfnGetFunctions(VBOX_XPCOMC_VERSION); diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 46c64e7..5ec0dee 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -624,6 +624,7 @@ virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool, 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

--- src/vbox/vbox_common.c | 63 +++++++++++++++++++++++++++++------------ src/vbox/vbox_driver.c | 52 ++-------------------------------- src/vbox/vbox_tmpl.c | 24 ---------------- src/vbox/vbox_uniformed_api.h | 17 ----------- 4 files changed, 47 insertions(+), 109 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index e32bee5..b1136c7 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8293,9 +8293,10 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) * 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; @@ -8314,14 +8315,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 @@ -8331,8 +8332,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; @@ -8342,7 +8343,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; @@ -8362,7 +8364,7 @@ virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *na return ret; } -int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool) +static int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool) { VBOX_OBJECT_CHECK(pool->conn, int, -1); vboxArray hardDisks = VBOX_ARRAY_INITIALIZER; @@ -8398,7 +8400,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) { VBOX_OBJECT_CHECK(pool->conn, int, -1); vboxArray hardDisks = VBOX_ARRAY_INITIALIZER; @@ -8449,7 +8452,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) { VBOX_OBJECT_CHECK(pool->conn, virStorageVolPtr, NULL); vboxArray hardDisks = VBOX_ARRAY_INITIALIZER; @@ -8517,7 +8521,8 @@ virStorageVolPtr vboxStorageVolLookupByName(virStoragePoolPtr pool, const char * return ret; } -virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char *key) +static virStorageVolPtr +vboxStorageVolLookupByKey(virConnectPtr conn, const char *key) { VBOX_OBJECT_CHECK(conn, virStorageVolPtr, NULL); vboxIIDUnion hddIID; @@ -8579,7 +8584,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) { VBOX_OBJECT_CHECK(conn, virStorageVolPtr, NULL); PRUnichar *hddPathUtf16 = NULL; @@ -8651,7 +8657,7 @@ virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const char *path return ret; } -virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool, +static virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool, const char *xml, unsigned int flags) { VBOX_OBJECT_CHECK(pool->conn, virStorageVolPtr, NULL); @@ -8755,7 +8761,7 @@ virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool, return ret; } -int vboxStorageVolDelete(virStorageVolPtr vol, unsigned int flags) +static int vboxStorageVolDelete(virStorageVolPtr vol, unsigned int flags) { VBOX_OBJECT_CHECK(vol->conn, int, -1); unsigned char uuid[VIR_UUID_BUFLEN]; @@ -8910,7 +8916,8 @@ int vboxStorageVolDelete(virStorageVolPtr vol, unsigned int flags) return ret; } -int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info) +static int +vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info) { VBOX_OBJECT_CHECK(vol->conn, int, -1); IHardDisk *hardDisk = NULL; @@ -8961,7 +8968,7 @@ int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info) return ret; } -char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) +static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) { VBOX_OBJECT_CHECK(vol->conn, char *, NULL); IHardDisk *hardDisk = NULL; @@ -9049,7 +9056,7 @@ char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) return ret; } -char *vboxStorageVolGetPath(virStorageVolPtr vol) +static char *vboxStorageVolGetPath(virStorageVolPtr vol) { VBOX_OBJECT_CHECK(vol->conn, char *, NULL); IHardDisk *hardDisk = NULL; @@ -9190,6 +9197,26 @@ virNetworkDriver vboxCommonNetworkDriver = { .networkGetXMLDesc = vboxNetworkGetXMLDesc, /* 0.6.4 */ }; +virStorageDriver vboxCommonStorageDriver = { + .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 */ +}; + static void updateDriver(void) { /* Update the vboxDriver according to the vboxUniformedAPI. diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c index 6c86973..7874e35 100644 --- a/src/vbox/vbox_driver.c +++ b/src/vbox/vbox_driver.c @@ -48,19 +48,9 @@ VIR_LOG_INIT("vbox.vbox_driver"); -extern virStorageDriver vbox22StorageDriver; -extern virStorageDriver vbox30StorageDriver; -extern virStorageDriver vbox31StorageDriver; -extern virStorageDriver vbox32StorageDriver; -extern virStorageDriver vbox40StorageDriver; -extern virStorageDriver vbox41StorageDriver; -extern virStorageDriver vbox42StorageDriver; -extern virStorageDriver vbox42_20StorageDriver; -extern virStorageDriver vbox43StorageDriver; -extern virStorageDriver vbox43_4StorageDriver; - extern virDriver vboxCommonDriver; extern virNetworkDriver vboxCommonNetworkDriver; +extern virStorageDriver vboxCommonStorageDriver; static virDriver vboxDriverDummy; @@ -81,7 +71,7 @@ int vboxRegister(void) */ driver = &vboxDriverDummy; networkDriver = &vboxCommonNetworkDriver; - storageDriver = &vbox22StorageDriver; + storageDriver = &vboxCommonStorageDriver; /* Init the glue and get the API version. */ if (VBoxCGlueInit(&uVersion) == 0) { @@ -91,44 +81,6 @@ int vboxRegister(void) 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); - } - /* Register vboxUniformedAPI. */ if (vboxRegisterUniformedAPI(uVersion) == 0) /* Only if successfully register the uniformed api, * can we use the vboxCommonDriver. Or use the diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 73a72c7..0bce8c4 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -5116,27 +5116,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 5ec0dee..a638d5c 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

--- src/vbox/vbox_tmpl.c | 65 +------------------------------------------------- 1 file changed, 1 insertion(+), 64 deletions(-) diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 0bce8c4..9d73ae9 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -42,24 +42,10 @@ #include "internal.h" #include "datatypes.h" #include "domain_conf.h" -#include "snapshot_conf.h" -#include "vbox_snapshot_conf.h" -#include "network_conf.h" -#include "virerror.h" #include "domain_event.h" -#include "storage_conf.h" -#include "virstoragefile.h" -#include "viruuid.h" #include "viralloc.h" -#include "nodeinfo.h" #include "virlog.h" -#include "vbox_driver.h" -#include "configmake.h" -#include "virfile.h" -#include "fdstream.h" -#include "viruri.h" #include "virstring.h" -#include "virtime.h" #include "virutil.h" /* This one changes from version to version. */ @@ -133,19 +119,9 @@ VIR_LOG_INIT("vbox.vbox_tmpl"); } \ } while (0) -#define VBOX_COM_UNALLOC_MEM(arg) \ - do { \ - if (arg) { \ - data->pFuncs->pfnComUnallocMem(arg); \ - (arg) = NULL; \ - } \ - } while (0) - #define VBOX_UTF16_TO_UTF8(arg1, arg2) data->pFuncs->pfnUtf16ToUtf8(arg1, arg2) #define VBOX_UTF8_TO_UTF16(arg1, arg2) data->pFuncs->pfnUtf8ToUtf16(arg1, arg2) -#define VBOX_ADDREF(arg) (arg)->vtbl->nsisupports.AddRef((nsISupports *)(arg)) - #define VBOX_RELEASE(arg) \ do { \ if (arg) { \ @@ -161,39 +137,12 @@ if (!data->vboxObj) {\ return ret;\ } -#define VBOX_OBJECT_HOST_CHECK(conn, type, value) \ -vboxGlobalData *data = conn->privateData;\ -type ret = value;\ -IHost *host = NULL;\ -if (!data->vboxObj) {\ - return ret;\ -}\ -data->vboxObj->vtbl->GetHost(data->vboxObj, &host);\ -if (!host) {\ - return ret;\ -} - #if VBOX_API_VERSION < 3001000 - # define VBOX_MEDIUM_RELEASE(arg) \ if (arg)\ (arg)->vtbl->imedium.nsisupports.Release((nsISupports *)(arg)) -# define VBOX_MEDIUM_FUNC_ARG1(object, func, arg1) \ - (object)->vtbl->imedium.func((IMedium *)(object), arg1) -# define VBOX_MEDIUM_FUNC_ARG2(object, func, arg1, arg2) \ - (object)->vtbl->imedium.func((IMedium *)(object), arg1, arg2) - #else /* VBOX_API_VERSION >= 3001000 */ - -# define MediaState_Inaccessible MediumState_Inaccessible -# define HardDiskVariant_Standard MediumVariant_Standard -# define HardDiskVariant_Fixed MediumVariant_Fixed # define VBOX_MEDIUM_RELEASE(arg) VBOX_RELEASE(arg) -# define VBOX_MEDIUM_FUNC_ARG1(object, func, arg1) \ - (object)->vtbl->func(object, arg1) -# define VBOX_MEDIUM_FUNC_ARG2(object, func, arg1, arg2) \ - (object)->vtbl->func(object, arg1, arg2) - #endif /* VBOX_API_VERSION >= 3001000 */ #define DEBUGPRUnichar(msg, strUtf16) \ @@ -241,29 +190,17 @@ static vboxGlobalData *g_pVBoxGlobalData = NULL; #if VBOX_API_VERSION < 4000000 -# define VBOX_OBJECT_GET_MACHINE(/* in */ iid_value, /* out */ machine) \ - data->vboxObj->vtbl->GetMachine(data->vboxObj, iid_value, machine) - # define VBOX_SESSION_OPEN(/* in */ iid_value, /* unused */ machine) \ data->vboxObj->vtbl->OpenSession(data->vboxObj, data->vboxSession, iid_value) -# define VBOX_SESSION_OPEN_EXISTING(/* in */ iid_value, /* unused */ machine) \ - data->vboxObj->vtbl->OpenExistingSession(data->vboxObj, data->vboxSession, iid_value) - # define VBOX_SESSION_CLOSE() \ data->vboxSession->vtbl->Close(data->vboxSession) #else /* VBOX_API_VERSION >= 4000000 */ -# define VBOX_OBJECT_GET_MACHINE(/* in */ iid_value, /* out */ machine) \ - data->vboxObj->vtbl->FindMachine(data->vboxObj, iid_value, machine) - # define VBOX_SESSION_OPEN(/* unused */ iid_value, /* in */ machine) \ machine->vtbl->LockMachine(machine, data->vboxSession, LockType_Write) -# define VBOX_SESSION_OPEN_EXISTING(/* unused */ iid_value, /* in */ machine) \ - machine->vtbl->LockMachine(machine, data->vboxSession, LockType_Shared) - # define VBOX_SESSION_CLOSE() \ data->vboxSession->vtbl->UnlockMachine(data->vboxSession) @@ -2151,7 +2088,7 @@ _unregisterMachine(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine **machine) { nsresult rc; vboxArray media = VBOX_ARRAY_INITIALIZER; - rc = VBOX_OBJECT_GET_MACHINE(IID_MEMBER(value), machine); + rc = data->vboxObj->vtbl->FindMachine(data->vboxObj, IID_MEMBER(value), machine); if (NS_FAILED(rc)) { virReportError(VIR_ERR_NO_DOMAIN, "%s", _("no domain with matching uuid")); -- 1.7.9.5
participants (1)
-
Taowei