mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 07:05:28 +00:00
vbox: Rewrite vboxStorageVolLookupByKey
This commit is contained in:
parent
8a8fa504aa
commit
f67ae174eb
@ -276,3 +276,70 @@ virStorageVolPtr vboxStorageVolLookupByName(virStoragePoolPtr pool, const char *
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
||||||
|
{
|
||||||
|
vboxGlobalData *data = conn->privateData;
|
||||||
|
vboxIIDUnion hddIID;
|
||||||
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
||||||
|
IHardDisk *hardDisk = NULL;
|
||||||
|
PRUnichar *hddNameUtf16 = NULL;
|
||||||
|
char *hddNameUtf8 = NULL;
|
||||||
|
PRUint32 hddstate;
|
||||||
|
nsresult rc;
|
||||||
|
virStorageVolPtr ret = NULL;
|
||||||
|
|
||||||
|
if (!data->vboxObj) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
VBOX_IID_INITIALIZE(&hddIID);
|
||||||
|
if (!key)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (virUUIDParse(key, uuid) < 0) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("Could not parse UUID from '%s'"), key);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.GetName(hardDisk, &hddNameUtf16);
|
||||||
|
if (!hddNameUtf16)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
VBOX_UTF16_TO_UTF8(hddNameUtf16, &hddNameUtf8);
|
||||||
|
if (!hddNameUtf8) {
|
||||||
|
VBOX_UTF16_FREE(hddNameUtf16);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vboxConnectNumOfStoragePools(conn) == 1) {
|
||||||
|
ret = virGetStorageVol(conn, "default-pool", hddNameUtf8, key,
|
||||||
|
NULL, NULL);
|
||||||
|
VIR_DEBUG("Storage Volume Pool: %s", "default-pool");
|
||||||
|
} else {
|
||||||
|
/* TODO: currently only one default pool and thus
|
||||||
|
* nothing here, change it when pools are supported
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
VIR_DEBUG("Storage Volume Name: %s", key);
|
||||||
|
VIR_DEBUG("Storage Volume key : %s", hddNameUtf8);
|
||||||
|
|
||||||
|
VBOX_UTF8_FREE(hddNameUtf8);
|
||||||
|
VBOX_UTF16_FREE(hddNameUtf16);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VBOX_MEDIUM_RELEASE(hardDisk);
|
||||||
|
vboxIIDUnalloc(&hddIID);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -104,7 +104,10 @@ typedef IUSBDeviceFilters IUSBCommon;
|
|||||||
|
|
||||||
#if VBOX_API_VERSION < 3001000
|
#if VBOX_API_VERSION < 3001000
|
||||||
typedef IHardDiskAttachment IMediumAttachment;
|
typedef IHardDiskAttachment IMediumAttachment;
|
||||||
#endif /* VBOX_API_VERSION < 3001000 */
|
#else /* VBOX_API_VERSION >= 3001000 */
|
||||||
|
typedef IMedium IHardDisk;
|
||||||
|
typedef IMediumAttachment IHardDiskAttachment;
|
||||||
|
#endif /* VBOX_API_VERSION >= 3001000 */
|
||||||
|
|
||||||
#include "vbox_uniformed_api.h"
|
#include "vbox_uniformed_api.h"
|
||||||
|
|
||||||
@ -171,8 +174,6 @@ if (arg)\
|
|||||||
|
|
||||||
#else /* VBOX_API_VERSION >= 3001000 */
|
#else /* VBOX_API_VERSION >= 3001000 */
|
||||||
|
|
||||||
typedef IMedium IHardDisk;
|
|
||||||
typedef IMediumAttachment IHardDiskAttachment;
|
|
||||||
# define MediaState_Inaccessible MediumState_Inaccessible
|
# define MediaState_Inaccessible MediumState_Inaccessible
|
||||||
# define HardDiskVariant_Standard MediumVariant_Standard
|
# define HardDiskVariant_Standard MediumVariant_Standard
|
||||||
# define HardDiskVariant_Fixed MediumVariant_Fixed
|
# define HardDiskVariant_Fixed MediumVariant_Fixed
|
||||||
@ -2033,72 +2034,6 @@ _registerDomainEvent(virHypervisorDriverPtr driver)
|
|||||||
* The Storage Functions here on
|
* The Storage Functions here on
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static virStorageVolPtr
|
|
||||||
vboxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|
||||||
{
|
|
||||||
VBOX_OBJECT_CHECK(conn, virStorageVolPtr, NULL);
|
|
||||||
vboxIID hddIID = VBOX_IID_INITIALIZER;
|
|
||||||
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
||||||
IHardDisk *hardDisk = NULL;
|
|
||||||
nsresult rc;
|
|
||||||
|
|
||||||
if (!key)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (virUUIDParse(key, uuid) < 0) {
|
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("Could not parse UUID from '%s'"), key);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 *hddNameUtf16 = NULL;
|
|
||||||
char *hddNameUtf8 = NULL;
|
|
||||||
|
|
||||||
VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetName, &hddNameUtf16);
|
|
||||||
VBOX_UTF16_TO_UTF8(hddNameUtf16, &hddNameUtf8);
|
|
||||||
|
|
||||||
if (hddNameUtf8) {
|
|
||||||
if (vboxConnectNumOfStoragePools(conn) == 1) {
|
|
||||||
ret = virGetStorageVol(conn, "default-pool", hddNameUtf8, key,
|
|
||||||
NULL, NULL);
|
|
||||||
VIR_DEBUG("Storage Volume Pool: %s", "default-pool");
|
|
||||||
} else {
|
|
||||||
/* TODO: currently only one default pool and thus
|
|
||||||
* nothing here, change it when pools are supported
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_DEBUG("Storage Volume Name: %s", key);
|
|
||||||
VIR_DEBUG("Storage Volume key : %s", hddNameUtf8);
|
|
||||||
|
|
||||||
VBOX_UTF8_FREE(hddNameUtf8);
|
|
||||||
VBOX_UTF16_FREE(hddNameUtf16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VBOX_MEDIUM_RELEASE(hardDisk);
|
|
||||||
}
|
|
||||||
|
|
||||||
vboxIIDUnalloc(&hddIID);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static virStorageVolPtr
|
static virStorageVolPtr
|
||||||
vboxStorageVolLookupByPath(virConnectPtr conn, const char *path)
|
vboxStorageVolLookupByPath(virConnectPtr conn, const char *path)
|
||||||
{
|
{
|
||||||
@ -3660,6 +3595,20 @@ _virtualboxOpenMedium(IVirtualBox *vboxObj ATTRIBUTE_UNUSED,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static nsresult
|
||||||
|
_virtualboxGetHardDiskByIID(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IHardDisk **hardDisk)
|
||||||
|
{
|
||||||
|
#if VBOX_API_VERSION < 4000000
|
||||||
|
return vboxObj->vtbl->GetHardDisk(vboxObj, IID_MEMBER(value), hardDisk);
|
||||||
|
#elif VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000
|
||||||
|
return vboxObj->vtbl->FindMedium(vboxObj, IID_MEMBER(value), DeviceType_HardDisk,
|
||||||
|
hardDisk);
|
||||||
|
#else /* VBOX_API_VERSION >= 4002000 */
|
||||||
|
return vboxObj->vtbl->OpenMedium(vboxObj, IID_MEMBER(value), DeviceType_HardDisk,
|
||||||
|
AccessMode_ReadWrite, PR_FALSE, hardDisk);
|
||||||
|
#endif /* VBOX_API_VERSION >= 4002000 */
|
||||||
|
}
|
||||||
|
|
||||||
static nsresult
|
static nsresult
|
||||||
_virtualboxFindDHCPServerByNetworkName(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server)
|
_virtualboxFindDHCPServerByNetworkName(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server)
|
||||||
{
|
{
|
||||||
@ -5340,6 +5289,7 @@ static vboxUniformedIVirtualBox _UIVirtualBox = {
|
|||||||
.RegisterMachine = _virtualboxRegisterMachine,
|
.RegisterMachine = _virtualboxRegisterMachine,
|
||||||
.FindMedium = _virtualboxFindMedium,
|
.FindMedium = _virtualboxFindMedium,
|
||||||
.OpenMedium = _virtualboxOpenMedium,
|
.OpenMedium = _virtualboxOpenMedium,
|
||||||
|
.GetHardDiskByIID = _virtualboxGetHardDiskByIID,
|
||||||
.FindDHCPServerByNetworkName = _virtualboxFindDHCPServerByNetworkName,
|
.FindDHCPServerByNetworkName = _virtualboxFindDHCPServerByNetworkName,
|
||||||
.CreateDHCPServer = _virtualboxCreateDHCPServer,
|
.CreateDHCPServer = _virtualboxCreateDHCPServer,
|
||||||
.RemoveDHCPServer = _virtualboxRemoveDHCPServer,
|
.RemoveDHCPServer = _virtualboxRemoveDHCPServer,
|
||||||
|
@ -198,6 +198,7 @@ typedef struct {
|
|||||||
nsresult (*RegisterMachine)(IVirtualBox *vboxObj, IMachine *machine);
|
nsresult (*RegisterMachine)(IVirtualBox *vboxObj, IMachine *machine);
|
||||||
nsresult (*FindMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium);
|
nsresult (*FindMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium);
|
||||||
nsresult (*OpenMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium);
|
nsresult (*OpenMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium);
|
||||||
|
nsresult (*GetHardDiskByIID)(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IHardDisk **hardDisk);
|
||||||
nsresult (*FindDHCPServerByNetworkName)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server);
|
nsresult (*FindDHCPServerByNetworkName)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server);
|
||||||
nsresult (*CreateDHCPServer)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server);
|
nsresult (*CreateDHCPServer)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server);
|
||||||
nsresult (*RemoveDHCPServer)(IVirtualBox *vboxObj, IDHCPServer *server);
|
nsresult (*RemoveDHCPServer)(IVirtualBox *vboxObj, IDHCPServer *server);
|
||||||
@ -598,7 +599,7 @@ virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *na
|
|||||||
int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool);
|
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);
|
||||||
|
|
||||||
/* 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