From patchwork Tue Oct 13 16:57:02 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 35877 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 2E8CAB7B9E for ; Wed, 14 Oct 2009 04:06:44 +1100 (EST) Received: from localhost ([127.0.0.1]:47930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mxkpd-0000f7-Ap for incoming@patchwork.ozlabs.org; Tue, 13 Oct 2009 13:06:41 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mxkh0-0004C7-GY for qemu-devel@nongnu.org; Tue, 13 Oct 2009 12:57:46 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mxkgu-00047r-Ez for qemu-devel@nongnu.org; Tue, 13 Oct 2009 12:57:45 -0400 Received: from [199.232.76.173] (port=51967 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mxkgu-00047d-1p for qemu-devel@nongnu.org; Tue, 13 Oct 2009 12:57:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56438) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mxkgt-00024a-GE for qemu-devel@nongnu.org; Tue, 13 Oct 2009 12:57:39 -0400 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 n9DGvcAj015835; Tue, 13 Oct 2009 12:57:38 -0400 Received: from localhost (vpn-13-167.rdu.redhat.com [10.11.13.167]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9DGvbDJ000766; Tue, 13 Oct 2009 12:57:37 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 13 Oct 2009 13:57:02 -0300 Message-Id: <1255453026-18637-6-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1255453026-18637-1-git-send-email-lcapitulino@redhat.com> References: <1255453026-18637-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: aliguori@us.ibm.com, kraxel@redhat.com Subject: [Qemu-devel] [PATCH 5/9] monitor: QError support 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 paves the way for QError support in the Monitor, it adds a QError member to the Monitor struct and functions to check and print it. Additionally, it introduces qemu_error_structed() which should be used by functions that are called by monitor handlers and print error information. This new function has to be used in place of qemu_error(), which will become private when all the conversion is done. Basically, the Monitor's error flow is something like this: 1. An error happens in the handler, it calls qemu_error_structed() 2. qemu_error_structed() builds the right QObjects with the error information and stores them in the Monitor struct 3. The handler returns 4. Top level Monitor code checks the Monitor struct and calls qerror_print() to print the error Signed-off-by: Luiz Capitulino --- monitor.c | 44 +++++++++++++++++++++++++++++++++++++++++++- sysemu.h | 2 ++ 2 files changed, 45 insertions(+), 1 deletions(-) diff --git a/monitor.c b/monitor.c index 39d3201..6f0ad11 100644 --- a/monitor.c +++ b/monitor.c @@ -49,6 +49,7 @@ #include "qlist.h" #include "qdict.h" #include "qstring.h" +#include "qerror.h" //#define DEBUG //#define DEBUG_COMPLETION @@ -103,6 +104,7 @@ struct Monitor { CPUState *mon_cpu; BlockDriverCompletionFunc *password_completion_cb; void *password_opaque; + QError *error; QLIST_HEAD(,mon_fd_t) fds; QLIST_ENTRY(Monitor) entry; }; @@ -3148,6 +3150,18 @@ fail: return NULL; } +static inline int monitor_has_error(const Monitor *mon) +{ + return mon->error != NULL; +} + +static void monitor_print_error(Monitor *mon) +{ + qerror_print(mon->error); + QDECREF(mon->error); + mon->error = NULL; +} + static void monitor_handle_command(Monitor *mon, const char *cmdline) { QDict *qdict; @@ -3173,7 +3187,10 @@ static void monitor_handle_command(Monitor *mon, const char *cmdline) cmd->mhandler.cmd(mon, qdict); } - qemu_errors_to_previous(); + if (monitor_has_error(mon)) + monitor_print_error(mon); + + qemu_errors_to_previous(); out: QDECREF(qdict); @@ -3624,3 +3641,28 @@ void qemu_error(const char *fmt, ...) break; } } + +void qemu_error_structed(QErrorCode code, const char *fmt, ...) +{ + va_list va; + QError *qerror; + + assert(qemu_error_sink != NULL); + + va_start(va, fmt); + qerror = qerror_from_va(code, fmt, va); + va_end(va); + + assert(qerror != NULL); + + switch (qemu_error_sink->dest) { + case ERR_SINK_FILE: + qerror_print(qerror); + QDECREF(qerror); + break; + case ERR_SINK_MONITOR: + assert(qemu_error_sink->mon->error == NULL); + qemu_error_sink->mon->error = qerror; + break; + } +} diff --git a/sysemu.h b/sysemu.h index 896916f..02247fe 100644 --- a/sysemu.h +++ b/sysemu.h @@ -7,6 +7,7 @@ #include "qemu-queue.h" #include "qemu-timer.h" #include "qdict.h" +#include "qerror.h" #ifdef _WIN32 #include @@ -70,6 +71,7 @@ int qemu_loadvm_state(QEMUFile *f); void qemu_errors_to_file(FILE *fp); void qemu_errors_to_mon(Monitor *mon); void qemu_errors_to_previous(void); +void qemu_error_structed(QErrorCode code, const char *fmt, ...); void qemu_error(const char *fmt, ...) __attribute__ ((format(printf, 1, 2))); #ifdef _WIN32