@@ -46,7 +46,7 @@ struct MigrationState
int64_t bandwidth_limit;
size_t bytes_xfer;
size_t xfer_limit;
- QemuThread thread;
+ QemuThread *thread;
QEMUBH *cleanup_bh;
QEMUFile *file;
@@ -148,6 +148,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops);
QEMUFile *qemu_fopen(const char *filename, const char *mode);
QEMUFile *qemu_fdopen(int fd, const char *mode);
QEMUFile *qemu_fopen_socket(int fd, const char *mode);
+QEMUFile *qemu_fopen_mc(void *opaque, const char *mode);
QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
int qemu_get_fd(QEMUFile *f);
int qemu_fclose(QEMUFile *f);
@@ -93,6 +93,9 @@ static void process_incoming_migration_co(void *opaque)
int ret;
ret = qemu_loadvm_state(f);
+ if (ret >= 0) {
+ mc_process_incoming_checkpoints_if_requested(f);
+ }
qemu_fclose(f);
free_xbzrle_decoded_buf();
if (ret < 0) {
@@ -313,14 +316,17 @@ static void migrate_fd_cleanup(void *opaque)
{
MigrationState *s = opaque;
- qemu_bh_delete(s->cleanup_bh);
- s->cleanup_bh = NULL;
+ if(s->cleanup_bh) {
+ qemu_bh_delete(s->cleanup_bh);
+ s->cleanup_bh = NULL;
+ }
if (s->file) {
DPRINTF("closing file\n");
qemu_mutex_unlock_iothread();
- qemu_thread_join(&s->thread);
+ qemu_thread_join(s->thread);
qemu_mutex_lock_iothread();
+ g_free(s->thread);
qemu_fclose(s->file);
s->file = NULL;
@@ -695,11 +701,27 @@ static void *migration_thread(void *opaque)
s->downtime = end_time - start_time;
runstate_set(RUN_STATE_POSTMIGRATE);
} else {
+ if(migrate_use_mc()) {
+ qemu_fflush(s->file);
+ if (migrate_use_mc_net()) {
+ if (mc_enable_buffering() < 0 ||
+ mc_start_buffer() < 0) {
+ migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_ERROR);
+ }
+ }
+ }
+
if (old_vm_running) {
vm_start();
}
}
- qemu_bh_schedule(s->cleanup_bh);
+
+ if (migrate_use_mc() && s->state != MIG_STATE_ERROR) {
+ mc_init_checkpointer(s);
+ } else {
+ qemu_bh_schedule(s->cleanup_bh);
+ }
+
qemu_mutex_unlock_iothread();
return NULL;
@@ -720,6 +742,7 @@ void migrate_fd_connect(MigrationState *s)
/* Notify before starting migration thread */
notifier_list_notify(&migration_state_notifiers, s);
- qemu_thread_create(&s->thread, migration_thread, s,
+ s->thread = g_malloc0(sizeof(*s->thread));
+ qemu_thread_create(s->thread, migration_thread, s,
QEMU_THREAD_JOINABLE);
}
@@ -4145,6 +4145,8 @@ int main(int argc, char **argv, char **envp)
default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS);
register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL);
+ register_savevm(NULL, "mc", -1, MC_VERSION, mc_info_save,
+ mc_info_load, NULL);
if (nb_numa_nodes > 0) {
int i;