mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
vbox: Rewrite vboxDomainDestroyFlags
This commit is contained in:
parent
14babb4981
commit
25d807d42a
@ -2553,3 +2553,48 @@ int vboxDomainReboot(virDomainPtr dom, unsigned int flags)
|
||||
vboxIIDUnalloc(&iid);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vboxDomainDestroyFlags(virDomainPtr dom, unsigned int flags)
|
||||
{
|
||||
VBOX_OBJECT_CHECK(dom->conn, int, -1);
|
||||
IMachine *machine = NULL;
|
||||
vboxIIDUnion iid;
|
||||
IConsole *console = NULL;
|
||||
PRUint32 state;
|
||||
PRBool isAccessible = PR_FALSE;
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
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",
|
||||
_("machine already powered down"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
gVBoxAPI.UISession.OpenExisting(data, &iid, machine);
|
||||
gVBoxAPI.UISession.GetConsole(data->vboxSession, &console);
|
||||
if (console) {
|
||||
gVBoxAPI.UIConsole.PowerDown(console);
|
||||
VBOX_RELEASE(console);
|
||||
dom->id = -1;
|
||||
ret = 0;
|
||||
}
|
||||
gVBoxAPI.UISession.Close(data->vboxSession);
|
||||
|
||||
cleanup:
|
||||
VBOX_RELEASE(machine);
|
||||
vboxIIDUnalloc(&iid);
|
||||
return ret;
|
||||
}
|
||||
|
@ -933,68 +933,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16,
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
vboxDomainDestroyFlags(virDomainPtr dom,
|
||||
unsigned int flags)
|
||||
{
|
||||
VBOX_OBJECT_CHECK(dom->conn, int, -1);
|
||||
IMachine *machine = NULL;
|
||||
vboxIID iid = VBOX_IID_INITIALIZER;
|
||||
IConsole *console = NULL;
|
||||
PRUint32 state = MachineState_Null;
|
||||
PRBool isAccessible = PR_FALSE;
|
||||
nsresult rc;
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
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",
|
||||
_("machine already powered down"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
|
||||
data->vboxSession->vtbl->GetConsole(data->vboxSession, &console);
|
||||
if (console) {
|
||||
|
||||
#if VBOX_API_VERSION == 2002000
|
||||
console->vtbl->PowerDown(console);
|
||||
#else
|
||||
IProgress *progress = NULL;
|
||||
console->vtbl->PowerDown(console, &progress);
|
||||
if (progress) {
|
||||
progress->vtbl->WaitForCompletion(progress, -1);
|
||||
VBOX_RELEASE(progress);
|
||||
}
|
||||
#endif
|
||||
VBOX_RELEASE(console);
|
||||
dom->id = -1;
|
||||
ret = 0;
|
||||
}
|
||||
VBOX_SESSION_CLOSE();
|
||||
}
|
||||
|
||||
cleanup:
|
||||
VBOX_RELEASE(machine);
|
||||
vboxIIDUnalloc(&iid);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
vboxDomainDestroy(virDomainPtr dom)
|
||||
{
|
||||
@ -9849,6 +9787,23 @@ _consolePowerButton(IConsole *console)
|
||||
return console->vtbl->PowerButton(console);
|
||||
}
|
||||
|
||||
static nsresult
|
||||
_consolePowerDown(IConsole *console)
|
||||
{
|
||||
nsresult rc;
|
||||
#if VBOX_API_VERSION == 2002000
|
||||
rc = console->vtbl->PowerDown(console);
|
||||
#else
|
||||
IProgress *progress = NULL;
|
||||
rc = console->vtbl->PowerDown(console, &progress);
|
||||
if (progress) {
|
||||
rc = progress->vtbl->WaitForCompletion(progress, -1);
|
||||
VBOX_RELEASE(progress);
|
||||
}
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
_consoleReset(IConsole *console)
|
||||
{
|
||||
@ -10381,6 +10336,7 @@ static vboxUniformedIConsole _UIConsole = {
|
||||
.Pause = _consolePause,
|
||||
.Resume = _consoleResume,
|
||||
.PowerButton = _consolePowerButton,
|
||||
.PowerDown = _consolePowerDown,
|
||||
.Reset = _consoleReset,
|
||||
};
|
||||
|
||||
|
@ -240,6 +240,7 @@ typedef struct {
|
||||
nsresult (*Pause)(IConsole *console);
|
||||
nsresult (*Resume)(IConsole *console);
|
||||
nsresult (*PowerButton)(IConsole *console);
|
||||
nsresult (*PowerDown)(IConsole *console);
|
||||
nsresult (*Reset)(IConsole *console);
|
||||
} vboxUniformedIConsole;
|
||||
|
||||
@ -426,6 +427,7 @@ int vboxDomainResume(virDomainPtr dom);
|
||||
int vboxDomainShutdownFlags(virDomainPtr dom, unsigned int flags);
|
||||
int vboxDomainShutdown(virDomainPtr dom);
|
||||
int vboxDomainReboot(virDomainPtr dom, unsigned int flags);
|
||||
int vboxDomainDestroyFlags(virDomainPtr dom, unsigned int flags);
|
||||
|
||||
/* Version specified functions for installing uniformed API */
|
||||
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
||||
|
Loading…
Reference in New Issue
Block a user