[PATCH v3 7/9] hyperv: fix domainSuspend and domainResume on Hyper-V V2

Matt Coleman mcoleman at datto.com
Wed Oct 21 08:46:11 UTC 2020


Signed-off-by: Matt Coleman <matt at datto.com>
---
 src/hyperv/hyperv_driver.c      | 34 ++++++++++++++++++++++++---------
 src/hyperv/hyperv_wmi_classes.h |  1 +
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 791f34444d..4c70af6496 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -891,19 +891,26 @@ hypervDomainSuspend(virDomainPtr domain)
     int result = -1;
     hypervPrivate *priv = domain->conn->privateData;
     Msvm_ComputerSystem *computerSystem = NULL;
+    int requestedState;
+
+    switch (priv->wmiVersion) {
+    case HYPERV_WMI_VERSION_V1:
+        requestedState = MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_PAUSED;
+        break;
+    case HYPERV_WMI_VERSION_V2:
+        requestedState = MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_QUIESCE;
+        break;
+    }
 
     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"));
+    if (computerSystem->data.common->EnabledState != MSVM_COMPUTERSYSTEM_ENABLEDSTATE_ENABLED) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not active"));
         goto cleanup;
     }
 
-    result = hypervInvokeMsvmComputerSystemRequestStateChange
-               (domain, MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_PAUSED);
+    result = hypervInvokeMsvmComputerSystemRequestStateChange(domain, requestedState);
 
  cleanup:
     hypervFreeObject(priv, (hypervObject *)computerSystem);
@@ -919,12 +926,21 @@ hypervDomainResume(virDomainPtr domain)
     int result = -1;
     hypervPrivate *priv = domain->conn->privateData;
     Msvm_ComputerSystem *computerSystem = NULL;
+    int expectedState;
+
+    switch (priv->wmiVersion) {
+    case HYPERV_WMI_VERSION_V1:
+        expectedState = MSVM_COMPUTERSYSTEM_ENABLEDSTATE_PAUSED;
+        break;
+    case HYPERV_WMI_VERSION_V2:
+        expectedState = MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_QUIESCE;
+        break;
+    }
 
     if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0)
-        goto cleanup;
+        return -1;
 
-    if (computerSystem->data.common->EnabledState !=
-        MSVM_COMPUTERSYSTEM_ENABLEDSTATE_PAUSED) {
+    if (computerSystem->data.common->EnabledState != expectedState) {
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                        _("Domain is not paused"));
         goto cleanup;
diff --git a/src/hyperv/hyperv_wmi_classes.h b/src/hyperv/hyperv_wmi_classes.h
index 7f4159dd8e..0074d8889e 100644
--- a/src/hyperv/hyperv_wmi_classes.h
+++ b/src/hyperv/hyperv_wmi_classes.h
@@ -73,6 +73,7 @@ enum _Msvm_ComputerSystem_EnabledState {
 enum _Msvm_ComputerSystem_RequestedState {
     MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_ENABLED = 2,
     MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_DISABLED = 3,
+    MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_QUIESCE = 9,
     MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_REBOOT = 10,
     MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_RESET = 11,
     MSVM_COMPUTERSYSTEM_REQUESTEDSTATE_PAUSED = 32768,
-- 
2.27.0





More information about the libvir-list mailing list