From patchwork Tue Jun 5 05:49:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonit Halperin X-Patchwork-Id: 163010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 80EAEB6EEC for ; Tue, 5 Jun 2012 15:49:06 +1000 (EST) Received: from localhost ([::1]:53531 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sbmdc-0001aX-C3 for incoming@patchwork.ozlabs.org; Tue, 05 Jun 2012 01:49:04 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbmdI-0001Jk-Vz for qemu-devel@nongnu.org; Tue, 05 Jun 2012 01:48:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SbmdG-0005JW-Vy for qemu-devel@nongnu.org; Tue, 05 Jun 2012 01:48:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56535) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbmdG-0005JL-OD for qemu-devel@nongnu.org; Tue, 05 Jun 2012 01:48:42 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q555mfnJ015687 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 5 Jun 2012 01:48:41 -0400 Received: from dhcp-0-9.tlv.redhat.com (dhcp-4-73.tlv.redhat.com [10.35.4.73]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q555mZB3025474; Tue, 5 Jun 2012 01:48:39 -0400 From: Yonit Halperin To: qemu-devel@nongnu.org Date: Tue, 5 Jun 2012 08:49:43 +0300 Message-Id: <1338875386-21051-3-git-send-email-yhalperi@redhat.com> In-Reply-To: <1338875386-21051-1-git-send-email-yhalperi@redhat.com> References: <1338875386-21051-1-git-send-email-yhalperi@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Yonit Halperin , aliguori@us.ibm.com, alevy@redhat.com, kraxel@redhat.com Subject: [Qemu-devel] [RFC PATCH 2/5] migration: moving migration start code to a separated routine X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Preparation for asynchronous migration state change notifiers. In a following patch the migrate_start routine will be used as the completion callback of the "migration start" notifiers list. Signed-off-by: Yonit Halperin --- migration.c | 73 +++++++++++++++++++++++++++++++++++++++++++++------------- migration.h | 2 + 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/migration.c b/migration.c index acaf293..91c807d 100644 --- a/migration.c +++ b/migration.c @@ -41,6 +41,14 @@ enum { MIG_STATE_COMPLETED, }; +enum { + MIGRATION_PROTOCOL_ERROR, + MIGRATION_PROTOCOL_TCP, + MIGRATION_PROTOCOL_EXEC, + MIGRATION_PROTOCOL_UNIX, + MIGRATION_PROTOCOL_FD, +}; + #define MAX_THROTTLE (32 << 20) /* Migration speed throttling */ static NotifierList migration_state_notifiers = @@ -361,13 +369,16 @@ void migrate_fd_connect(MigrationState *s) migrate_fd_put_ready(s); } -static MigrationState *migrate_init(int blk, int inc) +static MigrationState *migrate_init(int protocol, const char *protocol_param, + int blk, int inc) { MigrationState *s = migrate_get_current(); int64_t bandwidth_limit = s->bandwidth_limit; memset(s, 0, sizeof(*s)); s->bandwidth_limit = bandwidth_limit; + s->protocol = protocol; + s->protocol_param = g_strdup(protocol_param); s->blk = blk; s->shared = inc; @@ -389,13 +400,50 @@ void migrate_del_blocker(Error *reason) migration_blockers = g_slist_remove(migration_blockers, reason); } +static void migrate_start(MigrationState *s, Error **errp) +{ + int ret; + + switch (s->protocol) { + case MIGRATION_PROTOCOL_TCP: + ret = tcp_start_outgoing_migration(s, s->protocol_param, errp); + break; +#if !defined(WIN32) + case MIGRATION_PROTOCOL_EXEC: + ret = exec_start_outgoing_migration(s, s->protocol_param); + break; + case MIGRATION_PROTOCOL_UNIX: + ret = unix_start_outgoing_migration(s, s->protocol_param); + break; + case MIGRATION_PROTOCOL_FD: + ret = fd_start_outgoing_migration(s, s->protocol_param); + break; +#endif + default: + ret = -EPROTONOSUPPORT; + } + + g_free(s->protocol_param); + s->protocol_param = NULL; + + if (ret < 0) { + if (!error_is_set(errp)) { + DPRINTF("migration failed: %s\n", strerror(-ret)); + /* FIXME: we should return meaningful errors */ + error_set(errp, QERR_UNDEFINED_ERROR); + } + return; + } + notifier_list_notify(&migration_state_notifiers, s); +} + void qmp_migrate(const char *uri, bool has_blk, bool blk, bool has_inc, bool inc, bool has_detach, bool detach, Error **errp) { MigrationState *s = migrate_get_current(); const char *p; - int ret; + int migrate_protocol; if (s->state == MIG_STATE_ACTIVE) { error_set(errp, QERR_MIGRATION_ACTIVE); @@ -411,33 +459,24 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, return; } - s = migrate_init(blk, inc); - if (strstart(uri, "tcp:", &p)) { - ret = tcp_start_outgoing_migration(s, p, errp); + migrate_protocol = MIGRATION_PROTOCOL_TCP; #if !defined(WIN32) } else if (strstart(uri, "exec:", &p)) { - ret = exec_start_outgoing_migration(s, p); + migrate_protocol = MIGRATION_PROTOCOL_EXEC; } else if (strstart(uri, "unix:", &p)) { - ret = unix_start_outgoing_migration(s, p); + migrate_protocol = MIGRATION_PROTOCOL_UNIX; } else if (strstart(uri, "fd:", &p)) { - ret = fd_start_outgoing_migration(s, p); + migrate_protocol = MIGRATION_PROTOCOL_FD; #endif } else { error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); return; } + s = migrate_init(migrate_protocol, p, blk, inc); - if (ret < 0) { - if (!error_is_set(errp)) { - DPRINTF("migration failed: %s\n", strerror(-ret)); - /* FIXME: we should return meaningful errors */ - error_set(errp, QERR_UNDEFINED_ERROR); - } - return; - } + migrate_start(s, errp); - notifier_list_notify(&migration_state_notifiers, s); } void qmp_migrate_cancel(Error **errp) diff --git a/migration.h b/migration.h index 2e9ca2e..5ad67d7 100644 --- a/migration.h +++ b/migration.h @@ -33,6 +33,8 @@ struct MigrationState void *opaque; int blk; int shared; + int protocol; + char *protocol_param; }; void process_incoming_migration(QEMUFile *f);