if (s->to_dst_file) {
Error *local_err = NULL;
+ QEMUFile *tmp;
trace_migrate_fd_cleanup();
qemu_mutex_unlock_iothread();
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) &&
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.");
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);
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);
}
/*
QemuThread thread;
QEMUBH *cleanup_bh;
QEMUFile *to_dst_file;
+ /*
+ * Protects to_dst_file pointer. We need to make sure we won't
+ * yield or hang during the critical section, since this lock will
+ * be used in OOB command handler.
+ */
+ QemuMutex qemu_file_lock;
/* bytes already send at the beggining of current interation */
uint64_t iteration_initial_bytes;