From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@gmail.com,
blauwirbel@gmail.com, pbonzini@redhat.com, eblake@redhat.com,
Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH V2 3/6] libqblock error handling
Date: Mon, 10 Sep 2012 16:26:23 +0800 [thread overview]
Message-ID: <1347265586-17698-4-git-send-email-xiawenc@linux.vnet.ibm.com> (raw)
In-Reply-To: <1347265586-17698-1-git-send-email-xiawenc@linux.vnet.ibm.com>
This patch contains error handling APIs, which user could call them to
get error details.
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
libqblock/libqblock-error.c | 60 +++++++++++++++++++++++++++++++++++++++++++
libqblock/libqblock-error.h | 50 +++++++++++++++++++++++++++++++++++
2 files changed, 110 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..d5ebabf
--- /dev/null
+++ b/libqblock/libqblock-error.c
@@ -0,0 +1,60 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include "libqblock-error.h"
+#include "libqblock-internal.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;
+ case QB_ERR_BLOCK_OUT_OF_RANGE:
+ err_ret_str = "request is out of image's range.";
+ 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..0690cfb
--- /dev/null
+++ b/libqblock/libqblock-error.h
@@ -0,0 +1,50 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#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 error string.
+ *
+ * return a human readable string, it would be truncated if buf is not big
+ * enough.
+ *
+ * @broker: operation broker, must be valid.
+ * @buf: buf to receive the string.
+ * @buf_size: the size of the string buf.
+ */
+DLL_PUBLIC
+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.
+ */
+DLL_PUBLIC
+int qb_error_get_errno(struct QBroker *broker);
+
+#endif
--
1.7.1
next prev parent reply other threads:[~2012-09-10 8:27 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-10 8:26 [Qemu-devel] [PATCH V2 0/6] libqblock, qemu block layer library Wenchao Xia
2012-09-10 8:26 ` [Qemu-devel] [PATCH V2 1/6] libqblock API design Wenchao Xia
2012-09-10 21:07 ` Eric Blake
2012-09-11 3:16 ` Wenchao Xia
2012-09-14 2:03 ` Wenchao Xia
2012-09-11 20:28 ` Blue Swirl
2012-09-12 2:54 ` Wenchao Xia
2012-09-12 8:19 ` Kevin Wolf
2012-09-12 9:21 ` Wenchao Xia
2012-09-14 19:08 ` Blue Swirl
2012-09-10 8:26 ` [Qemu-devel] [PATCH V2 2/6] libqblock type and structure defines Wenchao Xia
2012-09-10 21:27 ` Eric Blake
2012-09-11 3:26 ` Wenchao Xia
2012-09-11 4:12 ` Eric Blake
2012-09-11 20:31 ` Blue Swirl
2012-09-11 22:52 ` Eric Blake
2012-09-12 3:05 ` Wenchao Xia
2012-09-12 12:59 ` Eric Blake
2012-09-13 3:24 ` Wenchao Xia
2012-09-13 3:33 ` Eric Blake
2012-09-13 3:49 ` Eric Blake
2012-09-14 18:11 ` Blue Swirl
2012-09-17 2:23 ` Wenchao Xia
2012-09-17 19:08 ` Blue Swirl
2012-09-14 18:02 ` Blue Swirl
2012-09-10 8:26 ` Wenchao Xia [this message]
2012-09-10 21:33 ` [Qemu-devel] [PATCH V2 3/6] libqblock error handling Eric Blake
2012-09-11 4:36 ` Wenchao Xia
2012-09-11 20:32 ` Blue Swirl
2012-09-12 2:58 ` Wenchao Xia
2012-09-14 17:09 ` Blue Swirl
2012-09-10 8:26 ` [Qemu-devel] [PATCH V2 4/6] libqblock export some qemu block function Wenchao Xia
2012-09-10 8:26 ` [Qemu-devel] [PATCH V2 5/6] libqblock building system Wenchao Xia
2012-09-10 8:26 ` [Qemu-devel] [PATCH V2 6/6] libqblock test example 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=1347265586-17698-4-git-send-email-xiawenc@linux.vnet.ibm.com \
--to=xiawenc@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=blauwirbel@gmail.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).