From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, armbru@redhat.com, kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 08/10] monitor: QError support
Date: Tue, 17 Nov 2009 17:43:55 -0200 [thread overview]
Message-ID: <1258487037-24950-9-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1258487037-24950-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 | 42 +++++++++++++++++++++++++++++++++++++++++-
sysemu.h | 6 ++++++
2 files changed, 47 insertions(+), 1 deletions(-)
diff --git a/monitor.c b/monitor.c
index 3286ba2..74abef9 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,26 @@ void qemu_error(const char *fmt, ...)
break;
}
}
+
+void qemu_error_full(const char *file, int linenr, const char *fmt, ...)
+{
+ va_list va;
+ QError *qerror;
+
+ assert(qemu_error_sink != NULL);
+
+ va_start(va, fmt);
+ qerror = qerror_from_info(file, linenr, 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..656f6a4 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,11 @@ 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_full(const char *file, int linenr, const char *fmt, ...)
+ __attribute__ ((format(printf, 3, 4)));
+
+#define qemu_error_new(fmt, ...) \
+ qemu_error_full(__FILE__, __LINE__, fmt, ## __VA_ARGS__)
#ifdef _WIN32
/* Polling handling */
--
1.6.5.2.180.gc5b3e
next prev parent reply other threads:[~2009-11-17 19:44 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-17 19:43 [Qemu-devel] [PATCH 00/10]: QError v4 Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 01/10] QJSON: Introduce qobject_from_jsonv() Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 02/10] QString: Introduce qstring_append_chr() Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 03/10] QString: Introduce qstring_append_int() Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 04/10] QString: Introduce qstring_from_substr() Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 05/10] utests: Add qstring_append_chr() unit-test Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 06/10] utests: Add qstring_from_substr() unit-test Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 07/10] Introduce QError Luiz Capitulino
2009-11-18 15:16 ` Markus Armbruster
2009-11-18 17:23 ` Luiz Capitulino
2009-11-19 8:42 ` Markus Armbruster
2009-11-19 12:59 ` [Qemu-devel] " Paolo Bonzini
2009-11-18 18:14 ` [Qemu-devel] " Daniel P. Berrange
2009-11-18 19:58 ` Anthony Liguori
2009-11-18 20:13 ` Luiz Capitulino
2009-11-17 19:43 ` Luiz Capitulino [this message]
2009-11-18 15:16 ` [Qemu-devel] [PATCH 08/10] monitor: QError support Markus Armbruster
2009-11-18 17:29 ` Luiz Capitulino
2009-11-18 18:16 ` Daniel P. Berrange
2009-11-17 19:43 ` [Qemu-devel] [PATCH 09/10] qdev: Use QError for 'device not found' error Luiz Capitulino
2009-11-18 15:17 ` Markus Armbruster
2009-11-18 17:32 ` Luiz Capitulino
2009-11-20 7:23 ` Amit Shah
2009-11-17 19:43 ` [Qemu-devel] [PATCH 10/10] monitor: do_info_balloon(): use QError Luiz Capitulino
2009-11-18 15:17 ` Markus Armbruster
2009-11-18 15:58 ` Anthony Liguori
2009-11-18 18:10 ` Luiz Capitulino
2009-11-18 16:06 ` [Qemu-devel] [PATCH 00/10]: QError v4 Markus Armbruster
2009-11-18 18:08 ` Anthony Liguori
2009-11-19 2:36 ` Jamie Lokier
2009-11-20 15:56 ` Anthony Liguori
2009-11-20 16:20 ` Luiz Capitulino
2009-11-20 16:27 ` Anthony Liguori
2009-11-20 17:57 ` Markus Armbruster
2009-11-20 17:29 ` Markus Armbruster
2009-11-20 17:37 ` Anthony Liguori
2009-11-19 10:11 ` Markus Armbruster
2009-11-20 16:13 ` Anthony Liguori
2009-11-20 18:47 ` Markus Armbruster
2009-11-20 19:04 ` Anthony Liguori
2009-11-21 10:02 ` Markus Armbruster
2009-11-22 16:08 ` Anthony Liguori
2009-11-23 13:06 ` Luiz Capitulino
2009-11-23 13:11 ` Anthony Liguori
2009-11-23 13:34 ` Luiz Capitulino
2009-11-23 13:50 ` Alexander Graf
2009-11-24 11:55 ` Luiz Capitulino
2009-11-24 12:13 ` Alexander Graf
2009-11-23 16:08 ` Markus Armbruster
2009-11-23 12:42 ` Luiz Capitulino
2009-11-23 16:15 ` Markus Armbruster
2009-11-18 18:13 ` [Qemu-devel] " Paolo Bonzini
2009-11-19 10:25 ` Markus Armbruster
2009-11-19 13:01 ` Paolo Bonzini
2009-11-19 14:11 ` 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=1258487037-24950-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).