--- src/vbox/vbox_storage.c | 73 +++++++++++++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 65 ------------------------------------ src/vbox/vbox_uniformed_api.h | 2 ++ 3 files changed, 75 insertions(+), 65 deletions(-)
diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c index ffa91a9..75711f7 100644 --- a/src/vbox/vbox_storage.c +++ b/src/vbox/vbox_storage.c @@ -203,3 +203,76 @@ int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int n return ret; } + +virStorageVolPtr vboxStorageVolLookupByName(virStoragePoolPtr pool, const char *name) +{ + vboxGlobalData *data = pool->conn->privateData; + vboxArray hardDisks = VBOX_ARRAY_INITIALIZER; + nsresult rc; + size_t i; + virStorageVolPtr ret = NULL; + + if (!data->vboxObj) { + return ret; + } + + 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; +} diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index ac712d8..cc7e35e 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2034,71 +2034,6 @@ _registerDomainEvent(virHypervisorDriverPtr 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 4a6ec33..a6eb3ef 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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list