From patchwork Sat Mar 18 13:41:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon X-Patchwork-Id: 9632183 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 B0C3760249 for ; Sat, 18 Mar 2017 13:42:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CFC31FF26 for ; Sat, 18 Mar 2017 13:42:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DE302623C; Sat, 18 Mar 2017 13:42:00 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id AB50D1FF26 for ; Sat, 18 Mar 2017 13:41:59 +0000 (UTC) Received: from localhost ([::1]:53425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpEcH-0001Kt-5d for patchwork-qemu-devel@patchwork.kernel.org; Sat, 18 Mar 2017 09:41:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpEc5-0001KS-Q3 for qemu-devel@nongnu.org; Sat, 18 Mar 2017 09:41:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cpEc2-0006qP-Nn for qemu-devel@nongnu.org; Sat, 18 Mar 2017 09:41:45 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:52912) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cpEbj-0006eW-CW for qemu-devel@nongnu.org; Sat, 18 Mar 2017 09:41:42 -0400 Received: from mfilter2-d.gandi.net (mfilter2-d.gandi.net [217.70.178.140]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 11CD71720A4; Sat, 18 Mar 2017 14:41:20 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter2-d.gandi.net Received: from relay4-d.mail.gandi.net ([IPv6:::ffff:217.70.183.196]) by mfilter2-d.gandi.net (mfilter2-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id W6OVZZkOmlkW; Sat, 18 Mar 2017 14:41:18 +0100 (CET) X-Originating-IP: 10.58.1.145 Received: from webmail.eu.com (webmail5-d.mgt.gandi.net [10.58.1.145]) (Authenticated sender: lists@whitewinterwolf.com) by relay4-d.mail.gandi.net (Postfix) with ESMTPA id 747411720B1; Sat, 18 Mar 2017 14:41:16 +0100 (CET) MIME-Version: 1.0 Date: Sat, 18 Mar 2017 14:41:16 +0100 From: Simon To: "Daniel P. Berrange" In-Reply-To: <20170316102652.GG15193@redhat.com> References: <11569d75b61122820f186a32cdd20689@whitewinterwolf.com> <20170315144124.GP7770@redhat.com> <23d89ab3bd16ebf7a864ab75c300de7b@whitewinterwolf.com> <20170315180822.GU7770@redhat.com> <20170316102652.GG15193@redhat.com> Message-ID: <14585f602461dbefb3adaf16591ce5e5@whitewinterwolf.com> X-Sender: qemu.bugs@whitewinterwolf.com User-Agent: Roundcube Webmail/1.1.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.70.183.196 Subject: Re: [Qemu-devel] [Bug 1217339] [PATCH v2] Unix signal to send ACPI-shutdown to Guest X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , QEMU Developers Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Hi, The patch below adds the new command-line option `-powerdown' which changes the behavior for both SIGHUP and SIGINT signals to cause a clean power down of the guest using an ACPI shutdown request. If this option is not used, the original behavior is kept. Regards, Simon. Signed-off-by: Simon Geusebroek --- -- diff -ru a/qemu-options.hx b/qemu-options.hx --- a/qemu-options.hx 2016-12-20 21:16:49.000000000 +0100 +++ b/qemu-options.hx 2017-03-18 14:17:35.759915414 +0100 @@ -3322,6 +3322,19 @@ disk image. ETEXI +DEF("powerdown", 0, QEMU_OPTION_powerdown, \ + "-powerdown Cleanly power down the guest on SIGINT or SIGHUP\n", \ + QEMU_ARCH_ALL) +STEXI +@item -powerdown +@findex -powerdown +Don't forcefully shutdown the guest upon SIGINT (Ctrl-C) or SIGHUP (terminal +closure) signals, but instead attempt to cleanly stop them using an ACPI +shutdown request. +Non ACPI-aware and stuck guests will remain up, the SIGTERM signal will still +forcefully shutdown them. +ETEXI + DEF("loadvm", HAS_ARG, QEMU_OPTION_loadvm, \ "-loadvm [tag|id]\n" \ " start right away with a saved state (loadvm in monitor)\n", diff -ru a/vl.c b/vl.c --- a/vl.c 2016-12-20 21:16:54.000000000 +0100 +++ b/vl.c 2017-03-18 13:48:21.227967255 +0100 @@ -164,6 +164,7 @@ int fd_bootchk = 1; static int no_reboot; int no_shutdown = 0; +int powerdown = 0; int cursor_hide = 1; int graphic_rotate = 0; const char *watchdog; @@ -1871,7 +1872,11 @@ /* Cannot call qemu_system_shutdown_request directly because * we are in a signal handler. */ - shutdown_requested = 1; + if (powerdown == 1 && (signal == SIGINT || signal == SIGHUP)) { + powerdown_requested = 1; + } else { + shutdown_requested = 1; + } qemu_notify_event(); } @@ -3794,6 +3799,9 @@ case QEMU_OPTION_no_shutdown: no_shutdown = 1; break; + case QEMU_OPTION_powerdown: + powerdown = 1; + break; case QEMU_OPTION_show_cursor: cursor_hide = 0; break;