From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@gmail.com,
pbonzini@redhat.com, eblake@redhat.com,
Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 3/6] libqblock error handling
Date: Mon, 3 Sep 2012 17:18:43 +0800 [thread overview]
Message-ID: <1346663926-20188-4-git-send-email-xiawenc@linux.vnet.ibm.com> (raw)
In-Reply-To: <1346663926-20188-1-git-send-email-xiawenc@linux.vnet.ibm.com>
This patch contains error handling APIs.
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
libqblock/libqblock-error.c | 44 +++++++++++++++++++++++++++++++++++++++++++
libqblock/libqblock-error.h | 34 +++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 0 deletions(-)
create mode 100644 libqblock/libqblock-error.c
create mode 100644 libqblock/libqblock-error.h
diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
new file mode 100644
index 0000000..28d1d77
--- /dev/null
+++ b/libqblock/libqblock-error.c
@@ -0,0 +1,44 @@
+#include "libqblock-error.h"
+#include "libqblock-helper.h"
+
+void qb_error_get_human_str(struct QBroker *broker,
+ char *buf, int buf_size)
+{
+ const char *err_ret_str;
+ switch (broker->err_ret) {
+ case QB_ERR_MEM_ERR:
+ err_ret_str = "Not enough memory.";
+ break;
+ case QB_ERR_INTERNAL_ERR:
+ err_ret_str = "Internal error.";
+ break;
+ case QB_ERR_INVALID_PARAM:
+ err_ret_str = "Invalid param.";
+ break;
+ default:
+ err_ret_str = "Unknow error.";
+ break;
+ }
+ if (broker == NULL) {
+ snprintf(buf, buf_size, "%s", err_ret_str);
+ return;
+ }
+
+ if (broker->err_ret == QB_ERR_INTERNAL_ERR) {
+ snprintf(buf, buf_size, "%s %s errno [%d]. strerror [%s].",
+ err_ret_str, broker->err_msg,
+ broker->err_no, strerror(-broker->err_no));
+ } else {
+ snprintf(buf, buf_size, "%s %s",
+ err_ret_str, broker->err_msg);
+ }
+ return;
+}
+
+int qb_error_get_errno(struct QBroker *broker)
+{
+ if (broker->err_ret == QB_ERR_INTERNAL_ERR) {
+ return broker->err_no;
+ }
+ return 0;
+}
diff --git a/libqblock/libqblock-error.h b/libqblock/libqblock-error.h
new file mode 100644
index 0000000..b11df7c
--- /dev/null
+++ b/libqblock/libqblock-error.h
@@ -0,0 +1,34 @@
+#ifndef LIBQBLOCK_ERROR
+#define LIBQBLOCK_ERROR
+
+#include "libqblock-types.h"
+
+#define QB_ERR_MEM_ERR (-1)
+#define QB_ERR_INTERNAL_ERR (-2)
+#define QB_ERR_INVALID_PARAM (-3)
+#define QB_ERR_BLOCK_OUT_OF_RANGE (-100)
+
+/* error handling */
+/**
+ * qb_error_get_human_str: get human readable erro string.
+ *
+ * return a human readable string.
+ *
+ * @broker: operation broker, must be valid.
+ * @buf: buf to receive the string.
+ * @buf_size: the size of the string buf.
+ */
+void qb_error_get_human_str(struct QBroker *broker,
+ char *buf, int buf_size);
+
+/**
+ * qb_error_get_errno: get error number, only valid when err_ret is
+ * QB_ERR_INTERNAL_ERR.
+ *
+ * return negative errno or 0 if last error is not QB_ERR_INTERNAL_ERR.
+ *
+ * @broker: operation broker.
+ */
+int qb_error_get_errno(struct QBroker *broker);
+
+#endif
--
1.7.1
next prev parent reply other threads:[~2012-09-03 9:22 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-03 9:18 [Qemu-devel] [PATCH 0/6] libqblock, qemu block layer library Wenchao Xia
2012-09-03 9:18 ` [Qemu-devel] [PATCH 1/6] libqblock APIs Wenchao Xia
2012-09-03 13:18 ` Paolo Bonzini
2012-09-04 3:15 ` Wenchao Xia
2012-09-04 6:50 ` Paolo Bonzini
2012-09-04 9:05 ` Wenchao Xia
2012-09-10 8:10 ` Wenchao Xia
2012-09-03 13:56 ` Eric Blake
2012-09-03 14:05 ` Paolo Bonzini
2012-09-04 7:05 ` Wenchao Xia
2012-09-04 7:29 ` Paolo Bonzini
2012-09-04 6:42 ` Wenchao Xia
2012-09-04 11:35 ` Eric Blake
2012-09-04 13:47 ` Paolo Bonzini
2012-09-03 19:22 ` Blue Swirl
2012-09-03 9:18 ` [Qemu-devel] [PATCH 2/6] libqblock public type defines Wenchao Xia
2012-09-03 13:13 ` Paolo Bonzini
2012-09-04 2:00 ` Wenchao Xia
2012-09-03 14:20 ` Eric Blake
2012-09-04 7:10 ` Wenchao Xia
2012-09-04 7:37 ` Paolo Bonzini
2012-09-03 19:31 ` Blue Swirl
2012-09-04 7:19 ` Wenchao Xia
2012-09-04 7:38 ` Paolo Bonzini
2012-09-04 19:22 ` Blue Swirl
2012-09-10 8:22 ` Wenchao Xia
2012-09-03 9:18 ` Wenchao Xia [this message]
2012-09-03 14:22 ` [Qemu-devel] [PATCH 3/6] libqblock error handling Eric Blake
2012-09-04 7:12 ` Wenchao Xia
2012-09-10 8:20 ` Wenchao Xia
2012-09-03 9:18 ` [Qemu-devel] [PATCH 4/6] libqblock internal used functions Wenchao Xia
2012-09-03 13:18 ` Paolo Bonzini
2012-09-04 3:19 ` Wenchao Xia
2012-09-03 14:28 ` Eric Blake
2012-09-03 15:18 ` Paolo Bonzini
2012-09-04 7:15 ` Wenchao Xia
2012-09-04 7:38 ` Paolo Bonzini
2012-09-04 11:38 ` Eric Blake
2012-09-04 13:49 ` Paolo Bonzini
2012-09-04 13:51 ` Kevin Wolf
2012-09-10 8:23 ` Wenchao Xia
2012-09-03 9:18 ` [Qemu-devel] [PATCH 5/6] libqblock test example Wenchao Xia
2012-09-03 19:27 ` Blue Swirl
2012-09-03 9:18 ` [Qemu-devel] [PATCH 6/6] libqblock building system Wenchao Xia
2012-09-03 13:10 ` [Qemu-devel] xbzrle migration cache size advise for high memory changes workload ? Alexandre DERUMIER
2012-09-04 14:05 ` Orit Wasserman
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=1346663926-20188-4-git-send-email-xiawenc@linux.vnet.ibm.com \
--to=xiawenc@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.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).