From 02fc93d6249554df666bcab333c2c5d540301708 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Thu, 9 Oct 2008 15:38:31 +0000 Subject: [PATCH] Centralize majority of error reporting logic. --- ChangeLog | 10 ++++ src/domain_conf.c | 27 ++-------- src/hash.c | 26 ++-------- src/internal.h | 6 +++ src/lxc_conf.c | 21 -------- src/lxc_conf.h | 7 ++- src/network_conf.c | 23 ++------- src/openvz_conf.c | 22 -------- src/openvz_conf.h | 7 ++- src/proxy_internal.c | 23 ++------- src/qemu_conf.c | 21 -------- src/qemu_conf.h | 8 ++- src/qparams.c | 10 ++-- src/sexpr.c | 25 ++-------- src/storage_conf.c | 19 ------- src/storage_conf.h | 7 ++- src/test.c | 28 ++++------- src/util.c | 27 ++-------- src/virterror.c | 41 +++++++++++++++ src/xen_internal.c | 116 +++++++++++++++---------------------------- src/xen_unified.c | 24 ++------- src/xend_internal.c | 59 ++-------------------- src/xm_internal.c | 28 +++-------- src/xml.c | 43 +++++----------- src/xs_internal.c | 23 ++------- 25 files changed, 175 insertions(+), 476 deletions(-) diff --git a/ChangeLog b/ChangeLog index d1944ee475..4e75c0572f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Thu Oct 9 11:30:00 EST Cole Robinson + + * src/domain_conf.c src/hash.c src/internal.h src/lxc_conf.c + src/lxc_conf.h src/network_conf.c src/openvz_conf.c src/openvz_conf.h + src/proxy_internal.c src/qemu_conf.c src/qemu_conf.h src/qparams.c + src/sexpr.c src/storage_conf.c src/storage_conf.h src/test.c + src/util.c src/virterror.c src/xen_internal.c src/xen_unified.c + src/xend_internal.c src/xm_internal.c src/xml.c src/xs_internal.c: + Centralize majority of error reporting logic. + Thu Oct 9 15:49:25 BST Daniel P Berrange * src/lxc_driver.c: Annotate unused parameter diff --git a/src/domain_conf.c b/src/domain_conf.c index 6a35064f80..e8d248f55e 100644 --- a/src/domain_conf.c +++ b/src/domain_conf.c @@ -141,30 +141,9 @@ VIR_ENUM_IMPL(virDomainHostdevSubsys, VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST, "usb", "pci") -static void virDomainReportError(virConnectPtr conn, - int code, const char *fmt, ...) - ATTRIBUTE_FORMAT(printf, 3, 4); - -static void virDomainReportError(virConnectPtr conn, - int code, const char *fmt, ...) -{ - va_list args; - char errorMessage[1024]; - const char *virerr; - - if (fmt) { - va_start(args, fmt); - vsnprintf(errorMessage, sizeof(errorMessage)-1, fmt, args); - va_end(args); - } else { - errorMessage[0] = '\0'; - } - - virerr = __virErrorMsg(code, (errorMessage[0] ? errorMessage : NULL)); - __virRaiseError(conn, NULL, NULL, VIR_FROM_DOMAIN, code, VIR_ERR_ERROR, - virerr, errorMessage, NULL, -1, -1, virerr, errorMessage); -} - +#define virDomainReportError(conn, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_DOMAIN, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) virDomainObjPtr virDomainFindByID(const virDomainObjPtr doms, int id) diff --git a/src/hash.c b/src/hash.c index d4b8a746a4..3efda2cbe0 100644 --- a/src/hash.c +++ b/src/hash.c @@ -31,6 +31,10 @@ /* #define DEBUG_GROW */ +#define virHashError(conn, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_NONE, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) + /* * A single entry in the hash table */ @@ -595,28 +599,6 @@ void *virHashSearch(virHashTablePtr table, virHashSearcher iter, const void *dat * * ************************************************************************/ -/** - * virHashError: - * @conn: the connection if available - * @error: the error number - * @info: extra information string - * - * Handle an error at the connection level - */ -static void -virHashError(virConnectPtr conn, virErrorNumber error, const char *info) -{ - const char *errmsg; - - if (error == VIR_ERR_OK) - return; - - errmsg = __virErrorMsg(error, info); - __virRaiseError(conn, NULL, NULL, VIR_FROM_NONE, error, VIR_ERR_ERROR, - errmsg, info, NULL, 0, 0, errmsg, info); -} - - /** * virDomainFreeName: * @domain: a domain object diff --git a/src/internal.h b/src/internal.h index a3d48faa1f..2ae764d8f8 100644 --- a/src/internal.h +++ b/src/internal.h @@ -313,6 +313,12 @@ void __virRaiseError(virConnectPtr conn, int int1, int int2, const char *msg, ...) ATTRIBUTE_FORMAT(printf, 12, 13); const char *__virErrorMsg(virErrorNumber error, const char *info); +void __virReportErrorHelper(virConnectPtr conn, int domcode, int errcode, + const char *filename ATTRIBUTE_UNUSED, + const char *funcname ATTRIBUTE_UNUSED, + long long linenr ATTRIBUTE_UNUSED, + const char *fmt, ...) + ATTRIBUTE_FORMAT(printf, 7, 8); /************************************************************************ * * diff --git a/src/lxc_conf.c b/src/lxc_conf.c index bea6bbe273..d522c4e80c 100644 --- a/src/lxc_conf.c +++ b/src/lxc_conf.c @@ -30,27 +30,6 @@ #include "lxc_conf.h" /* Functions */ -void lxcError(virConnectPtr conn, virDomainPtr dom, int code, - const char *fmt, ...) -{ - va_list args; - char errorMessage[1024]; - const char *codeErrorMessage; - - if (fmt) { - va_start(args, fmt); - vsnprintf(errorMessage, sizeof(errorMessage)-1, fmt, args); - va_end(args); - } else { - errorMessage[0] = '\0'; - } - - codeErrorMessage = __virErrorMsg(code, fmt); - __virRaiseError(conn, dom, NULL, VIR_FROM_LXC, code, VIR_ERR_ERROR, - codeErrorMessage, errorMessage, NULL, 0, 0, - codeErrorMessage, errorMessage); -} - virCapsPtr lxcCapsInit(void) { struct utsname utsname; diff --git a/src/lxc_conf.h b/src/lxc_conf.h index 00442b4fec..4d57046e6c 100644 --- a/src/lxc_conf.h +++ b/src/lxc_conf.h @@ -49,10 +49,9 @@ struct __lxc_driver { int lxcLoadDriverConfig(lxc_driver_t *driver); virCapsPtr lxcCapsInit(void); -void lxcError(virConnectPtr conn, - virDomainPtr dom, - int code, const char *fmt, ...) - ATTRIBUTE_FORMAT(printf,4,5); +#define lxcError(conn, dom, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_LXC, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) #endif /* LXC_CONF_H */ diff --git a/src/network_conf.c b/src/network_conf.c index 4627fba17c..800ead9748 100644 --- a/src/network_conf.c +++ b/src/network_conf.c @@ -48,26 +48,9 @@ VIR_ENUM_IMPL(virNetworkForward, VIR_NETWORK_FORWARD_LAST, "none", "nat", "route" ) -static void virNetworkReportError(virConnectPtr conn, - int code, const char *fmt, ...) -{ - va_list args; - char errorMessage[1024]; - const char *virerr; - - if (fmt) { - va_start(args, fmt); - vsnprintf(errorMessage, sizeof(errorMessage)-1, fmt, args); - va_end(args); - } else { - errorMessage[0] = '\0'; - } - - virerr = __virErrorMsg(code, (errorMessage[0] ? errorMessage : NULL)); - __virRaiseError(conn, NULL, NULL, VIR_FROM_NETWORK, code, VIR_ERR_ERROR, - virerr, errorMessage, NULL, -1, -1, virerr, errorMessage); -} - +#define virNetworkReportError(conn, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_NETWORK, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) virNetworkObjPtr virNetworkFindByUUID(const virNetworkObjPtr nets, const unsigned char *uuid) diff --git a/src/openvz_conf.c b/src/openvz_conf.c index aa8493a85d..c48c2194eb 100644 --- a/src/openvz_conf.c +++ b/src/openvz_conf.c @@ -53,28 +53,6 @@ static int openvzGetVPSUUID(int vpsid, char *uuidstr); static int openvzLocateConfFile(int vpsid, char *conffile, int maxlen); static int openvzAssignUUIDs(void); -void -openvzError (virConnectPtr conn, virErrorNumber code, const char *fmt, ...) -{ - va_list args; - char errorMessage[1024]; - const char *errmsg; - - if (fmt) { - va_start(args, fmt); - vsnprintf(errorMessage, sizeof(errorMessage)-1, fmt, args); - va_end(args); - } else { - errorMessage[0] = '\0'; - } - - errmsg = __virErrorMsg(code, (errorMessage[0] ? errorMessage : NULL)); - __virRaiseError (conn, NULL, NULL, VIR_FROM_OPENVZ, - code, VIR_ERR_ERROR, errmsg, errorMessage, NULL, 0, 0, - errmsg, errorMessage); -} - - int strtoI(const char *str) { diff --git a/src/openvz_conf.h b/src/openvz_conf.h index 68c00ea5b0..fbe4f695a8 100644 --- a/src/openvz_conf.h +++ b/src/openvz_conf.h @@ -41,6 +41,11 @@ enum { OPENVZ_WARN, OPENVZ_ERR }; fprintf(stderr, msg);\ fprintf(stderr, "\n"); } +#define openvzError(conn, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_OPENVZ, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) + + /* OpenVZ commands - Replace with wrapper scripts later? */ #define VZLIST "vzlist" #define VZCTL "vzctl" @@ -50,8 +55,6 @@ struct openvz_driver { virDomainObjPtr domains; }; -void openvzError (virConnectPtr conn, virErrorNumber code, const char *fmt, ...) - ATTRIBUTE_FORMAT(printf, 3, 4); int openvz_readline(int fd, char *ptr, int maxlen); int openvzReadConfigParam(int vpsid ,const char * param, char *value, int maxlen); virCapsPtr openvzCapsInit(void); diff --git a/src/proxy_internal.c b/src/proxy_internal.c index 13785598bc..0186eba2ba 100644 --- a/src/proxy_internal.c +++ b/src/proxy_internal.c @@ -92,26 +92,9 @@ struct xenUnifiedDriver xenProxyDriver = { * * ************************************************************************/ -/** - * virProxyError: - * @conn: the connection if available - * @error: the error number - * @info: extra information string - * - * Handle an error at the xend daemon interface - */ -static void -virProxyError(virConnectPtr conn, virErrorNumber error, const char *info) -{ - const char *errmsg; - - if (error == VIR_ERR_OK) - return; - - errmsg = __virErrorMsg(error, info); - __virRaiseError(conn, NULL, NULL, VIR_FROM_PROXY, error, VIR_ERR_ERROR, - errmsg, info, NULL, 0, 0, errmsg, info); -} +#define virProxyError(conn, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_PROXY, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) /************************************************************************ * * diff --git a/src/qemu_conf.c b/src/qemu_conf.c index 5c41f9a85c..4c01f5c7e4 100644 --- a/src/qemu_conf.c +++ b/src/qemu_conf.c @@ -59,27 +59,6 @@ VIR_ENUM_IMPL(virDomainDiskQEMUBus, VIR_DOMAIN_DISK_BUS_LAST, #define qemudLog(level, msg...) fprintf(stderr, msg) -void qemudReportError(virConnectPtr conn, - virDomainPtr dom, - virNetworkPtr net, - int code, const char *fmt, ...) { - va_list args; - char errorMessage[1024]; - const char *virerr; - - if (fmt) { - va_start(args, fmt); - vsnprintf(errorMessage, sizeof(errorMessage)-1, fmt, args); - va_end(args); - } else { - errorMessage[0] = '\0'; - } - - virerr = __virErrorMsg(code, (errorMessage[0] ? errorMessage : NULL)); - __virRaiseError(conn, dom, net, VIR_FROM_QEMU, code, VIR_ERR_ERROR, - virerr, errorMessage, NULL, -1, -1, virerr, errorMessage); -} - int qemudLoadDriverConfig(struct qemud_driver *driver, const char *filename) { virConfPtr conf; diff --git a/src/qemu_conf.h b/src/qemu_conf.h index 88dfaded9d..5ea57f039b 100644 --- a/src/qemu_conf.h +++ b/src/qemu_conf.h @@ -71,11 +71,9 @@ struct qemud_driver { }; -void qemudReportError(virConnectPtr conn, - virDomainPtr dom, - virNetworkPtr net, - int code, const char *fmt, ...) - ATTRIBUTE_FORMAT(printf,5,6); +#define qemudReportError(conn, dom, net, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_QEMU, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) int qemudLoadDriverConfig(struct qemud_driver *driver, diff --git a/src/qparams.c b/src/qparams.c index f068cb4212..ed5bddc400 100644 --- a/src/qparams.c +++ b/src/qparams.c @@ -30,13 +30,9 @@ #include "memory.h" #include "qparams.h" -static void -qparam_report_oom(void) -{ - const char *virerr = __virErrorMsg(VIR_ERR_NO_MEMORY, NULL); - __virRaiseError(NULL, NULL, NULL, VIR_FROM_NONE, VIR_ERR_NO_MEMORY, VIR_ERR_ERROR, - virerr, NULL, NULL, -1, -1, virerr, NULL); -} +#define qparam_report_oom(void) \ + __virReportErrorHelper(NULL, VIR_FROM_NONE, VIR_ERR_NO_MEMORY, \ + __FILE__, __FUNCTION__, __LINE__, NULL) struct qparam_set * new_qparam_set (int init_alloc, ...) diff --git a/src/sexpr.c b/src/sexpr.c index b607e4147f..c168754483 100644 --- a/src/sexpr.c +++ b/src/sexpr.c @@ -23,26 +23,9 @@ #include "util.h" #include "memory.h" -/** - * virSexprError: - * @conn: the connection if available - * @error: the error number - * @info: extra information string - * - * Handle an error in the S-Expression code - */ -static void -virSexprError(virErrorNumber error, const char *info) -{ - const char *errmsg; - - if (error == VIR_ERR_OK) - return; - - errmsg = __virErrorMsg(error, info); - __virRaiseError(NULL, NULL, NULL, VIR_FROM_SEXPR, error, VIR_ERR_ERROR, - errmsg, info, NULL, 0, 0, errmsg, info); -} +#define virSexprError(code, fmt...) \ + __virReportErrorHelper(NULL, VIR_FROM_SEXPR, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) /** * sexpr_new: @@ -278,7 +261,7 @@ sexpr2string(const struct sexpr * sexpr, char *buffer, size_t n_buffer) return (ret); error: buffer[n_buffer - 1] = 0; - virSexprError(VIR_ERR_SEXPR_SERIAL, buffer); + virSexprError(VIR_ERR_SEXPR_SERIAL, "%s", buffer); return (0); } diff --git a/src/storage_conf.c b/src/storage_conf.c index 29d74c8142..5884e9c6ce 100644 --- a/src/storage_conf.c +++ b/src/storage_conf.c @@ -49,25 +49,6 @@ #define virStorageLog(msg...) fprintf(stderr, msg) -void -virStorageReportError(virConnectPtr conn, int code, const char *fmt, ...) { - va_list args; - char errorMessage[1024]; - - if (fmt) { - va_start(args, fmt); - vsnprintf(errorMessage, sizeof(errorMessage)-1, fmt, args); - va_end(args); - } else { - errorMessage[0] = '\0'; - } - virStorageLog("%s", errorMessage); - __virRaiseError(conn, NULL, NULL, VIR_FROM_STORAGE, code, VIR_ERR_ERROR, - NULL, NULL, NULL, -1, -1, "%s", errorMessage); -} - - - void virStorageVolDefFree(virStorageVolDefPtr def) { int i; diff --git a/src/storage_conf.h b/src/storage_conf.h index 3500039dff..c86bf4b520 100644 --- a/src/storage_conf.h +++ b/src/storage_conf.h @@ -247,10 +247,9 @@ static inline int virStoragePoolObjIsActive(virStoragePoolObjPtr pool) { return pool->active; } -void virStorageReportError(virConnectPtr conn, - int code, - const char *fmt, ...) - ATTRIBUTE_FORMAT(printf, 3, 4); +#define virStorageReportError(conn, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_STORAGE, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) int virStoragePoolObjScanConfigs(virStorageDriverStatePtr driver); diff --git a/src/test.c b/src/test.c index 69c9090505..ad51736250 100644 --- a/src/test.c +++ b/src/test.c @@ -114,22 +114,9 @@ static const virNodeInfo defaultNodeInfo = { privconn = (testConnPtr)conn->privateData; -static void -testError(virConnectPtr con, - virDomainPtr dom, - virNetworkPtr net, - virErrorNumber error, - const char *info) -{ - const char *errmsg; - - if (error == VIR_ERR_OK) - return; - - errmsg = __virErrorMsg(error, info); - __virRaiseError(con, dom, net, VIR_FROM_TEST, error, VIR_ERR_ERROR, - errmsg, info, NULL, 0, 0, errmsg, info, 0); -} +#define testError(conn, dom, net, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_TEST, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) static virCapsPtr testBuildCapabilities(virConnectPtr conn) { @@ -600,12 +587,14 @@ static char *testGetHostname (virConnectPtr conn) r = gethostname (hostname, HOST_NAME_MAX+1); if (r == -1) { - testError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR, strerror (errno)); + testError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR, "%s", + strerror (errno)); return NULL; } str = strdup (hostname); if (str == NULL) { - testError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR, strerror (errno)); + testError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR, "%s", + strerror (errno)); return NULL; } return str; @@ -617,7 +606,8 @@ static char * testGetURI (virConnectPtr conn) GET_CONNECTION(conn); if (asprintf (&uri, "test://%s", privconn->path) == -1) { - testError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR, strerror (errno)); + testError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR, "%s", + strerror (errno)); return NULL; } return uri; diff --git a/src/util.c b/src/util.c index ca14be1624..ebe86b2c81 100644 --- a/src/util.c +++ b/src/util.c @@ -62,32 +62,13 @@ # define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif -#define MAX_ERROR_LEN 1024 - #define virLog(msg...) fprintf(stderr, msg) #ifndef PROXY -static void -ReportError(virConnectPtr conn, - int code, const char *fmt, ...) - ATTRIBUTE_FORMAT(printf, 3, 4); - -static void -ReportError(virConnectPtr conn, - int code, const char *fmt, ...) { - va_list args; - char errorMessage[MAX_ERROR_LEN]; - - if (fmt) { - va_start(args, fmt); - vsnprintf(errorMessage, MAX_ERROR_LEN-1, fmt, args); - va_end(args); - } else { - errorMessage[0] = '\0'; - } - __virRaiseError(conn, NULL, NULL, VIR_FROM_NONE, code, VIR_ERR_ERROR, - NULL, NULL, NULL, -1, -1, "%s", errorMessage); -} + +#define ReportError(conn, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_NONE, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) int virFileStripSuffix(char *str, const char *suffix) diff --git a/src/virterror.c b/src/virterror.c index 4aa7f42963..21c7339c56 100644 --- a/src/virterror.c +++ b/src/virterror.c @@ -722,3 +722,44 @@ __virErrorMsg(virErrorNumber error, const char *info) } return (errmsg); } + +/** + * __virReportErrorHelper + * + * @conn: the connection to the hypervisor if available + * @dom: the domain if available + * @net: the network if available + * @domcode: the virErrorDomain indicating where it's coming from + * @errcode: the virErrorNumber code for the error + * @filename: Source file error is dispatched from + * @funcname: Function error is dispatched from + * @linenr: Line number error is dispatched from + * @msg: the message to display/transmit + * @...: extra parameters for the message display + * + * Helper function to do most of the grunt work for individual driver + * ReportError + */ +void __virReportErrorHelper(virConnectPtr conn, int domcode, int errcode, + const char *filename ATTRIBUTE_UNUSED, + const char *funcname ATTRIBUTE_UNUSED, + long long linenr ATTRIBUTE_UNUSED, + const char *fmt, ...) +{ + va_list args; + char errorMessage[1024]; + const char *virerr; + + if (fmt) { + va_start(args, fmt); + vsnprintf(errorMessage, sizeof(errorMessage)-1, fmt, args); + va_end(args); + } else { + errorMessage[0] = '\0'; + } + + virerr = __virErrorMsg(errcode, (errorMessage[0] ? errorMessage : NULL)); + __virRaiseError(conn, NULL, NULL, domcode, errcode, VIR_ERR_ERROR, + virerr, errorMessage, NULL, -1, -1, virerr, errorMessage); + +} diff --git a/src/xen_internal.c b/src/xen_internal.c index c3aaa605e5..f498cc3d96 100644 --- a/src/xen_internal.c +++ b/src/xen_internal.c @@ -717,28 +717,10 @@ struct xenUnifiedDriver xenHypervisorDriver = { }; #endif /* !PROXY */ -/** - * virXenError: - * @conn: connection, if known - * @error: the error number - * @info: extra information string - * @value: extra information number - * - * Handle an error at the xend daemon interface - */ -static void -virXenError(virConnectPtr conn, - virErrorNumber error, const char *info, int value) -{ - const char *errmsg; - - if ((error == VIR_ERR_OK) || (in_init != 0)) - return; - - errmsg = __virErrorMsg(error, info); - __virRaiseError(conn, NULL, NULL, VIR_FROM_XEN, error, VIR_ERR_ERROR, - errmsg, info, NULL, value, 0, errmsg, info, value); -} +#define virXenError(conn, code, fmt...) \ + if (in_init == 0) \ + __virReportErrorHelper(conn, VIR_FROM_XEN, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) #ifndef PROXY @@ -780,29 +762,6 @@ virXenErrorFunc(virConnectPtr conn, #endif /* PROXY */ -/** - * virXenPerror: - * @conn: the connection (if available) - * @msg: name of system call or file (as in perror(3)) - * - * Raise error from a failed system call, using errno as the source. - */ -static void -virXenPerror (virConnectPtr conn, const char *msg) -{ - char *msg_s; - - if (VIR_ALLOC_N(msg_s, strlen (msg) + 10) == 0) { - strcpy (msg_s, msg); - strcat (msg_s, ": %s"); - } - - __virRaiseError (conn, NULL, NULL, - VIR_FROM_XEN, VIR_ERR_SYSTEM_ERROR, VIR_ERR_ERROR, - msg, NULL, NULL, errno, 0, - msg_s ? msg_s : msg, strerror (errno)); -} - /** * xenHypervisorDoV0Op: * @handle: the handle to the Xen hypervisor @@ -825,17 +784,18 @@ xenHypervisorDoV0Op(int handle, xen_op_v0 * op) hc.arg[0] = (unsigned long) op; if (lock_pages(op, sizeof(dom0_op_t)) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " locking", sizeof(*op)); + virXenError(NULL, VIR_ERR_XEN_CALL, " locking"); return (-1); } ret = ioctl(handle, xen_ioctl_hypercall_cmd, (unsigned long) &hc); if (ret < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl ", xen_ioctl_hypercall_cmd); + virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl %d", + xen_ioctl_hypercall_cmd); } if (unlock_pages(op, sizeof(dom0_op_t)) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " releasing", sizeof(*op)); + virXenError(NULL, VIR_ERR_XEN_CALL, " releasing"); ret = -1; } @@ -866,17 +826,18 @@ xenHypervisorDoV1Op(int handle, xen_op_v1* op) hc.arg[0] = (unsigned long) op; if (lock_pages(op, sizeof(dom0_op_t)) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " locking", sizeof(*op)); + virXenError(NULL, VIR_ERR_XEN_CALL, " locking"); return (-1); } ret = ioctl(handle, xen_ioctl_hypercall_cmd, (unsigned long) &hc); if (ret < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl ", xen_ioctl_hypercall_cmd); + virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl %d", + xen_ioctl_hypercall_cmd); } if (unlock_pages(op, sizeof(dom0_op_t)) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " releasing", sizeof(*op)); + virXenError(NULL, VIR_ERR_XEN_CALL, " releasing"); ret = -1; } @@ -908,17 +869,18 @@ xenHypervisorDoV2Sys(int handle, xen_op_v2_sys* op) hc.arg[0] = (unsigned long) op; if (lock_pages(op, sizeof(dom0_op_t)) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " locking", sizeof(*op)); + virXenError(NULL, VIR_ERR_XEN_CALL, " locking"); return (-1); } ret = ioctl(handle, xen_ioctl_hypercall_cmd, (unsigned long) &hc); if (ret < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " sys ioctl ", xen_ioctl_hypercall_cmd); + virXenError(NULL, VIR_ERR_XEN_CALL, " sys ioctl %d", + xen_ioctl_hypercall_cmd); } if (unlock_pages(op, sizeof(dom0_op_t)) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " releasing", sizeof(*op)); + virXenError(NULL, VIR_ERR_XEN_CALL, " releasing"); ret = -1; } @@ -950,17 +912,18 @@ xenHypervisorDoV2Dom(int handle, xen_op_v2_dom* op) hc.arg[0] = (unsigned long) op; if (lock_pages(op, sizeof(dom0_op_t)) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " locking", sizeof(*op)); + virXenError(NULL, VIR_ERR_XEN_CALL, " locking"); return (-1); } ret = ioctl(handle, xen_ioctl_hypercall_cmd, (unsigned long) &hc); if (ret < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl ", xen_ioctl_hypercall_cmd); + virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl %d", + xen_ioctl_hypercall_cmd); } if (unlock_pages(op, sizeof(dom0_op_t)) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " releasing", sizeof(*op)); + virXenError(NULL, VIR_ERR_XEN_CALL, " releasing"); ret = -1; } @@ -989,8 +952,7 @@ virXen_getdomaininfolist(int handle, int first_domain, int maxids, if (lock_pages(XEN_GETDOMAININFOLIST_DATA(dominfos), XEN_GETDOMAININFO_SIZE * maxids) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " locking", - XEN_GETDOMAININFO_SIZE * maxids); + virXenError(NULL, VIR_ERR_XEN_CALL, " locking"); return (-1); } if (hypervisor_version > 1) { @@ -1045,8 +1007,7 @@ virXen_getdomaininfolist(int handle, int first_domain, int maxids, } if (unlock_pages(XEN_GETDOMAININFOLIST_DATA(dominfos), XEN_GETDOMAININFO_SIZE * maxids) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " release", - XEN_GETDOMAININFO_SIZE * maxids); + virXenError(NULL, VIR_ERR_XEN_CALL, " release"); ret = -1; } return(ret); @@ -1644,7 +1605,7 @@ virXen_setvcpumap(int handle, int id, unsigned int vcpu, xen_op_v2_dom op; if (lock_pages(cpumap, maplen) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " locking", maplen); + virXenError(NULL, VIR_ERR_XEN_CALL, " locking"); return (-1); } memset(&op, 0, sizeof(op)); @@ -1680,7 +1641,7 @@ virXen_setvcpumap(int handle, int id, unsigned int vcpu, VIR_FREE(new); if (unlock_pages(cpumap, maplen) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " release", maplen); + virXenError(NULL, VIR_ERR_XEN_CALL, " release"); ret = -1; } } else { @@ -1777,7 +1738,7 @@ virXen_getvcpusinfo(int handle, int id, unsigned int vcpu, virVcpuInfoPtr ipt, } if ((cpumap != NULL) && (maplen > 0)) { if (lock_pages(cpumap, maplen) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " locking", maplen); + virXenError(NULL, VIR_ERR_XEN_CALL, " locking"); return (-1); } memset(cpumap, 0, maplen); @@ -1795,7 +1756,7 @@ virXen_getvcpusinfo(int handle, int id, unsigned int vcpu, virVcpuInfoPtr ipt, } ret = xenHypervisorDoV2Dom(handle, &op); if (unlock_pages(cpumap, maplen) < 0) { - virXenError(NULL, VIR_ERR_XEN_CALL, " release", maplen); + virXenError(NULL, VIR_ERR_XEN_CALL, " release"); ret = -1; } } @@ -1891,7 +1852,7 @@ xenHypervisorInit(void) char error[100]; regerror (errcode, &flags_hvm_rec, error, sizeof error); regfree (&flags_hvm_rec); - virXenError (NULL, VIR_ERR_INTERNAL_ERROR, error, 0); + virXenError (NULL, VIR_ERR_INTERNAL_ERROR, "%s", error); in_init = 0; return -1; } @@ -1901,7 +1862,7 @@ xenHypervisorInit(void) regerror (errcode, &flags_pae_rec, error, sizeof error); regfree (&flags_pae_rec); regfree (&flags_hvm_rec); - virXenError (NULL, VIR_ERR_INTERNAL_ERROR, error, 0); + virXenError (NULL, VIR_ERR_INTERNAL_ERROR, "%s", error); in_init = 0; return -1; } @@ -1912,7 +1873,7 @@ xenHypervisorInit(void) regfree (&xen_cap_rec); regfree (&flags_pae_rec); regfree (&flags_hvm_rec); - virXenError (NULL, VIR_ERR_INTERNAL_ERROR, error, 0); + virXenError (NULL, VIR_ERR_INTERNAL_ERROR, "%s", error); in_init = 0; return -1; } @@ -1966,7 +1927,7 @@ xenHypervisorInit(void) */ hypervisor_version = -1; - virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl ", IOCTL_PRIVCMD_HYPERCALL); + virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl %lu", IOCTL_PRIVCMD_HYPERCALL); close(fd); in_init = 0; return(-1); @@ -1980,7 +1941,7 @@ xenHypervisorInit(void) hypervisor_version = 2; if (VIR_ALLOC(ipt) < 0) { - virXenError(NULL, VIR_ERR_NO_MEMORY, __FUNCTION__, 0); + virXenError(NULL, VIR_ERR_NO_MEMORY, NULL); return(-1); } /* Currently consider RHEL5.0 Fedora7, xen-3.1, and xen-unstable */ @@ -2043,7 +2004,7 @@ xenHypervisorInit(void) DEBUG0("Failed to find any Xen hypervisor method\n"); hypervisor_version = -1; - virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl ", IOCTL_PRIVCMD_HYPERCALL); + virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl %lu", IOCTL_PRIVCMD_HYPERCALL); close(fd); in_init = 0; VIR_FREE(ipt); @@ -2083,7 +2044,7 @@ xenHypervisorOpen(virConnectPtr conn, ret = open(XEN_HYPERVISOR_SOCKET, O_RDWR); if (ret < 0) { - virXenError(conn, VIR_ERR_NO_XEN, XEN_HYPERVISOR_SOCKET, 0); + virXenError(conn, VIR_ERR_NO_XEN, "%s", XEN_HYPERVISOR_SOCKET); return (-1); } @@ -2414,7 +2375,7 @@ xenHypervisorMakeCapabilitiesInternal(virConnectPtr conn, return caps; no_memory: - virXenError(NULL, VIR_ERR_NO_MEMORY, __FUNCTION__, 0); + virXenError(NULL, VIR_ERR_NO_MEMORY, NULL); virCapabilitiesFree(caps); return NULL; } @@ -2437,7 +2398,8 @@ xenHypervisorMakeCapabilities(virConnectPtr conn) cpuinfo = fopen ("/proc/cpuinfo", "r"); if (cpuinfo == NULL) { if (errno != ENOENT) { - virXenPerror (NULL, "/proc/cpuinfo"); + virXenError (conn, VIR_ERR_SYSTEM_ERROR, + "/proc/cpuinfo: %s", strerror(errno)); return NULL; } } @@ -2446,7 +2408,9 @@ xenHypervisorMakeCapabilities(virConnectPtr conn) if (capabilities == NULL) { if (errno != ENOENT) { fclose(cpuinfo); - virXenPerror (NULL, "/sys/hypervisor/properties/capabilities"); + virXenError (conn, VIR_ERR_SYSTEM_ERROR, + "/sys/hypervisor/properties/capabilities: %s", + strerror(errno)); return NULL; } } @@ -2479,7 +2443,7 @@ xenHypervisorGetCapabilities (virConnectPtr conn) char *xml; if (!(xml = virCapabilitiesFormatXML(priv->caps))) { - virXenError(conn, VIR_ERR_NO_MEMORY, NULL, 0); + virXenError(conn, VIR_ERR_NO_MEMORY, NULL); return NULL; } diff --git a/src/xen_unified.c b/src/xen_unified.c index dae68d38e3..016181e968 100644 --- a/src/xen_unified.c +++ b/src/xen_unified.c @@ -58,23 +58,9 @@ static struct xenUnifiedDriver *drivers[XEN_UNIFIED_NR_DRIVERS] = { [XEN_UNIFIED_XM_OFFSET] = &xenXMDriver, }; -/** - * xenUnifiedError: - * @conn: the connection - * @error: the error number - * @info: extra information string - * - * Handle an error at the xend daemon interface - */ -static void -xenUnifiedError (virConnectPtr conn, virErrorNumber error, const char *info) -{ - const char *errmsg; - - errmsg = __virErrorMsg (error, info); - __virRaiseError (conn, NULL, NULL, VIR_FROM_XEN, error, VIR_ERR_ERROR, - errmsg, info, NULL, 0, 0, errmsg, info); -} +#define xenUnifiedError(conn, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_XEN, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) /* * Helper functions currently used in the NUMA code @@ -418,12 +404,12 @@ xenUnifiedGetHostname (virConnectPtr conn) r = gethostname (hostname, HOST_NAME_MAX+1); if (r == -1) { - xenUnifiedError (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno)); + xenUnifiedError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno)); return NULL; } str = strdup (hostname); if (str == NULL) { - xenUnifiedError (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno)); + xenUnifiedError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno)); return NULL; } return str; diff --git a/src/xend_internal.c b/src/xend_internal.c index 0125913472..2d10e111ef 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -104,61 +104,12 @@ virDomainXMLDevID(virDomainPtr domain, int ref_len); #endif -static void virXendError(virConnectPtr conn, virErrorNumber error, - const char *fmt, ...) - ATTRIBUTE_FORMAT(printf,3,4); +#define virXendError(conn, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_XEND, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) -#define MAX_ERROR_MESSAGE_LEN 1024 - -/** - * virXendError: - * @conn: the connection if available - * @error: the error number - * @fmt: format string followed by variable args - * - * Handle an error at the xend daemon interface - */ -static void -virXendError(virConnectPtr conn, virErrorNumber error, - const char *fmt, ...) -{ - va_list args; - char msg[MAX_ERROR_MESSAGE_LEN]; - const char *msg2; - - if (fmt) { - va_start (args, fmt); - vsnprintf (msg, sizeof (msg), fmt, args); - va_end (args); - } else { - msg[0] = '\0'; - } - - msg2 = __virErrorMsg (error, fmt ? msg : NULL); - __virRaiseError(conn, NULL, NULL, VIR_FROM_XEND, error, VIR_ERR_ERROR, - msg2, msg, NULL, 0, 0, msg2, msg); -} - -/** - * virXendErrorInt: - * @conn: the connection if available - * @error: the error number - * @val: extra integer information - * - * Handle an error at the xend daemon interface - */ -static void -virXendErrorInt(virConnectPtr conn, virErrorNumber error, int val) -{ - const char *errmsg; - - if (error == VIR_ERR_OK) - return; - - errmsg = __virErrorMsg(error, NULL); - __virRaiseError(conn, NULL, NULL, VIR_FROM_XEND, error, VIR_ERR_ERROR, - errmsg, NULL, NULL, val, 0, errmsg, val); -} +#define virXendErrorInt(conn, code, ival) \ + virXendError(conn, code, "%d", ival) /** * do_connect: diff --git a/src/xm_internal.c b/src/xm_internal.c index ad7f892932..a2dd9aaf6c 100644 --- a/src/xm_internal.c +++ b/src/xm_internal.c @@ -124,25 +124,9 @@ struct xenUnifiedDriver xenXMDriver = { NULL, /* domainSetSchedulerParameters */ }; -static void -xenXMError(virConnectPtr conn, int code, const char *fmt, ...) -{ - va_list args; - char errorMessage[1024]; - const char *virerr; - - if (fmt) { - va_start(args, fmt); - vsnprintf(errorMessage, sizeof(errorMessage)-1, fmt, args); - va_end(args); - } else { - errorMessage[0] = '\0'; - } - - virerr = __virErrorMsg(code, (errorMessage[0] ? errorMessage : NULL)); - __virRaiseError(conn, NULL, NULL, VIR_FROM_XENXM, code, VIR_ERR_ERROR, - virerr, errorMessage, NULL, -1, -1, virerr, errorMessage); -} +#define xenXMError(conn, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_XENXM, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) int xenXMInit (void) @@ -400,7 +384,7 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) { int ret = -1; if (now == ((time_t)-1)) { - xenXMError (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno)); + xenXMError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno)); return (-1); } @@ -412,7 +396,7 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) { /* Process the files in the config dir */ if (!(dh = opendir(configDir))) { - xenXMError (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno)); + xenXMError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno)); return (-1); } @@ -484,7 +468,7 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) { } else { /* Completely new entry */ newborn = 1; if (VIR_ALLOC(entry) < 0) { - xenXMError (conn, VIR_ERR_NO_MEMORY, strerror (errno)); + xenXMError (conn, VIR_ERR_NO_MEMORY, "%s", strerror(errno)); goto cleanup; } memcpy(entry->filename, path, PATH_MAX); diff --git a/src/xml.c b/src/xml.c index f7813ad370..6e6e0f6ce9 100644 --- a/src/xml.c +++ b/src/xml.c @@ -22,28 +22,9 @@ #include "util.h" #include "memory.h" -/** - * virXMLError: - * @conn: a connection if any - * @error: the error number - * @info: information/format string - * @value: extra integer parameter for the error string - * - * Report an error coming from the XML module. - */ -static void -virXMLError(virConnectPtr conn, virErrorNumber error, const char *info, - int value) -{ - const char *errmsg; - - if (error == VIR_ERR_OK) - return; - - errmsg = __virErrorMsg(error, info); - __virRaiseError(conn, NULL, NULL, VIR_FROM_XML, error, VIR_ERR_ERROR, - errmsg, info, NULL, value, 0, errmsg, info, value); -} +#define virXMLError(conn, code, fmt...) \ + __virReportErrorHelper(conn, VIR_FROM_XML, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) /************************************************************************ @@ -73,7 +54,7 @@ virXPathString(virConnectPtr conn, if ((ctxt == NULL) || (xpath == NULL)) { virXMLError(conn, VIR_ERR_INTERNAL_ERROR, - _("Invalid parameter to virXPathString()"), 0); + _("Invalid parameter to virXPathString()")); return (NULL); } relnode = ctxt->node; @@ -86,7 +67,7 @@ virXPathString(virConnectPtr conn, ret = strdup((char *) obj->stringval); xmlXPathFreeObject(obj); if (ret == NULL) { - virXMLError(conn, VIR_ERR_NO_MEMORY, _("strdup failed"), 0); + virXMLError(conn, VIR_ERR_NO_MEMORY, _("strdup failed")); } ctxt->node = relnode; return (ret); @@ -114,7 +95,7 @@ virXPathNumber(virConnectPtr conn, if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) { virXMLError(conn, VIR_ERR_INTERNAL_ERROR, - _("Invalid parameter to virXPathNumber()"), 0); + _("Invalid parameter to virXPathNumber()")); return (-1); } relnode = ctxt->node; @@ -156,7 +137,7 @@ virXPathLong(virConnectPtr conn, if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) { virXMLError(conn, VIR_ERR_INTERNAL_ERROR, - _("Invalid parameter to virXPathNumber()"), 0); + _("Invalid parameter to virXPathNumber()")); return (-1); } relnode = ctxt->node; @@ -211,7 +192,7 @@ virXPathULong(virConnectPtr conn, if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) { virXMLError(conn, VIR_ERR_INTERNAL_ERROR, - _("Invalid parameter to virXPathNumber()"), 0); + _("Invalid parameter to virXPathNumber()")); return (-1); } relnode = ctxt->node; @@ -269,7 +250,7 @@ virXPathBoolean(virConnectPtr conn, if ((ctxt == NULL) || (xpath == NULL)) { virXMLError(conn, VIR_ERR_INTERNAL_ERROR, - _("Invalid parameter to virXPathBoolean()"), 0); + _("Invalid parameter to virXPathBoolean()")); return (-1); } relnode = ctxt->node; @@ -307,7 +288,7 @@ virXPathNode(virConnectPtr conn, if ((ctxt == NULL) || (xpath == NULL)) { virXMLError(conn, VIR_ERR_INTERNAL_ERROR, - _("Invalid parameter to virXPathNode()"), 0); + _("Invalid parameter to virXPathNode()")); return (NULL); } relnode = ctxt->node; @@ -349,7 +330,7 @@ virXPathNodeSet(virConnectPtr conn, if ((ctxt == NULL) || (xpath == NULL)) { virXMLError(conn, VIR_ERR_INTERNAL_ERROR, - _("Invalid parameter to virXPathNodeSet()"), 0); + _("Invalid parameter to virXPathNodeSet()")); return (-1); } @@ -369,7 +350,7 @@ virXPathNodeSet(virConnectPtr conn, if (list != NULL && ret) { if (VIR_ALLOC_N(*list, ret) < 0) { virXMLError(conn, VIR_ERR_NO_MEMORY, - _("allocate string array"), + _("allocate string array size %lu"), ret * sizeof(**list)); ret = -1; } else { diff --git a/src/xs_internal.c b/src/xs_internal.c index 316604a979..fce7fa79c5 100644 --- a/src/xs_internal.c +++ b/src/xs_internal.c @@ -87,26 +87,9 @@ struct xenUnifiedDriver xenStoreDriver = { #endif /* ! PROXY */ -/** - * virXenStoreError: - * @conn: the connection if available - * @error: the error number - * @info: extra information string - * - * Handle an error at the xend store interface - */ -static void -virXenStoreError(virConnectPtr conn, virErrorNumber error, const char *info) -{ - const char *errmsg; - - if (error == VIR_ERR_OK) - return; - - errmsg = __virErrorMsg(error, info); - __virRaiseError(conn, NULL, NULL, VIR_FROM_XENSTORE, error, VIR_ERR_ERROR, - errmsg, info, NULL, 0, 0, errmsg, info); -} +#define virXenStoreError(conn, code, fmt...) \ + __virReportErrorHelper(NULL, VIR_FROM_XENSTORE, code, __FILE__, \ + __FUNCTION__, __LINE__, fmt) /************************************************************************ * * -- GitLab