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

vbox: Rewrite vboxDomainSetMemory

上级 0ba1c214
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册