From patchwork Thu Nov 7 08:21:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhanghaoyu (A)" X-Patchwork-Id: 289224 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F1B362C00B3 for ; Thu, 7 Nov 2013 19:22:20 +1100 (EST) Received: from localhost ([::1]:38876 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VeKr4-0005cg-S1 for incoming@patchwork.ozlabs.org; Thu, 07 Nov 2013 03:22:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VeKqk-0005UG-Au for qemu-devel@nongnu.org; Thu, 07 Nov 2013 03:22:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VeKqf-0002hz-Ft for qemu-devel@nongnu.org; Thu, 07 Nov 2013 03:21:58 -0500 Received: from szxga01-in.huawei.com ([119.145.14.64]:1107) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VeKqe-0002hE-RZ for qemu-devel@nongnu.org; Thu, 07 Nov 2013 03:21:53 -0500 Received: from 172.24.2.119 (EHLO szxeml210-edg.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BMF42862; Thu, 07 Nov 2013 16:21:32 +0800 (CST) Received: from SZXEML415-HUB.china.huawei.com (10.82.67.154) by szxeml210-edg.china.huawei.com (172.24.2.183) with Microsoft SMTP Server (TLS) id 14.3.158.1; Thu, 7 Nov 2013 16:21:28 +0800 Received: from szxeml556-mbx.china.huawei.com ([169.254.3.69]) by szxeml415-hub.china.huawei.com ([10.82.67.154]) with mapi id 14.03.0158.001; Thu, 7 Nov 2013 16:21:24 +0800 From: "Zhanghaoyu (A)" To: "qemu-devel@nongnu.org" , Paolo Bonzini , "Michael S. Tsirkin" , Marcelo Tosatti , Eric Blake , Gleb Natapov Thread-Topic: [patch] avoid a bogus COMPLETED->CANCELLED transition Thread-Index: Ac7bklfq/SLLk21RRYiGUI915wnLnA== Date: Thu, 7 Nov 2013 08:21:23 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.135.68.97] MIME-Version: 1.0 X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.64 Cc: "Huangweidong \(C\)" , "Zhanghaoyu \(A\)" , Luonengjun , Zengjunliang , "Wangrui \(K\)" Subject: [Qemu-devel] [patch] avoid a bogus COMPLETED->CANCELLED transition 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 Avoid a bogus COMPLETED->CANCELLED transition. There is a period of time from the timing of setting COMPLETED state to that of migration thread exits, so during which it's problematic in COMPLETED->CANCELLED transition. Signed-off-by: Zeng Junliang Signed-off-by: Zhang Haoyu Reviewed-by: Paolo Bonzini --- migration.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/migration.c b/migration.c index 2b1ab20..fd73b97 100644 --- a/migration.c +++ b/migration.c @@ -326,9 +326,16 @@ void migrate_fd_error(MigrationState *s) static void migrate_fd_cancel(MigrationState *s) { + int old_state ; DPRINTF("cancelling migration\n"); - migrate_set_state(s, s->state, MIG_STATE_CANCELLED); + do { + old_state = s->state; + if (old_state != MIG_STATE_SETUP && old_state != MIG_STATE_ACTIVE) { + break; + } + migrate_set_state(s, old_state, MIG_STATE_CANCELLED); + } while (s->state != MIG_STATE_CANCELLED); } void add_migration_state_change_notifier(Notifier *notify)