From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoF2W-0005a9-TQ for qemu-devel@nongnu.org; Sun, 16 Jun 2013 11:38:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UoF2V-0000QY-Ua for qemu-devel@nongnu.org; Sun, 16 Jun 2013 11:38:48 -0400 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:43725) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoF2V-0000Pt-BH for qemu-devel@nongnu.org; Sun, 16 Jun 2013 11:38:47 -0400 Received: from /spool/local by e28smtp02.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 16 Jun 2013 21:01:09 +0530 Received: from d28relay04.in.ibm.com (d28relay04.in.ibm.com [9.184.220.61]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id A6F331258043 for ; Sun, 16 Jun 2013 21:07:38 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r5GFcb8l23461910 for ; Sun, 16 Jun 2013 21:08:37 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r5GFcfYN019289 for ; Sun, 16 Jun 2013 15:38:42 GMT From: Lei Li Date: Sun, 16 Jun 2013 23:37:31 +0800 Message-Id: <1371397053-4503-6-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1371397053-4503-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1371397053-4503-1-git-send-email-lilei@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 5/7] migration-local: implementation of incoming part List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: lagarcia@br.ibm.com, aliguori@us.ibm.com, Lei Li , quintela@redhat.com Signed-off-by: Lei Li --- include/migration/migration.h | 6 +++++ migration-local.c | 39 ++++++++++++++++++++++++++++++++++ migration-unix.c | 47 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 0 deletions(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index 12c75cf..e0693c2 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -73,6 +73,10 @@ void process_incoming_migration(QEMUFile *f); void qemu_start_incoming_migration(const char *uri, Error **errp); +void start_local_incoming_migration(QEMUFile *f); + +void qemu_start_local_incoming_migration(const char *uri, Error **errp); + uint64_t migrate_max_downtime(void); void do_info_migrate_print(Monitor *mon, const QObject *data); @@ -89,6 +93,8 @@ void tcp_start_outgoing_migration(MigrationState *s, const char *host_port, Erro void unix_start_incoming_migration(const char *path, Error **errp); +void unix_start_local_incoming_migration(const char *path, Error **errp); + void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **errp); void unix_start_local_outgoing_migration(LocalMigState *s, const char *path, Error **errp); diff --git a/migration-local.c b/migration-local.c index a97dd3a..61da76f 100644 --- a/migration-local.c +++ b/migration-local.c @@ -114,3 +114,42 @@ fail: vm_start(); } } + +/********************************************************************** + * Incoming part + */ + +void qemu_start_local_incoming_migration(const char *uri, Error **errp) +{ + const char *p; + + if (strstart(uri, "unix:", &p)) { + unix_start_local_incoming_migration(p, errp); + } else { + error_setg(errp, "unknown migration protocol: %s", uri); + } +} + +void start_local_incoming_migration(QEMUFile *f) +{ + int ret; + + ret = qemu_loadvm_state(f); + if (ret < 0) { + fprintf(stderr, "load of migration failed\n"); + exit(EXIT_FAILURE); + } + qemu_announce_self(); + + DPRINTF("successfully loaded vm state\n"); + + bdrv_clear_incoming_migration_all(); + /* Make sure all file formats flush their mutable metadata */ + bdrv_invalidate_cache_all(); + + if (autostart) { + vm_start(); + } else { + runstate_set(RUN_STATE_PAUSED); + } +} diff --git a/migration-unix.c b/migration-unix.c index a21262a..ba7c0d0 100644 --- a/migration-unix.c +++ b/migration-unix.c @@ -108,3 +108,50 @@ void unix_start_incoming_migration(const char *path, Error **errp) qemu_set_fd_handler2(s, NULL, unix_accept_incoming_migration, NULL, (void *)(intptr_t)s); } + +static void unix_accept_local_incoming_migration(void *opaque) +{ + struct sockaddr_un addr; + socklen_t addrlen = sizeof(addr); + int s = (intptr_t)opaque; + QEMUFile *f; + int c; + + do { + c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen); + } while (c == -1 && errno == EINTR); + qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL); + close(s); + + DPRINTF("accepted migration\n"); + + if (c == -1) { + fprintf(stderr, "could not accept migration connection\n"); + goto out; + } + + f = qemu_fopen_socket(c, "rb"); + if (f == NULL) { + fprintf(stderr, "could not qemu_fopen socket\n"); + goto out; + } + + start_local_incoming_migration(f); + return; + +out: + close(c); +} + +void unix_start_local_incoming_migration(const char *path, Error **errp) +{ + int ret; + + ret = unix_listen(path, NULL, 0, errp); + if (ret < 0) { + return; + } + + qemu_set_fd_handler2(ret, NULL, unix_accept_local_incoming_migration, NULL, + (void *)(intptr_t)ret); +} -- 1.7.7.6