mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
vbox: Rewrite vboxStoragePoolNumOfVolumes
We use typedef IMedium IHardDisk to make IHardDisk hierachy from IMedium (Actually it did on vbox 2.2 and 3.0's C++ API). So when calling VBOX_MEDIUM_FUNC_ARG*(IHardDisk, func, args) we can directly replace it to gVBoxAPI.UIMedium.func(IHardDisk, args) When dealing with this two types, we get some rules from it's hierachy relationship. When using IHardDisk and IMedium as input, we can't transfer a IMedium to IHardDisk. Like: gVBoxAPI.UIHardDisk.func(IHardDisk *hardDisk, args) Here, we can't put a *IMedium as a argument. When using IHardDisk and IMedium as output, we can't transfer a IHardDisk to IMedium. Like: gVBoxAPI.UIMachine.GetMedium(IMedium **out) Here, we can't put a **IHardDisk as a argument. If this case do happen, we either change the API to GetHardDisk or write a new one.
This commit is contained in:
parent
459886d41b
commit
ce381d3764
@ -230,6 +230,7 @@ src/vbox/vbox_XPCOMCGlue.c
|
||||
src/vbox/vbox_driver.c
|
||||
src/vbox/vbox_common.c
|
||||
src/vbox/vbox_network.c
|
||||
src/vbox/vbox_storage.c
|
||||
src/vbox/vbox_snapshot_conf.c
|
||||
src/vbox/vbox_tmpl.c
|
||||
src/vmware/vmware_conf.c
|
||||
|
@ -279,6 +279,17 @@ enum HostNetworkInterfaceType
|
||||
HostNetworkInterfaceType_HostOnly = 2
|
||||
};
|
||||
|
||||
enum MediaState
|
||||
{
|
||||
MediaState_NotCreated = 0,
|
||||
MediaState_Created = 1,
|
||||
MediaState_LockedRead = 2,
|
||||
MediaState_LockedWrite = 3,
|
||||
MediaState_Inaccessible = 4,
|
||||
MediaState_Creating = 5,
|
||||
MediaState_Deleting = 6
|
||||
};
|
||||
|
||||
# define VBOX_E_OBJECT_NOT_FOUND 0x80BB0001
|
||||
# define VBOX_E_INVALID_VM_STATE 0x80BB0002
|
||||
# define VBOX_E_VM_ERROR 0x80BB0003
|
||||
@ -319,6 +330,7 @@ typedef nsISupports IDisplay;
|
||||
typedef nsISupports IHost;
|
||||
typedef nsISupports IHostNetworkInterface;
|
||||
typedef nsISupports IDHCPServer;
|
||||
typedef IMedium IHardDisk;
|
||||
|
||||
/* Macros for all vbox drivers. */
|
||||
|
||||
|
@ -34,6 +34,8 @@
|
||||
|
||||
VIR_LOG_INIT("vbox.vbox_storage");
|
||||
|
||||
static vboxUniformedAPI gVBoxAPI;
|
||||
|
||||
/**
|
||||
* The Storage Functions here on
|
||||
*/
|
||||
@ -104,3 +106,44 @@ virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *na
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool)
|
||||
{
|
||||
vboxGlobalData *data = pool->conn->privateData;
|
||||
vboxArray hardDisks = VBOX_ARRAY_INITIALIZER;
|
||||
PRUint32 hardDiskAccessible = 0;
|
||||
nsresult rc;
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
|
||||
if (!data->vboxObj) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
rc = gVBoxAPI.UArray.vboxArrayGet(&hardDisks, data->vboxObj,
|
||||
gVBoxAPI.UArray.handleGetHardDisks(data->vboxObj));
|
||||
if (NS_FAILED(rc)) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("could not get number of volumes in the pool: %s, rc=%08x"),
|
||||
pool->name, (unsigned)rc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (i = 0; i < hardDisks.count; ++i) {
|
||||
IHardDisk *hardDisk = hardDisks.items[i];
|
||||
PRUint32 hddstate;
|
||||
|
||||
if (!hardDisk)
|
||||
continue;
|
||||
|
||||
gVBoxAPI.UIMedium.GetState(hardDisk, &hddstate);
|
||||
if (hddstate != MediaState_Inaccessible)
|
||||
hardDiskAccessible++;
|
||||
}
|
||||
|
||||
gVBoxAPI.UArray.vboxArrayRelease(&hardDisks);
|
||||
|
||||
ret = hardDiskAccessible;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -2033,40 +2033,6 @@ _registerDomainEvent(virHypervisorDriverPtr driver)
|
||||
* The Storage Functions here on
|
||||
*/
|
||||
|
||||
static int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool)
|
||||
{
|
||||
VBOX_OBJECT_CHECK(pool->conn, int, -1);
|
||||
vboxArray hardDisks = VBOX_ARRAY_INITIALIZER;
|
||||
PRUint32 hardDiskAccessible = 0;
|
||||
nsresult rc;
|
||||
size_t i;
|
||||
|
||||
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;
|
||||
|
||||
VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetState, &hddstate);
|
||||
if (hddstate != MediaState_Inaccessible)
|
||||
hardDiskAccessible++;
|
||||
}
|
||||
}
|
||||
|
||||
vboxArrayRelease(&hardDisks);
|
||||
|
||||
ret = hardDiskAccessible;
|
||||
} else {
|
||||
ret = -1;
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("could not get number of volumes in the pool: %s, rc=%08x"),
|
||||
pool->name, (unsigned)rc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int nnames) {
|
||||
VBOX_OBJECT_CHECK(pool->conn, int, -1);
|
||||
vboxArray hardDisks = VBOX_ARRAY_INITIALIZER;
|
||||
@ -3579,6 +3545,11 @@ static void* _handleGetMachines(IVirtualBox *vboxObj)
|
||||
return vboxObj->vtbl->GetMachines;
|
||||
}
|
||||
|
||||
static void* _handleGetHardDisks(IVirtualBox *vboxObj)
|
||||
{
|
||||
return vboxObj->vtbl->GetHardDisks;
|
||||
}
|
||||
|
||||
static void* _handleUSBGetDeviceFilters(IUSBCommon *USBCommon)
|
||||
{
|
||||
return USBCommon->vtbl->GetDeviceFilters;
|
||||
@ -4928,6 +4899,11 @@ static nsresult _mediumGetLocation(IMedium *medium, PRUnichar **location)
|
||||
return medium->vtbl->GetLocation(medium, location);
|
||||
}
|
||||
|
||||
static nsresult _mediumGetState(IMedium *medium, PRUint32 *state)
|
||||
{
|
||||
return medium->vtbl->GetState(medium, state);
|
||||
}
|
||||
|
||||
static nsresult _mediumGetReadOnly(IMedium *medium ATTRIBUTE_UNUSED,
|
||||
PRBool *readOnly ATTRIBUTE_UNUSED)
|
||||
{
|
||||
@ -5446,6 +5422,7 @@ static vboxUniformedArray _UArray = {
|
||||
.vboxArrayGetWithIIDArg = _vboxArrayGetWithIIDArg,
|
||||
.vboxArrayRelease = vboxArrayRelease,
|
||||
.handleGetMachines = _handleGetMachines,
|
||||
.handleGetHardDisks = _handleGetHardDisks,
|
||||
.handleUSBGetDeviceFilters = _handleUSBGetDeviceFilters,
|
||||
.handleMachineGetMediumAttachments = _handleMachineGetMediumAttachments,
|
||||
.handleMachineGetSharedFolders = _handleMachineGetSharedFolders,
|
||||
@ -5648,6 +5625,7 @@ static vboxUniformedIUSBDeviceFilter _UIUSBDeviceFilter = {
|
||||
static vboxUniformedIMedium _UIMedium = {
|
||||
.GetId = _mediumGetId,
|
||||
.GetLocation = _mediumGetLocation,
|
||||
.GetState = _mediumGetState,
|
||||
.GetReadOnly = _mediumGetReadOnly,
|
||||
.GetParent = _mediumGetParent,
|
||||
.GetChildren = _mediumGetChildren,
|
||||
|
@ -170,6 +170,7 @@ typedef struct {
|
||||
void (*vboxArrayRelease)(vboxArray *array);
|
||||
/* Generate function pointers for vboxArrayGet */
|
||||
void* (*handleGetMachines)(IVirtualBox *vboxObj);
|
||||
void* (*handleGetHardDisks)(IVirtualBox *vboxObj);
|
||||
void* (*handleUSBGetDeviceFilters)(IUSBCommon *USBCommon);
|
||||
void* (*handleMachineGetMediumAttachments)(IMachine *machine);
|
||||
void* (*handleMachineGetSharedFolders)(IMachine *machine);
|
||||
@ -407,6 +408,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
nsresult (*GetId)(IMedium *medium, vboxIIDUnion *iidu);
|
||||
nsresult (*GetLocation)(IMedium *medium, PRUnichar **location);
|
||||
nsresult (*GetState)(IMedium *medium, PRUint32 *state);
|
||||
nsresult (*GetReadOnly)(IMedium *medium, PRBool *readOnly);
|
||||
nsresult (*GetParent)(IMedium *medium, IMedium **parent);
|
||||
nsresult (*GetChildren)(IMedium *medium, PRUint32 *childrenSize, IMedium ***children);
|
||||
@ -592,6 +594,7 @@ int vboxStorageClose(virConnectPtr conn);
|
||||
int vboxConnectNumOfStoragePools(virConnectPtr conn);
|
||||
int vboxConnectListStoragePools(virConnectPtr conn, char **const names, int nnames);
|
||||
virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *name);
|
||||
int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool);
|
||||
|
||||
/* Version specified functions for installing uniformed API */
|
||||
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
||||
|
Loading…
Reference in New Issue
Block a user