#endif
/* Migration speed throttling */
-static uint32_t max_throttle = (32 << 20);
+static int64_t max_throttle = (32 << 20);
static MigrationState *current_migration;
-void qemu_start_incoming_migration(const char *uri)
+static NotifierList migration_state_notifiers =
+ NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
+
+int qemu_start_incoming_migration(const char *uri)
{
const char *p;
+ int ret;
if (strstart(uri, "tcp:", &p))
- tcp_start_incoming_migration(p);
+ ret = tcp_start_incoming_migration(p);
#if !defined(WIN32)
else if (strstart(uri, "exec:", &p))
- exec_start_incoming_migration(p);
+ ret = exec_start_incoming_migration(p);
else if (strstart(uri, "unix:", &p))
- unix_start_incoming_migration(p);
+ ret = unix_start_incoming_migration(p);
else if (strstart(uri, "fd:", &p))
- fd_start_incoming_migration(p);
+ ret = fd_start_incoming_migration(p);
#endif
- else
+ else {
fprintf(stderr, "unknown migration protocol: %s\n", uri);
+ ret = -EPROTONOSUPPORT;
+ }
+ return ret;
+}
+
+void process_incoming_migration(QEMUFile *f)
+{
+ if (qemu_loadvm_state(f) < 0) {
+ fprintf(stderr, "load of migration failed\n");
+ exit(0);
+ }
+ qemu_announce_self();
+ DPRINTF("successfully loaded vm state\n");
+
+ if (autostart) {
+ vm_start();
+ } else {
+ runstate_set(RUN_STATE_PRELAUNCH);
+ }
}
int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
MigrationState *s = NULL;
const char *p;
- int detach = qdict_get_int(qdict, "detach");
+ int detach = qdict_get_try_bool(qdict, "detach", 0);
+ int blk = qdict_get_try_bool(qdict, "blk", 0);
+ int inc = qdict_get_try_bool(qdict, "inc", 0);
const char *uri = qdict_get_str(qdict, "uri");
if (current_migration &&
return -1;
}
+ if (qemu_savevm_state_blocked(mon)) {
+ return -1;
+ }
+
if (strstart(uri, "tcp:", &p)) {
s = tcp_start_outgoing_migration(mon, p, max_throttle, detach,
- (int)qdict_get_int(qdict, "blk"),
- (int)qdict_get_int(qdict, "inc"));
+ blk, inc);
#if !defined(WIN32)
} else if (strstart(uri, "exec:", &p)) {
s = exec_start_outgoing_migration(mon, p, max_throttle, detach,
- (int)qdict_get_int(qdict, "blk"),
- (int)qdict_get_int(qdict, "inc"));
+ blk, inc);
} else if (strstart(uri, "unix:", &p)) {
s = unix_start_outgoing_migration(mon, p, max_throttle, detach,
- (int)qdict_get_int(qdict, "blk"),
- (int)qdict_get_int(qdict, "inc"));
+ blk, inc);
} else if (strstart(uri, "fd:", &p)) {
s = fd_start_outgoing_migration(mon, p, max_throttle, detach,
- (int)qdict_get_int(qdict, "blk"),
- (int)qdict_get_int(qdict, "inc"));
+ blk, inc);
#endif
} else {
monitor_printf(mon, "unknown migration protocol: %s\n", uri);
}
current_migration = s;
+ notifier_list_notify(&migration_state_notifiers, NULL);
return 0;
}
{
MigrationState *s = current_migration;
- if (s)
+ if (s && s->get_status(s) == MIG_STATE_ACTIVE) {
s->cancel(s);
-
+ }
return 0;
}
int do_migrate_set_speed(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
- double d;
+ int64_t d;
FdMigrationState *s;
- d = qdict_get_double(qdict, "value");
- d = MAX(0, MIN(UINT32_MAX, d));
+ d = qdict_get_int(qdict, "value");
+ if (d < 0) {
+ d = 0;
+ }
max_throttle = d;
s = migrate_to_fms(current_migration);
{
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;
}
qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
qemu_file_put_notify(s->file);
+ if (qemu_file_has_error(s->file)) {
+ migrate_fd_error(s);
+ }
}
ssize_t migrate_fd_put_buffer(void *opaque, const void *data, size_t size)
FdMigrationState *s = opaque;
ssize_t ret;
+ if (s->state != MIG_STATE_ACTIVE) {
+ return -EIO;
+ }
+
do {
ret = s->write(s, data, size);
} while (ret == -1 && ((s->get_error(s)) == EINTR));
if (ret == -1)
ret = -(s->get_error(s));
- if (ret == -EAGAIN)
+ if (ret == -EAGAIN) {
qemu_set_fd_handler2(s->fd, NULL, NULL, migrate_fd_put_notify, s);
+ }
return ret;
}
DPRINTF("iterate\n");
if (qemu_savevm_state_iterate(s->mon, s->file) == 1) {
- int state;
- int old_vm_running = vm_running;
+ int old_vm_running = runstate_is_running();
DPRINTF("done iterating\n");
- vm_stop(0);
+ vm_stop(RUN_STATE_FINISH_MIGRATE);
- qemu_aio_flush();
- bdrv_flush_all();
if ((qemu_savevm_state_complete(s->mon, s->file)) < 0) {
if (old_vm_running) {
vm_start();
}
- state = MIG_STATE_ERROR;
- } else {
- state = MIG_STATE_COMPLETED;
+ s->state = MIG_STATE_ERROR;
}
if (migrate_fd_cleanup(s) < 0) {
if (old_vm_running) {
vm_start();
}
- state = MIG_STATE_ERROR;
+ s->state = MIG_STATE_ERROR;
}
- s->state = state;
+ if (s->state == MIG_STATE_ACTIVE) {
+ s->state = MIG_STATE_COMPLETED;
+ runstate_set(RUN_STATE_POSTMIGRATE);
+ }
+ 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);
}
- free(s);
+ g_free(s);
}
void migrate_fd_wait_for_unfreeze(void *opaque)
ret = select(s->fd + 1, NULL, &wfds, NULL, NULL);
} while (ret == -1 && (s->get_error(s)) == EINTR);
+
+ if (ret == -1) {
+ qemu_file_set_error(s->file);
+ }
}
int migrate_fd_close(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;
+ }
+}