mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 12:35:17 +00:00
vbox: Rewrite vboxStorageVolGetPath
This commit is contained in:
parent
4df7b206aa
commit
013aa0815c
@ -839,3 +839,58 @@ char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
|
||||
vboxIIDUnalloc(&hddIID);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *vboxStorageVolGetPath(virStorageVolPtr vol)
|
||||
{
|
||||
vboxGlobalData *data = vol->conn->privateData;
|
||||
IHardDisk *hardDisk = NULL;
|
||||
PRUnichar *hddLocationUtf16 = NULL;
|
||||
char *hddLocationUtf8 = NULL;
|
||||
unsigned char uuid[VIR_UUID_BUFLEN];
|
||||
vboxIIDUnion hddIID;
|
||||
PRUint32 hddstate;
|
||||
nsresult rc;
|
||||
char *ret = NULL;
|
||||
|
||||
if (!data->vboxObj) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (virUUIDParse(vol->key, uuid) < 0) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("Could not parse UUID from '%s'"), vol->key);
|
||||
return ret;
|
||||
}
|
||||
|
||||
VBOX_IID_INITIALIZE(&hddIID);
|
||||
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.GetLocation(hardDisk, &hddLocationUtf16);
|
||||
if (!hddLocationUtf16)
|
||||
goto cleanup;
|
||||
|
||||
VBOX_UTF16_TO_UTF8(hddLocationUtf16, &hddLocationUtf8);
|
||||
if (!hddLocationUtf8)
|
||||
goto cleanup;
|
||||
|
||||
ignore_value(VIR_STRDUP(ret, hddLocationUtf8));
|
||||
|
||||
VIR_DEBUG("Storage Volume Name: %s", vol->name);
|
||||
VIR_DEBUG("Storage Volume Path: %s", hddLocationUtf8);
|
||||
VIR_DEBUG("Storage Volume Pool: %s", vol->pool);
|
||||
|
||||
VBOX_UTF8_FREE(hddLocationUtf8);
|
||||
|
||||
cleanup:
|
||||
VBOX_UTF16_FREE(hddLocationUtf16);
|
||||
VBOX_MEDIUM_RELEASE(hardDisk);
|
||||
vboxIIDUnalloc(&hddIID);
|
||||
return ret;
|
||||
}
|
||||
|
@ -2029,67 +2029,6 @@ _registerDomainEvent(virHypervisorDriverPtr driver)
|
||||
|
||||
#endif /* !(VBOX_API_VERSION == 2002000 || VBOX_API_VERSION >= 4000000) */
|
||||
|
||||
/**
|
||||
* The Storage Functions here on
|
||||
*/
|
||||
|
||||
static char *vboxStorageVolGetPath(virStorageVolPtr vol) {
|
||||
VBOX_OBJECT_CHECK(vol->conn, char *, NULL);
|
||||
IHardDisk *hardDisk = NULL;
|
||||
unsigned char uuid[VIR_UUID_BUFLEN];
|
||||
vboxIID hddIID = VBOX_IID_INITIALIZER;
|
||||
nsresult rc;
|
||||
|
||||
if (virUUIDParse(vol->key, uuid) < 0) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("Could not parse UUID from '%s'"), vol->key);
|
||||
return ret;
|
||||
}
|
||||
|
||||
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 *hddLocationUtf16 = NULL;
|
||||
char *hddLocationUtf8 = NULL;
|
||||
|
||||
VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetLocation, &hddLocationUtf16);
|
||||
|
||||
VBOX_UTF16_TO_UTF8(hddLocationUtf16, &hddLocationUtf8);
|
||||
if (hddLocationUtf8) {
|
||||
|
||||
ignore_value(VIR_STRDUP(ret, hddLocationUtf8));
|
||||
|
||||
VIR_DEBUG("Storage Volume Name: %s", vol->name);
|
||||
VIR_DEBUG("Storage Volume Path: %s", hddLocationUtf8);
|
||||
VIR_DEBUG("Storage Volume Pool: %s", vol->pool);
|
||||
|
||||
VBOX_UTF8_FREE(hddLocationUtf8);
|
||||
}
|
||||
|
||||
VBOX_UTF16_FREE(hddLocationUtf16);
|
||||
}
|
||||
|
||||
VBOX_MEDIUM_RELEASE(hardDisk);
|
||||
}
|
||||
|
||||
vboxIIDUnalloc(&hddIID);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int _pfnInitialize(vboxGlobalData *data)
|
||||
{
|
||||
data->pFuncs = g_pfnGetFunctions(VBOX_XPCOMC_VERSION);
|
||||
|
@ -624,6 +624,7 @@ virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool,
|
||||
int vboxStorageVolDelete(virStorageVolPtr vol, unsigned int flags);
|
||||
int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info);
|
||||
char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags);
|
||||
char *vboxStorageVolGetPath(virStorageVolPtr vol);
|
||||
|
||||
/* Version specified functions for installing uniformed API */
|
||||
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
||||
|
Loading…
x
Reference in New Issue
Block a user