From patchwork Thu Feb 11 01:50:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 45101 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 07AFEB7C7E for ; Thu, 11 Feb 2010 13:28:07 +1100 (EST) Received: from localhost ([127.0.0.1]:35805 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NfOmh-0005la-Ml for incoming@patchwork.ozlabs.org; Wed, 10 Feb 2010 21:28:03 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NfOD5-0007Xt-SX for qemu-devel@nongnu.org; Wed, 10 Feb 2010 20:51:15 -0500 Received: from [199.232.76.173] (port=57766 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NfOD5-0007Xb-Fi for qemu-devel@nongnu.org; Wed, 10 Feb 2010 20:51:15 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NfOD3-0001Le-Qd for qemu-devel@nongnu.org; Wed, 10 Feb 2010 20:51:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:1025) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NfOD3-0001LY-DD for qemu-devel@nongnu.org; Wed, 10 Feb 2010 20:51:13 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1B1pCv3006610 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 10 Feb 2010 20:51:12 -0500 Received: from localhost (vpn-10-105.rdu.redhat.com [10.11.10.105]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1B1pBI7027878; Wed, 10 Feb 2010 20:51:11 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 10 Feb 2010 23:50:06 -0200 Message-Id: <1265853007-27300-21-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1265853007-27300-1-git-send-email-lcapitulino@redhat.com> References: <1265853007-27300-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: armbru@redhat.com Subject: [Qemu-devel] [PATCH 20/21] Monitor: Debug stray prints the right way 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 QObject Monitor handlers should not call any Monitor print function: they should only build objects, printing is done by common code. Current QMP code will ignore such calls, as we can't send garbage to clients, additionally it will also emit an undefined error on the assumption that print calls usually report errors. However, the right way to deal with this is to rely on a return code. This has been fixed by other commit already. Now, this commit drops the error from monitor_vprintf() and adds a better debugging mechanism for those 'stray' prints: we count them if debug is enabled and let the developer know if a QObject handler is trying to print anything. Signed-off-by: Luiz Capitulino --- monitor.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 files changed, 41 insertions(+), 1 deletions(-) diff --git a/monitor.c b/monitor.c index 2f43136..d9592e9 100644 --- a/monitor.c +++ b/monitor.c @@ -137,6 +137,9 @@ struct Monitor { CPUState *mon_cpu; BlockDriverCompletionFunc *password_completion_cb; void *password_opaque; +#ifdef CONFIG_DEBUG_MONITOR + int print_calls_nr; +#endif QError *error; QLIST_HEAD(,mon_fd_t) fds; QLIST_ENTRY(Monitor) entry; @@ -146,8 +149,27 @@ struct Monitor { #define MON_DEBUG(fmt, ...) do { \ fprintf(stderr, "Monitor: "); \ fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) + +static inline void mon_print_count_inc(Monitor *mon) +{ + mon->print_calls_nr++; +} + +static inline void mon_print_count_init(Monitor *mon) +{ + mon->print_calls_nr = 0; +} + +static inline int mon_print_count_get(const Monitor *mon) +{ + return mon->print_calls_nr; +} + #else /* !CONFIG_DEBUG_MONITOR */ #define MON_DEBUG(fmt, ...) do { } while (0) +static inline void mon_print_count_inc(Monitor *mon) { } +static inline void mon_print_count_init(Monitor *mon) { } +static inline int mon_print_count_get(const Monitor *mon) { return 0; } #endif /* CONFIG_DEBUG_MONITOR */ static QLIST_HEAD(mon_list, Monitor) mon_list; @@ -230,8 +252,9 @@ void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) if (!mon) return; + mon_print_count_inc(mon); + if (monitor_ctrl_mode(mon)) { - qemu_error_new(QERR_UNDEFINED_ERROR); return; } @@ -3873,6 +3896,21 @@ static void handler_audit(Monitor *mon, const mon_cmd_t *cmd, int ret) MON_DEBUG("command '%s' returned success but passed an error\n", cmd->name); } + + if (mon_print_count_get(mon) > 0 && strcmp(cmd->name, "info") != 0) { + /* + * Handlers should not call Monitor print functions. + * + * Action: Ignore them in QMP. + * + * (XXX: we don't check any 'info' or 'query' command here + * because the user print function _is_ called by do_info(), hence + * we will trigger this check. This problem will go away when we + * make 'query' commands real and kill do_info()) + */ + MON_DEBUG("command '%s' called print functions %d time(s)\n", + cmd->name, mon_print_count_get(mon)); + } #endif } @@ -3882,6 +3920,8 @@ static void monitor_call_handler(Monitor *mon, const mon_cmd_t *cmd, int ret; QObject *data = NULL; + mon_print_count_init(mon); + ret = cmd->mhandler.cmd_new(mon, params, &data); handler_audit(mon, cmd, ret);