--- src/vbox/vbox_storage.c | 77 +++++++++++++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 77 ----------------------------------------- src/vbox/vbox_uniformed_api.h | 1 + 3 files changed, 78 insertions(+), 77 deletions(-) diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c index 805d0d2..1878139 100644 --- a/src/vbox/vbox_storage.c +++ b/src/vbox/vbox_storage.c @@ -343,3 +343,80 @@ virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char *key) vboxIIDUnalloc(&hddIID); return ret; } + +virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const char *path) +{ + vboxGlobalData *data = conn->privateData; + 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; + virStorageVolPtr ret = NULL; + + if (!data->vboxObj) { + return ret; + } + + 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; +} diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 6c4cd73..224c896 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2034,83 +2034,6 @@ _registerDomainEvent(virHypervisorDriverPtr 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 385502f..f3650e5 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 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list