[libvirt] [PATCH] qemu: forbid suspend if already pmsuspended

Michal Privoznik mprivozn at redhat.com
Thu Aug 23 13:31:31 UTC 2012


If a domain is pmsuspended then virsh suspend will succeed. Beside
obvious flaw, virsh resume will report success and change domain
state to running which is another mistake. Therefore we must forbid
any attempts for suspend and resume when pmsuspended.
---
 src/libvirt.c          |    4 ++++
 src/qemu/qemu_driver.c |   18 ++++++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index e0ac391..b034ed6 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -2329,6 +2329,8 @@ virDomainRef(virDomainPtr domain)
  * hypervisor level will stay allocated. Use virDomainResume() to reactivate
  * the domain.
  * This function may require privileged access.
+ * Moreover, suspend may not be supported if domain is in some
+ * special state like VIR_DOMAIN_PMSUSPENDED.
  *
  * Returns 0 in case of success and -1 in case of failure.
  */
@@ -2375,6 +2377,8 @@ error:
  * Resume a suspended domain, the process is restarted from the state where
  * it was frozen by calling virDomainSuspend().
  * This function may require privileged access
+ * Moreover, resume may not be supported if domain is in some
+ * special state like VIR_DOMAIN_PMSUSPENDED.
  *
  * Returns 0 in case of success and -1 in case of failure.
  */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8c7b34d..256fa71 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1572,6 +1572,7 @@ static int qemudDomainSuspend(virDomainPtr dom) {
     qemuDomainObjPrivatePtr priv;
     virDomainPausedReason reason;
     int eventDetail;
+    int state;
 
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -1607,7 +1608,13 @@ static int qemudDomainSuspend(virDomainPtr dom) {
                        "%s", _("domain is not running"));
         goto endjob;
     }
-    if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) {
+
+    state = virDomainObjGetState(vm, NULL);
+    if (state == VIR_DOMAIN_PMSUSPENDED) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       "%s", _("domain is pmsuspended"));
+        goto endjob;
+    } else if (state != VIR_DOMAIN_PAUSED) {
         if (qemuProcessStopCPUs(driver, vm, reason, QEMU_ASYNC_JOB_NONE) < 0) {
             goto endjob;
         }
@@ -1639,6 +1646,7 @@ static int qemudDomainResume(virDomainPtr dom) {
     virDomainObjPtr vm;
     int ret = -1;
     virDomainEventPtr event = NULL;
+    int state;
 
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -1659,7 +1667,13 @@ static int qemudDomainResume(virDomainPtr dom) {
                        "%s", _("domain is not running"));
         goto endjob;
     }
-    if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
+
+    state = virDomainObjGetState(vm, NULL);
+    if (state == VIR_DOMAIN_PMSUSPENDED) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       "%s", _("domain is pmsuspended"));
+        goto endjob;
+    } else if (state == VIR_DOMAIN_PAUSED) {
         if (qemuProcessStartCPUs(driver, vm, dom->conn,
                                  VIR_DOMAIN_RUNNING_UNPAUSED,
                                  QEMU_ASYNC_JOB_NONE) < 0) {
-- 
1.7.8.6




More information about the libvir-list mailing list