From patchwork Mon May 24 08:25:26 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 53402 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AC51FB7D51 for ; Mon, 24 May 2010 18:29:30 +1000 (EST) Received: from localhost ([127.0.0.1]:44525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGT2N-00054T-CR for incoming@patchwork.ozlabs.org; Mon, 24 May 2010 04:29:27 -0400 Received: from [140.186.70.92] (port=57718 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGSyh-0003Xt-MC for qemu-devel@nongnu.org; Mon, 24 May 2010 04:25:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OGSye-0004S3-V6 for qemu-devel@nongnu.org; Mon, 24 May 2010 04:25:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30015) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGSye-0004Rv-EV for qemu-devel@nongnu.org; Mon, 24 May 2010 04:25:36 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4O8PZUi001060 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 24 May 2010 04:25:35 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4O8PTZ2015804; Mon, 24 May 2010 04:25:34 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 24 May 2010 10:25:26 +0200 Message-Id: <1bb9c5ca9d1a4b35bae5bfafac53a99a1a7d2d45.1274688090.git.quintela@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 2/5] Factorize common migration incoming code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Juan Quintela --- migration-exec.c | 14 +------------- migration-fd.c | 14 +------------- migration-tcp.c | 15 ++------------- migration-unix.c | 15 ++------------- migration.c | 13 +++++++++++++ migration.h | 2 ++ 6 files changed, 21 insertions(+), 52 deletions(-) diff --git a/migration-exec.c b/migration-exec.c index 5435827..07af11a 100644 --- a/migration-exec.c +++ b/migration-exec.c @@ -111,20 +111,8 @@ err_after_alloc: static void exec_accept_incoming_migration(void *opaque) { QEMUFile *f = opaque; - int ret; - ret = qemu_loadvm_state(f); - if (ret < 0) { - fprintf(stderr, "load of migration failed\n"); - goto err; - } - qemu_announce_self(); - DPRINTF("successfully loaded vm state\n"); - - if (autostart) - vm_start(); - -err: + process_incoming_migration(f); qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL); qemu_fclose(f); } diff --git a/migration-fd.c b/migration-fd.c index 0abd372..6d14505 100644 --- a/migration-fd.c +++ b/migration-fd.c @@ -104,20 +104,8 @@ err_after_alloc: static void fd_accept_incoming_migration(void *opaque) { QEMUFile *f = opaque; - int ret; - ret = qemu_loadvm_state(f); - if (ret < 0) { - fprintf(stderr, "load of migration failed\n"); - goto err; - } - qemu_announce_self(); - DPRINTF("successfully loaded vm state\n"); - - if (autostart) - vm_start(); - -err: + process_incoming_migration(f); qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL); qemu_fclose(f); } diff --git a/migration-tcp.c b/migration-tcp.c index 95ce722..20f2e37 100644 --- a/migration-tcp.c +++ b/migration-tcp.c @@ -143,7 +143,7 @@ static void tcp_accept_incoming_migration(void *opaque) socklen_t addrlen = sizeof(addr); int s = (unsigned long)opaque; QEMUFile *f; - int c, ret; + int c; do { c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen); @@ -162,18 +162,7 @@ static void tcp_accept_incoming_migration(void *opaque) goto out; } - ret = qemu_loadvm_state(f); - if (ret < 0) { - fprintf(stderr, "load of migration failed\n"); - goto out_fopen; - } - qemu_announce_self(); - DPRINTF("successfully loaded vm state\n"); - - if (autostart) - vm_start(); - -out_fopen: + process_incoming_migration(f); qemu_fclose(f); out: qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL); diff --git a/migration-unix.c b/migration-unix.c index 49de1b9..57232c0 100644 --- a/migration-unix.c +++ b/migration-unix.c @@ -149,7 +149,7 @@ static void unix_accept_incoming_migration(void *opaque) socklen_t addrlen = sizeof(addr); int s = (unsigned long)opaque; QEMUFile *f; - int c, ret; + int c; do { c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen); @@ -168,18 +168,7 @@ static void unix_accept_incoming_migration(void *opaque) goto out; } - ret = qemu_loadvm_state(f); - if (ret < 0) { - fprintf(stderr, "load of migration failed\n"); - goto out_fopen; - } - qemu_announce_self(); - DPRINTF("successfully loaded vm state\n"); - - if (autostart) - vm_start(); - -out_fopen: + process_incoming_migration(f); qemu_fclose(f); out: qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL); diff --git a/migration.c b/migration.c index cf30a8e..6ab5d90 100644 --- a/migration.c +++ b/migration.c @@ -54,6 +54,19 @@ int qemu_start_incoming_migration(const char *uri) return ret; } +void process_incoming_migration(QEMUFile *f) +{ + if (qemu_loadvm_state(f) < 0) { + fprintf(stderr, "load of migration failed\n"); + exit(0); + } + qemu_announce_self(); + DPRINTF("successfully loaded vm state\n"); + + if (autostart) + vm_start(); +} + int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data) { MigrationState *s = NULL; diff --git a/migration.h b/migration.h index dd423a1..017e9c3 100644 --- a/migration.h +++ b/migration.h @@ -50,6 +50,8 @@ struct FdMigrationState void *opaque; }; +void process_incoming_migration(QEMUFile *f); + int qemu_start_incoming_migration(const char *uri); int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data);