hyperv: implement domainReboot and domainReset

Co-authored-by: Sri Ramanujam <sramanujam@datto.com>
Signed-off-by: Matt Coleman <matt@datto.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Matt Coleman 2020-10-21 04:46:09 -04:00 committed by Michal Privoznik
parent 7bf302fb63
commit 8943b14838
2 changed files with 44 additions and 0 deletions

View File

@ -287,6 +287,29 @@ hypervGetMemSDByVSSDInstanceId(hypervPrivate *priv, const char *id,
}
static int
hypervRequestStateChange(virDomainPtr domain, int state)
{
int result = -1;
hypervPrivate *priv = domain->conn->privateData;
Msvm_ComputerSystem *computerSystem = NULL;
if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0)
goto cleanup;
if (computerSystem->data.common->EnabledState != MSVM_COMPUTERSYSTEM_ENABLEDSTATE_ENABLED) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not active"));
goto cleanup;
}
result = hypervInvokeMsvmComputerSystemRequestStateChange(domain, state);
cleanup:
hypervFreeObject(priv, (hypervObject *)computerSystem);
return result;
}
/*
* API-specific utility functions
@ -923,6 +946,24 @@ hypervDomainResume(virDomainPtr domain)
static int
hypervDomainReboot(virDomainPtr domain, unsigned int flags)
{
virCheckFlags(0, -1);
return hypervRequestStateChange(domain, MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_REBOOT);
}
static int
hypervDomainReset(virDomainPtr domain, unsigned int flags)
{
virCheckFlags(0, -1);
return hypervRequestStateChange(domain, MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_RESET);
}
static int
hypervDomainDestroyFlags(virDomainPtr domain, unsigned int flags)
{
@ -1953,6 +1994,8 @@ static virHypervisorDriver hypervHypervisorDriver = {
.domainLookupByName = hypervDomainLookupByName, /* 0.9.5 */
.domainSuspend = hypervDomainSuspend, /* 0.9.5 */
.domainResume = hypervDomainResume, /* 0.9.5 */
.domainReboot = hypervDomainReboot, /* 6.9.0 */
.domainReset = hypervDomainReset, /* 6.9.0 */
.domainDestroy = hypervDomainDestroy, /* 0.9.5 */
.domainDestroyFlags = hypervDomainDestroyFlags, /* 0.9.5 */
.domainGetOSType = hypervDomainGetOSType, /* 0.9.5 */

View File

@ -74,6 +74,7 @@ enum _Msvm_ComputerSystem_RequestedState {
MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_ENABLED = 2,
MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_DISABLED = 3,
MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_REBOOT = 10,
MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_RESET = 11,
MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_PAUSED = 32768,
MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_SUSPENDED = 32769,
};