diff mbox

[RFC,V2,08/10] Qemu: Add save_before_stop callback to run just before stopping VCPU during migration

Message ID 1448372127-28115-9-git-send-email-tianyu.lan@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

lan,Tianyu Nov. 24, 2015, 1:35 p.m. UTC
This patch is to add a callback which is called just before stopping VCPU.
It's for VF migration to trigger mailbox irq as later as possible to
decrease service downtime.

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
---
 include/migration/vmstate.h |  3 +++
 include/sysemu/sysemu.h     |  1 +
 migration/migration.c       |  3 ++-
 migration/savevm.c          | 13 +++++++++++++
 4 files changed, 19 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index dc681a6..093faf1 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -58,6 +58,9 @@  typedef struct SaveVMHandlers {
 
     /* This runs after restoring CPU related state */
     void (*post_load_state)(void *opaque);
+
+    /* This runs before stopping VCPU */
+    void (*save_before_stop)(QEMUFile *f, void *opaque);
     LoadStateHandler *load_state;
 } SaveVMHandlers;
 
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index df80951..3d0d72c 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -84,6 +84,7 @@  void qemu_announce_self(void);
 bool qemu_savevm_state_blocked(Error **errp);
 void qemu_savevm_state_begin(QEMUFile *f,
                              const MigrationParams *params);
+void qemu_savevm_save_before_stop(QEMUFile *f);
 void qemu_savevm_state_header(QEMUFile *f);
 int qemu_savevm_state_iterate(QEMUFile *f);
 void qemu_savevm_state_complete(QEMUFile *f);
diff --git a/migration/migration.c b/migration/migration.c
index c6ac08a..fccadea 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -759,7 +759,6 @@  int64_t migrate_xbzrle_cache_size(void)
 }
 
 /* migration thread support */
-
 static void *migration_thread(void *opaque)
 {
     MigrationState *s = opaque;
@@ -788,6 +787,8 @@  static void *migration_thread(void *opaque)
             } else {
                 int ret;
 
+                qemu_savevm_save_before_stop(s->file);
+
                 qemu_mutex_lock_iothread();
                 start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
                 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
diff --git a/migration/savevm.c b/migration/savevm.c
index 48b6223..c2e4802 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -715,6 +715,19 @@  void qemu_savevm_post_load(void)
     }
 }
 
+void qemu_savevm_save_before_stop(QEMUFile *f)
+{
+    SaveStateEntry *se;
+
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
+        if (!se->ops || !se->ops->save_before_stop) {
+            continue;
+        }
+   
+        se->ops->save_before_stop(f, se->opaque);
+    }
+}
+
 
 void qemu_savevm_state_header(QEMUFile *f)
 {