qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, aliguori@us.ibm.com, kraxel@redhat.com,
	hollisb@us.ibm.com
Subject: [Qemu-devel] [PATCH 3/7] monitor: QError support
Date: Thu, 29 Oct 2009 16:42:26 -0200	[thread overview]
Message-ID: <1256841750-15228-4-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1256841750-15228-1-git-send-email-lcapitulino@redhat.com>

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 monitor handlers which report errors.

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 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

When in protocol mode, step 4 will use the specified QError to
build a protocol error response, intead of calling qerror_print().

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 109ff5c..4d56b8e 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;
 };
@@ -3146,6 +3148,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;
@@ -3171,7 +3185,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);
@@ -3622,3 +3639,27 @@ void qemu_error(const char *fmt, ...)
         break;
     }
 }
+
+void qemu_error_qerror(QErrorCode code, 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(code, 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 17af024..440a47c 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_qerror(QErrorCode code, const char *file, int linenr,
+                       const char *fmt, ...)
+                      __attribute__ ((format(printf, 4, 5)));
+
+#define qemu_error_structed(code, fmt, ...) \
+    qemu_error_qerror(code, __FILE__, __LINE__, fmt, ## __VA_ARGS__)
 
 #ifdef _WIN32
 /* Polling handling */
-- 
1.6.5.2.74.g610f9

  parent reply	other threads:[~2009-10-29 18:42 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-29 18:42 [Qemu-devel] [RFC 0/7] QError v1 Luiz Capitulino
2009-10-29 18:42 ` [Qemu-devel] [PATCH 1/7] QJSon: Introduce qobject_from_json_va() Luiz Capitulino
2009-10-29 18:42 ` [Qemu-devel] [PATCH 2/7] Introduce QError Luiz Capitulino
2009-10-29 20:14   ` [Qemu-devel] " Anthony Liguori
2009-10-29 20:48     ` Luiz Capitulino
2009-10-29 22:08       ` Paolo Bonzini
2009-10-30  2:25         ` Jamie Lokier
2009-10-30 13:05         ` Anthony Liguori
2009-10-30 13:48           ` Luiz Capitulino
2009-10-29 18:42 ` Luiz Capitulino [this message]
2009-10-29 18:42 ` [Qemu-devel] [PATCH 4/7] QError: Add QERR_DEV_NFOUND Luiz Capitulino
2009-10-29 18:42 ` [Qemu-devel] [PATCH 5/7] qdev: Use QError for not found error Luiz Capitulino
2009-10-29 18:42 ` [Qemu-devel] [PATCH 6/7] QError: Add do_info_balloon() errors Luiz Capitulino
2009-10-29 18:42 ` [Qemu-devel] [PATCH 7/7] monitor: do_info_balloon(): use QError Luiz Capitulino
2009-10-29 22:12 ` [Qemu-devel] Re: [RFC 0/7] QError v1 Paolo Bonzini
2009-10-30 12:28   ` Luiz Capitulino
2009-10-30 12:56     ` Gerd Hoffmann
2009-10-30 13:09       ` Anthony Liguori
2009-10-30 13:45         ` Paolo Bonzini
2009-10-30 13:47         ` Luiz Capitulino
2009-10-30 13:59           ` Anthony Liguori
2009-10-30 14:46             ` Luiz Capitulino
2009-10-30 16:28         ` Jamie Lokier
2009-10-30 16:34           ` Paolo Bonzini
2009-10-30 17:15           ` Daniel P. Berrange
2009-10-30 17:33             ` Paolo Bonzini
2009-10-30 17:48               ` Anthony Liguori
2009-11-01 12:28               ` Vincent Hanquez
2009-10-30 17:40           ` Anthony Liguori
2009-10-30 18:09             ` Jamie Lokier
2009-10-30 18:10               ` Paolo Bonzini
2009-10-30 19:04               ` Anthony Liguori

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=1256841750-15228-4-git-send-email-lcapitulino@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=hollisb@us.ibm.com \
    --cc=kraxel@redhat.com \
    --cc=pbonzini@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).