From patchwork Thu Feb 11 01:50:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 45099 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 BBD85B6F11 for ; Thu, 11 Feb 2010 13:26:14 +1100 (EST) Received: from localhost ([127.0.0.1]:34547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NfOkt-0004Qd-TP for incoming@patchwork.ozlabs.org; Wed, 10 Feb 2010 21:26:11 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NfOD3-0007Va-22 for qemu-devel@nongnu.org; Wed, 10 Feb 2010 20:51:13 -0500 Received: from [199.232.76.173] (port=57764 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NfOD2-0007V3-M6 for qemu-devel@nongnu.org; Wed, 10 Feb 2010 20:51:12 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NfOD1-0001LQ-Dd for qemu-devel@nongnu.org; Wed, 10 Feb 2010 20:51:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37408) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NfOD1-0001LM-1f for qemu-devel@nongnu.org; Wed, 10 Feb 2010 20:51:11 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1B1pADe000838 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 10 Feb 2010 20:51:10 -0500 Received: from localhost (vpn-10-105.rdu.redhat.com [10.11.10.105]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1B1p8vj031294; Wed, 10 Feb 2010 20:51:09 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 10 Feb 2010 23:50:05 -0200 Message-Id: <1265853007-27300-20-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.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: armbru@redhat.com Subject: [Qemu-devel] [PATCH 19/21] Monitor: Audit handler return 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 This commit verifies the following two rules specified by Markus Armbruster: 1. If the handler returns failure, it must have passed an error. If it didn't, it's broken. Report an internal error to the client, and report the bug to the programmer. 2. If the handler returns success, it must not have passed an error. If it did, it's broken. Report the error to the client, and report the bug to the programmer. Signed-off-by: Luiz Capitulino --- monitor.c | 32 +++++++++++++++++++++++++++++++- 1 files changed, 31 insertions(+), 1 deletions(-) diff --git a/monitor.c b/monitor.c index d5b406c..2f43136 100644 --- a/monitor.c +++ b/monitor.c @@ -3848,12 +3848,42 @@ static int is_async_return(const QObject *data) return 0; } +static void handler_audit(Monitor *mon, const mon_cmd_t *cmd, int ret) +{ + if (ret && !monitor_has_error(mon)) { + /* + * If it returns failure, it must have passed on error. + * + * Action: Report an internal error to the client if in QMP. + */ + if (monitor_ctrl_mode(mon)) { + qemu_error_new(QERR_UNDEFINED_ERROR); + } + MON_DEBUG("command '%s' returned failure but did not pass an error\n", + cmd->name); + } + +#ifdef CONFIG_DEBUG_MONITOR + if (!ret && monitor_has_error(mon)) { + /* + * If it returns success, it must not have passed an error. + * + * Action: Report the passed error to the client. + */ + MON_DEBUG("command '%s' returned success but passed an error\n", + cmd->name); + } +#endif +} + static void monitor_call_handler(Monitor *mon, const mon_cmd_t *cmd, const QDict *params) { + int ret; QObject *data = NULL; - cmd->mhandler.cmd_new(mon, params, &data); + ret = cmd->mhandler.cmd_new(mon, params, &data); + handler_audit(mon, cmd, ret); if (is_async_return(data)) { /*