[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 8/9] qemu: Update domain status to paused while suspend event is emitted



This introduces a new paused reason VIR_DOMAIN_PAUSED_SUSPEND,
and new suspend event type VIR_DOMAIN_EVENT_SUSPENDED_SUSPEND.

While a SUSPEND event occurs, the running domain status will be
transferred to "paused" with reason "VIR_DOMAIN_PAUSED_SUSPEND",
and a new domain lifecycle event emitted with type
VIR_DOMAIN_EVENT_SUSPENDED_SUSPEND.
---
 examples/domain-events/events-c/event-test.c |    3 +++
 include/libvirt/libvirt.h.in                 |    2 ++
 src/qemu/qemu_process.c                      |   23 +++++++++++++++++++++++
 tools/virsh.c                                |    2 ++
 4 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c
index 1629358..9231604 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -115,6 +115,9 @@ static const char *eventDetailToString(int event, int detail) {
             case VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT:
                 ret = "Snapshot";
                 break;
+            case VIR_DOMAIN_EVENT_SUSPENDED_SUSPEND:
+                ret = "Event suspend";
+                break;
             }
             break;
         case VIR_DOMAIN_EVENT_RESUMED:
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index aa02bcb..11b7388 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -145,6 +145,7 @@ typedef enum {
     VIR_DOMAIN_PAUSED_WATCHDOG = 6,     /* paused due to a watchdog event */
     VIR_DOMAIN_PAUSED_FROM_SNAPSHOT = 7, /* paused after restoring from snapshot */
     VIR_DOMAIN_PAUSED_SHUTTING_DOWN = 8, /* paused during shutdown process */
+    VIR_DOMAIN_PAUSED_SUSPEND = 9,       /* paused due to a suspend event */
 
 #ifdef VIR_ENUM_SENTINELS
     VIR_DOMAIN_PAUSED_LAST
@@ -2682,6 +2683,7 @@ typedef enum {
     VIR_DOMAIN_EVENT_SUSPENDED_WATCHDOG = 3,  /* Suspended due to a watchdog firing */
     VIR_DOMAIN_EVENT_SUSPENDED_RESTORED = 4,  /* Restored from paused state file */
     VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT = 5, /* Restored from paused snapshot */
+    VIR_DOMAIN_EVENT_SUSPENDED_SUSPEND = 6, /* Suspended due to a suspend event */
 
 #ifdef VIR_ENUM_SENTINELS
     VIR_DOMAIN_EVENT_SUSPENDED_LAST
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 2cff63e..19e6e03 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1085,10 +1085,33 @@ qemuProcessHandleSuspend(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
 {
     struct qemud_driver *driver = qemu_driver;
     virDomainEventPtr event = NULL;
+    virDomainEventPtr lifecycleEvent = NULL;
 
     virDomainObjLock(vm);
     event = virDomainEventSuspendNewFromObj(vm);
 
+    if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
+        qemuDomainObjPrivatePtr priv = vm->privateData;
+        VIR_DEBUG("Transitioned guest %s to paused state due to "
+                  "QMP suspend event", vm->def->name);
+
+        virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
+                             VIR_DOMAIN_PAUSED_SUSPEND);
+        lifecycleEvent = virDomainEventNewFromObj(vm,
+                                                  VIR_DOMAIN_EVENT_SUSPENDED,
+                                                  VIR_DOMAIN_EVENT_SUSPENDED_SUSPEND);
+
+        VIR_FREE(priv->lockState);
+        if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState) < 0)
+            VIR_WARN("Unable to release lease on %s", vm->def->name);
+        VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState));
+
+        if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) {
+            VIR_WARN("Unable to save status on vm %s after suspend event",
+                     vm->def->name);
+        }
+    }
+
     virDomainObjUnlock(vm);
 
     if (event) {
diff --git a/tools/virsh.c b/tools/virsh.c
index aef050f..9063131 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -18628,6 +18628,8 @@ vshDomainStateReasonToString(int state, int reason)
             return N_("from snapshot");
         case VIR_DOMAIN_PAUSED_SHUTTING_DOWN:
             return N_("shutting down");
+        case VIR_DOMAIN_PAUSED_SUSPEND:
+            return N_("Event suspend");
         case VIR_DOMAIN_PAUSED_UNKNOWN:
         case VIR_DOMAIN_PAUSED_LAST:
             ;
-- 
1.7.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]