From patchwork Sat Feb 6 09:28:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 8242071 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 345FD9F38B for ; Sat, 6 Feb 2016 09:37:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5CC632011E for ; Sat, 6 Feb 2016 09:37:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E2A6200F2 for ; Sat, 6 Feb 2016 09:37:48 +0000 (UTC) Received: from localhost ([::1]:52620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRzJL-0000Kb-MM for patchwork-qemu-devel@patchwork.kernel.org; Sat, 06 Feb 2016 04:37:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRzBj-0002bi-8w for qemu-devel@nongnu.org; Sat, 06 Feb 2016 04:29:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRzBa-0001Qx-Lr for qemu-devel@nongnu.org; Sat, 06 Feb 2016 04:29:49 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:22350) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRzBZ-0001Qk-QN for qemu-devel@nongnu.org; Sat, 06 Feb 2016 04:29:46 -0500 Received: from 172.24.1.49 (EHLO SZXEML424-HUB.china.huawei.com) ([172.24.1.49]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BVU12145; Sat, 06 Feb 2016 17:29:37 +0800 (CST) Received: from localhost (10.177.24.212) by SZXEML424-HUB.china.huawei.com (10.82.67.153) with Microsoft SMTP Server id 14.3.235.1; Sat, 6 Feb 2016 17:29:31 +0800 From: zhanghailiang To: Date: Sat, 6 Feb 2016 17:28:36 +0800 Message-ID: <1454750932-7556-25-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1454750932-7556-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1454750932-7556-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.0A020206.56B5BD01.00AF, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 5325abb37d962e20574bd31f78002b87 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.66 Cc: xiecl.fnst@cn.fujitsu.com, lizhijian@cn.fujitsu.com, quintela@redhat.com, armbru@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, Paolo Bonzini , amit.shah@redhat.com, zhangchen.fnst@cn.fujitsu.com, hongyang.yang@easystack.cn Subject: [Qemu-devel] [PATCH COLO-Frame v14 24/40] COLO: Process shutdown command for VM in COLO 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If VM is in COLO FT state, we should do some extra work before normal shutdown process. SVM will ignore the shutdown command if this command is issued directly to it, PVM will send the shutdown command to SVM if it gets this command. Cc: Paolo Bonzini Signed-off-by: zhanghailiang Signed-off-by: Li Zhijian Reviewed-by: Dr. David Alan Gilbert --- v14: - Remove 'colo_shutdown' variable, use colo_shutdown_request directly v13: - Move COLO shutdown related codes to colo.c file (Dave's suggestion) --- include/migration/colo.h | 2 ++ include/sysemu/sysemu.h | 3 +++ migration/colo.c | 42 ++++++++++++++++++++++++++++++++++++++++-- qapi-schema.json | 4 +++- stubs/migration-colo.c | 5 +++++ vl.c | 19 ++++++++++++++++--- 6 files changed, 69 insertions(+), 6 deletions(-) diff --git a/include/migration/colo.h b/include/migration/colo.h index e32eef4..919b135 100644 --- a/include/migration/colo.h +++ b/include/migration/colo.h @@ -35,4 +35,6 @@ COLOMode get_colo_mode(void); /* failover */ void colo_do_failover(MigrationState *s); + +bool colo_shutdown(void); #endif diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 3bb8897..91eeda3 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -52,6 +52,8 @@ typedef enum WakeupReason { QEMU_WAKEUP_REASON_OTHER, } WakeupReason; +extern int colo_shutdown_requested; + void qemu_system_reset_request(void); void qemu_system_suspend_request(void); void qemu_register_suspend_notifier(Notifier *notifier); @@ -59,6 +61,7 @@ void qemu_system_wakeup_request(WakeupReason reason); void qemu_system_wakeup_enable(WakeupReason reason, bool enabled); void qemu_register_wakeup_notifier(Notifier *notifier); void qemu_system_shutdown_request(void); +void qemu_system_shutdown_request_core(void); void qemu_system_powerdown_request(void); void qemu_register_powerdown_notifier(Notifier *notifier); void qemu_system_debug_request(void); diff --git a/migration/colo.c b/migration/colo.c index 515d561..92be985 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -330,6 +330,18 @@ static int colo_do_checkpoint_transaction(MigrationState *s, goto out; } + if (colo_shutdown_requested) { + colo_put_cmd(s->to_dst_file, COLO_MESSAGE_GUEST_SHUTDOWN, &local_err); + if (local_err) { + goto out; + } + qemu_fflush(s->to_dst_file); + colo_shutdown_requested = 0; + qemu_system_shutdown_request_core(); + /* Fix me: Just let the colo thread exit ? */ + qemu_thread_exit(0); + } + ret = 0; /* Resume primary guest */ qemu_mutex_lock_iothread(); @@ -390,8 +402,9 @@ static void colo_process_checkpoint(MigrationState *s) } current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); - if (current_time - checkpoint_time < - s->parameters[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY]) { + if ((current_time - checkpoint_time < + s->parameters[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY]) && + !colo_shutdown_requested) { int64_t delay_ms; delay_ms = s->parameters[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY] - @@ -465,6 +478,15 @@ static void colo_wait_handle_cmd(QEMUFile *f, int *checkpoint_request, case COLO_MESSAGE_CHECKPOINT_REQUEST: *checkpoint_request = 1; break; + case COLO_MESSAGE_GUEST_SHUTDOWN: + qemu_mutex_lock_iothread(); + vm_stop_force_state(RUN_STATE_COLO); + qemu_system_shutdown_request_core(); + qemu_mutex_unlock_iothread(); + /* the main thread will exit and terminate the whole + * process, do we need some cleanup? + */ + qemu_thread_exit(0); default: *checkpoint_request = 0; error_setg(errp, "Got unknown COLO command: %d", cmd); @@ -636,3 +658,19 @@ out: return NULL; } + +bool colo_shutdown(void) +{ + /* + * if in colo mode, we need do some significant work before respond + * to the shutdown request. + */ + if (migration_incoming_in_colo_state()) { + return true; /* primary's responsibility */ + } + if (migration_in_colo_state()) { + colo_shutdown_requested = 1; + return true; + } + return false; +} diff --git a/qapi-schema.json b/qapi-schema.json index 7fec696..4d8ba04 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -752,12 +752,14 @@ # # @vmstate-loaded: VM's state has been loaded by SVM. # +# @guest-shutdown: shutdown require from PVM to SVM +# # Since: 2.6 ## { 'enum': 'COLOMessage', 'data': [ 'checkpoint-ready', 'checkpoint-request', 'checkpoint-reply', 'vmstate-send', 'vmstate-size', 'vmstate-received', - 'vmstate-loaded' ] } + 'vmstate-loaded', 'guest-shutdown' ] } ## # @COLOMode diff --git a/stubs/migration-colo.c b/stubs/migration-colo.c index a6cd6e5..1996cd9 100644 --- a/stubs/migration-colo.c +++ b/stubs/migration-colo.c @@ -43,3 +43,8 @@ void qmp_x_colo_lost_heartbeat(Error **errp) " with --enable-colo option in order to support" " COLO feature"); } + +bool colo_shutdown(void) +{ + return false; +} diff --git a/vl.c b/vl.c index f16fe2d..90da8d1 100644 --- a/vl.c +++ b/vl.c @@ -1631,6 +1631,8 @@ static NotifierList wakeup_notifiers = NOTIFIER_LIST_INITIALIZER(wakeup_notifiers); static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE); +int colo_shutdown_requested; + int qemu_shutdown_requested_get(void) { return shutdown_requested; @@ -1762,7 +1764,10 @@ void qemu_system_guest_panicked(void) void qemu_system_reset_request(void) { if (no_reboot) { - shutdown_requested = 1; + qemu_system_shutdown_request(); + if (!shutdown_requested) {/* colo handle it ? */ + return; + } } else { reset_requested = 1; } @@ -1835,14 +1840,22 @@ void qemu_system_killed(int signal, pid_t pid) qemu_notify_event(); } -void qemu_system_shutdown_request(void) +void qemu_system_shutdown_request_core(void) { - trace_qemu_system_shutdown_request(); replay_shutdown_request(); shutdown_requested = 1; qemu_notify_event(); } +void qemu_system_shutdown_request(void) +{ + trace_qemu_system_shutdown_request(); + if (colo_shutdown()) { + return; + } + qemu_system_shutdown_request_core(); +} + static void qemu_system_powerdown(void) { qapi_event_send_powerdown(&error_abort);