migration: run setup callbacks out of big lock
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 22 Feb 2013 16:36:28 +0000 (17:36 +0100)
committerJuan Quintela <quintela@redhat.com>
Mon, 11 Mar 2013 12:32:01 +0000 (13:32 +0100)
Only the migration_bitmap_sync() call needs the iothread lock.

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
arch_init.c
block-migration.c
include/migration/vmstate.h
migration.c
savevm.c

index 32b437897c5ead389056ecb02922b5ed0fa19cc9..6089c5338660df0ee1a9316d2e7a9472155034dc 100644 (file)
@@ -570,10 +570,6 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
     bitmap_set(migration_bitmap, 0, ram_pages);
     migration_dirty_pages = ram_pages;
 
-    qemu_mutex_lock_ramlist();
-    bytes_transferred = 0;
-    reset_ram_globals();
-
     if (migrate_use_xbzrle()) {
         XBZRLE.cache = cache_init(migrate_xbzrle_cache_size() /
                                   TARGET_PAGE_SIZE,
@@ -587,8 +583,14 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
         acct_clear();
     }
 
+    qemu_mutex_lock_iothread();
+    qemu_mutex_lock_ramlist();
+    bytes_transferred = 0;
+    reset_ram_globals();
+
     memory_global_dirty_log_start();
     migration_bitmap_sync();
+    qemu_mutex_unlock_iothread();
 
     qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE);
 
index 8da5f868afac07431d960d67a1e8e22c9da5e173..2fd76997945cf513b76f301f1d0a7b6f0fdeacad 100644 (file)
@@ -583,10 +583,12 @@ static int block_save_setup(QEMUFile *f, void *opaque)
     DPRINTF("Enter save live setup submitted %d transferred %d\n",
             block_mig_state.submitted, block_mig_state.transferred);
 
+    qemu_mutex_lock_iothread();
     init_blk_migration(f);
 
     /* start track dirty blocks */
     set_dirty_tracking(1);
+    qemu_mutex_unlock_iothread();
 
     ret = flush_blks(f);
     blk_mig_reset_dirty_cursor();
index a816ac324373a889d0f364b2f499d6ae5c4c4010..a64db941bc0d1d7d44af05e7c0758c9e502b95b6 100644 (file)
@@ -36,7 +36,6 @@ typedef struct SaveVMHandlers {
     void (*set_params)(const MigrationParams *params, void * opaque);
     SaveStateHandler *save_state;
 
-    int (*save_live_setup)(QEMUFile *f, void *opaque);
     void (*cancel)(void *opaque);
     int (*save_live_complete)(QEMUFile *f, void *opaque);
 
@@ -51,6 +50,7 @@ typedef struct SaveVMHandlers {
     int (*save_live_iterate)(QEMUFile *f, void *opaque);
 
     /* This runs outside the iothread lock!  */
+    int (*save_live_setup)(QEMUFile *f, void *opaque);
     uint64_t (*save_live_pending)(QEMUFile *f, void *opaque, uint64_t max_size);
 
     LoadStateHandler *load_state;
index 92a7152d67b39454f1ce15d5b67cd172620f8844..e64c92d75b70d5b2dc953d54fb9815fe7b25a620 100644 (file)
@@ -660,10 +660,8 @@ static void *buffered_file_thread(void *opaque)
     bool old_vm_running = false;
     bool last_round = false;
 
-    qemu_mutex_lock_iothread();
     DPRINTF("beginning savevm\n");
     qemu_savevm_state_begin(s->file, &s->params);
-    qemu_mutex_unlock_iothread();
 
     while (s->state == MIG_STATE_ACTIVE) {
         int64_t current_time;
index e10a045df662aaf6b36240b3f59e5dd60ac9d2b8..7c7774e932d4b331573131ee7a430312da47a830 100644 (file)
--- a/savevm.c
+++ b/savevm.c
@@ -1768,7 +1768,10 @@ static int qemu_savevm_state(QEMUFile *f)
         return -EINVAL;
     }
 
+    qemu_mutex_unlock_iothread();
     qemu_savevm_state_begin(f, &params);
+    qemu_mutex_lock_iothread();
+
     while (qemu_file_get_error(f) == 0) {
         if (qemu_savevm_state_iterate(f) > 0) {
             break;