mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-11-08 22:39:56 +00:00
vbox: Rewrite vboxDomainSuspend
This commit is contained in:
parent
caba5247fd
commit
8b89505a20
@ -2362,3 +2362,50 @@ int vboxDomainIsUpdated(virDomainPtr dom)
|
||||
vboxIIDUnalloc(&iid);
|
||||
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,
|
||||
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)
|
||||
{
|
||||
VBOX_OBJECT_CHECK(dom->conn, int, -1);
|
||||
@ -10045,6 +9993,12 @@ _consoleSaveState(IConsole *console, IProgress **progress)
|
||||
return console->vtbl->SaveState(console, progress);
|
||||
}
|
||||
|
||||
static nsresult
|
||||
_consolePause(IConsole *console)
|
||||
{
|
||||
return console->vtbl->Pause(console);
|
||||
}
|
||||
|
||||
static nsresult
|
||||
_progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
|
||||
{
|
||||
@ -10473,6 +10427,11 @@ static bool _machineStateNotStart(PRUint32 state)
|
||||
(state == MachineState_Aborted));
|
||||
}
|
||||
|
||||
static bool _machineStateRunning(PRUint32 state)
|
||||
{
|
||||
return state == MachineState_Running;
|
||||
}
|
||||
|
||||
static vboxUniformedPFN _UPFN = {
|
||||
.Initialize = _pfnInitialize,
|
||||
.Uninitialize = _pfnUninitialize,
|
||||
@ -10553,6 +10512,7 @@ static vboxUniformedISession _UISession = {
|
||||
|
||||
static vboxUniformedIConsole _UIConsole = {
|
||||
.SaveState = _consoleSaveState,
|
||||
.Pause = _consolePause,
|
||||
};
|
||||
|
||||
static vboxUniformedIProgress _UIProgress = {
|
||||
@ -10638,6 +10598,7 @@ static vboxUniformedIMedium _UIMedium = {
|
||||
static uniformedMachineStateChecker _machineStateChecker = {
|
||||
.Online = _machineStateOnline,
|
||||
.NotStart = _machineStateNotStart,
|
||||
.Running = _machineStateRunning,
|
||||
};
|
||||
|
||||
void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
|
||||
|
@ -237,6 +237,7 @@ typedef struct {
|
||||
/* Functions for IConsole */
|
||||
typedef struct {
|
||||
nsresult (*SaveState)(IConsole *console, IProgress **progress);
|
||||
nsresult (*Pause)(IConsole *console);
|
||||
} vboxUniformedIConsole;
|
||||
|
||||
/* Functions for IProgress */
|
||||
@ -339,6 +340,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
bool (*Online)(PRUint32 state);
|
||||
bool (*NotStart)(PRUint32 state);
|
||||
bool (*Running)(PRUint32 state);
|
||||
} uniformedMachineStateChecker;
|
||||
|
||||
typedef struct {
|
||||
@ -414,6 +416,7 @@ virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
|
||||
int vboxDomainIsActive(virDomainPtr dom);
|
||||
int vboxDomainIsPersistent(virDomainPtr dom);
|
||||
int vboxDomainIsUpdated(virDomainPtr dom);
|
||||
int vboxDomainSuspend(virDomainPtr dom);
|
||||
|
||||
/* Version specified functions for installing uniformed API */
|
||||
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
||||
|
Loading…
Reference in New Issue
Block a user