From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41616) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsKwf-0006Ii-4g for qemu-devel@nongnu.org; Thu, 27 Jun 2013 18:45:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UsKwc-0002yE-71 for qemu-devel@nongnu.org; Thu, 27 Jun 2013 18:45:41 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]:40611) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsKwc-0002y6-2E for qemu-devel@nongnu.org; Thu, 27 Jun 2013 18:45:38 -0400 Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 27 Jun 2013 18:45:37 -0400 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id AED446E8028 for ; Thu, 27 Jun 2013 18:45:30 -0400 (EDT) Received: from d01av05.pok.ibm.com (d01av05.pok.ibm.com [9.56.224.195]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r5RMj1x1242904 for ; Thu, 27 Jun 2013 18:45:01 -0400 Received: from d01av05.pok.ibm.com (loopback [127.0.0.1]) by d01av05.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r5RMj1oo010313 for ; Thu, 27 Jun 2013 18:45:01 -0400 From: mrhines@linux.vnet.ibm.com Date: Thu, 27 Jun 2013 18:44:56 -0400 Message-Id: <1372373098-5877-5-git-send-email-mrhines@linux.vnet.ibm.com> In-Reply-To: <1372373098-5877-1-git-send-email-mrhines@linux.vnet.ibm.com> References: <1372373098-5877-1-git-send-email-mrhines@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 4/6] rdma: allow state transitions between other states besides ACTIVE List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, quintela@redhat.com, knoel@redhat.com, owasserm@redhat.com, abali@us.ibm.com, mrhines@us.ibm.com, gokul@us.ibm.com, pbonzini@redhat.com, chegu_vinod@hp.com From: "Michael R. Hines" This patch is in preparation for the next ones: Until now the MIG_STATE_SETUP state was not really a 'formal' state. It has been used as a 'zero' state and QEMU has been unconditionally transitioning into this state when the QMP migrate command was called. In preparation for timing this state, we have to make this state a a 'real' state which actually gets transitioned from later in the migration_thread() from SETUP => ACTIVE, rather than just automatically dropping into this state at the beginninig of the migration. This means that the state transition function (migration_finish_set_state()) needs to be capable of transitioning from valid states _other_ than just MIG_STATE_ACTIVE. The function is in fact already capable of doing that, but was not allowing the old state to be a parameter specified as an input. This patch fixes that and only makes the transition if the current state matches the old state that the caller intended to transition from. Reviewed-by: Juan Quintela Tested-by: Michael R. Hines Signed-off-by: Michael R. Hines --- migration.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/migration.c b/migration.c index 62c6b85..cbfdb2c 100644 --- a/migration.c +++ b/migration.c @@ -295,9 +295,9 @@ static void migrate_fd_cleanup(void *opaque) notifier_list_notify(&migration_state_notifiers, s); } -static void migrate_finish_set_state(MigrationState *s, int new_state) +static void migrate_set_state(MigrationState *s, int old_state, int new_state) { - if (__sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE, + if (__sync_val_compare_and_swap(&s->state, old_state, new_state) == new_state) { trace_migrate_set_state(new_state); } @@ -316,7 +316,7 @@ static void migrate_fd_cancel(MigrationState *s) { DPRINTF("cancelling migration\n"); - migrate_finish_set_state(s, MIG_STATE_CANCELLED); + migrate_set_state(s, s->state, MIG_STATE_CANCELLED); } void add_migration_state_change_notifier(Notifier *notify) @@ -546,14 +546,14 @@ static void *migration_thread(void *opaque) qemu_savevm_state_complete(s->file); qemu_mutex_unlock_iothread(); if (!qemu_file_get_error(s->file)) { - migrate_finish_set_state(s, MIG_STATE_COMPLETED); + migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_COMPLETED); break; } } } if (qemu_file_get_error(s->file)) { - migrate_finish_set_state(s, MIG_STATE_ERROR); + migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_ERROR); break; } current_time = qemu_get_clock_ms(rt_clock); -- 1.7.10.4