static MigrationState *current_migration;
+static NotifierList migration_state_notifiers =
+ NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
+
int qemu_start_incoming_migration(const char *uri)
{
const char *p;
}
current_migration = s;
+ notifier_list_notify(&migration_state_notifiers, NULL);
return 0;
}
{
DPRINTF("setting error state\n");
s->state = MIG_STATE_ERROR;
+ notifier_list_notify(&migration_state_notifiers, NULL);
migrate_fd_cleanup(s);
}
ret = -1;
}
s->file = NULL;
+ } else {
+ if (s->mon) {
+ monitor_resume(s->mon);
+ }
}
- if (s->fd != -1)
+ if (s->fd != -1) {
close(s->fd);
-
- /* Don't resume monitor until we've flushed all of the buffers */
- if (s->mon) {
- monitor_resume(s->mon);
+ s->fd = -1;
}
- s->fd = -1;
-
return ret;
}
if (ret == -EAGAIN) {
qemu_set_fd_handler2(s->fd, NULL, NULL, migrate_fd_put_notify, s);
} else if (ret < 0) {
- if (s->mon) {
- monitor_resume(s->mon);
- }
s->state = MIG_STATE_ERROR;
+ notifier_list_notify(&migration_state_notifiers, NULL);
}
return ret;
int old_vm_running = vm_running;
DPRINTF("done iterating\n");
- vm_stop(0);
+ vm_stop(VMSTOP_MIGRATE);
if ((qemu_savevm_state_complete(s->mon, s->file)) < 0) {
if (old_vm_running) {
state = MIG_STATE_ERROR;
}
s->state = state;
+ notifier_list_notify(&migration_state_notifiers, NULL);
}
}
DPRINTF("cancelling migration\n");
s->state = MIG_STATE_CANCELLED;
+ notifier_list_notify(&migration_state_notifiers, NULL);
qemu_savevm_state_cancel(s->mon, s->file);
migrate_fd_cleanup(s);
if (s->state == MIG_STATE_ACTIVE) {
s->state = MIG_STATE_CANCELLED;
+ notifier_list_notify(&migration_state_notifiers, NULL);
migrate_fd_cleanup(s);
}
- qemu_free(s);
+ g_free(s);
}
void migrate_fd_wait_for_unfreeze(void *opaque)
{
FdMigrationState *s = opaque;
+ if (s->mon) {
+ monitor_resume(s->mon);
+ }
qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
return s->close(s);
}
+
+void add_migration_state_change_notifier(Notifier *notify)
+{
+ notifier_list_add(&migration_state_notifiers, notify);
+}
+
+void remove_migration_state_change_notifier(Notifier *notify)
+{
+ notifier_list_remove(&migration_state_notifiers, notify);
+}
+
+int get_migration_state(void)
+{
+ if (current_migration) {
+ return migrate_fd_get_status(current_migration);
+ } else {
+ return MIG_STATE_ERROR;
+ }
+}