From patchwork Mon May 15 21:41:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9728095 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 157B060231 for ; Mon, 15 May 2017 21:44:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2399C289BA for ; Mon, 15 May 2017 21:44:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15A87289BF; Mon, 15 May 2017 21:44:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2D2CA289BA for ; Mon, 15 May 2017 21:44:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dANkX-0007Lk-T3; Mon, 15 May 2017 21:41:53 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dANkW-0007Le-CJ for xen-devel@lists.xenproject.org; Mon, 15 May 2017 21:41:52 +0000 Received: from [193.109.254.147] by server-2.bemta-6.messagelabs.com id EC/94-03058-F902A195; Mon, 15 May 2017 21:41:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHIsWRWlGSWpSXmKPExsVysWW7jO48Bal Ig87P5hbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bMnc9YC3aFVVy82svewPjRpYuRi0NIYDaT xJPHOxm7GDk5WATsJdZ0PwSzGQXKJG6v2c8KYWdLbHh/jwmixk7i7MzlLBDNGxglHn9+BtTAw cEmoCLxa1UMSI2IgKTE767TzCA1zAI/mSW+H/3PBpIQFgiTWNa8BmqQqkTvjUUsIDavgJnEhw 3H2UDmcAqYS/z6GgFiCgGFJ2/mBKmQENCWeHx6OiPISAmBPkaJGc9fMk1gFFjAyLCKUaM4tag stUjXyFIvqSgzPaMkNzEzR9fQwEwvN7W4ODE9NScxqVgvOT93EyMwrBiAYAfjgUWBhxglOZiU RHnd2aUihfiS8lMqMxKLM+KLSnNSiw8xynBwKEnwtssD5QSLUtNTK9Iyc4ABDpOW4OBREuE9C ZLmLS5IzC3OTIdInWLU5Xi39MN7JiGWvPy8VClx3gyQIgGQoozSPLgRsGi7xCgrJczLCHSUEE 9BalFuZgmq/CtGcQ5GJWHepSBTeDLzSuA2vQI6ggnoiLCX4iBHlCQipKQaGNXzezR02hNCV4Y bHPS/aBhTG/xbLJH5rOBU4zscP1pbOtOLEiduij/X478lp2LChYyOtX2rhG6H/Pf4HevsqaDa ks1m6nrn99z9H4JtGRevl//tfPHTIXvZk6v0P3hG8N6wDi9VeFJYOf9hpfIGsy1J1an2f2a93 6ZqWRHLNuFAu2liltBlJZbijERDLeai4kQAJma7KbECAAA= X-Env-Sender: eblake@redhat.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1494884509!97816286!1 X-Originating-IP: [209.132.183.28] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMjA5LjEzMi4xODMuMjggPT4gNTQwNjQ=\n X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 14237 invoked from network); 15 May 2017 21:41:50 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by server-7.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 May 2017 21:41:50 -0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17A34804FE; Mon, 15 May 2017 21:41:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 17A34804FE DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 17A34804FE Received: from red.redhat.com (ovpn-123-244.rdu2.redhat.com [10.10.123.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5738618343; Mon, 15 May 2017 21:41:27 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 15 May 2017 16:41:11 -0500 Message-Id: <20170515214114.15442-3-eblake@redhat.com> In-Reply-To: <20170515214114.15442-1-eblake@redhat.com> References: <20170515214114.15442-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 15 May 2017 21:41:48 +0000 (UTC) Cc: Stefano Stabellini , berrange@redhat.com, Eduardo Habkost , "Michael S. Tsirkin" , Juan Quintela , armbru@redhat.com, alistair.francis@xilinx.com, zhanghailiang , "open list:X86" , Anthony Perard , Paolo Bonzini , "Dr. David Alan Gilbert" , Richard Henderson Subject: [Xen-devel] [PATCH v9 2/5] shutdown: Prepare for use of an enum in reset/shutdown_request X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP We want to track why a guest was shutdown; in particular, being able to tell the difference between a guest request (such as ACPI request) and host request (such as SIGINT) will prove useful to libvirt. Since all requests eventually end up changing shutdown_requested in vl.c, the logical change is to make that value track the reason, rather than its current 0/1 contents. Since command-line options control whether a reset request is turned into a shutdown request instead, the same treatment is given to reset_requested. This patch adds an internal enum ShutdownCause that describes reasons that a shutdown can be requested, and changes qemu_system_reset() to pass the reason through, although for now nothing is actually changed with regards to what gets reported. The enum could be exported via QAPI at a later date, if deemed necessary, but for now, there has not been a request to expose that much detail to end clients. For the most part, we turn 0 into SHUTDOWN_CAUSE_NONE, and 1 into SHUTDOWN_CAUSE_HOST_ERROR; the only specific case where we have enough information right now to use a different value is when we are reacting to a host signal. It will take a further patch to edit all call-sites that can trigger a reset or shutdown request to properly pass in any other reasons; this patch includes TODOs to point such places out. qemu_system_reset() trades its 'bool report' parameter for a 'ShutdownCause reason', with all non-zero values having the same effect; this lets us get rid of the weird #defines for VMRESET_* as synonyms for bools. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster --- v9: one more stray FIXME v8: s/FIXME/TODO/, include SHUTDOWN_CAUSE__MAX now rather than later, tweak comment on GUEST_SHUTDOWN to mention suspend v7: drop 'bool report' from qemu_system_reset(), reorder enum to put HOST_ERROR == 1, improve commit message v6: make ShutdownCause internal-only, add SHUTDOWN_CAUSE_NONE so that comparison to 0 still works, tweak initial FIXME values v5: no change v4: s/ShutdownType/ShutdownCause/, no thanks to mingw header pollution v3: new patch --- include/sysemu/sysemu.h | 23 ++++++++++++++++----- vl.c | 53 ++++++++++++++++++++++++++++++------------------- hw/i386/xen/xen-hvm.c | 7 +++++-- migration/colo.c | 2 +- migration/savevm.c | 2 +- 5 files changed, 58 insertions(+), 29 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 15656b7..52102fd 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -33,8 +33,21 @@ VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, void qemu_del_vm_change_state_handler(VMChangeStateEntry *e); void vm_state_notify(int running, RunState state); -#define VMRESET_SILENT false -#define VMRESET_REPORT true +/* Enumeration of various causes for shutdown. */ +typedef enum ShutdownCause { + SHUTDOWN_CAUSE_NONE, /* No shutdown request pending */ + SHUTDOWN_CAUSE_HOST_ERROR, /* An error prevents further use of guest */ + SHUTDOWN_CAUSE_HOST_QMP, /* Reaction to a QMP command, like 'quit' */ + SHUTDOWN_CAUSE_HOST_SIGNAL, /* Reaction to a signal, such as SIGINT */ + SHUTDOWN_CAUSE_HOST_UI, /* Reaction to UI event, like window close */ + SHUTDOWN_CAUSE_GUEST_SHUTDOWN,/* Guest shutdown/suspend request, via + ACPI or other hardware-specific means */ + SHUTDOWN_CAUSE_GUEST_RESET, /* Guest reset request, and command line + turns that into a shutdown */ + SHUTDOWN_CAUSE_GUEST_PANIC, /* Guest panicked, and command line turns + that into a shutdown */ + SHUTDOWN_CAUSE__MAX, +} ShutdownCause; void vm_start(void); int vm_prepare_start(void); @@ -62,10 +75,10 @@ void qemu_system_debug_request(void); void qemu_system_vmstop_request(RunState reason); void qemu_system_vmstop_request_prepare(void); bool qemu_vmstop_requested(RunState *r); -int qemu_shutdown_requested_get(void); -int qemu_reset_requested_get(void); +ShutdownCause qemu_shutdown_requested_get(void); +ShutdownCause qemu_reset_requested_get(void); void qemu_system_killed(int signal, pid_t pid); -void qemu_system_reset(bool report); +void qemu_system_reset(ShutdownCause reason); void qemu_system_guest_panicked(GuestPanicInformation *info); size_t qemu_target_page_size(void); diff --git a/vl.c b/vl.c index 7396748..5c61d8c 100644 --- a/vl.c +++ b/vl.c @@ -1597,8 +1597,9 @@ void vm_state_notify(int running, RunState state) } } -static int reset_requested; -static int shutdown_requested, shutdown_signal; +static ShutdownCause reset_requested; +static ShutdownCause shutdown_requested; +static int shutdown_signal; static pid_t shutdown_pid; static int powerdown_requested; static int debug_requested; @@ -1612,19 +1613,19 @@ static NotifierList wakeup_notifiers = NOTIFIER_LIST_INITIALIZER(wakeup_notifiers); static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE); -int qemu_shutdown_requested_get(void) +ShutdownCause qemu_shutdown_requested_get(void) { return shutdown_requested; } -int qemu_reset_requested_get(void) +ShutdownCause qemu_reset_requested_get(void) { return reset_requested; } static int qemu_shutdown_requested(void) { - return atomic_xchg(&shutdown_requested, 0); + return atomic_xchg(&shutdown_requested, SHUTDOWN_CAUSE_NONE); } static void qemu_kill_report(void) @@ -1647,14 +1648,15 @@ static void qemu_kill_report(void) } } -static int qemu_reset_requested(void) +static ShutdownCause qemu_reset_requested(void) { - int r = reset_requested; + ShutdownCause r = reset_requested; + if (r && replay_checkpoint(CHECKPOINT_RESET_REQUESTED)) { - reset_requested = 0; + reset_requested = SHUTDOWN_CAUSE_NONE; return r; } - return false; + return SHUTDOWN_CAUSE_NONE; } static int qemu_suspend_requested(void) @@ -1686,7 +1688,10 @@ static int qemu_debug_requested(void) return r; } -void qemu_system_reset(bool report) +/* + * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE. + */ +void qemu_system_reset(ShutdownCause reason) { MachineClass *mc; @@ -1699,7 +1704,8 @@ void qemu_system_reset(bool report) } else { qemu_devices_reset(); } - if (report) { + if (reason) { + /* TODO update event based on reason */ qapi_event_send_reset(&error_abort); } cpu_synchronize_all_post_reset(); @@ -1738,9 +1744,10 @@ void qemu_system_guest_panicked(GuestPanicInformation *info) void qemu_system_reset_request(void) { if (no_reboot) { - shutdown_requested = 1; + /* TODO - add a parameter to allow callers to specify reason */ + shutdown_requested = SHUTDOWN_CAUSE_HOST_ERROR; } else { - reset_requested = 1; + reset_requested = SHUTDOWN_CAUSE_HOST_ERROR; } cpu_stop_current(); qemu_notify_event(); @@ -1807,7 +1814,7 @@ void qemu_system_killed(int signal, pid_t pid) /* Cannot call qemu_system_shutdown_request directly because * we are in a signal handler. */ - shutdown_requested = 1; + shutdown_requested = SHUTDOWN_CAUSE_HOST_SIGNAL; qemu_notify_event(); } @@ -1815,7 +1822,8 @@ void qemu_system_shutdown_request(void) { trace_qemu_system_shutdown_request(); replay_shutdown_request(); - shutdown_requested = 1; + /* TODO - add a parameter to allow callers to specify reason */ + shutdown_requested = SHUTDOWN_CAUSE_HOST_ERROR; qemu_notify_event(); } @@ -1846,14 +1854,18 @@ void qemu_system_debug_request(void) static bool main_loop_should_exit(void) { RunState r; + ShutdownCause request; + if (qemu_debug_requested()) { vm_stop(RUN_STATE_DEBUG); } if (qemu_suspend_requested()) { qemu_system_suspend(); } - if (qemu_shutdown_requested()) { + request = qemu_shutdown_requested(); + if (request) { qemu_kill_report(); + /* TODO update event based on request */ qapi_event_send_shutdown(&error_abort); if (no_shutdown) { vm_stop(RUN_STATE_SHUTDOWN); @@ -1861,9 +1873,10 @@ static bool main_loop_should_exit(void) return true; } } - if (qemu_reset_requested()) { + request = qemu_reset_requested(); + if (request) { pause_all_vcpus(); - qemu_system_reset(VMRESET_REPORT); + qemu_system_reset(request); resume_all_vcpus(); if (!runstate_check(RUN_STATE_RUNNING) && !runstate_check(RUN_STATE_INMIGRATE)) { @@ -1872,7 +1885,7 @@ static bool main_loop_should_exit(void) } if (qemu_wakeup_requested()) { pause_all_vcpus(); - qemu_system_reset(VMRESET_SILENT); + qemu_system_reset(SHUTDOWN_CAUSE_NONE); notifier_list_notify(&wakeup_notifiers, &wakeup_reason); wakeup_reason = QEMU_WAKEUP_REASON_NONE; resume_all_vcpus(); @@ -4682,7 +4695,7 @@ int main(int argc, char **argv, char **envp) reading from the other reads, because timer polling functions query clock values from the log. */ replay_checkpoint(CHECKPOINT_RESET); - qemu_system_reset(VMRESET_SILENT); + qemu_system_reset(SHUTDOWN_CAUSE_NONE); register_global_state(); if (replay_mode != REPLAY_MODE_NONE) { replay_vmstate_init(); diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index b1c05ff..222d89a 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -1089,11 +1089,14 @@ static void cpu_handle_ioreq(void *opaque) * causes Xen to powerdown the domain. */ if (runstate_is_running()) { + ShutdownCause request; + if (qemu_shutdown_requested_get()) { destroy_hvm_domain(false); } - if (qemu_reset_requested_get()) { - qemu_system_reset(VMRESET_REPORT); + request = qemu_reset_requested_get(); + if (request) { + qemu_system_reset(request); destroy_hvm_domain(true); } } diff --git a/migration/colo.c b/migration/colo.c index 963c802..12d355a 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -623,7 +623,7 @@ void *colo_process_incoming_thread(void *opaque) } qemu_mutex_lock_iothread(); - qemu_system_reset(VMRESET_SILENT); + qemu_system_reset(SHUTDOWN_CAUSE_NONE); vmstate_loading = true; if (qemu_loadvm_state(fb) < 0) { error_report("COLO: loadvm failed"); diff --git a/migration/savevm.c b/migration/savevm.c index 7f66d58..b89dede 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2286,7 +2286,7 @@ int load_vmstate(const char *name) return -EINVAL; } - qemu_system_reset(VMRESET_SILENT); + qemu_system_reset(SHUTDOWN_CAUSE_NONE); mis->from_src_file = f; aio_context_acquire(aio_context);