From patchwork Wed May 30 09:02:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonit Halperin X-Patchwork-Id: 161895 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 804D6B6EE6 for ; Wed, 30 May 2012 19:02:12 +1000 (EST) Received: from localhost ([::1]:56977 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZenB-0008QI-9I for incoming@patchwork.ozlabs.org; Wed, 30 May 2012 05:02:09 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZemp-0008F1-1e for qemu-devel@nongnu.org; Wed, 30 May 2012 05:01:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SZemm-0003vd-0h for qemu-devel@nongnu.org; Wed, 30 May 2012 05:01:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24981) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZeml-0003vL-Ox for qemu-devel@nongnu.org; Wed, 30 May 2012 05:01:43 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q4U91fro030752 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 30 May 2012 05:01:41 -0400 Received: from dhcp-0-9.tlv.redhat.com (dhcp-4-73.tlv.redhat.com [10.35.4.73]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q4U91Z47009698; Wed, 30 May 2012 05:01:40 -0400 From: Yonit Halperin To: qemu-devel@nongnu.org Date: Wed, 30 May 2012 12:02:38 +0300 Message-Id: <1338368559-16535-4-git-send-email-yhalperi@redhat.com> In-Reply-To: <1338368559-16535-1-git-send-email-yhalperi@redhat.com> References: <1338368559-16535-1-git-send-email-yhalperi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Yonit Halperin , spice-devel@freedesktop.org Subject: [Qemu-devel] [RFC PATCH 3/4] migration: moving migration completion 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. Signed-off-by: Yonit Halperin --- migration.c | 31 ++++++++++++++++--------------- migration.h | 1 + 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/migration.c b/migration.c index 91c807d..c86611d 100644 --- a/migration.c +++ b/migration.c @@ -187,24 +187,32 @@ static int migrate_fd_cleanup(MigrationState *s) return ret; } +static void migrate_end(MigrationState *s, int end_state) +{ + s->state = end_state; + if (s->state == MIG_STATE_COMPLETED) { + runstate_set(RUN_STATE_POSTMIGRATE); + } else if (s->state == MIG_STATE_ERROR && s->start_vm_in_error) { + vm_start(); + } + notifier_list_notify(&migration_state_notifiers, s); +} + void migrate_fd_error(MigrationState *s) { DPRINTF("setting error state\n"); - s->state = MIG_STATE_ERROR; - notifier_list_notify(&migration_state_notifiers, s); migrate_fd_cleanup(s); + migrate_end(s, MIG_STATE_ERROR); } static void migrate_fd_completed(MigrationState *s) { DPRINTF("setting completed state\n"); if (migrate_fd_cleanup(s) < 0) { - s->state = MIG_STATE_ERROR; + migrate_end(s, MIG_STATE_ERROR); } else { - s->state = MIG_STATE_COMPLETED; - runstate_set(RUN_STATE_POSTMIGRATE); + migrate_end(s, MIG_STATE_COMPLETED); } - notifier_list_notify(&migration_state_notifiers, s); } static void migrate_fd_put_notify(void *opaque) @@ -257,7 +265,7 @@ static void migrate_fd_put_ready(void *opaque) if (ret < 0) { migrate_fd_error(s); } else if (ret == 1) { - int old_vm_running = runstate_is_running(); + s->start_vm_in_error = runstate_is_running(); DPRINTF("done iterating\n"); qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); @@ -268,11 +276,6 @@ static void migrate_fd_put_ready(void *opaque) } else { migrate_fd_completed(s); } - if (s->state != MIG_STATE_COMPLETED) { - if (old_vm_running) { - vm_start(); - } - } } } @@ -283,11 +286,9 @@ static void migrate_fd_cancel(MigrationState *s) DPRINTF("cancelling migration\n"); - s->state = MIG_STATE_CANCELLED; - notifier_list_notify(&migration_state_notifiers, s); qemu_savevm_state_cancel(s->file); - migrate_fd_cleanup(s); + migrate_end(s, MIG_STATE_CANCELLED); } static void migrate_fd_wait_for_unfreeze(void *opaque) diff --git a/migration.h b/migration.h index 5ad67d7..6a0f49f 100644 --- a/migration.h +++ b/migration.h @@ -35,6 +35,7 @@ struct MigrationState int shared; int protocol; char *protocol_param; + bool start_vm_in_error; }; void process_incoming_migration(QEMUFile *f);