mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
vbox: Rewrite vboxStorageVolLookupByPath
This commit is contained in:
parent
1599319c7e
commit
fc41e00391
@ -343,3 +343,80 @@ virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
vboxIIDUnalloc(&hddIID);
|
vboxIIDUnalloc(&hddIID);
|
||||||
return ret;
|
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;
|
||||||
|
}
|
||||||
|
@ -2034,83 +2034,6 @@ _registerDomainEvent(virHypervisorDriverPtr driver)
|
|||||||
* The Storage Functions here on
|
* 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,
|
static virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool,
|
||||||
const char *xml,
|
const char *xml,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
|
@ -601,6 +601,7 @@ int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool);
|
|||||||
int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int nnames);
|
int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int nnames);
|
||||||
virStorageVolPtr vboxStorageVolLookupByName(virStoragePoolPtr pool, const char *name);
|
virStorageVolPtr vboxStorageVolLookupByName(virStoragePoolPtr pool, const char *name);
|
||||||
virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char *key);
|
virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char *key);
|
||||||
|
virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const char *path);
|
||||||
|
|
||||||
/* Version specified functions for installing uniformed API */
|
/* Version specified functions for installing uniformed API */
|
||||||
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
||||||
|
Loading…
Reference in New Issue
Block a user