From patchwork Thu Apr 27 19:22:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9703387 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 DAADE602CC for ; Thu, 27 Apr 2017 19:25:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7D7928409 for ; Thu, 27 Apr 2017 19:25:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC802285F3; Thu, 27 Apr 2017 19:25:32 +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 9E9EE28409 for ; Thu, 27 Apr 2017 19:25:31 +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 1d3p02-0005Cj-6E; Thu, 27 Apr 2017 19:22:46 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3p01-0005Cd-Gs for xen-devel@lists.xenproject.org; Thu, 27 Apr 2017 19:22:45 +0000 Received: from [193.109.254.147] by server-4.bemta-6.messagelabs.com id C3/6D-02956-40542095; Thu, 27 Apr 2017 19:22:44 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHIsWRWlGSWpSXmKPExsVysWW7jC6zK1O kweGDWhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bro/uYC1Z5VTz6+4mtgfG2VRcjJ4eQwFwm idbZTF2MHBwsAo4SD49ZgIQZBcokppxsYoGwsyV2nLvHDmKzCDhIvN+yByjOBdS6gVHi8+mdj CC9bAIqEr9WxYDUiAhISvzuOs0MUsMs8JNZ4vvR/2wgCWGBMIkfExuZIQapSmxvP8cEYvMKmE lsaT7GCGJzCphLnL3+hRXiNjOJfZuvg8UlBLQlLrQ/AlssIdDHKDFr4zb2CYwCCxgZVjFqFKc WlaUW6RpZ6CUVZaZnlOQmZuboGhqY6eWmFhcnpqfmJCYV6yXn525iBIYVAxDsYDy/NvAQoyQH k5Ior+xBxkghvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErw3nZkihQSLUtNTK9Iyc4ABDpOW4OBRE uGdD5LmLS5IzC3OTIdInWLU5Xi39MN7JiGWvPy8VClx3iyQIgGQoozSPLgRsGi7xCgrJczLCH SUEE9BalFuZgmq/CtGcQ5GJWHeOSBTeDLzSuA2vQI6ggnoCBYXBpAjShIRUlINjLFmi1arfVD 2O/WvMF26759E5LGl2yv0TBeZhPLsFuRS4XT4tkXx4mtLFoebny/qsTGmK9xfWsHuEhZSf2yu 7aK8h2fNmdYV+jTu+ffxwRbvpbF56S4XLxqc+8bMxPHzTNiR9e8XK+5OUpI6FOPjeqj2VsvOP Yun+f6YqftuwWndDu5nb0+ouiuxFGckGmoxFxUnAgBRbS5MsQIAAA== X-Env-Sender: eblake@redhat.com X-Msg-Ref: server-11.tower-27.messagelabs.com!1493320962!68807456!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 6406 invoked from network); 27 Apr 2017 19:22:43 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by server-11.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 27 Apr 2017 19:22:43 -0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B268BC04BD53; Thu, 27 Apr 2017 19:22:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B268BC04BD53 DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B268BC04BD53 Received: from red.redhat.com (ovpn-123-177.rdu2.redhat.com [10.10.123.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E45E784C6; Thu, 27 Apr 2017 19:22:28 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 27 Apr 2017 14:22:09 -0500 Message-Id: <20170427192211.30640-3-eblake@redhat.com> In-Reply-To: <20170427192211.30640-1-eblake@redhat.com> References: <20170427192211.30640-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 27 Apr 2017 19:22:42 +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 v3 2/4] 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 a QAPI enum ShutdownType that describes reasons that a shutdown can be requested, and changes qemu_system_reset() to pass the reason through, although for now it is not reported. The next patch will actually wire things up to modify events to report data based on the reason, and to pass the correct enum value in from various call-sites that can trigger a reset/shutdown. Since QAPI generates enums starting at 0, it's easier if we use a different number as our sentinel that no request has happened yet. Most of the changes are in vl.c, but xen was using things externally. Signed-off-by: Eric Blake --- v3: new patch --- qapi-schema.json | 23 +++++++++++++++++++++++ include/sysemu/sysemu.h | 2 +- vl.c | 44 ++++++++++++++++++++++++++++---------------- hw/i386/xen/xen-hvm.c | 9 ++++++--- migration/colo.c | 2 +- migration/savevm.c | 2 +- 6 files changed, 60 insertions(+), 22 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 01b087f..8b9819f 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -2304,6 +2304,29 @@ { 'command': 'system_powerdown' } ## +# @ShutdownType: +# +# Enumeration of various causes for shutdown. +# +# @host-qmp: Reaction to a QMP command, such as 'quit' +# @host-signal: Reaction to a signal, such as SIGINT +# @host-ui: Reaction to a UI event, such as closing the window +# @host-replay: The host is replaying an earlier shutdown event +# @host-error: Qemu encountered an error that prevents further use of the guest +# @guest-shutdown: The guest requested a shutdown, such as via ACPI or +# other hardware-specific action +# @guest-reset: The guest requested a reset, and the command line +# response to a reset is to instead trigger a shutdown +# @guest-panic: The guest panicked, and the command line response to +# a panic is to trigger a shutdown +# +# Since: 2.10 +## +{ 'enum': 'ShutdownType', + 'data': [ 'host-qmp', 'host-signal', 'host-ui', 'host-replay', 'host-error', + 'guest-shutdown', 'guest-reset', 'guest-panic' ] } + +## # @cpu: # # This command is a nop that is only provided for the purposes of compatibility. diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 16175f7..00a907f 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -65,7 +65,7 @@ bool qemu_vmstop_requested(RunState *r); int qemu_shutdown_requested_get(void); int qemu_reset_requested_get(void); void qemu_system_killed(int signal, pid_t pid); -void qemu_system_reset(bool report); +void qemu_system_reset(bool report, int reason); void qemu_system_guest_panicked(GuestPanicInformation *info); size_t qemu_target_page_size(void); diff --git a/vl.c b/vl.c index 879786a..608cc82 100644 --- a/vl.c +++ b/vl.c @@ -1597,8 +1597,8 @@ void vm_state_notify(int running, RunState state) } } -static int reset_requested; -static int shutdown_requested, shutdown_signal; +static int reset_requested = -1; +static int shutdown_requested = -1, shutdown_signal; static pid_t shutdown_pid; static int powerdown_requested; static int debug_requested; @@ -1624,7 +1624,7 @@ int qemu_reset_requested_get(void) static int qemu_shutdown_requested(void) { - return atomic_xchg(&shutdown_requested, 0); + return atomic_xchg(&shutdown_requested, -1); } static void qemu_kill_report(void) @@ -1650,11 +1650,11 @@ static void qemu_kill_report(void) static int qemu_reset_requested(void) { int r = reset_requested; - if (r && replay_checkpoint(CHECKPOINT_RESET_REQUESTED)) { - reset_requested = 0; + if (r >= 0 && replay_checkpoint(CHECKPOINT_RESET_REQUESTED)) { + reset_requested = -1; return r; } - return false; + return -1; } static int qemu_suspend_requested(void) @@ -1686,7 +1686,12 @@ static int qemu_debug_requested(void) return r; } -void qemu_system_reset(bool report) +/* + * Reset the VM. If @report is VMRESET_REPORT, issue an event, using + * the @reason interpreted as ShutdownType for details. Otherwise, + * @report is VMRESET_SILENT and @reason is ignored. + */ +void qemu_system_reset(bool report, int reason) { MachineClass *mc; @@ -1700,6 +1705,7 @@ void qemu_system_reset(bool report) qemu_devices_reset(); } if (report) { + assert(reason >= 0); 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; + /* FIXME - add a parameter to allow callers to specify reason */ + shutdown_requested = SHUTDOWN_TYPE_GUEST_RESET; } else { - reset_requested = 1; + reset_requested = SHUTDOWN_TYPE_GUEST_RESET; } 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_TYPE_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; + /* FIXME - add a parameter to allow callers to specify reason */ + shutdown_requested = SHUTDOWN_TYPE_GUEST_SHUTDOWN; qemu_notify_event(); } @@ -1846,13 +1854,16 @@ void qemu_system_debug_request(void) static bool main_loop_should_exit(void) { RunState r; + int 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 >= 0) { qemu_kill_report(); qapi_event_send_shutdown(&error_abort); if (no_shutdown) { @@ -1861,9 +1872,10 @@ static bool main_loop_should_exit(void) return true; } } - if (qemu_reset_requested()) { + request = qemu_reset_requested(); + if (request >= 0) { pause_all_vcpus(); - qemu_system_reset(VMRESET_REPORT); + qemu_system_reset(VMRESET_REPORT, request); resume_all_vcpus(); if (!runstate_check(RUN_STATE_RUNNING) && !runstate_check(RUN_STATE_INMIGRATE)) { @@ -1872,7 +1884,7 @@ static bool main_loop_should_exit(void) } if (qemu_wakeup_requested()) { pause_all_vcpus(); - qemu_system_reset(VMRESET_SILENT); + qemu_system_reset(VMRESET_SILENT, -1); notifier_list_notify(&wakeup_notifiers, &wakeup_reason); wakeup_reason = QEMU_WAKEUP_REASON_NONE; resume_all_vcpus(); @@ -4684,7 +4696,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(VMRESET_SILENT, -1); 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..3a6484c 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()) { - if (qemu_shutdown_requested_get()) { + int request; + + if (qemu_shutdown_requested_get() >= 0) { destroy_hvm_domain(false); } - if (qemu_reset_requested_get()) { - qemu_system_reset(VMRESET_REPORT); + request = qemu_reset_requested_get(); + if (request >= 0) { + qemu_system_reset(VMRESET_REPORT, request); destroy_hvm_domain(true); } } diff --git a/migration/colo.c b/migration/colo.c index c19eb3f..17a5482 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -611,7 +611,7 @@ void *colo_process_incoming_thread(void *opaque) } qemu_mutex_lock_iothread(); - qemu_system_reset(VMRESET_SILENT); + qemu_system_reset(VMRESET_SILENT, -1); 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 03ae1bd..dcbaf00 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2292,7 +2292,7 @@ int load_vmstate(const char *name) return -EINVAL; } - qemu_system_reset(VMRESET_SILENT); + qemu_system_reset(VMRESET_SILENT, -1); mis->from_src_file = f; aio_context_acquire(aio_context);