diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index a4c7b3544e490341b7b073d64adfeaa3bdd59eb0..b8287104310bab8397335aded37e7cccde5be65f 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -2669,3 +2669,82 @@ int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory) vboxIIDUnalloc(&iid); 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; +} diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index c7f00ffb5c75f98988ebe9e1eeb55db362417ba9..4f57762bfdecc2186aabd3c0b265903e19dc44cd 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -933,7 +933,7 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16, return result; } -static virDomainState vboxConvertState(enum MachineState state) +static virDomainState _vboxConvertState(PRUint32 state) { switch (state) { case MachineState_Running: @@ -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 vboxDomainGetState(virDomainPtr dom, int *state, @@ -1059,7 +979,7 @@ vboxDomainGetState(virDomainPtr dom, machine->vtbl->GetState(machine, &mstate); - *state = vboxConvertState(mstate); + *state = _vboxConvertState(mstate); if (reason) *reason = 0; @@ -9556,12 +9476,24 @@ _machineGetUSBCommon(IMachine *machine, IUSBCommon **USBCommon) #endif } +static nsresult +_machineGetCPUCount(IMachine *machine, PRUint32 *CPUCount) +{ + return machine->vtbl->GetCPUCount(machine, CPUCount); +} + static nsresult _machineSetCPUCount(IMachine *machine, PRUint32 CPUCount) { return machine->vtbl->SetCPUCount(machine, CPUCount); } +static nsresult +_machineGetMemorySize(IMachine *machine, PRUint32 *memorySize) +{ + return machine->vtbl->GetMemorySize(machine, memorySize); +} + static nsresult _machineSetMemorySize(IMachine *machine, PRUint32 memorySize) { @@ -9829,6 +9761,12 @@ _systemPropertiesGetMaxDevicesPerPortForStorageBus(ISystemProperties *systemProp } #endif +static nsresult +_systemPropertiesGetMaxGuestRAM(ISystemProperties *systemProperties, PRUint32 *maxGuestRAM) +{ + return systemProperties->vtbl->GetMaxGuestRAM(systemProperties, maxGuestRAM); +} + static nsresult _biosSettingsSetACPIEnabled(IBIOSSettings *bios, PRBool ACPIEnabled) { @@ -10235,7 +10173,9 @@ static vboxUniformedIMachine _UIMachine = { .GetParallelPort = _machineGetParallelPort, .GetVRDxServer = _machineGetVRDxServer, .GetUSBCommon = _machineGetUSBCommon, + .GetCPUCount = _machineGetCPUCount, .SetCPUCount = _machineSetCPUCount, + .GetMemorySize = _machineGetMemorySize, .SetMemorySize = _machineSetMemorySize, .SetCPUProperty = _machineSetCPUProperty, .SetBootOrder = _machineSetBootOrder, @@ -10279,6 +10219,7 @@ static vboxUniformedISystemProperties _UISystemProperties = { .GetParallelPortCount = _systemPropertiesGetParallelPortCount, .GetMaxPortCountForStorageBus = _systemPropertiesGetMaxPortCountForStorageBus, .GetMaxDevicesPerPortForStorageBus = _systemPropertiesGetMaxDevicesPerPortForStorageBus, + .GetMaxGuestRAM = _systemPropertiesGetMaxGuestRAM, }; static vboxUniformedIBIOSSettings _UIBIOSSettings = { @@ -10363,6 +10304,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI) pVBoxAPI->unregisterMachine = _unregisterMachine; pVBoxAPI->deleteConfig = _deleteConfig; pVBoxAPI->vboxAttachDrivesOld = _vboxAttachDrivesOld; + pVBoxAPI->vboxConvertState = _vboxConvertState; pVBoxAPI->UPFN = _UPFN; pVBoxAPI->UIID = _UIID; pVBoxAPI->UArray = _UArray; diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index bc76904cc1180a50a44532bcc288c42f55100ff5..897e10c0542123a95a7d0ace6fff82bbd0cbbbdc 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -212,7 +212,9 @@ typedef struct { nsresult (*GetParallelPort)(IMachine *machine, PRUint32 slot, IParallelPort **port); nsresult (*GetVRDxServer)(IMachine *machine, IVRDxServer **VRDxServer); nsresult (*GetUSBCommon)(IMachine *machine, IUSBCommon **USBCommon); + nsresult (*GetCPUCount)(IMachine *machine, PRUint32 *CPUCount); nsresult (*SetCPUCount)(IMachine *machine, PRUint32 CPUCount); + nsresult (*GetMemorySize)(IMachine *machine, PRUint32 *memorySize); nsresult (*SetMemorySize)(IMachine *machine, PRUint32 memorySize); nsresult (*SetCPUProperty)(IMachine *machine, PRUint32 property, PRBool value); nsresult (*SetBootOrder)(IMachine *machine, PRUint32 position, PRUint32 device); @@ -263,6 +265,7 @@ typedef struct { PRUint32 *maxPortCount); nsresult (*GetMaxDevicesPerPortForStorageBus)(ISystemProperties *systemProperties, PRUint32 bus, PRUint32 *maxDevicesPerPort); + nsresult (*GetMaxGuestRAM)(ISystemProperties *systemProperties, PRUint32 *maxGuestRAM); } vboxUniformedISystemProperties; /* Functions for IBIOSSettings */ @@ -360,6 +363,7 @@ typedef struct { nsresult (*unregisterMachine)(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine **machine); void (*deleteConfig)(IMachine *machine); void (*vboxAttachDrivesOld)(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine); + virDomainState (*vboxConvertState)(PRUint32 state); vboxUniformedPFN UPFN; vboxUniformedIID UIID; vboxUniformedArray UArray; @@ -431,6 +435,7 @@ int vboxDomainDestroyFlags(virDomainPtr dom, unsigned int flags); int vboxDomainDestroy(virDomainPtr dom); char *vboxDomainGetOSType(virDomainPtr dom); int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory); +int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);