diff --git a/ChangeLog b/ChangeLog index d1944ee4750ffbe95f2387240ceaa03b6fea9d51..4e75c0572fd0ed6501ffc6027766b9413c58e9d9 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 6a35064f804f7782c11d1b057ac791d0a98851d0..e8d248f55e6d0734c159e661a97d9fe14cf4e6a5 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 d4b8a746a4e983e6f98db1772310be759ffe1128..3efda2cbe08f1414141ab202bc1efd9a496355b1 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 a3d48faa1fcbceb8c7bb5692277956177dee8a40..2ae764d8f887bc14d81c8ac11e7e41c9fa7af72f 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 bea6bbe27346ac37796c02ec44ce393262fae18f..d522c4e80c0214762a4861d3f1873270a9ee668c 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 00442b4fec7456f16f801eed03491e17e113bf8c..4d57046e6c7d36db2665f2c6579a8dc87cd23000 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 4627fba17c277585e4bfc20aac32630d99572f5e..800ead97489ac3a0906bad754cde486c9f3978f0 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 aa8493a85dee48e7b5cbb5f376af7a2753fc8aad..c48c2194ebc347d795cfec3610225d5fa6e3f964 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 68c00ea5b05db7174f601b1f7fea50991dbda64a..fbe4f695a82babb70349d318979e5b304bea957c 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 13785598bc0139460b0f4e4bf268aa034745e5a3..0186eba2ba62bba194cf2148716dc9c4dfc773aa 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 5c41f9a85c56bd14cab56ae029ce269049c74064..4c01f5c7e49b588ae4990c074a0a9200bfb423aa 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 88dfaded9d793f60adfbb53294eab03d1b746da8..5ea57f039b10c0cf47d645ea7c42b9ba3e55c33a 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 f068cb42124d4cfe71de20de5ec317ad681a7d32..ed5bddc400da5830a41cd461eb72b18d32f976bf 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 b607e4147fff053f2a4a600f83b5e907141e1916..c1687544835328a2ec149de09d429d8842e690ad 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 29d74c814280bafcd8fa830529ba20b0db58f8e5..5884e9c6ce4c63064a0aa85ac69d9caa8ddc827c 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 3500039dffde8485da393e26b73ee013dd92884e..c86bf4b520b4c1fafcfa88e44b95e169259576c7 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 69c90905050e309fbc6163b06ff9a0343fb06a38..ad51736250617f82c9cce70da0d14af2bb1e7e2e 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 ca14be1624cb63d719765d304d6c3c685fc24a27..ebe86b2c816c83cd4ade502ba97ce2c067789de2 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 4aa7f4296393eca8dab87e844aa9796417ddbe2f..21c7339c560cddf9b103244b20852f1d27b61669 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 c3aaa605e5f6ffe076129aa16c21a3627b120d40..f498cc3d96ad0f47cc9ea1e8369e08618d16db96 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 dae68d38e3877d56db118760c1a1d22cdd792da7..016181e968006d272601f6850fc297f5f2c73e8d 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 0125913472d694219e0dddcf2e70bd8b6406ea65..2d10e111effbea61403d9d82ab10ec2b14079953 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 ad7f8929321634ba3a6016fb02a1e45597054303..a2dd9aaf6c45bac8253f0d248c378a7bb5904a9e 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 f7813ad370aa7863a9378b9fa07b7d952d1070e7..6e6e0f6ce9fdd8149956691e664ba54cd296dc0f 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 316604a9795bd84b3878ceee1a63be78907f358b..fce7fa79c53ad87f9712c956f824a32eef22ef6f 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) /************************************************************************ * *