---
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