From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX3Li-0006XX-6p for qemu-devel@nongnu.org; Wed, 02 Sep 2015 04:24:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZX3Ld-0001Ai-Q3 for qemu-devel@nongnu.org; Wed, 02 Sep 2015 04:24:54 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:21648) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX3Ld-00019W-5m for qemu-devel@nongnu.org; Wed, 02 Sep 2015 04:24:49 -0400 From: zhanghailiang Date: Wed, 2 Sep 2015 16:23:13 +0800 Message-ID: <1441182199-8328-27-git-send-email-zhang.zhanghailiang@huawei.com> In-Reply-To: <1441182199-8328-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1441182199-8328-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH COLO-Frame v9 26/32] COLO: Implement shutdown checkpoint List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: lizhijian@cn.fujitsu.com, quintela@redhat.com, yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, arei.gonglei@huawei.com, stefanha@redhat.com, amit.shah@redhat.com, Paolo Bonzini , yanghy@cn.fujitsu.com, zhanghailiang 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: Li Zhijian --- include/sysemu/sysemu.h | 3 +++ migration/colo.c | 27 +++++++++++++++++++++++---- qapi-schema.json | 5 +++-- vl.c | 26 ++++++++++++++++++++++++-- 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 15d6d00..e576f65 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 0113e1b..ca303c1 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -212,7 +212,7 @@ static int colo_ctl_get(QEMUFile *f, uint32_t require) static int colo_do_checkpoint_transaction(MigrationState *s, QEMUSizedBuffer *buffer) { - int ret; + int colo_shutdown, ret; size_t size; QEMUFile *trans = NULL; @@ -239,7 +239,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s, ret = -1; goto out; } - /* suspend and save vm state to colo buffer */ + colo_shutdown = colo_shutdown_requested; vm_stop_force_state(RUN_STATE_COLO); qemu_mutex_unlock_iothread(); trace_colo_vm_state_change("run", "stop"); @@ -291,6 +291,15 @@ static int colo_do_checkpoint_transaction(MigrationState *s, goto out; } + if (colo_shutdown) { + colo_ctl_put(s->to_dst_file, COLO_CMD_GUEST_SHUTDOWN, 0); + 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 master */ qemu_mutex_lock_iothread(); @@ -357,8 +366,9 @@ static void *colo_thread(void *opaque) } current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); - if (current_time - checkpoint_time < - s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY]) { + if ((current_time - checkpoint_time < + s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY]) && + !colo_shutdown_requested) { g_usleep(100000); continue; } @@ -467,6 +477,15 @@ static int colo_wait_handle_cmd(QEMUFile *f, int *checkpoint_request) case COLO_CMD_CHECKPOINT_REQUEST: *checkpoint_request = 1; return 0; + case COLO_CMD_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 termiante the whole + * process, do we need some cleanup? + */ + qemu_thread_exit(0); default: return -EINVAL; } diff --git a/qapi-schema.json b/qapi-schema.json index 75e1770..c19cf97 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -698,13 +698,14 @@ # # @vmstate-loaded: VM's state has been loaded by SVM # +# @guest-shutdown: shutdown require from PVM to SVM +# # Since: 2.5 ## { 'enum': 'COLOCmd', 'data': [ 'invalid', 'checkpoint-ready', 'checkpoint-request', 'checkpoint-reply', 'vmstate-send', 'vmstate-size', - 'vmstate-received', 'vmstate-loaded', 'guest-shutdown', - 'ram-steal'] } + 'vmstate-received', 'vmstate-loaded', 'guest-shutdown' ] } ## # @COLOMode diff --git a/vl.c b/vl.c index d5e900b..bee3095 100644 --- a/vl.c +++ b/vl.c @@ -1637,6 +1637,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; @@ -1753,6 +1755,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; @@ -1821,13 +1827,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 (migration_incoming_in_colo_state()) { + return ; /* primary's responsibility */ + } + if (migration_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); -- 1.8.3.1