[libvirt] PATCH: Ensure filename/funcname/linenr gets passed to error func

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The current virRaiseError() function does not accept any information about
these source location of the error. The various virReportSystemError and
virReportOOMError wrappers all collect this info, but then discard it.

This patch turns virRaiseError  into virRaiseErrorFull() and adds params
for linenr, filename & funcname, and then adds a macro providing the
original virRaiseError() API contract, and collecting source location
info. The other wrappers are changed to call virRaiseErrorFull() directly
preserving their source location data. Finally the source location is
passed into the virLogMessage call.

This should address the issue that Mattias mentioned in the VMWare driver
thread.

Regards,
Daniel

diff -r 625ffe1918a4 src/virterror.c
--- a/src/virterror.c	Thu May 21 15:56:27 2009 +0100
+++ b/src/virterror.c	Thu May 21 16:13:49 2009 +0100
@@ -587,10 +587,11 @@ virSetConnError(virConnectPtr conn)
 
 
 /**
- * virRaiseError:
+ * virRaiseErrorFull:
  * @conn: the connection to the hypervisor if available
- * @dom: the domain if available
- * @net: the network if available
+ * @filename: filename where error was raised
+ * @funcname: function name where error was raised
+ * @linenr: line number where error was raised
  * @domain: the virErrorDomain indicating where it's coming from
  * @code: the virErrorNumber code for the error
  * @level: the virErrorLevel for the error
@@ -606,12 +607,19 @@ virSetConnError(virConnectPtr conn)
  * immediately if a callback is found and store it for later handling.
  */
 void
-virRaiseError(virConnectPtr conn,
-              virDomainPtr dom ATTRIBUTE_UNUSED,
-              virNetworkPtr net ATTRIBUTE_UNUSED,
-              int domain, int code, virErrorLevel level,
-              const char *str1, const char *str2, const char *str3,
-              int int1, int int2, const char *msg, ...)
+virRaiseErrorFull(virConnectPtr conn,
+                  const char *filename ATTRIBUTE_UNUSED,
+                  const char *funcname,
+                  size_t linenr,
+                  int domain,
+                  int code,
+                  virErrorLevel level,
+                  const char *str1,
+                  const char *str2,
+                  const char *str3,
+                  int int1,
+                  int int2,
+                  const char *fmt, ...)
 {
     virErrorPtr to;
     void *userData = virUserData;
@@ -647,18 +655,18 @@ virRaiseError(virConnectPtr conn,
     /*
      * formats the message
      */
-    if (msg == NULL) {
+    if (fmt == NULL) {
         str = strdup(_("No error message provided"));
     } else {
-        VIR_GET_VAR_STR(msg, str);
+        VIR_GET_VAR_STR(fmt, str);
     }
 
     /*
      * Hook up the error or warning to the logging facility
-     * TODO: pass function name and lineno
+     * XXXX should we include filename as 'category' instead of domain name ?
      */
     virLogMessage(virErrorDomainName(domain), virErrorLevelPriority(level),
-                  NULL, 0, 1, "%s", str);
+                  funcname, linenr, 1, "%s", str);
 
     /*
      * Save the information about the error
@@ -1064,10 +1072,12 @@ virErrorMsg(virErrorNumber error, const 
  * 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,
-                          size_t linenr ATTRIBUTE_UNUSED,
+void virReportErrorHelper(virConnectPtr conn,
+                          int domcode,
+                          int errcode,
+                          const char *filename,
+                          const char *funcname,
+                          size_t linenr,
                           const char *fmt, ...)
 {
     va_list args;
@@ -1083,8 +1093,10 @@ void virReportErrorHelper(virConnectPtr 
     }
 
     virerr = virErrorMsg(errcode, (errorMessage[0] ? errorMessage : NULL));
-    virRaiseError(conn, NULL, NULL, domcode, errcode, VIR_ERR_ERROR,
-                  virerr, errorMessage, NULL, -1, -1, virerr, errorMessage);
+    virRaiseErrorFull(conn, filename, funcname, linenr,
+                      domcode, errcode, VIR_ERR_ERROR,
+                      virerr, errorMessage, NULL,
+                      -1, -1, virerr, errorMessage);
 
 }
 
@@ -1113,9 +1125,9 @@ const char *virStrerror(int theerrno, ch
 void virReportSystemErrorFull(virConnectPtr conn,
                               int domcode,
                               int theerrno,
-                              const char *filename ATTRIBUTE_UNUSED,
-                              const char *funcname ATTRIBUTE_UNUSED,
-                              size_t linenr ATTRIBUTE_UNUSED,
+                              const char *filename,
+                              const char *funcname,
+                              size_t linenr,
                               const char *fmt, ...)
 {
     char strerror_buf[1024];
@@ -1145,19 +1157,21 @@ void virReportSystemErrorFull(virConnect
     if (!msgDetail)
         msgDetail = errnoDetail;
 
-    virRaiseError(conn, NULL, NULL, domcode, VIR_ERR_SYSTEM_ERROR, VIR_ERR_ERROR,
-                  msg, msgDetail, NULL, -1, -1, msg, msgDetail);
+    virRaiseErrorFull(conn, filename, funcname, linenr,
+                      domcode, VIR_ERR_SYSTEM_ERROR, VIR_ERR_ERROR,
+                      msg, msgDetail, NULL, -1, -1, msg, msgDetail);
 }
 
 void virReportOOMErrorFull(virConnectPtr conn,
                            int domcode,
-                           const char *filename ATTRIBUTE_UNUSED,
-                           const char *funcname ATTRIBUTE_UNUSED,
-                           size_t linenr ATTRIBUTE_UNUSED)
+                           const char *filename,
+                           const char *funcname,
+                           size_t linenr)
 {
     const char *virerr;
 
     virerr = virErrorMsg(VIR_ERR_NO_MEMORY, NULL);
-    virRaiseError(conn, NULL, NULL, domcode, VIR_ERR_NO_MEMORY, VIR_ERR_ERROR,
-                  virerr, NULL, NULL, -1, -1, virerr, NULL);
+    virRaiseErrorFull(conn, filename, funcname, linenr,
+                      domcode, VIR_ERR_NO_MEMORY, VIR_ERR_ERROR,
+                      virerr, NULL, NULL, -1, -1, virerr, NULL);
 }
diff -r 625ffe1918a4 src/virterror_internal.h
--- a/src/virterror_internal.h	Thu May 21 15:56:27 2009 +0100
+++ b/src/virterror_internal.h	Thu May 21 16:13:49 2009 +0100
@@ -33,17 +33,28 @@ extern void *virUserData;
  *									*
  ************************************************************************/
 int virErrorInitialize(void);
-void virRaiseError(virConnectPtr conn,
-                   virDomainPtr dom,
-                   virNetworkPtr net,
-                   int domain,
-                   int code,
-                   virErrorLevel level,
-                   const char *str1,
-                   const char *str2,
-                   const char *str3,
-                   int int1, int int2, const char *msg, ...)
-  ATTRIBUTE_FORMAT(printf, 12, 13);
+void virRaiseErrorFull(virConnectPtr conn,
+                       const char *filename,
+                       const char *funcname,
+                       size_t linenr,
+                       int domain,
+                       int code,
+                       virErrorLevel level,
+                       const char *str1,
+                       const char *str2,
+                       const char *str3,
+                       int int1,
+                       int int2,
+                       const char *fmt, ...)
+    ATTRIBUTE_FORMAT(printf, 13, 14);
+
+/* Includes 'dom' and 'net' for compatbility, but they're ignored */
+#define virRaiseError(conn, dom, net, domain, code, level,              \
+                      str1, str2, str3, int1, int2, msg, ...)           \
+    virRaiseErrorFull(conn, __FILE__, __FUNCTION__, __LINE__,           \
+                      domain, code, level, str1, str2, str3, int1, int2, \
+                      msg, __VA_ARGS__)
+
 const char *virErrorMsg(virErrorNumber error, const char *info);
 void virReportErrorHelper(virConnectPtr conn, int domcode, int errcode,
                           const char *filename ATTRIBUTE_UNUSED,


-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]