From patchwork Tue Dec 15 08:22:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 556819 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1DF6A1402D9 for ; Tue, 15 Dec 2015 19:25:06 +1100 (AEDT) Received: from localhost ([::1]:35579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8kut-0003uR-Q2 for incoming@patchwork.ozlabs.org; Tue, 15 Dec 2015 03:25:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8ku9-0002iQ-Nw for qemu-devel@nongnu.org; Tue, 15 Dec 2015 03:24:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a8ku6-0000p0-Hq for qemu-devel@nongnu.org; Tue, 15 Dec 2015 03:24:17 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:51563) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8ku5-0000nq-Ll for qemu-devel@nongnu.org; Tue, 15 Dec 2015 03:24:14 -0500 Received: from 172.24.1.47 (EHLO SZXEML429-HUB.china.huawei.com) ([172.24.1.47]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CYB20993; Tue, 15 Dec 2015 16:23:58 +0800 (CST) Received: from localhost (10.177.24.212) by SZXEML429-HUB.china.huawei.com (10.82.67.184) with Microsoft SMTP Server id 14.3.235.1; Tue, 15 Dec 2015 16:23:50 +0800 From: zhanghailiang To: Date: Tue, 15 Dec 2015 16:22:25 +0800 Message-ID: <1450167779-9960-5-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1450167779-9960-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1450167779-9960-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.566FCE1F.0076, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: df54c8784dc947b1794fb7c0d22b83cf X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Cc: lizhijian@cn.fujitsu.com, quintela@redhat.com, yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, zhanghailiang , arei.gonglei@huawei.com, stefanha@redhat.com, amit.shah@redhat.com, hongyang.yang@easystack.cn Subject: [Qemu-devel] [PATCH COLO-Frame v12 04/38] migration: Export migrate_set_state() 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 Fix the first parameter of migrate_set_state(), and export it. We will use it in later. Signed-off-by: zhanghailiang Reviewed-by: Dr. David Alan Gilbert --- v12: - Add Reviewed-by tag v11: - New patch which is split from patch 'migration: Add state records for migration incoming' (Juan's suggestion) Signed-off-by: zhanghailiang --- include/migration/migration.h | 2 ++ migration/migration.c | 36 +++++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index 1f004e4..4b19e80 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -169,6 +169,8 @@ struct MigrationState RAMBlock *last_req_rb; }; +void migrate_set_state(int *state, int old_state, int new_state); + void process_incoming_migration(QEMUFile *f); void qemu_start_incoming_migration(const char *uri, Error **errp); diff --git a/migration/migration.c b/migration/migration.c index 0d525ee..c9cd80d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -798,9 +798,9 @@ void qmp_migrate_start_postcopy(Error **errp) /* shared migration helpers */ -static void migrate_set_state(MigrationState *s, int old_state, int new_state) +void migrate_set_state(int *state, int old_state, int new_state) { - if (atomic_cmpxchg(&s->state, old_state, new_state) == old_state) { + if (atomic_cmpxchg(state, old_state, new_state) == old_state) { trace_migrate_set_state(new_state); migrate_generate_event(new_state); } @@ -833,7 +833,7 @@ static void migrate_fd_cleanup(void *opaque) (s->state != MIGRATION_STATUS_POSTCOPY_ACTIVE)); if (s->state == MIGRATION_STATUS_CANCELLING) { - migrate_set_state(s, MIGRATION_STATUS_CANCELLING, + migrate_set_state(&s->state, MIGRATION_STATUS_CANCELLING, MIGRATION_STATUS_CANCELLED); } @@ -844,7 +844,8 @@ void migrate_fd_error(MigrationState *s) { trace_migrate_fd_error(); assert(s->file == NULL); - migrate_set_state(s, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_FAILED); + migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_FAILED); notifier_list_notify(&migration_state_notifiers, s); } @@ -864,7 +865,7 @@ static void migrate_fd_cancel(MigrationState *s) if (!migration_is_setup_or_active(old_state)) { break; } - migrate_set_state(s, old_state, MIGRATION_STATUS_CANCELLING); + migrate_set_state(&s->state, old_state, MIGRATION_STATUS_CANCELLING); } while (s->state != MIGRATION_STATUS_CANCELLING); /* @@ -938,7 +939,7 @@ MigrationState *migrate_init(const MigrationParams *params) s->migration_thread_running = false; s->last_req_rb = NULL; - migrate_set_state(s, MIGRATION_STATUS_NONE, MIGRATION_STATUS_SETUP); + migrate_set_state(&s->state, MIGRATION_STATUS_NONE, MIGRATION_STATUS_SETUP); QSIMPLEQ_INIT(&s->src_page_requests); @@ -1037,7 +1038,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, } else { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); - migrate_set_state(s, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_FAILED); + migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_FAILED); return; } @@ -1416,7 +1418,7 @@ static int postcopy_start(MigrationState *ms, bool *old_vm_running) int ret; const QEMUSizedBuffer *qsb; int64_t time_at_stop = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); - migrate_set_state(ms, MIGRATION_STATUS_ACTIVE, + migrate_set_state(&ms->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_POSTCOPY_ACTIVE); trace_postcopy_start(); @@ -1507,7 +1509,7 @@ static int postcopy_start(MigrationState *ms, bool *old_vm_running) ret = qemu_file_get_error(ms->file); if (ret) { error_report("postcopy_start: Migration stream errored"); - migrate_set_state(ms, MIGRATION_STATUS_POSTCOPY_ACTIVE, + migrate_set_state(&ms->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, MIGRATION_STATUS_FAILED); } @@ -1516,7 +1518,7 @@ static int postcopy_start(MigrationState *ms, bool *old_vm_running) fail_closefb: qemu_fclose(fb); fail: - migrate_set_state(ms, MIGRATION_STATUS_POSTCOPY_ACTIVE, + migrate_set_state(&ms->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, MIGRATION_STATUS_FAILED); qemu_mutex_unlock_iothread(); return -1; @@ -1585,11 +1587,13 @@ static void migration_completion(MigrationState *s, int current_active_state, goto fail; } - migrate_set_state(s, current_active_state, MIGRATION_STATUS_COMPLETED); + migrate_set_state(&s->state, current_active_state, + MIGRATION_STATUS_COMPLETED); return; fail: - migrate_set_state(s, current_active_state, MIGRATION_STATUS_FAILED); + migrate_set_state(&s->state, current_active_state, + MIGRATION_STATUS_FAILED); } bool migrate_colo_enabled(void) @@ -1640,7 +1644,8 @@ static void *migration_thread(void *opaque) s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start; current_active_state = MIGRATION_STATUS_ACTIVE; - migrate_set_state(s, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_ACTIVE); + migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_ACTIVE); trace_migration_thread_setup_complete(); @@ -1683,7 +1688,8 @@ static void *migration_thread(void *opaque) } if (qemu_file_get_error(s->file)) { - migrate_set_state(s, current_active_state, MIGRATION_STATUS_FAILED); + migrate_set_state(&s->state, current_active_state, + MIGRATION_STATUS_FAILED); trace_migration_thread_file_err(); break; } @@ -1764,7 +1770,7 @@ void migrate_fd_connect(MigrationState *s) if (migrate_postcopy_ram()) { if (open_return_path_on_source(s)) { error_report("Unable to open return-path for postcopy"); - migrate_set_state(s, MIGRATION_STATUS_SETUP, + migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_FAILED); migrate_fd_cleanup(s); return;