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

vbox: Rewrite vboxDomainSuspend

上级 caba5247
...@@ -2362,3 +2362,50 @@ int vboxDomainIsUpdated(virDomainPtr dom) ...@@ -2362,3 +2362,50 @@ int vboxDomainIsUpdated(virDomainPtr dom)
vboxIIDUnalloc(&iid); vboxIIDUnalloc(&iid);
return ret; return ret;
} }
int vboxDomainSuspend(virDomainPtr dom)
{
VBOX_OBJECT_CHECK(dom->conn, int, -1);
IMachine *machine = NULL;
vboxIIDUnion iid;
IConsole *console = NULL;
PRBool isAccessible = PR_FALSE;
PRUint32 state;
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.Running(state)) {
/* set state pause */
gVBoxAPI.UISession.OpenExisting(data, &iid, machine);
gVBoxAPI.UISession.GetConsole(data->vboxSession, &console);
if (console) {
gVBoxAPI.UIConsole.Pause(console);
VBOX_RELEASE(console);
ret = 0;
} else {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("error while suspending the domain"));
goto cleanup;
}
gVBoxAPI.UISession.Close(data->vboxSession);
} else {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("machine not in running state to suspend it"));
goto cleanup;
}
cleanup:
VBOX_RELEASE(machine);
vboxIIDUnalloc(&iid);
return ret;
}
...@@ -933,58 +933,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16, ...@@ -933,58 +933,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16,
return result; return result;
} }
static int vboxDomainSuspend(virDomainPtr dom)
{
VBOX_OBJECT_CHECK(dom->conn, int, -1);
IMachine *machine = NULL;
vboxIID iid = VBOX_IID_INITIALIZER;
IConsole *console = NULL;
PRBool isAccessible = PR_FALSE;
PRUint32 state;
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_Running) {
/* set state pause */
VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
data->vboxSession->vtbl->GetConsole(data->vboxSession, &console);
if (console) {
console->vtbl->Pause(console);
VBOX_RELEASE(console);
ret = 0;
} else {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("error while suspending the domain"));
goto cleanup;
}
VBOX_SESSION_CLOSE();
} else {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("machine not in running state to suspend it"));
goto cleanup;
}
}
cleanup:
VBOX_RELEASE(machine);
vboxIIDUnalloc(&iid);
return ret;
}
static int vboxDomainResume(virDomainPtr dom) static int vboxDomainResume(virDomainPtr dom)
{ {
VBOX_OBJECT_CHECK(dom->conn, int, -1); VBOX_OBJECT_CHECK(dom->conn, int, -1);
...@@ -10045,6 +9993,12 @@ _consoleSaveState(IConsole *console, IProgress **progress) ...@@ -10045,6 +9993,12 @@ _consoleSaveState(IConsole *console, IProgress **progress)
return console->vtbl->SaveState(console, progress); return console->vtbl->SaveState(console, progress);
} }
static nsresult
_consolePause(IConsole *console)
{
return console->vtbl->Pause(console);
}
static nsresult static nsresult
_progressWaitForCompletion(IProgress *progress, PRInt32 timeout) _progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
{ {
...@@ -10473,6 +10427,11 @@ static bool _machineStateNotStart(PRUint32 state) ...@@ -10473,6 +10427,11 @@ static bool _machineStateNotStart(PRUint32 state)
(state == MachineState_Aborted)); (state == MachineState_Aborted));
} }
static bool _machineStateRunning(PRUint32 state)
{
return state == MachineState_Running;
}
static vboxUniformedPFN _UPFN = { static vboxUniformedPFN _UPFN = {
.Initialize = _pfnInitialize, .Initialize = _pfnInitialize,
.Uninitialize = _pfnUninitialize, .Uninitialize = _pfnUninitialize,
...@@ -10553,6 +10512,7 @@ static vboxUniformedISession _UISession = { ...@@ -10553,6 +10512,7 @@ static vboxUniformedISession _UISession = {
static vboxUniformedIConsole _UIConsole = { static vboxUniformedIConsole _UIConsole = {
.SaveState = _consoleSaveState, .SaveState = _consoleSaveState,
.Pause = _consolePause,
}; };
static vboxUniformedIProgress _UIProgress = { static vboxUniformedIProgress _UIProgress = {
...@@ -10638,6 +10598,7 @@ static vboxUniformedIMedium _UIMedium = { ...@@ -10638,6 +10598,7 @@ static vboxUniformedIMedium _UIMedium = {
static uniformedMachineStateChecker _machineStateChecker = { static uniformedMachineStateChecker _machineStateChecker = {
.Online = _machineStateOnline, .Online = _machineStateOnline,
.NotStart = _machineStateNotStart, .NotStart = _machineStateNotStart,
.Running = _machineStateRunning,
}; };
void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI) void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
......
...@@ -237,6 +237,7 @@ typedef struct { ...@@ -237,6 +237,7 @@ typedef struct {
/* Functions for IConsole */ /* Functions for IConsole */
typedef struct { typedef struct {
nsresult (*SaveState)(IConsole *console, IProgress **progress); nsresult (*SaveState)(IConsole *console, IProgress **progress);
nsresult (*Pause)(IConsole *console);
} vboxUniformedIConsole; } vboxUniformedIConsole;
/* Functions for IProgress */ /* Functions for IProgress */
...@@ -339,6 +340,7 @@ typedef struct { ...@@ -339,6 +340,7 @@ typedef struct {
typedef struct { typedef struct {
bool (*Online)(PRUint32 state); bool (*Online)(PRUint32 state);
bool (*NotStart)(PRUint32 state); bool (*NotStart)(PRUint32 state);
bool (*Running)(PRUint32 state);
} uniformedMachineStateChecker; } uniformedMachineStateChecker;
typedef struct { typedef struct {
...@@ -414,6 +416,7 @@ virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml, ...@@ -414,6 +416,7 @@ virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
int vboxDomainIsActive(virDomainPtr dom); int vboxDomainIsActive(virDomainPtr dom);
int vboxDomainIsPersistent(virDomainPtr dom); int vboxDomainIsPersistent(virDomainPtr dom);
int vboxDomainIsUpdated(virDomainPtr dom); int vboxDomainIsUpdated(virDomainPtr dom);
int vboxDomainSuspend(virDomainPtr dom);
/* 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.
先完成此消息的编辑!
想要评论请 注册