mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
vbox: Rewrite vboxDomainSetMemory
This commit is contained in:
parent
0ba1c21471
commit
2cd7a218de
@ -2615,3 +2615,57 @@ char *vboxDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) {
|
||||
ignore_value(VIR_STRDUP(osType, "hvm"));
|
||||
return osType;
|
||||
}
|
||||
|
||||
int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory)
|
||||
{
|
||||
VBOX_OBJECT_CHECK(dom->conn, int, -1);
|
||||
IMachine *machine = NULL;
|
||||
vboxIIDUnion iid;
|
||||
PRUint32 state;
|
||||
PRBool isAccessible = PR_FALSE;
|
||||
nsresult rc;
|
||||
|
||||
if (openSessionForMachine(data, dom->uuid, &iid, &machine, false) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!machine)
|
||||
goto cleanup;
|
||||
|
||||
gVBoxAPI.UIMachine.GetAccessible(machine, &isAccessible);
|
||||
if (!isAccessible)
|
||||
goto cleanup;
|
||||
|
||||
gVBoxAPI.UIMachine.GetState(machine, &state);
|
||||
|
||||
if (!gVBoxAPI.machineStateChecker.PoweredOff(state)) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||
_("memory size can't be changed unless domain is powered down"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
rc = gVBoxAPI.UISession.Open(data, &iid, machine);
|
||||
if (NS_FAILED(rc))
|
||||
goto cleanup;
|
||||
|
||||
rc = gVBoxAPI.UISession.GetMachine(data->vboxSession, &machine);
|
||||
if (NS_SUCCEEDED(rc) && machine) {
|
||||
|
||||
rc = gVBoxAPI.UIMachine.SetMemorySize(machine,
|
||||
VIR_DIV_UP(memory, 1024));
|
||||
if (NS_SUCCEEDED(rc)) {
|
||||
gVBoxAPI.UIMachine.SaveSettings(machine);
|
||||
ret = 0;
|
||||
} else {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("could not set the memory size of the "
|
||||
"domain to: %lu Kb, rc=%08x"),
|
||||
memory, (unsigned)rc);
|
||||
}
|
||||
}
|
||||
gVBoxAPI.UISession.Close(data->vboxSession);
|
||||
|
||||
cleanup:
|
||||
VBOX_RELEASE(machine);
|
||||
vboxIIDUnalloc(&iid);
|
||||
return ret;
|
||||
}
|
||||
|
@ -933,63 +933,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16,
|
||||
return result;
|
||||
}
|
||||
|
||||
static int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory)
|
||||
{
|
||||
VBOX_OBJECT_CHECK(dom->conn, int, -1);
|
||||
IMachine *machine = NULL;
|
||||
vboxIID iid = VBOX_IID_INITIALIZER;
|
||||
PRUint32 state = MachineState_Null;
|
||||
PRBool isAccessible = PR_FALSE;
|
||||
nsresult rc;
|
||||
|
||||
vboxIIDFromUUID(&iid, dom->uuid);
|
||||
rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
|
||||
if (NS_FAILED(rc)) {
|
||||
virReportError(VIR_ERR_NO_DOMAIN,
|
||||
_("no domain with matching id %d"), dom->id);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!machine)
|
||||
goto cleanup;
|
||||
|
||||
machine->vtbl->GetAccessible(machine, &isAccessible);
|
||||
if (isAccessible) {
|
||||
machine->vtbl->GetState(machine, &state);
|
||||
|
||||
if (state != MachineState_PoweredOff) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||
_("memory size can't be changed unless domain is powered down"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
rc = VBOX_SESSION_OPEN(iid.value, machine);
|
||||
if (NS_SUCCEEDED(rc)) {
|
||||
rc = data->vboxSession->vtbl->GetMachine(data->vboxSession, &machine);
|
||||
if (NS_SUCCEEDED(rc) && machine) {
|
||||
|
||||
rc = machine->vtbl->SetMemorySize(machine,
|
||||
VIR_DIV_UP(memory, 1024));
|
||||
if (NS_SUCCEEDED(rc)) {
|
||||
machine->vtbl->SaveSettings(machine);
|
||||
ret = 0;
|
||||
} else {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("could not set the memory size of the "
|
||||
"domain to: %lu Kb, rc=%08x"),
|
||||
memory, (unsigned)rc);
|
||||
}
|
||||
}
|
||||
VBOX_SESSION_CLOSE();
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
VBOX_RELEASE(machine);
|
||||
vboxIIDUnalloc(&iid);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static virDomainState vboxConvertState(enum MachineState state)
|
||||
{
|
||||
switch (state) {
|
||||
|
@ -430,6 +430,7 @@ int vboxDomainReboot(virDomainPtr dom, unsigned int flags);
|
||||
int vboxDomainDestroyFlags(virDomainPtr dom, unsigned int flags);
|
||||
int vboxDomainDestroy(virDomainPtr dom);
|
||||
char *vboxDomainGetOSType(virDomainPtr dom);
|
||||
int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory);
|
||||
|
||||
/* Version specified functions for installing uniformed API */
|
||||
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
||||
|
Loading…
x
Reference in New Issue
Block a user