From 0f8277d940c925096d8dc0df36b63c406a2c2188 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Tue, 29 Jun 2010 14:12:42 -0300 Subject: [PATCH 2/2] Factorize common migration incoming code RH-Author: Juan Quintela Message-id: Patchwork-id: 10333 O-Subject: [PATCH 2/2] Factorize common migration incoming code Bugzilla: 570174 RH-Acked-by: Amit Shah RH-Acked-by: Luiz Capitulino RH-Acked-by: Jes Sorensen Move duplicate code into process_incoming_migration(). migration-unix was wrong and didn't call vm_start(), factorizacion fixes that also. In addition to factorising common code, the changes also exit qemu if incoming migration failed. Earlier code just sat there doing nothing. Signed-off-by: Juan Quintela --- migration-exec.c | 14 +------------- migration-fd.c | 14 +------------- migration-tcp.c | 15 ++------------- migration-unix.c | 13 ++----------- migration.c | 13 +++++++++++++ migration.h | 2 ++ 6 files changed, 21 insertions(+), 50 deletions(-) Signed-off-by: Eduardo Habkost --- migration-exec.c | 14 +------------- migration-fd.c | 14 +------------- migration-tcp.c | 15 ++------------- migration-unix.c | 13 ++----------- migration.c | 13 +++++++++++++ migration.h | 2 ++ 6 files changed, 21 insertions(+), 50 deletions(-) diff --git a/migration-exec.c b/migration-exec.c index c5d3c53..ba08c6a 100644 --- a/migration-exec.c +++ b/migration-exec.c @@ -111,20 +111,8 @@ err_after_alloc: static void exec_accept_incoming_migration(void *opaque) { QEMUFile *f = opaque; - int ret; - ret = qemu_loadvm_state(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: + process_incoming_migration(f); qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL); qemu_fclose(f); } diff --git a/migration-fd.c b/migration-fd.c index d28c809..588299e 100644 --- a/migration-fd.c +++ b/migration-fd.c @@ -104,20 +104,8 @@ err_after_alloc: static void fd_accept_incoming_migration(void *opaque) { QEMUFile *f = opaque; - int ret; - ret = qemu_loadvm_state(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: + process_incoming_migration(f); qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL); qemu_fclose(f); } diff --git a/migration-tcp.c b/migration-tcp.c index c328e73..0de6c2e 100644 --- a/migration-tcp.c +++ b/migration-tcp.c @@ -143,7 +143,7 @@ static void tcp_accept_incoming_migration(void *opaque) socklen_t addrlen = sizeof(addr); int s = (unsigned long)opaque; QEMUFile *f; - int c, ret; + int c; do { c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen); @@ -162,18 +162,7 @@ static void tcp_accept_incoming_migration(void *opaque) goto out; } - ret = qemu_loadvm_state(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: + process_incoming_migration(f); qemu_fclose(f); out: qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL); diff --git a/migration-unix.c b/migration-unix.c index 9685c4b..7dd8abb 100644 --- a/migration-unix.c +++ b/migration-unix.c @@ -149,7 +149,7 @@ static void unix_accept_incoming_migration(void *opaque) socklen_t addrlen = sizeof(addr); int s = (unsigned long)opaque; QEMUFile *f; - int c, ret; + int c; do { c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen); @@ -168,16 +168,7 @@ static void unix_accept_incoming_migration(void *opaque) goto out; } - ret = qemu_loadvm_state(f); - if (ret < 0) { - fprintf(stderr, "load of migration failed\n"); - goto out_fopen; - } - qemu_announce_self(); - dprintf("successfully loaded vm state\n"); - - -out_fopen: + process_incoming_migration(f); qemu_fclose(f); out: qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL); diff --git a/migration.c b/migration.c index c44d845..d37ccd7 100644 --- a/migration.c +++ b/migration.c @@ -62,6 +62,19 @@ int qemu_start_incoming_migration(const char *uri) 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; diff --git a/migration.h b/migration.h index dd423a1..017e9c3 100644 --- a/migration.h +++ b/migration.h @@ -50,6 +50,8 @@ struct FdMigrationState void *opaque; }; +void process_incoming_migration(QEMUFile *f); + int qemu_start_incoming_migration(const char *uri); int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data); -- 1.7.0.3