Received: from eggs.gnu.org ([2001:4830:134:3::10]:55362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLACw-0003dq-Ag for qemu-devel@nongnu.org; Mon, 18 Jan 2016 08:50:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLACr-00060I-GY for qemu-devel@nongnu.org; Mon, 18 Jan 2016 08:50:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55119) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLACr-000605-BA for qemu-devel@nongnu.org; Mon, 18 Jan 2016 08:50:53 -0500 From: Markus Armbruster References: <1450753771-5666-1-git-send-email-qhjin_dev@163.com> Date: Mon, 18 Jan 2016 14:50:50 +0100 In-Reply-To: <1450753771-5666-1-git-send-email-qhjin_dev@163.com> (Qinghua Jin's message of "Tue, 22 Dec 2015 11:09:31 +0800") Message-ID: <8737tvnghx.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v3] qmp: return err msg when powerdown a vm when it isn't in running state List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Qinghua Jin Cc: Fam Zheng , qemu-devel@nongnu.org, P J P Qinghua Jin writes: > When send system_powerdown to QMP when the vm isn't in RUN_STATE_RUNNING, > it will be ignored by system. So reply a err msg with the situation. > > Signed-off-by: Qinghua Jin > --- > > This is an update of the patch as per Fam Zheng's suggestion: > http://lists.gnu.org/archive/html/qemu-devel/2015-12/msg03949.html > > qmp.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/qmp.c b/qmp.c > index 0a1fa19..384df56 100644 > --- a/qmp.c > +++ b/qmp.c > @@ -114,8 +114,13 @@ void qmp_system_reset(Error **errp) > qemu_system_reset_request(); > } > > -void qmp_system_powerdown(Error **erp) > +void qmp_system_powerdown(Error **errp) > { > + if (!runstate_check(RUN_STATE_RUNNING)) { > + error_setg(errp, > + "Can not powerdown virtual machine as it is not running"); > + return; > + } > qemu_system_powerdown_request(); > } This is the handler for QMP command system_powerdown. The patch makes the QMP command fail in run states other than RUN_STATE_RUNNING. There are other callers: the HMP command handler hmp_system_powerdown(), GTK's gd_menu_powerdown(), Cocoa's powerDownQEMU(). They all ignore the error. Why is that appropriate? qemu_system_powerdown_request() sets powerdown_requested = 1. This makes the next qemu_powerdown_requested() return 1. Gets called only by main_loop_should_exit(). I can't quite see how "it will be ignored by system" when we're in RUN_STATE_RUNNING. Can you explain?