From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, peter.crosthwaite@xilinx.com, jcody@redhat.com,
mreitz@redhat.com, stefanha@redhat.com,
Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH V11 3/8] util: add error_append()
Date: Tue, 11 Feb 2014 14:23:03 -0500 [thread overview]
Message-ID: <1392146588-12120-4-git-send-email-xiawenc@linux.vnet.ibm.com> (raw)
In-Reply-To: <1392146588-12120-1-git-send-email-xiawenc@linux.vnet.ibm.com>
Some old code in error_set() is factored out, so this function can
call it.
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
include/qapi/error.h | 6 ++++++
util/error.c | 44 +++++++++++++++++++++++++++++++++++++++-----
2 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/include/qapi/error.h b/include/qapi/error.h
index c0f0c3b..b36236e 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -30,6 +30,12 @@ typedef struct Error Error;
void error_set(Error **err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(3, 4);
/**
+ * Append message to err if errp != NULL. If errp is already set, "\n" will be inserted
+ * after old message. If errp is not set yet, it is same as error_setg().
+ */
+void error_append(Error **errp, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
+
+/**
* Set an indirect pointer to an error given a ErrorClass value and a
* printf-style human message, followed by a strerror() string if
* @os_error is not zero.
diff --git a/util/error.c b/util/error.c
index f11f1d5..5053650 100644
--- a/util/error.c
+++ b/util/error.c
@@ -25,10 +25,12 @@ struct Error
Error *error_abort;
-void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...)
+static void error_vset(Error **errp,
+ ErrorClass err_class,
+ const char *fmt,
+ va_list ap)
{
Error *err;
- va_list ap;
int saved_errno = errno;
if (errp == NULL) {
@@ -37,10 +39,7 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...)
assert(*errp == NULL);
err = g_malloc0(sizeof(*err));
-
- va_start(ap, fmt);
err->msg = g_strdup_vprintf(fmt, ap);
- va_end(ap);
err->err_class = err_class;
if (errp == &error_abort) {
@@ -53,6 +52,41 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...)
errno = saved_errno;
}
+void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ error_vset(errp, err_class, fmt, ap);
+ va_end(ap);
+}
+
+void error_append(Error **errp, const char *fmt, ...)
+{
+ va_list ap;
+ Error *err_old;
+ gchar *msg;
+
+ if (error_is_set(errp)) {
+ err_old = *errp;
+ *errp = NULL;
+ va_start(ap, fmt);
+ msg = g_strdup_vprintf(fmt, ap);
+ va_end(ap);
+
+ error_set(errp, err_old->err_class,
+ "%s\n%s", error_get_pretty(err_old), msg);
+
+ g_free(msg);
+ error_free(err_old);
+ return;
+ }
+
+ va_start(ap, fmt);
+ error_vset(errp, ERROR_CLASS_GENERIC_ERROR, fmt, ap);
+ va_end(ap);
+}
+
void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
const char *fmt, ...)
{
--
1.7.1
next prev parent reply other threads:[~2014-02-11 6:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-11 19:23 [Qemu-devel] [PATCH V11 0/8] qcow2: rollback the modification on fail in snapshot creation Wenchao Xia
2014-02-11 19:23 ` [Qemu-devel] [PATCH V11 1/8] snapshot: add parameter *errp in snapshot create Wenchao Xia
2014-02-11 19:23 ` [Qemu-devel] [PATCH V11 2/8] qcow2: add error message in qcow2_write_snapshots() Wenchao Xia
2014-02-11 19:23 ` Wenchao Xia [this message]
2014-02-11 19:23 ` [Qemu-devel] [PATCH V11 4/8] qcow2: return int for qcow2_free_clusters() Wenchao Xia
2014-02-11 19:23 ` [Qemu-devel] [PATCH V11 5/8] qcow2: full rollback on fail in qcow2_write_snapshots() Wenchao Xia
2014-02-11 19:23 ` [Qemu-devel] [PATCH V11 6/8] qcow2: rollback on fail in qcow2_snapshot_create() Wenchao Xia
2014-02-11 19:23 ` [Qemu-devel] [PATCH V11 7/8] blkdebug: add debug events for snapshot Wenchao Xia
2014-02-11 19:23 ` [Qemu-devel] [PATCH V11 8/8] qemu-iotests: add test for qcow2 snapshot Wenchao Xia
2014-02-13 7:22 ` [Qemu-devel] [PATCH V11 0/8] qcow2: rollback the modification on fail in snapshot creation Wenchao Xia
2014-02-21 0:11 ` Wenchao Xia
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=1392146588-12120-4-git-send-email-xiawenc@linux.vnet.ibm.com \
--to=xiawenc@linux.vnet.ibm.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=peter.crosthwaite@xilinx.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).