From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yoshiaki Tamura Subject: [PATCH 17/19] migration-tcp: modify tcp_accept_incoming_migration() to handle ft_mode, and add a hack not to close fd when ft_mode is enabled. Date: Fri, 28 Jan 2011 16:21:50 +0900 Message-ID: <1296199312-26334-18-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> References: <1296199312-26334-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> Cc: avi@redhat.com, anthony@codemonkey.ws, aliguori@us.ibm.com, mtosatti@redhat.com, dlaor@redhat.com, mst@redhat.com, kwolf@redhat.com, ananth@in.ibm.com, psuriset@linux.vnet.ibm.com, vatsa@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com, blauwirbel@gmail.com, ohmura.kei@lab.ntt.co.jp, Yoshiaki Tamura To: kvm@vger.kernel.org, qemu-devel@nongnu.org Return-path: Received: from sh.osrg.net ([192.16.179.4]:58918 "EHLO sh.osrg.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753139Ab1A1HXp (ORCPT ); Fri, 28 Jan 2011 02:23:45 -0500 In-Reply-To: <1296199312-26334-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> Sender: kvm-owner@vger.kernel.org List-ID: When ft_mode is set in the header, tcp_accept_incoming_migration() sets ft_trans_incoming() as a callback, and call qemu_file_get_notify() to receive FT transaction iteratively. We also need a hack no to close fd before moving to ft_transaction mode, so that we can reuse the fd for it. vm_change_state_handler is added to turn off ft_mode when cont is pressed. Signed-off-by: Yoshiaki Tamura --- migration-tcp.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 66 insertions(+), 1 deletions(-) diff --git a/migration-tcp.c b/migration-tcp.c index 55777c8..84076d6 100644 --- a/migration-tcp.c +++ b/migration-tcp.c @@ -18,6 +18,8 @@ #include "sysemu.h" #include "buffered_file.h" #include "block.h" +#include "ft_trans_file.h" +#include "event-tap.h" //#define DEBUG_MIGRATION_TCP @@ -29,6 +31,8 @@ do { } while (0) #endif +static VMChangeStateEntry *vmstate; + static int socket_errno(FdMigrationState *s) { return socket_error(); @@ -56,7 +60,8 @@ static int socket_read(FdMigrationState *s, const void * buf, size_t size) static int tcp_close(FdMigrationState *s) { DPRINTF("tcp_close\n"); - if (s->fd != -1) { + /* FIX ME: accessing ft_mode here isn't clean */ + if (s->fd != -1 && ft_mode != FT_INIT) { close(s->fd); s->fd = -1; } @@ -150,6 +155,36 @@ MigrationState *tcp_start_outgoing_migration(Monitor *mon, return &s->mig_state; } +static void ft_trans_incoming(void *opaque) +{ + QEMUFile *f = opaque; + + qemu_file_get_notify(f); + if (qemu_file_has_error(f)) { + ft_mode = FT_ERROR; + qemu_fclose(f); + } +} + +static void ft_trans_reset(void *opaque, int running, int reason) +{ + QEMUFile *f = opaque; + + if (running) { + if (ft_mode != FT_ERROR) { + qemu_fclose(f); + } + ft_mode = FT_OFF; + qemu_del_vm_change_state_handler(vmstate); + } +} + +static void ft_trans_schedule_replay(QEMUFile *f) +{ + event_tap_schedule_replay(); + vmstate = qemu_add_vm_change_state_handler(ft_trans_reset, f); +} + static void tcp_accept_incoming_migration(void *opaque) { struct sockaddr_in addr; @@ -175,8 +210,38 @@ static void tcp_accept_incoming_migration(void *opaque) goto out; } + if (ft_mode == FT_INIT) { + autostart = 0; + } + process_incoming_migration(f); + + if (ft_mode == FT_INIT) { + int ret; + + socket_set_nodelay(c); + + f = qemu_fopen_ft_trans(s, c); + if (f == NULL) { + fprintf(stderr, "could not qemu_fopen_ft_trans\n"); + goto out; + } + + /* need to wait sender to setup */ + ret = qemu_ft_trans_begin(f); + if (ret < 0) { + goto out; + } + + qemu_set_fd_handler2(c, NULL, ft_trans_incoming, NULL, f); + ft_trans_schedule_replay(f); + ft_mode = FT_TRANSACTION_RECV; + + return; + } + qemu_fclose(f); + out: close(c); out2: -- 1.7.1.2 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=48312 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Piig8-0000rf-FT for qemu-devel@nongnu.org; Fri, 28 Jan 2011 02:23:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Piig6-00078m-Gi for qemu-devel@nongnu.org; Fri, 28 Jan 2011 02:23:32 -0500 Received: from sh.osrg.net ([192.16.179.4]:58328) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Piig5-00073L-W3 for qemu-devel@nongnu.org; Fri, 28 Jan 2011 02:23:30 -0500 From: Yoshiaki Tamura Date: Fri, 28 Jan 2011 16:21:50 +0900 Message-Id: <1296199312-26334-18-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> In-Reply-To: <1296199312-26334-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> References: <1296199312-26334-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> Subject: [Qemu-devel] [PATCH 17/19] migration-tcp: modify tcp_accept_incoming_migration() to handle ft_mode, and add a hack not to close fd when ft_mode is enabled. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kvm@vger.kernel.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, aliguori@us.ibm.com, mtosatti@redhat.com, ananth@in.ibm.com, mst@redhat.com, dlaor@redhat.com, vatsa@linux.vnet.ibm.com, Yoshiaki Tamura , blauwirbel@gmail.com, ohmura.kei@lab.ntt.co.jp, avi@redhat.com, psuriset@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com When ft_mode is set in the header, tcp_accept_incoming_migration() sets ft_trans_incoming() as a callback, and call qemu_file_get_notify() to receive FT transaction iteratively. We also need a hack no to close fd before moving to ft_transaction mode, so that we can reuse the fd for it. vm_change_state_handler is added to turn off ft_mode when cont is pressed. Signed-off-by: Yoshiaki Tamura --- migration-tcp.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 66 insertions(+), 1 deletions(-) diff --git a/migration-tcp.c b/migration-tcp.c index 55777c8..84076d6 100644 --- a/migration-tcp.c +++ b/migration-tcp.c @@ -18,6 +18,8 @@ #include "sysemu.h" #include "buffered_file.h" #include "block.h" +#include "ft_trans_file.h" +#include "event-tap.h" //#define DEBUG_MIGRATION_TCP @@ -29,6 +31,8 @@ do { } while (0) #endif +static VMChangeStateEntry *vmstate; + static int socket_errno(FdMigrationState *s) { return socket_error(); @@ -56,7 +60,8 @@ static int socket_read(FdMigrationState *s, const void * buf, size_t size) static int tcp_close(FdMigrationState *s) { DPRINTF("tcp_close\n"); - if (s->fd != -1) { + /* FIX ME: accessing ft_mode here isn't clean */ + if (s->fd != -1 && ft_mode != FT_INIT) { close(s->fd); s->fd = -1; } @@ -150,6 +155,36 @@ MigrationState *tcp_start_outgoing_migration(Monitor *mon, return &s->mig_state; } +static void ft_trans_incoming(void *opaque) +{ + QEMUFile *f = opaque; + + qemu_file_get_notify(f); + if (qemu_file_has_error(f)) { + ft_mode = FT_ERROR; + qemu_fclose(f); + } +} + +static void ft_trans_reset(void *opaque, int running, int reason) +{ + QEMUFile *f = opaque; + + if (running) { + if (ft_mode != FT_ERROR) { + qemu_fclose(f); + } + ft_mode = FT_OFF; + qemu_del_vm_change_state_handler(vmstate); + } +} + +static void ft_trans_schedule_replay(QEMUFile *f) +{ + event_tap_schedule_replay(); + vmstate = qemu_add_vm_change_state_handler(ft_trans_reset, f); +} + static void tcp_accept_incoming_migration(void *opaque) { struct sockaddr_in addr; @@ -175,8 +210,38 @@ static void tcp_accept_incoming_migration(void *opaque) goto out; } + if (ft_mode == FT_INIT) { + autostart = 0; + } + process_incoming_migration(f); + + if (ft_mode == FT_INIT) { + int ret; + + socket_set_nodelay(c); + + f = qemu_fopen_ft_trans(s, c); + if (f == NULL) { + fprintf(stderr, "could not qemu_fopen_ft_trans\n"); + goto out; + } + + /* need to wait sender to setup */ + ret = qemu_ft_trans_begin(f); + if (ret < 0) { + goto out; + } + + qemu_set_fd_handler2(c, NULL, ft_trans_incoming, NULL, f); + ft_trans_schedule_replay(f); + ft_mode = FT_TRANSACTION_RECV; + + return; + } + qemu_fclose(f); + out: close(c); out2: -- 1.7.1.2