From patchwork Thu Jun 18 08:58:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 486227 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 BFC36140187 for ; Thu, 18 Jun 2015 19:17:30 +1000 (AEST) Received: from localhost ([::1]:51250 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5Vwu-0005Ox-T6 for incoming@patchwork.ozlabs.org; Thu, 18 Jun 2015 05:17:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5Vgi-00023B-1U for qemu-devel@nongnu.org; Thu, 18 Jun 2015 05:00:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5Vge-0002to-GK for qemu-devel@nongnu.org; Thu, 18 Jun 2015 05:00:43 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:5741) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5Vgd-0002rf-Q1 for qemu-devel@nongnu.org; Thu, 18 Jun 2015 05:00:40 -0400 Received: from 172.24.2.119 (EHLO szxeml434-hub.china.huawei.com) ([172.24.2.119]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BHW55682; Thu, 18 Jun 2015 17:00:26 +0800 (CST) Received: from localhost (10.177.22.69) by szxeml434-hub.china.huawei.com (10.82.67.225) with Microsoft SMTP Server id 14.3.158.1; Thu, 18 Jun 2015 17:00:15 +0800 From: zhanghailiang To: Date: Thu, 18 Jun 2015 16:58:54 +0800 Message-ID: <1434617935-6924-31-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.2.msysgit.0 In-Reply-To: <1434617935-6924-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1434617935-6924-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.22.69] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.558288B0.00DF, 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: 0a4c6cb8de67122951de968d002d608c 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: 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, amit.shah@redhat.com, Paolo Bonzini , laijs@cn.fujitsu.com Subject: [Qemu-devel] [PATCH COLO-Frame v6 30/31] COLO: Implement shutdown checkpoint 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 For Secondary VM, we forbid it shutdown directly when in COLO mode, FOR Primary VM's shutdown, we should do some work to ensure the consistent action between PVM and SVM. Cc: Paolo Bonzini Signed-off-by: zhanghailiang Signed-off-by: Lai Jiangshan Signed-off-by: Li Zhijian --- include/sysemu/sysemu.h | 3 +++ migration/colo.c | 32 +++++++++++++++++++++++++++++++- vl.c | 26 ++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 0304aa7..a77e18f 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -51,6 +51,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); @@ -58,6 +60,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 8d6d166..499a042 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -68,6 +68,8 @@ enum { COLO_CHECKPOINT_SEND, COLO_CHECKPOINT_RECEIVED, COLO_CHECKPOINT_LOADED, + + COLO_GUEST_SHUTDOWN }; static QEMUBH *colo_bh; @@ -224,7 +226,7 @@ static int colo_ctl_get(QEMUFile *f, uint64_t require) static int colo_do_checkpoint_transaction(MigrationState *s, QEMUFile *control) { - int ret; + int colo_shutdown, ret; size_t size; QEMUFile *trans = NULL; @@ -251,6 +253,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s, QEMUFile *control) } /* suspend and save vm state to colo buffer */ qemu_mutex_lock_iothread(); + colo_shutdown = colo_shutdown_requested; vm_stop_force_state(RUN_STATE_COLO); qemu_mutex_unlock_iothread(); trace_colo_vm_state_change("run", "stop"); @@ -266,6 +269,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s, QEMUFile *control) /* Disable block migration */ s->params.blk = 0; s->params.shared = 0; + qemu_savevm_state_header(trans); qemu_savevm_state_begin(trans, &s->params); qemu_mutex_lock_iothread(); qemu_savevm_state_complete(trans); @@ -308,6 +312,16 @@ static int colo_do_checkpoint_transaction(MigrationState *s, QEMUFile *control) } trace_colo_receive_message("COLO_CHECKPOINT_LOADED"); + if (colo_shutdown) { + colo_ctl_put(s->file, COLO_GUEST_SHUTDOWN); + qemu_fflush(s->file); + colo_shutdown_requested = 0; + qemu_system_shutdown_request_core(); + while (1) { + ; + } + } + ret = 0; /* resume master */ qemu_mutex_lock_iothread(); @@ -372,6 +386,10 @@ static void *colo_thread(void *opaque) error_report("failover request"); goto out; } + + if (colo_shutdown_requested) { + goto do_checkpoint; + } /* wait for a colo checkpoint */ proxy_checkpoint_req = colo_proxy_compare(); if (proxy_checkpoint_req < 0) { @@ -489,6 +507,18 @@ static int colo_wait_handle_cmd(QEMUFile *f, int *checkpoint_request) case COLO_CHECKPOINT_NEW: *checkpoint_request = 1; return 0; + case COLO_GUEST_SHUTDOWN: + qemu_mutex_lock_iothread(); + vm_stop_force_state(RUN_STATE_COLO); + qemu_system_shutdown_request_core(); + qemu_mutex_unlock_iothread(); + trace_colo_receive_message("COLO_GUEST_SHUTDOWN"); + /* the main thread will exit and termiante the whole + * process, do we need some cleanup? + */ + for (;;) { + ; + } default: return -1; } diff --git a/vl.c b/vl.c index 8f81062..0ff9e37 100644 --- a/vl.c +++ b/vl.c @@ -1543,6 +1543,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; @@ -1659,6 +1661,10 @@ void qemu_system_reset(bool report) void qemu_system_reset_request(void) { if (no_reboot) { + qemu_system_shutdown_request(); + if (!shutdown_requested) {/* colo handle it ? */ + return; + } shutdown_requested = 1; } else { reset_requested = 1; @@ -1727,13 +1733,29 @@ void qemu_system_killed(int signal, pid_t pid) qemu_system_shutdown_request(); } -void qemu_system_shutdown_request(void) +void qemu_system_shutdown_request_core(void) { - trace_qemu_system_shutdown_request(); shutdown_requested = 1; qemu_notify_event(); } +void qemu_system_shutdown_request(void) +{ + trace_qemu_system_shutdown_request(); + /* + * if in colo mode, we need do some significant work before respond to the + * shutdown request. + */ + if (loadvm_in_colo_state()) { + return ; /* primary's responsibility */ + } + if (migrate_in_colo_state()) { + colo_shutdown_requested = 1; + return; + } + qemu_system_shutdown_request_core(); +} + static void qemu_system_powerdown(void) { qapi_event_send_powerdown(&error_abort);