From 8dc592e620b45c4745380b0694ec1aedc073bda2 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 27 Sep 2012 13:25:45 +0200 Subject: migration: use migrate_fd_close in migrate_fd_cleanup migrate_fd_cleanup will usually close the file descriptor via buffered_file_close's call to migrate_fd_close. However, in the case of s->file == NULL it is "inlining" migrate_fd_close (almost: there is a direct close() instead of using s->close(s)). To fix the inconsistency and clean up the code, allow multiple calls to migrate_fd_close and use the function in migrate_fd_cleanup. Signed-off-by: Paolo Bonzini --- migration.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'migration.c') diff --git a/migration.c b/migration.c index 300ab75aaf..a63596f9a0 100644 --- a/migration.c +++ b/migration.c @@ -243,21 +243,13 @@ static int migrate_fd_cleanup(MigrationState *s) { int ret = 0; - if (s->fd != -1) { - qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); - } - if (s->file) { DPRINTF("closing file\n"); ret = qemu_fclose(s->file); s->file = NULL; } - if (s->fd != -1) { - close(s->fd); - s->fd = -1; - } - + migrate_fd_close(s); return ret; } @@ -393,8 +385,13 @@ int migrate_fd_wait_for_unfreeze(MigrationState *s) int migrate_fd_close(MigrationState *s) { - qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); - return s->close(s); + int rc = 0; + if (s->fd != -1) { + qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); + rc = s->close(s); + s->fd = -1; + } + return rc; } void add_migration_state_change_notifier(Notifier *notify) -- cgit v1.2.3-55-g7522 From 1c12e1f5b2ce215ee25b4a4e365e76269edf911c Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 7 Aug 2012 10:51:51 +0200 Subject: migration: move qemu_fclose to process_incoming_migration The common suffix is now just process_incoming_migration. Reviewed-by: Orit Wasserman Signed-off-by: Paolo Bonzini --- migration-exec.c | 1 - migration-fd.c | 1 - migration-tcp.c | 1 - migration-unix.c | 1 - migration.c | 6 +++++- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'migration.c') diff --git a/migration-exec.c b/migration-exec.c index 2ce7770cfa..2b6fcb4262 100644 --- a/migration-exec.c +++ b/migration-exec.c @@ -87,7 +87,6 @@ static void exec_accept_incoming_migration(void *opaque) qemu_set_fd_handler2(qemu_get_fd(f), NULL, NULL, NULL, NULL); process_incoming_migration(f); - qemu_fclose(f); } void exec_start_incoming_migration(const char *command, Error **errp) diff --git a/migration-fd.c b/migration-fd.c index c678b23b7e..5fe28e09fd 100644 --- a/migration-fd.c +++ b/migration-fd.c @@ -91,7 +91,6 @@ static void fd_accept_incoming_migration(void *opaque) qemu_set_fd_handler2(qemu_get_fd(f), NULL, NULL, NULL, NULL); process_incoming_migration(f); - qemu_fclose(f); } void fd_start_incoming_migration(const char *infd, Error **errp) diff --git a/migration-tcp.c b/migration-tcp.c index 1279cc9677..5e855fe72f 100644 --- a/migration-tcp.c +++ b/migration-tcp.c @@ -102,7 +102,6 @@ static void tcp_accept_incoming_migration(void *opaque) } process_incoming_migration(f); - qemu_fclose(f); return; out: diff --git a/migration-unix.c b/migration-unix.c index 96ea71b787..dba72b4a54 100644 --- a/migration-unix.c +++ b/migration-unix.c @@ -102,7 +102,6 @@ static void unix_accept_incoming_migration(void *opaque) } process_incoming_migration(f); - qemu_fclose(f); return; out: diff --git a/migration.c b/migration.c index a63596f9a0..2741d979fc 100644 --- a/migration.c +++ b/migration.c @@ -85,7 +85,11 @@ void qemu_start_incoming_migration(const char *uri, Error **errp) void process_incoming_migration(QEMUFile *f) { - if (qemu_loadvm_state(f) < 0) { + int ret; + + ret = qemu_loadvm_state(f); + qemu_fclose(f); + if (ret < 0) { fprintf(stderr, "load of migration failed\n"); exit(0); } -- cgit v1.2.3-55-g7522 From 82a4da79fd6c108400637143f8439c2364bdb21e Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 7 Aug 2012 10:57:43 +0200 Subject: migration: move process_incoming_migration to a coroutine The final part of incoming migration, which now consists of process_incoming_migration for all protocols, is thus made non-blocking. Reviewed-by: Orit Wasserman Signed-off-by: Paolo Bonzini --- migration.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'migration.c') diff --git a/migration.c b/migration.c index 2741d979fc..73ce170ddf 100644 --- a/migration.c +++ b/migration.c @@ -83,11 +83,13 @@ void qemu_start_incoming_migration(const char *uri, Error **errp) } } -void process_incoming_migration(QEMUFile *f) +static void process_incoming_migration_co(void *opaque) { + QEMUFile *f = opaque; int ret; ret = qemu_loadvm_state(f); + qemu_set_fd_handler(qemu_get_fd(f), NULL, NULL, NULL); qemu_fclose(f); if (ret < 0) { fprintf(stderr, "load of migration failed\n"); @@ -107,6 +109,23 @@ void process_incoming_migration(QEMUFile *f) } } +static void enter_migration_coroutine(void *opaque) +{ + Coroutine *co = opaque; + qemu_coroutine_enter(co, NULL); +} + +void process_incoming_migration(QEMUFile *f) +{ + Coroutine *co = qemu_coroutine_create(process_incoming_migration_co); + int fd = qemu_get_fd(f); + + assert(fd != -1); + socket_set_nonblock(fd); + qemu_set_fd_handler(fd, enter_migration_coroutine, NULL, co); + qemu_coroutine_enter(co, f); +} + /* amount of nanoseconds we are willing to wait for migration to be down. * the choice of nanoseconds is because it is the maximum resolution that * get_clock() can achieve. It is an internal measure. All user-visible -- cgit v1.2.3-55-g7522