From: Daniel Henrique Barboza <danielhb...@gmail.com>

If the current QEMU guest can't wake up from suspend properly,
avoid suspending the guest at all. This is done by checking the
QEMU_CAPS_PM_WAKEUP_SUPPORT cap.

The absence of the cap indicates that we're dealing with a QEMU
version older than 4.0 (which implements the required QMP API).
In this case, proceed as usual with the suspend logic since
we can't assume whether the guest has support or not.

Fixes: https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1759509
Reported-by: Balamuruhan S <bal...@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb...@gmail.com>
Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
---
 src/qemu/qemu_driver.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fe2c586274..c4bd53677d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -19151,6 +19151,7 @@ qemuDomainPMSuspendForDuration(virDomainPtr dom,
                                unsigned int flags)
 {
     virQEMUDriverPtr driver = dom->conn->privateData;
+    qemuDomainObjPrivatePtr priv;
     virDomainObjPtr vm;
     qemuAgentPtr agent;
     int ret = -1;
@@ -19178,6 +19179,26 @@ qemuDomainPMSuspendForDuration(virDomainPtr dom,
     if (virDomainPMSuspendForDurationEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
+    priv = vm->privateData;
+
+    /*
+     * We can't check just for QEMU_CAPS_WAKEUP_SUSPEND_SUPPORT because,
+     * in case this cap is disabled, it is not possible to tell if the guest
+     * does not have wake-up from suspend support or if the current QEMU
+     * instance does not have the API.
+     *
+     * The case we want to handle here is when QEMU has the API and
+     * QEMU_CAPS_WAKEUP_SUSPEND_SUPPORT cap is disabled. Otherwise, do
+     * not interfere with the suspend process.
+     */
+    if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_QUERY_CURRENT_MACHINE) &&
+        !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_PM_WAKEUP_SUPPORT)) {
+
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                       _("Domain does not have suspend support"));
+        goto cleanup;
+    }
+
     if (qemuDomainObjBeginAgentJob(driver, vm, QEMU_AGENT_JOB_MODIFY) < 0)
         goto cleanup;
 
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to