mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
vbox: Rewrite vboxStorageVolLookupByName
This commit is contained in:
parent
c3c8cd4fdc
commit
8a8fa504aa
@ -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;
|
||||
}
|
||||
|
@ -2033,71 +2033,6 @@ _registerDomainEvent(virHypervisorDriverPtr driver)
|
||||
* The Storage Functions here on
|
||||
*/
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user