diff options
author | Peter Xu <peterx@redhat.com> | 2018-05-02 18:47:38 +0800 |
---|---|---|
committer | Juan Quintela <quintela@redhat.com> | 2018-05-15 22:12:41 +0200 |
commit | 62df066ffffdbd41b42ca91130611e40fbc53f0b (patch) | |
tree | b834f0b0dc36054f7a883be9a3a8e10ea66dec32 /migration/migration.c | |
parent | 3b563c4be01f42d2a4e641d50736bd5ac8e3b15f (diff) |
migration: introduce lock for to_dst_file
Let's introduce a lock for that QEMUFile since we are going to operate
on it in multiple threads.
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20180502104740.12123-23-peterx@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Diffstat (limited to 'migration/migration.c')
-rw-r--r-- | migration/migration.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/migration/migration.c b/migration/migration.c index 1beb5e07fb..3deded90e5 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1234,6 +1234,7 @@ static void migrate_fd_cleanup(void *opaque) if (s->to_dst_file) { Error *local_err = NULL; + QEMUFile *tmp; trace_migrate_fd_cleanup(); qemu_mutex_unlock_iothread(); @@ -1246,8 +1247,15 @@ static void migrate_fd_cleanup(void *opaque) if (multifd_save_cleanup(&local_err) != 0) { error_report_err(local_err); } - qemu_fclose(s->to_dst_file); + qemu_mutex_lock(&s->qemu_file_lock); + tmp = s->to_dst_file; s->to_dst_file = NULL; + qemu_mutex_unlock(&s->qemu_file_lock); + /* + * Close the file handle without the lock to make sure the + * critical section won't block for long. + */ + qemu_fclose(tmp); } assert((s->state != MIGRATION_STATUS_ACTIVE) && @@ -2531,14 +2539,20 @@ static MigThrError postcopy_pause(MigrationState *s) assert(s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE); while (true) { + QEMUFile *file; + migrate_set_state(&s->state, s->state, MIGRATION_STATUS_POSTCOPY_PAUSED); /* Current channel is possibly broken. Release it. */ assert(s->to_dst_file); - qemu_file_shutdown(s->to_dst_file); - qemu_fclose(s->to_dst_file); + qemu_mutex_lock(&s->qemu_file_lock); + file = s->to_dst_file; s->to_dst_file = NULL; + qemu_mutex_unlock(&s->qemu_file_lock); + + qemu_file_shutdown(file); + qemu_fclose(file); error_report("Detected IO failure for postcopy. " "Migration paused."); @@ -3007,6 +3021,7 @@ static void migration_instance_finalize(Object *obj) MigrationParameters *params = &ms->parameters; qemu_mutex_destroy(&ms->error_mutex); + qemu_mutex_destroy(&ms->qemu_file_lock); g_free(params->tls_hostname); g_free(params->tls_creds); qemu_sem_destroy(&ms->pause_sem); @@ -3046,6 +3061,7 @@ static void migration_instance_init(Object *obj) qemu_sem_init(&ms->postcopy_pause_sem, 0); qemu_sem_init(&ms->postcopy_pause_rp_sem, 0); qemu_sem_init(&ms->rp_state.rp_sem, 0); + qemu_mutex_init(&ms->qemu_file_lock); } /* |