From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, kraxel@redhat.com, armbru@redhat.com
Subject: [Qemu-devel] [PATCH 08/13] monitor: QError support
Date: Wed, 18 Nov 2009 23:05:31 -0200 [thread overview]
Message-ID: <1258592736-10252-9-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1258592736-10252-1-git-send-email-lcapitulino@redhat.com>
This commit adds QError support in the Monitor.
A QError member is added to the Monitor struct. This new member
stores error information and is also used to check if an error
has occurred when the called handler returns.
Additionally, a new macro called qemu_error_new() is introduced.
It builds on top of the QemuErrorSink API and should be used in
place of qemu_error().
When all conversion to qemu_error_new() is done, qemu_error() can
be turned private.
Basically, Monitor's error flow is something like this:
1. An error occurs in the handler, it calls qemu_error_new()
2. qemu_error_new() builds a new QError object and stores it 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 <lcapitulino@redhat.com>
---
monitor.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
sysemu.h | 7 +++++++
2 files changed, 49 insertions(+), 1 deletions(-)
diff --git a/monitor.c b/monitor.c
index 3286ba2..da05bf4 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;
};
@@ -224,6 +226,11 @@ static inline int monitor_handler_ported(const mon_cmd_t *cmd)
return cmd->user_print != NULL;
}
+static inline int monitor_has_error(const Monitor *mon)
+{
+ return mon->error != NULL;
+}
+
static void monitor_print_qobject(Monitor *mon, const QObject *data)
{
switch (qobject_type(data)) {
@@ -3168,6 +3175,13 @@ fail:
return 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;
@@ -3193,7 +3207,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);
@@ -3644,3 +3661,27 @@ void qemu_error(const char *fmt, ...)
break;
}
}
+
+void qemu_error_internal(const char *file, int linenr, const char *func,
+ const char *fmt, ...)
+{
+ va_list va;
+ QError *qerror;
+
+ assert(qemu_error_sink != NULL);
+
+ va_start(va, fmt);
+ qerror = qerror_from_info(file, linenr, func, fmt, &va);
+ va_end(va);
+
+ 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 b1887ef..70a2b04 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 <windows.h>
@@ -71,6 +72,12 @@ void qemu_errors_to_file(FILE *fp);
void qemu_errors_to_mon(Monitor *mon);
void qemu_errors_to_previous(void);
void qemu_error(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
+void qemu_error_internal(const char *file, int linenr, const char *func,
+ const char *fmt, ...)
+ __attribute__ ((format(printf, 4, 5)));
+
+#define qemu_error_new(fmt, ...) \
+ qemu_error_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
#ifdef _WIN32
/* Polling handling */
--
1.6.5.3.148.g785c5
next prev parent reply other threads:[~2009-11-19 1:06 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-19 1:05 [Qemu-devel] [PATCH 00/13]: QError v5 Luiz Capitulino
2009-11-19 1:05 ` [Qemu-devel] [PATCH 01/13] QJSON: Introduce qobject_from_jsonv() Luiz Capitulino
2009-11-19 1:05 ` [Qemu-devel] [PATCH 02/13] QString: Introduce qstring_append_chr() Luiz Capitulino
2009-11-19 1:05 ` [Qemu-devel] [PATCH 03/13] QString: Introduce qstring_append_int() Luiz Capitulino
2009-11-19 1:05 ` [Qemu-devel] [PATCH 04/13] QString: Introduce qstring_from_substr() Luiz Capitulino
2009-11-19 1:05 ` [Qemu-devel] [PATCH 05/13] utests: Add qstring_append_chr() unit-test Luiz Capitulino
2009-11-19 1:05 ` [Qemu-devel] [PATCH 06/13] utests: Add qstring_from_substr() unit-test Luiz Capitulino
2009-11-19 1:05 ` [Qemu-devel] [PATCH 07/13] Introduce QError Luiz Capitulino
2009-11-19 1:05 ` Luiz Capitulino [this message]
2009-11-19 1:05 ` [Qemu-devel] [PATCH 09/13] QError: Add QERR_DEVICE_NOT_FOUND Luiz Capitulino
2009-11-19 1:05 ` [Qemu-devel] [PATCH 10/13] qdev: Use QError for 'device not found' error Luiz Capitulino
2009-11-19 1:05 ` [Qemu-devel] [PATCH 11/13] QError: Add QERR_DEVICE_NOT_ACTIVE Luiz Capitulino
2009-11-19 1:05 ` [Qemu-devel] [PATCH 12/13] QError: Add QERR_KVM_MISSING_CAP Luiz Capitulino
2009-11-19 1:05 ` [Qemu-devel] [PATCH 13/13] monitor: do_info_balloon(): Use QError Luiz Capitulino
2009-11-19 13:59 ` [Qemu-devel] [PATCH 00/13]: QError v5 Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1258592736-10252-9-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).