提交 b4129753 编写于 作者: T Taowei 提交者: Michal Privoznik

vbox: Rewrite vboxDomainGetInfo

上级 2cd7a218
...@@ -2669,3 +2669,82 @@ int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory) ...@@ -2669,3 +2669,82 @@ int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory)
vboxIIDUnalloc(&iid); vboxIIDUnalloc(&iid);
return ret; return ret;
} }
int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info)
{
VBOX_OBJECT_CHECK(dom->conn, int, -1);
vboxArray machines = VBOX_ARRAY_INITIALIZER;
char *machineName = NULL;
PRUnichar *machineNameUtf16 = NULL;
nsresult rc;
size_t i = 0;
rc = gVBoxAPI.UArray.vboxArrayGet(&machines, data->vboxObj, ARRAY_GET_MACHINES);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not get list of machines, rc=%08x"), (unsigned)rc);
goto cleanup;
}
info->nrVirtCpu = 0;
for (i = 0; i < machines.count; ++i) {
IMachine *machine = machines.items[i];
PRBool isAccessible = PR_FALSE;
if (!machine)
continue;
gVBoxAPI.UIMachine.GetAccessible(machine, &isAccessible);
if (!isAccessible)
continue;
gVBoxAPI.UIMachine.GetName(machine, &machineNameUtf16);
VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineName);
if (STREQ(dom->name, machineName)) {
/* Get the Machine State (also match it with
* virDomainState). Get the Machine memory and
* for time being set max_balloon and cur_balloon to same
* Also since there is no direct way of checking
* the cputime required (one condition being the
* VM is remote), return zero for cputime. Get the
* number of CPU.
*/
PRUint32 CPUCount = 0;
PRUint32 memorySize = 0;
PRUint32 state;
PRUint32 maxMemorySize = 4 * 1024;
ISystemProperties *systemProperties = NULL;
gVBoxAPI.UIVirtualBox.GetSystemProperties(data->vboxObj, &systemProperties);
if (systemProperties) {
gVBoxAPI.UISystemProperties.GetMaxGuestRAM(systemProperties, &maxMemorySize);
VBOX_RELEASE(systemProperties);
systemProperties = NULL;
}
gVBoxAPI.UIMachine.GetCPUCount(machine, &CPUCount);
gVBoxAPI.UIMachine.GetMemorySize(machine, &memorySize);
gVBoxAPI.UIMachine.GetState(machine, &state);
info->cpuTime = 0;
info->nrVirtCpu = CPUCount;
info->memory = memorySize * 1024;
info->maxMem = maxMemorySize * 1024;
info->state = gVBoxAPI.vboxConvertState(state);
ret = 0;
}
VBOX_UTF8_FREE(machineName);
VBOX_COM_UNALLOC_MEM(machineNameUtf16);
if (info->nrVirtCpu)
break;
}
gVBoxAPI.UArray.vboxArrayRelease(&machines);
cleanup:
return ret;
}
...@@ -933,7 +933,7 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16, ...@@ -933,7 +933,7 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16,
return result; return result;
} }
static virDomainState vboxConvertState(enum MachineState state) static virDomainState _vboxConvertState(PRUint32 state)
{ {
switch (state) { switch (state) {
case MachineState_Running: case MachineState_Running:
...@@ -955,86 +955,6 @@ static virDomainState vboxConvertState(enum MachineState state) ...@@ -955,86 +955,6 @@ static virDomainState vboxConvertState(enum MachineState state)
} }
} }
static int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info)
{
VBOX_OBJECT_CHECK(dom->conn, int, -1);
vboxArray machines = VBOX_ARRAY_INITIALIZER;
char *machineName = NULL;
PRUnichar *machineNameUtf16 = NULL;
nsresult rc;
size_t i = 0;
rc = vboxArrayGet(&machines, data->vboxObj, data->vboxObj->vtbl->GetMachines);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not get list of machines, rc=%08x"), (unsigned)rc);
goto cleanup;
}
info->nrVirtCpu = 0;
for (i = 0; i < machines.count; ++i) {
IMachine *machine = machines.items[i];
PRBool isAccessible = PR_FALSE;
if (!machine)
continue;
machine->vtbl->GetAccessible(machine, &isAccessible);
if (isAccessible) {
machine->vtbl->GetName(machine, &machineNameUtf16);
VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineName);
if (STREQ(dom->name, machineName)) {
/* Get the Machine State (also match it with
* virDomainState). Get the Machine memory and
* for time being set max_balloon and cur_balloon to same
* Also since there is no direct way of checking
* the cputime required (one condition being the
* VM is remote), return zero for cputime. Get the
* number of CPU.
*/
PRUint32 CPUCount = 0;
PRUint32 memorySize = 0;
PRUint32 state = MachineState_Null;
PRUint32 maxMemorySize = 4 * 1024;
ISystemProperties *systemProperties = NULL;
data->vboxObj->vtbl->GetSystemProperties(data->vboxObj, &systemProperties);
if (systemProperties) {
systemProperties->vtbl->GetMaxGuestRAM(systemProperties, &maxMemorySize);
VBOX_RELEASE(systemProperties);
systemProperties = NULL;
}
machine->vtbl->GetCPUCount(machine, &CPUCount);
machine->vtbl->GetMemorySize(machine, &memorySize);
machine->vtbl->GetState(machine, &state);
info->cpuTime = 0;
info->nrVirtCpu = CPUCount;
info->memory = memorySize * 1024;
info->maxMem = maxMemorySize * 1024;
info->state = vboxConvertState(state);
ret = 0;
}
VBOX_UTF8_FREE(machineName);
VBOX_COM_UNALLOC_MEM(machineNameUtf16);
if (info->nrVirtCpu)
break;
}
}
vboxArrayRelease(&machines);
cleanup:
return ret;
}
static int static int
vboxDomainGetState(virDomainPtr dom, vboxDomainGetState(virDomainPtr dom,
int *state, int *state,
...@@ -1059,7 +979,7 @@ vboxDomainGetState(virDomainPtr dom, ...@@ -1059,7 +979,7 @@ vboxDomainGetState(virDomainPtr dom,
machine->vtbl->GetState(machine, &mstate); machine->vtbl->GetState(machine, &mstate);
*state = vboxConvertState(mstate); *state = _vboxConvertState(mstate);
if (reason) if (reason)
*reason = 0; *reason = 0;
...@@ -9556,12 +9476,24 @@ _machineGetUSBCommon(IMachine *machine, IUSBCommon **USBCommon) ...@@ -9556,12 +9476,24 @@ _machineGetUSBCommon(IMachine *machine, IUSBCommon **USBCommon)
#endif #endif
} }
static nsresult
_machineGetCPUCount(IMachine *machine, PRUint32 *CPUCount)
{
return machine->vtbl->GetCPUCount(machine, CPUCount);
}
static nsresult static nsresult
_machineSetCPUCount(IMachine *machine, PRUint32 CPUCount) _machineSetCPUCount(IMachine *machine, PRUint32 CPUCount)
{ {
return machine->vtbl->SetCPUCount(machine, CPUCount); return machine->vtbl->SetCPUCount(machine, CPUCount);
} }
static nsresult
_machineGetMemorySize(IMachine *machine, PRUint32 *memorySize)
{
return machine->vtbl->GetMemorySize(machine, memorySize);
}
static nsresult static nsresult
_machineSetMemorySize(IMachine *machine, PRUint32 memorySize) _machineSetMemorySize(IMachine *machine, PRUint32 memorySize)
{ {
...@@ -9829,6 +9761,12 @@ _systemPropertiesGetMaxDevicesPerPortForStorageBus(ISystemProperties *systemProp ...@@ -9829,6 +9761,12 @@ _systemPropertiesGetMaxDevicesPerPortForStorageBus(ISystemProperties *systemProp
} }
#endif #endif
static nsresult
_systemPropertiesGetMaxGuestRAM(ISystemProperties *systemProperties, PRUint32 *maxGuestRAM)
{
return systemProperties->vtbl->GetMaxGuestRAM(systemProperties, maxGuestRAM);
}
static nsresult static nsresult
_biosSettingsSetACPIEnabled(IBIOSSettings *bios, PRBool ACPIEnabled) _biosSettingsSetACPIEnabled(IBIOSSettings *bios, PRBool ACPIEnabled)
{ {
...@@ -10235,7 +10173,9 @@ static vboxUniformedIMachine _UIMachine = { ...@@ -10235,7 +10173,9 @@ static vboxUniformedIMachine _UIMachine = {
.GetParallelPort = _machineGetParallelPort, .GetParallelPort = _machineGetParallelPort,
.GetVRDxServer = _machineGetVRDxServer, .GetVRDxServer = _machineGetVRDxServer,
.GetUSBCommon = _machineGetUSBCommon, .GetUSBCommon = _machineGetUSBCommon,
.GetCPUCount = _machineGetCPUCount,
.SetCPUCount = _machineSetCPUCount, .SetCPUCount = _machineSetCPUCount,
.GetMemorySize = _machineGetMemorySize,
.SetMemorySize = _machineSetMemorySize, .SetMemorySize = _machineSetMemorySize,
.SetCPUProperty = _machineSetCPUProperty, .SetCPUProperty = _machineSetCPUProperty,
.SetBootOrder = _machineSetBootOrder, .SetBootOrder = _machineSetBootOrder,
...@@ -10279,6 +10219,7 @@ static vboxUniformedISystemProperties _UISystemProperties = { ...@@ -10279,6 +10219,7 @@ static vboxUniformedISystemProperties _UISystemProperties = {
.GetParallelPortCount = _systemPropertiesGetParallelPortCount, .GetParallelPortCount = _systemPropertiesGetParallelPortCount,
.GetMaxPortCountForStorageBus = _systemPropertiesGetMaxPortCountForStorageBus, .GetMaxPortCountForStorageBus = _systemPropertiesGetMaxPortCountForStorageBus,
.GetMaxDevicesPerPortForStorageBus = _systemPropertiesGetMaxDevicesPerPortForStorageBus, .GetMaxDevicesPerPortForStorageBus = _systemPropertiesGetMaxDevicesPerPortForStorageBus,
.GetMaxGuestRAM = _systemPropertiesGetMaxGuestRAM,
}; };
static vboxUniformedIBIOSSettings _UIBIOSSettings = { static vboxUniformedIBIOSSettings _UIBIOSSettings = {
...@@ -10363,6 +10304,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI) ...@@ -10363,6 +10304,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
pVBoxAPI->unregisterMachine = _unregisterMachine; pVBoxAPI->unregisterMachine = _unregisterMachine;
pVBoxAPI->deleteConfig = _deleteConfig; pVBoxAPI->deleteConfig = _deleteConfig;
pVBoxAPI->vboxAttachDrivesOld = _vboxAttachDrivesOld; pVBoxAPI->vboxAttachDrivesOld = _vboxAttachDrivesOld;
pVBoxAPI->vboxConvertState = _vboxConvertState;
pVBoxAPI->UPFN = _UPFN; pVBoxAPI->UPFN = _UPFN;
pVBoxAPI->UIID = _UIID; pVBoxAPI->UIID = _UIID;
pVBoxAPI->UArray = _UArray; pVBoxAPI->UArray = _UArray;
......
...@@ -212,7 +212,9 @@ typedef struct { ...@@ -212,7 +212,9 @@ typedef struct {
nsresult (*GetParallelPort)(IMachine *machine, PRUint32 slot, IParallelPort **port); nsresult (*GetParallelPort)(IMachine *machine, PRUint32 slot, IParallelPort **port);
nsresult (*GetVRDxServer)(IMachine *machine, IVRDxServer **VRDxServer); nsresult (*GetVRDxServer)(IMachine *machine, IVRDxServer **VRDxServer);
nsresult (*GetUSBCommon)(IMachine *machine, IUSBCommon **USBCommon); nsresult (*GetUSBCommon)(IMachine *machine, IUSBCommon **USBCommon);
nsresult (*GetCPUCount)(IMachine *machine, PRUint32 *CPUCount);
nsresult (*SetCPUCount)(IMachine *machine, PRUint32 CPUCount); nsresult (*SetCPUCount)(IMachine *machine, PRUint32 CPUCount);
nsresult (*GetMemorySize)(IMachine *machine, PRUint32 *memorySize);
nsresult (*SetMemorySize)(IMachine *machine, PRUint32 memorySize); nsresult (*SetMemorySize)(IMachine *machine, PRUint32 memorySize);
nsresult (*SetCPUProperty)(IMachine *machine, PRUint32 property, PRBool value); nsresult (*SetCPUProperty)(IMachine *machine, PRUint32 property, PRBool value);
nsresult (*SetBootOrder)(IMachine *machine, PRUint32 position, PRUint32 device); nsresult (*SetBootOrder)(IMachine *machine, PRUint32 position, PRUint32 device);
...@@ -263,6 +265,7 @@ typedef struct { ...@@ -263,6 +265,7 @@ typedef struct {
PRUint32 *maxPortCount); PRUint32 *maxPortCount);
nsresult (*GetMaxDevicesPerPortForStorageBus)(ISystemProperties *systemProperties, nsresult (*GetMaxDevicesPerPortForStorageBus)(ISystemProperties *systemProperties,
PRUint32 bus, PRUint32 *maxDevicesPerPort); PRUint32 bus, PRUint32 *maxDevicesPerPort);
nsresult (*GetMaxGuestRAM)(ISystemProperties *systemProperties, PRUint32 *maxGuestRAM);
} vboxUniformedISystemProperties; } vboxUniformedISystemProperties;
/* Functions for IBIOSSettings */ /* Functions for IBIOSSettings */
...@@ -360,6 +363,7 @@ typedef struct { ...@@ -360,6 +363,7 @@ typedef struct {
nsresult (*unregisterMachine)(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine **machine); nsresult (*unregisterMachine)(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine **machine);
void (*deleteConfig)(IMachine *machine); void (*deleteConfig)(IMachine *machine);
void (*vboxAttachDrivesOld)(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine); void (*vboxAttachDrivesOld)(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine);
virDomainState (*vboxConvertState)(PRUint32 state);
vboxUniformedPFN UPFN; vboxUniformedPFN UPFN;
vboxUniformedIID UIID; vboxUniformedIID UIID;
vboxUniformedArray UArray; vboxUniformedArray UArray;
...@@ -431,6 +435,7 @@ int vboxDomainDestroyFlags(virDomainPtr dom, unsigned int flags); ...@@ -431,6 +435,7 @@ int vboxDomainDestroyFlags(virDomainPtr dom, unsigned int flags);
int vboxDomainDestroy(virDomainPtr dom); int vboxDomainDestroy(virDomainPtr dom);
char *vboxDomainGetOSType(virDomainPtr dom); char *vboxDomainGetOSType(virDomainPtr dom);
int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory); int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory);
int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info);
/* Version specified functions for installing uniformed API */ /* Version specified functions for installing uniformed API */
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册