[PATCHv2 1/2] virerror: Add support for suppressing reporting of errors

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

 



It might be desired to suppress reporting of errors in some cases when
the failure isn't fatal but report them in other cases.

This patch adds plumbing to simplify doing this and still allows to view
the error when in debug mode.

The new helper virReportErrorConditional() takes a new first argument.
This boolean controls the reporting of the error.
---
 src/libvirt_private.syms |  2 +-
 src/util/virerror.c      | 31 ++++++++++++++++++++-----------
 src/util/virerror.h      | 21 +++++++++++++++------
 3 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a958d94..530ca34 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1330,7 +1330,7 @@ virErrorInitialize;
 virErrorSetErrnoFromLastError;
 virLastErrorIsSystemErrno;
 virRaiseErrorFull;
-virReportErrorHelper;
+virReportErrorHelperInternal;
 virReportOOMErrorFull;
 virReportSystemErrorFull;
 virSetError;
diff --git a/src/util/virerror.c b/src/util/virerror.c
index ca25678..14a06f4 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -1255,8 +1255,9 @@ virErrorMsg(virErrorNumber error, const char *info)
 }

 /**
- * virReportErrorHelper:
+ * virReportErrorHelperInternal:
  *
+ * @report: boolean to control wether to raise the error or not
  * @domcode: the virErrorDomain indicating where it's coming from
  * @errorcode: the virErrorNumber code for the error
  * @filename: Source file error is dispatched from
@@ -1268,12 +1269,14 @@ virErrorMsg(virErrorNumber error, const char *info)
  * Helper function to do most of the grunt work for individual driver
  * ReportError
  */
-void virReportErrorHelper(int domcode,
-                          int errorcode,
-                          const char *filename,
-                          const char *funcname,
-                          size_t linenr,
-                          const char *fmt, ...)
+void
+virReportErrorHelperInternal(bool report,
+                             int domcode,
+                             int errorcode,
+                             const char *filename,
+                             const char *funcname,
+                             size_t linenr,
+                             const char *fmt, ...)
 {
     int save_errno = errno;
     va_list args;
@@ -1289,10 +1292,16 @@ void virReportErrorHelper(int domcode,
     }

     virerr = virErrorMsg(errorcode, (errorMessage[0] ? errorMessage : NULL));
-    virRaiseErrorFull(filename, funcname, linenr,
-                      domcode, errorcode, VIR_ERR_ERROR,
-                      virerr, errorMessage, NULL,
-                      -1, -1, virerr, errorMessage);
+    if (report) {
+        virRaiseErrorFull(filename, funcname, linenr,
+                          domcode, errorcode, VIR_ERR_ERROR,
+                          virerr, errorMessage, NULL,
+                          -1, -1, virerr, errorMessage);
+    } else {
+        VIR_DEBUG("Suppressed error at %s:%zu %s: %s %s",
+                  filename, linenr, funcname, virerr, errorMessage);
+    }
+
     errno = save_errno;
 }

diff --git a/src/util/virerror.h b/src/util/virerror.h
index 05e9950..39db8f6 100644
--- a/src/util/virerror.h
+++ b/src/util/virerror.h
@@ -47,12 +47,16 @@ void virRaiseErrorFull(const char *filename,
                        const char *fmt, ...)
     ATTRIBUTE_FMT_PRINTF(12, 13);

-void virReportErrorHelper(int domcode, int errcode,
-                          const char *filename,
-                          const char *funcname,
-                          size_t linenr,
-                          const char *fmt, ...)
-  ATTRIBUTE_FMT_PRINTF(6, 7);
+void virReportErrorHelperInternal(bool report,
+                                  int domcode, int errcode,
+                                  const char *filename,
+                                  const char *funcname,
+                                  size_t linenr,
+                                  const char *fmt, ...)
+  ATTRIBUTE_FMT_PRINTF(7, 8);
+
+# define virReportErrorHelper(...)                  \
+    virReportErrorHelperInternal(true, __VA_ARGS__)

 void virReportSystemErrorFull(int domcode,
                               int theerrno,
@@ -168,6 +172,11 @@ void virReportOOMErrorFull(int domcode,
     virReportErrorHelper(VIR_FROM_THIS, code, __FILE__,              \
                          __FUNCTION__, __LINE__, __VA_ARGS__)

+# define virReportErrorConditional(report, code, ...)                   \
+    virReportErrorHelperInternal(report, VIR_FROM_THIS, code, __FILE__, \
+                                 __FUNCTION__, __LINE__, __VA_ARGS__)
+
+
 int virSetError(virErrorPtr newerr);
 void virDispatchError(virConnectPtr conn);
 const char *virStrerror(int theerrno, char *errBuf, size_t errBufLen);
-- 
1.8.3.2

--
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]