From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VC2j9-0001Ed-LQ for qemu-devel@nongnu.org; Wed, 21 Aug 2013 03:21:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VC2j0-00016E-AA for qemu-devel@nongnu.org; Wed, 21 Aug 2013 03:21:11 -0400 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:52826) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VC2iz-00015Y-Kx for qemu-devel@nongnu.org; Wed, 21 Aug 2013 03:21:02 -0400 Received: from /spool/local by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 21 Aug 2013 12:44:32 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id BF2EEE0054 for ; Wed, 21 Aug 2013 12:51:26 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r7L7KsSu44237004 for ; Wed, 21 Aug 2013 12:50:54 +0530 Received: from d28av01.in.ibm.com (localhost [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r7L7KuE8028552 for ; Wed, 21 Aug 2013 12:50:57 +0530 From: Lei Li Date: Wed, 21 Aug 2013 15:18:53 +0800 Message-Id: <1377069536-12658-17-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1377069536-12658-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1377069536-12658-1-git-send-email-lilei@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 16/18] migration-local: implementation of incoming part List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aarcange@redhat.com, aliguori@us.ibm.com, Lei Li , quintela@redhat.com, mrhines@linux.vnet.ibm.com, lagarcia@br.ibm.com, pbonzini@redhat.com, rcj@linux.vnet.ibm.com Implementation of incoming part of localhost migration. Signed-off-by: Lei Li --- include/migration/migration.h | 2 + include/migration/qemu-file.h | 8 ++-- migration-local.c | 99 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 4 deletions(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index a04f050..232f1d5 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -94,6 +94,8 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp); void local_start_outgoing_migration(void *opaque, const char *uri, Error **errp); +void local_start_incoming_migration(const char *uri, Error **errp); + void migrate_fd_error(MigrationState *s); void migrate_fd_connect(MigrationState *s); diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index 0f757fb..a34d418 100644 --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -77,10 +77,10 @@ typedef int (QEMURamHookFunc)(QEMUFile *f, void *opaque, uint64_t flags); * is saved (such as RDMA, for example.) */ typedef size_t (QEMURamSaveFunc)(QEMUFile *f, void *opaque, - ram_addr_t block_offset, - ram_addr_t offset, - size_t size, - int *bytes_sent); + ram_addr_t block_offset, + ram_addr_t offset, + size_t size, + int *bytes_sent); typedef struct QEMUFileOps { QEMUFilePutBufferFunc *put_buffer; diff --git a/migration-local.c b/migration-local.c index cf4a091..501371a 100644 --- a/migration-local.c +++ b/migration-local.c @@ -294,3 +294,102 @@ fail: g_free(local); migrate_fd_error(s); } + + +/********************************************************************** + * Incoming part + */ + +static void unix_accept_local_incoming(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_local(c, "rb"); + if (f == NULL) { + fprintf(stderr, "could not qemu_fopen socket\n"); + goto out; + } + + start_local_incoming_migration(f); + + return; + +out: + close(c); +} + +static void unix_local_incoming_connect(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, NULL, + (void *)(intptr_t)ret); +} +void local_start_incoming_migration(const char *uri, Error **errp) +{ + QEMUFileLocal *s = g_malloc0(sizeof(*s)); + Error *local_err = NULL; + + DPRINTF("Starting local incoming migration\n"); + + if (uri) { + unix_local_incoming_connect(uri, errp); + } else { + goto err; + } + + DPRINTF("unix_listen success\n"); + + return; + +err: + error_propagate(errp, local_err); + g_free(s); +} + +static 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); + } +} -- 1.7.7.6