Factorize common migration incoming code

Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Juan Quintela 2010-06-09 14:10:55 +02:00 committed by Anthony Liguori
parent 8ca5e80118
commit 511c023103
6 changed files with 21 additions and 52 deletions

View File

@ -121,20 +121,8 @@ err_after_alloc:
static void exec_accept_incoming_migration(void *opaque) static void exec_accept_incoming_migration(void *opaque)
{ {
QEMUFile *f = opaque; QEMUFile *f = opaque;
int ret;
ret = qemu_loadvm_state(f); process_incoming_migration(f);
if (ret < 0) {
fprintf(stderr, "load of migration failed\n");
goto err;
}
qemu_announce_self();
DPRINTF("successfully loaded vm state\n");
if (autostart)
vm_start();
err:
qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL); qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL);
qemu_fclose(f); qemu_fclose(f);
} }

View File

@ -104,20 +104,8 @@ err_after_alloc:
static void fd_accept_incoming_migration(void *opaque) static void fd_accept_incoming_migration(void *opaque)
{ {
QEMUFile *f = opaque; QEMUFile *f = opaque;
int ret;
ret = qemu_loadvm_state(f); process_incoming_migration(f);
if (ret < 0) {
fprintf(stderr, "load of migration failed\n");
goto err;
}
qemu_announce_self();
DPRINTF("successfully loaded vm state\n");
if (autostart)
vm_start();
err:
qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL); qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL);
qemu_fclose(f); qemu_fclose(f);
} }

View File

@ -141,7 +141,7 @@ static void tcp_accept_incoming_migration(void *opaque)
socklen_t addrlen = sizeof(addr); socklen_t addrlen = sizeof(addr);
int s = (unsigned long)opaque; int s = (unsigned long)opaque;
QEMUFile *f; QEMUFile *f;
int c, ret; int c;
do { do {
c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen); c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen);
@ -160,18 +160,7 @@ static void tcp_accept_incoming_migration(void *opaque)
goto out; goto out;
} }
ret = qemu_loadvm_state(f); process_incoming_migration(f);
if (ret < 0) {
fprintf(stderr, "load of migration failed\n");
goto out_fopen;
}
qemu_announce_self();
DPRINTF("successfully loaded vm state\n");
if (autostart)
vm_start();
out_fopen:
qemu_fclose(f); qemu_fclose(f);
out: out:
qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL); qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);

View File

@ -149,7 +149,7 @@ static void unix_accept_incoming_migration(void *opaque)
socklen_t addrlen = sizeof(addr); socklen_t addrlen = sizeof(addr);
int s = (unsigned long)opaque; int s = (unsigned long)opaque;
QEMUFile *f; QEMUFile *f;
int c, ret; int c;
do { do {
c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen); c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen);
@ -168,18 +168,7 @@ static void unix_accept_incoming_migration(void *opaque)
goto out; goto out;
} }
ret = qemu_loadvm_state(f); process_incoming_migration(f);
if (ret < 0) {
fprintf(stderr, "load of migration failed\n");
goto out_fopen;
}
qemu_announce_self();
DPRINTF("successfully loaded vm state\n");
if (autostart)
vm_start();
out_fopen:
qemu_fclose(f); qemu_fclose(f);
out: out:
qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL); qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);

View File

@ -58,6 +58,19 @@ int qemu_start_incoming_migration(const char *uri)
return ret; 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) int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
{ {
MigrationState *s = NULL; MigrationState *s = NULL;

View File

@ -50,6 +50,8 @@ struct FdMigrationState
void *opaque; void *opaque;
}; };
void process_incoming_migration(QEMUFile *f);
int qemu_start_incoming_migration(const char *uri); int qemu_start_incoming_migration(const char *uri);
int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data);