From patchwork Mon Apr 26 19:44:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 50999 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 05389B7D5C for ; Tue, 27 Apr 2010 05:51:43 +1000 (EST) Received: from localhost ([127.0.0.1]:35842 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O6ULE-0004gz-Rj for incoming@patchwork.ozlabs.org; Mon, 26 Apr 2010 15:51:40 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O6UEr-0005sC-5g for qemu-devel@nongnu.org; Mon, 26 Apr 2010 15:45:05 -0400 Received: from [140.186.70.92] (port=47605 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O6UEp-0005pw-MC for qemu-devel@nongnu.org; Mon, 26 Apr 2010 15:45:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O6UEn-0000OF-7A for qemu-devel@nongnu.org; Mon, 26 Apr 2010 15:45:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40131) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O6UEm-0000Nt-SF for qemu-devel@nongnu.org; Mon, 26 Apr 2010 15:45:01 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3QJiv39021289 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 26 Apr 2010 15:44:58 -0400 Received: from localhost (vpn-8-143.rdu.redhat.com [10.11.8.143]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3QJipUc032402 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 26 Apr 2010 15:44:54 -0400 Date: Mon, 26 Apr 2010 16:44:48 -0300 From: Luiz Capitulino To: Anthony Liguori Message-ID: <20100426164448.679a4d19@redhat.com> In-Reply-To: <4BD5E5E4.8000609@codemonkey.ws> References: <1272296853-30285-1-git-send-email-lcapitulino@redhat.com> <1272296853-30285-6-git-send-email-lcapitulino@redhat.com> <4BD5D234.2030508@codemonkey.ws> <20100426152238.5ece1c15@redhat.com> <4BD5DAA2.4050206@codemonkey.ws> <20100426155303.2c381ff7@redhat.com> <4BD5E2BB.8000105@codemonkey.ws> <4BD5E51A.9070402@web.de> <4BD5E5E4.8000609@codemonkey.ws> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, Jan Kiszka , qemu-devel@nongnu.org Subject: [Qemu-devel] Re: [PATCH 5/9] Monitor: Return before exiting with 'quit' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Mon, 26 Apr 2010 14:13:40 -0500 Anthony Liguori wrote: > On 04/26/2010 02:10 PM, Jan Kiszka wrote: > > > > Just suspend the monitor before leaving for termination. That should > > have both the proper visual and functional effect. > > > > Very good idea. Yeah, works great. Final version of the patch below, for-anthony branch updated. From 0e8d2b5575938b8876a3c4bb66ee13c5d306fb6d Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Tue, 6 Apr 2010 18:55:54 -0300 Subject: [PATCH 5/9] Monitor: Return before exiting with 'quit' The 'quit' Monitor command (implemented by do_quit()) calls exit() directly, this is problematic under QMP because QEMU exits before having a chance to send the ok response. Clients don't know if QEMU exited because of a problem or because the 'quit' command has been executed. This commit fixes that by moving the exit() call to the main loop, so that do_quit() requests the system to quit, instead of calling exit() directly. Signed-off-by: Luiz Capitulino --- monitor.c | 3 ++- sysemu.h | 2 ++ vl.c | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletions(-) diff --git a/monitor.c b/monitor.c index ef84298..0dc24a2 100644 --- a/monitor.c +++ b/monitor.c @@ -1017,7 +1017,8 @@ static void do_info_cpu_stats(Monitor *mon) */ static int do_quit(Monitor *mon, const QDict *qdict, QObject **ret_data) { - exit(0); + monitor_suspend(mon); + qemu_system_exit_request(); return 0; } diff --git a/sysemu.h b/sysemu.h index d0effa0..fa921df 100644 --- a/sysemu.h +++ b/sysemu.h @@ -45,9 +45,11 @@ void cpu_disable_ticks(void); void qemu_system_reset_request(void); void qemu_system_shutdown_request(void); void qemu_system_powerdown_request(void); +void qemu_system_exit_request(void); int qemu_shutdown_requested(void); int qemu_reset_requested(void); int qemu_powerdown_requested(void); +int qemu_exit_requested(void); extern qemu_irq qemu_system_powerdown; void qemu_system_reset(void); diff --git a/vl.c b/vl.c index a5a0f41..9ef6f2c 100644 --- a/vl.c +++ b/vl.c @@ -1697,6 +1697,7 @@ static int shutdown_requested; static int powerdown_requested; int debug_requested; int vmstop_requested; +static int exit_requested; int qemu_shutdown_requested(void) { @@ -1719,6 +1720,12 @@ int qemu_powerdown_requested(void) return r; } +int qemu_exit_requested(void) +{ + /* just return it, we'll exit() anyway */ + return exit_requested; +} + static int qemu_debug_requested(void) { int r = debug_requested; @@ -1789,6 +1796,12 @@ void qemu_system_powerdown_request(void) qemu_notify_event(); } +void qemu_system_exit_request(void) +{ + exit_requested = 1; + qemu_notify_event(); +} + #ifdef _WIN32 static void host_main_loop_wait(int *timeout) { @@ -1925,6 +1938,8 @@ static int vm_can_run(void) return 0; if (debug_requested) return 0; + if (exit_requested) + return 0; return 1; } @@ -1977,6 +1992,9 @@ static void main_loop(void) if ((r = qemu_vmstop_requested())) { vm_stop(r); } + if (qemu_exit_requested()) { + exit(0); + } } pause_all_vcpus(); }