From patchwork Wed Apr 20 14:44:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 8890651 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A992EBF29F for ; Wed, 20 Apr 2016 14:45:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1B6D520263 for ; Wed, 20 Apr 2016 14:45:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 61E2D20260 for ; Wed, 20 Apr 2016 14:45:13 +0000 (UTC) Received: from localhost ([::1]:50539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1astNQ-0006QX-E7 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Apr 2016 10:45:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1astN2-00069f-L2 for qemu-devel@nongnu.org; Wed, 20 Apr 2016 10:44:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1astN1-0002dX-LM for qemu-devel@nongnu.org; Wed, 20 Apr 2016 10:44:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60656) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1astN1-0002dR-G3 for qemu-devel@nongnu.org; Wed, 20 Apr 2016 10:44:47 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20ED2C05E16F for ; Wed, 20 Apr 2016 14:44:47 +0000 (UTC) Received: from emacs.mitica (ovpn-116-52.ams2.redhat.com [10.36.116.52]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3KEigqo020907; Wed, 20 Apr 2016 10:44:45 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 20 Apr 2016 16:44:30 +0200 Message-Id: <1461163481-11439-3-git-send-email-quintela@redhat.com> In-Reply-To: <1461163481-11439-1-git-send-email-quintela@redhat.com> References: <1461163481-11439-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 02/13] migration: Pass TCP args in an struct X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amit.shah@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Both for incomming and outgoing migration. Signed-off-by: Juan Quintela --- migration/tcp.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/migration/tcp.c b/migration/tcp.c index e1fa7f8..5d42c96 100644 --- a/migration/tcp.c +++ b/migration/tcp.c @@ -33,10 +33,16 @@ do { } while (0) #endif +struct OutgoingArgs { + MigrationState *s; +}; + static void tcp_wait_for_connect(int fd, Error *err, void *opaque) { - MigrationState *s = opaque; + struct OutgoingArgs *args = opaque; + MigrationState *s = args->s; + g_free(args); if (fd < 0) { DPRINTF("migrate connect error: %s\n", error_get_pretty(err)); s->to_dst_file = NULL; @@ -50,17 +56,26 @@ static void tcp_wait_for_connect(int fd, Error *err, void *opaque) void tcp_start_outgoing_migration(MigrationState *s, const char *host_port, Error **errp) { - inet_nonblocking_connect(host_port, tcp_wait_for_connect, s, errp); + struct OutgoingArgs *args = g_new0(struct OutgoingArgs, 1); + + args->s = s; + inet_nonblocking_connect(host_port, tcp_wait_for_connect, args, errp); } +struct IncomingArgs { + int s; +}; + static void tcp_accept_incoming_migration(void *opaque) { + struct IncomingArgs *args = opaque; struct sockaddr_in addr; socklen_t addrlen = sizeof(addr); - int s = (intptr_t)opaque; + int s = args->s; QEMUFile *f; int c; + g_free(args); do { c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen); } while (c < 0 && errno == EINTR); @@ -80,7 +95,6 @@ static void tcp_accept_incoming_migration(void *opaque) error_report("could not qemu_fopen socket"); goto out; } - process_incoming_migration(f); return; @@ -90,13 +104,14 @@ out: void tcp_start_incoming_migration(const char *host_port, Error **errp) { + struct IncomingArgs *args = g_new0(struct IncomingArgs, 1); int s; s = inet_listen(host_port, NULL, 256, SOCK_STREAM, 0, errp); if (s < 0) { + g_free(args); return; } - - qemu_set_fd_handler(s, tcp_accept_incoming_migration, NULL, - (void *)(intptr_t)s); + args->s = s; + qemu_set_fd_handler(s, tcp_accept_incoming_migration, NULL, args); }