From patchwork Mon Sep 10 08:26:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 182817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E17472C0096 for ; Mon, 10 Sep 2012 18:28:09 +1000 (EST) Received: from localhost ([::1]:40861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAzLj-0005fO-SO for incoming@patchwork.ozlabs.org; Mon, 10 Sep 2012 04:28:07 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAzLS-0005Qt-Da for qemu-devel@nongnu.org; Mon, 10 Sep 2012 04:27:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TAzLO-0007oe-CA for qemu-devel@nongnu.org; Mon, 10 Sep 2012 04:27:50 -0400 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:45645) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAzLN-0007oJ-Pf for qemu-devel@nongnu.org; Mon, 10 Sep 2012 04:27:46 -0400 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 10 Sep 2012 18:25:53 +1000 Received: from d23relay04.au.ibm.com (202.81.31.246) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 10 Sep 2012 18:25:51 +1000 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q8A8IZgA19398738 for ; Mon, 10 Sep 2012 18:18:35 +1000 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q8A8Rd2O027162 for ; Mon, 10 Sep 2012 18:27:40 +1000 Received: from RedHat62GAWSWenchao (wenchaox.cn.ibm.com [9.115.122.115]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q8A8QiXO025911; Mon, 10 Sep 2012 18:27:38 +1000 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 10 Sep 2012 16:26:23 +0800 Message-Id: <1347265586-17698-4-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1347265586-17698-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1347265586-17698-1-git-send-email-xiawenc@linux.vnet.ibm.com> x-cbid: 12091008-0260-0000-0000-000001D30F5C X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 202.81.31.140 Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@gmail.com, blauwirbel@gmail.com, pbonzini@redhat.com, eblake@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V2 3/6] libqblock error handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch contains error handling APIs, which user could call them to get error details. Signed-off-by: Wenchao Xia --- 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 + * + * 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 + * + * 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