From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38683) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VC2iu-0000n0-Sx for qemu-devel@nongnu.org; Wed, 21 Aug 2013 03:21:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VC2ij-000115-VG for qemu-devel@nongnu.org; Wed, 21 Aug 2013 03:20:56 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:58503) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VC2ij-00010F-5h for qemu-devel@nongnu.org; Wed, 21 Aug 2013 03:20:45 -0400 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 21 Aug 2013 12:41:50 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id C7FEF3940053 for ; Wed, 21 Aug 2013 12:50:29 +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 r7L7KacG49152060 for ; Wed, 21 Aug 2013 12:50:36 +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 r7L7Kc2d027020 for ; Wed, 21 Aug 2013 12:50:39 +0530 From: Lei Li Date: Wed, 21 Aug 2013 15:18:47 +0800 Message-Id: <1377069536-12658-11-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 10/18] migration-local: implementation of outgoing 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 outgoing part for localhost migration. The integration of migration thread and corresponding adjustment will be in coming patches. Signed-off-by: Lei Li --- include/migration/migration.h | 2 + migration-local.c | 85 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 0 deletions(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index 5336117..d2c7eff 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -92,6 +92,8 @@ void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error ** void rdma_start_incoming_migration(const char *host_port, Error **errp); +void local_start_outgoing_migration(void *opaque, const char *uri, Error **errp); + void migrate_fd_error(MigrationState *s); void migrate_fd_connect(MigrationState *s); diff --git a/migration-local.c b/migration-local.c index 93190fd..cf4a091 100644 --- a/migration-local.c +++ b/migration-local.c @@ -209,3 +209,88 @@ static void *qemu_fopen_local(int fd, const char *mode) return s->file; } + +/************************************************************************ + * Outgoing part + **/ + +static QEMUFileLocal *local_migration_init(void) +{ + QEMUFileLocal *s = g_malloc0(sizeof(*s)); + + s->state = MIG_STATE_SETUP; + trace_migrate_set_state(MIG_STATE_SETUP); + s->fd = -1; + s->last_block_sent = NULL; + + return s; +} + +static void unix_local_wait_for_connect(int fd, void *opaque) +{ + MigrationState *s = opaque; + + if (fd < 0) { + DPRINTF("migrate connect error\n"); + s->file = NULL; + migrate_fd_error(s); + } else { + DPRINTF("migrate connect success\n"); + s->file = qemu_fopen_local(fd, "wb"); + migrate_fd_connect(s); + } +} + +static void unix_local_outgoing_connect(MigrationState *s, const char *path, + Error **errp) +{ + unix_nonblocking_connect(path, unix_local_wait_for_connect, s, errp); +} + +void local_start_outgoing_migration(void *opaque, const char *uri, + Error **errp) +{ + MigrationState *s = opaque; + const char *path; + QEMUFileLocal *local; + Error *local_err = NULL; + int is_vm_running; + int ret; + + local = local_migration_init(); + if (local == NULL) { + error_setg(errp, "Failed to initialize\n"); + } + + bdrv_flush_all(); + + is_vm_running = runstate_is_running(); + + /* Stop the VM first */ + if (is_vm_running) { + ret = vm_stop(RUN_STATE_SAVE_VM); + if (ret < 0) { + goto fail; + } + } + + /* Start outgoing migration via unix socket. */ + if (uri) { + /* XXX. Creation of a new unix_start_outgoing_migration_* is + * not necessary, just for the first step. This will be replaced + * by vmsplice mechanism. + **/ + unix_local_outgoing_connect(s, path, &local_err); + } else { + error_set(errp, QERR_INVALID_PARAMETER_VALUE, + "uri", "a valid migration protocol"); + goto fail; + } + + return; + +fail: + error_propagate(errp, local_err); + g_free(local); + migrate_fd_error(s); +} -- 1.7.7.6