]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Filter out certain expected error messages from libvirtd
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 21 Jan 2011 17:25:01 +0000 (17:25 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 26 Jan 2011 14:54:23 +0000 (14:54 +0000)
Add a hook to the error reporting APIs to allow specific
error messages to be filtered out. Wire up libvirtd to
remove VIR_ERR_NO_DOMAIN & similar error codes from the
logs. They are still logged at DEBUG level.

* daemon/libvirtd.c: Filter VIR_ERR_NO_DOMAIN and friends
* src/libvirt_private.syms, src/util/virterror.c,
  src/util/virterror_internal.h: Hook for changing error
  reporting level

daemon/libvirtd.c
src/libvirt_private.syms
src/util/virterror.c
src/util/virterror_internal.h

index e6d73cc1429e94eeea41a049ad0c4f9c46b6620a..afc5c083e10011a737f43550a4c311cf13eaae65 100644 (file)
@@ -825,6 +825,30 @@ static void virshErrorHandler(void *opaque ATTRIBUTE_UNUSED, virErrorPtr err ATT
      * took care of reporting the error */
 }
 
+static int daemonErrorLogFilter(virErrorPtr err, int priority)
+{
+    /* These error codes don't really reflect real errors. They
+     * are expected events that occur when an app tries to check
+     * whether a particular guest already exists. This filters
+     * them to a lower log level to prevent pollution of syslog
+     */
+    switch (err->code) {
+    case VIR_ERR_NO_DOMAIN:
+    case VIR_ERR_NO_NETWORK:
+    case VIR_ERR_NO_STORAGE_POOL:
+    case VIR_ERR_NO_STORAGE_VOL:
+    case VIR_ERR_NO_NODE_DEVICE:
+    case VIR_ERR_NO_INTERFACE:
+    case VIR_ERR_NO_NWFILTER:
+    case VIR_ERR_NO_SECRET:
+    case VIR_ERR_NO_DOMAIN_SNAPSHOT:
+        return VIR_LOG_DEBUG;
+    }
+
+    return priority;
+}
+
+
 static struct qemud_server *qemudInitialize(void) {
     struct qemud_server *server;
 
@@ -3258,6 +3282,7 @@ int main(int argc, char **argv) {
 
     /* Disable error func, now logging is setup */
     virSetErrorFunc(NULL, virshErrorHandler);
+    virSetErrorLogPriorityFunc(daemonErrorLogFilter);
 
     /*
      * Call the daemon startup hook
index 003fc63d318a4e2350c0b01c7b2edc4d7e0e0717..b0ae692695a7526db1f374bc47a049e7d101663b 100644 (file)
@@ -923,6 +923,7 @@ virReportErrorHelper;
 virReportOOMErrorFull;
 virReportSystemErrorFull;
 virSetError;
+virSetErrorLogPriorityFunc;
 virStrerror;
 
 
index 91302846b538b6100da32cec36ef459dcc32780c..e45b5825be0d417ac297db79f42bb1f6dd81f7c5 100644 (file)
@@ -26,6 +26,7 @@ virThreadLocal virLastErr;
 
 virErrorFunc virErrorHandler = NULL;     /* global error handler */
 void *virUserData = NULL;        /* associated data */
+virErrorLogPriorityFunc virErrorLogPriorityFilter = NULL;
 
 /*
  * Macro used to format the message as a string in virRaiseError
@@ -721,14 +722,6 @@ virRaiseErrorFull(virConnectPtr conn ATTRIBUTE_UNUSED,
         VIR_GET_VAR_STR(fmt, str);
     }
 
-    /*
-     * Hook up the error or warning to the logging facility
-     * XXXX should we include filename as 'category' instead of domain name ?
-     */
-    priority = virErrorLevelPriority(level);
-    virLogMessage(virErrorDomainName(domain), priority,
-                  funcname, linenr, 1, "%s", str);
-
     /*
      * Save the information about the error
      */
@@ -749,6 +742,18 @@ virRaiseErrorFull(virConnectPtr conn ATTRIBUTE_UNUSED,
     to->int1 = int1;
     to->int2 = int2;
 
+    /*
+     * Hook up the error or warning to the logging facility
+     * XXXX should we include filename as 'category' instead of domain name ?
+     */
+    priority = virErrorLevelPriority(level);
+    if (virErrorLogPriorityFilter)
+        priority = virErrorLogPriorityFilter(to, priority);
+    virLogMessage(filename, priority,
+                  funcname, linenr,
+                  virErrorLogPriorityFilter ? 0 : 1,
+                  "%s", str);
+
     errno = save_errno;
 }
 
@@ -1335,3 +1340,8 @@ void virReportOOMErrorFull(int domcode,
                       domcode, VIR_ERR_NO_MEMORY, VIR_ERR_ERROR,
                       virerr, NULL, NULL, -1, -1, virerr, NULL);
 }
+
+void virSetErrorLogPriorityFunc(virErrorLogPriorityFunc func)
+{
+    virErrorLogPriorityFilter = func;
+}
index 601a88472f8b3cce69d30c2a2ecf0ecb526a38e6..8f32f4169de7956fed1e58fcc518f773b2bf9b18 100644 (file)
@@ -90,4 +90,7 @@ int virSetError(virErrorPtr newerr);
 void virDispatchError(virConnectPtr conn);
 const char *virStrerror(int theerrno, char *errBuf, size_t errBufLen);
 
+typedef int (*virErrorLogPriorityFunc)(virErrorPtr, int);
+void virSetErrorLogPriorityFunc(virErrorLogPriorityFunc func);
+
 #endif