static MigrationState *current_migration;
-void qemu_start_incoming_migration(const char *uri)
+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();
}
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 &&
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);
qdict_put_obj(qdict, name, obj);
}
-/**
- * do_info_migrate(): Migration status
- *
- * Return a QDict. If migration is active there will be another
- * QDict with RAM migration status and if block migration is active
- * another one with block migration status.
- *
- * The main QDict contains the following:
- *
- * - "status": migration status
- * - "ram": only present if "status" is "active", it is a QDict with the
- * following RAM information (in bytes):
- * - "transferred": amount transferred
- * - "remaining": amount remaining
- * - "total": total
- * - "disk": only present if "status" is "active" and it is a block migration,
- * it is a QDict with the following disk information (in bytes):
- * - "transferred": amount transferred
- * - "remaining": amount remaining
- * - "total": total
- *
- * Examples:
- *
- * 1. Migration is "completed":
- *
- * { "status": "completed" }
- *
- * 2. Migration is "active" and it is not a block migration:
- *
- * { "status": "active",
- * "ram": { "transferred": 123, "remaining": 123, "total": 246 } }
- *
- * 3. Migration is "active" and it is a block migration:
- *
- * { "status": "active",
- * "ram": { "total": 1057024, "remaining": 1053304, "transferred": 3720 },
- * "disk": { "total": 20971520, "remaining": 20880384, "transferred": 91136 }}
- */
void do_info_migrate(Monitor *mon, QObject **ret_data)
{
QDict *qdict;
migrate_fd_cleanup(s);
}
-void migrate_fd_cleanup(FdMigrationState *s)
+int migrate_fd_cleanup(FdMigrationState *s)
{
+ int ret = 0;
+
qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
if (s->file) {
DPRINTF("closing file\n");
- qemu_fclose(s->file);
+ if (qemu_fclose(s->file) != 0) {
+ ret = -1;
+ }
s->file = NULL;
}
}
s->fd = -1;
+
+ return ret;
}
void migrate_fd_put_notify(void *opaque)
} else {
state = MIG_STATE_COMPLETED;
}
- migrate_fd_cleanup(s);
+ if (migrate_fd_cleanup(s) < 0) {
+ if (old_vm_running) {
+ vm_start();
+ }
+ state = MIG_STATE_ERROR;
+ }
s->state = state;
}
}
s->state = MIG_STATE_CANCELLED;
migrate_fd_cleanup(s);
}
- free(s);
+ qemu_free(s);
}
void migrate_fd_wait_for_unfreeze(void *opaque)