[RFC 1/7] util: Add 'level' argument to virReportErrorHelper()

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

 



Up until now it's been assumed that every single error
reported through the helper would have VIR_ERR_ERROR level,
but this will no longer be the case going forward so we need
to make it a little more flexible.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 src/access/viraccessdriverpolkit.c |  2 +-
 src/access/viraccessmanager.c      |  2 +-
 src/datatypes.h                    | 30 ++++++++++++++++++++++++++----
 src/libvirt.c                      |  1 +
 src/util/virbuffer.c               |  4 ++--
 src/util/virconf.c                 |  6 ++++--
 src/util/virerror.c                |  4 +++-
 src/util/virerror.h                | 11 ++++++-----
 src/util/virkeyfile.c              |  6 ++++--
 src/util/virxml.c                  |  2 +-
 10 files changed, 49 insertions(+), 19 deletions(-)

diff --git a/src/access/viraccessdriverpolkit.c b/src/access/viraccessdriverpolkit.c
index 6954d74a15..1f87e7e152 100644
--- a/src/access/viraccessdriverpolkit.c
+++ b/src/access/viraccessdriverpolkit.c
@@ -34,7 +34,7 @@
 VIR_LOG_INIT("access.accessdriverpolkit");
 
 #define virAccessError(code, ...) \
-    virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \
+    virReportErrorHelper(VIR_FROM_THIS, code, VIR_ERR_ERROR, __FILE__, \
                          __FUNCTION__, __LINE__, __VA_ARGS__)
 
 #define VIR_ACCESS_DRIVER_POLKIT_ACTION_PREFIX "org.libvirt.api"
diff --git a/src/access/viraccessmanager.c b/src/access/viraccessmanager.c
index e7b5bf38da..f4230b253a 100644
--- a/src/access/viraccessmanager.c
+++ b/src/access/viraccessmanager.c
@@ -37,7 +37,7 @@
 VIR_LOG_INIT("access.accessmanager");
 
 #define virAccessError(code, ...) \
-    virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \
+    virReportErrorHelper(VIR_FROM_THIS, code, VIR_ERR_ERROR, __FILE__, \
                          __FUNCTION__, __LINE__, __VA_ARGS__)
 
 struct _virAccessManager {
diff --git a/src/datatypes.h b/src/datatypes.h
index e1b38706dc..87d6aa9a80 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -49,7 +49,7 @@ extern virClassPtr virAdmClientClass;
 # define virCheckConnectReturn(obj, retval) \
     do { \
         if (!virObjectIsClass(obj, virConnectClass)) { \
-            virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
+            virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -59,7 +59,7 @@ extern virClassPtr virAdmClientClass;
 # define virCheckConnectGoto(obj, label) \
     do { \
         if (!virObjectIsClass(obj, virConnectClass)) { \
-            virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
+            virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             goto label; \
@@ -71,7 +71,7 @@ extern virClassPtr virAdmClientClass;
         virDomainPtr _dom = (obj); \
         if (!virObjectIsClass(_dom, virDomainClass) || \
             !virObjectIsClass(_dom->conn, virConnectClass)) { \
-            virReportErrorHelper(VIR_FROM_DOM, VIR_ERR_INVALID_DOMAIN, \
+            virReportErrorHelper(VIR_FROM_DOM, VIR_ERR_INVALID_DOMAIN, VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -83,7 +83,7 @@ extern virClassPtr virAdmClientClass;
         virDomainPtr _dom = (obj); \
         if (!virObjectIsClass(_dom, virDomainClass) || \
             !virObjectIsClass(_dom->conn, virConnectClass)) { \
-            virReportErrorHelper(VIR_FROM_DOM, VIR_ERR_INVALID_DOMAIN, \
+            virReportErrorHelper(VIR_FROM_DOM, VIR_ERR_INVALID_DOMAIN, VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             goto label; \
@@ -97,6 +97,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_net->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_NETWORK, \
                                  VIR_ERR_INVALID_NETWORK, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -110,6 +111,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_net->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_NETWORK, \
                                  VIR_ERR_INVALID_NETWORK, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             goto label; \
@@ -123,6 +125,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_iface->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_INTERFACE, \
                                  VIR_ERR_INVALID_INTERFACE, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -137,6 +140,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_pool->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_STORAGE, \
                                  VIR_ERR_INVALID_STORAGE_POOL, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -151,6 +155,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_pool->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_STORAGE, \
                                  VIR_ERR_INVALID_STORAGE_POOL, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             goto label; \
@@ -164,6 +169,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_vol->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_STORAGE, \
                                  VIR_ERR_INVALID_STORAGE_VOL, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -177,6 +183,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_vol->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_STORAGE, \
                                  VIR_ERR_INVALID_STORAGE_VOL, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             goto label; \
@@ -190,6 +197,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_node->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_NODEDEV, \
                                  VIR_ERR_INVALID_NODE_DEVICE, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -204,6 +212,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_dev->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_NODEDEV, \
                                  VIR_ERR_INVALID_NODE_DEVICE, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             goto label; \
@@ -217,6 +226,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_secret->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_SECRET, \
                                  VIR_ERR_INVALID_SECRET, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -231,6 +241,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_secret->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_SECRET, \
                                  VIR_ERR_INVALID_SECRET, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -245,6 +256,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_st->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_STREAMS, \
                                  VIR_ERR_INVALID_STREAM, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -258,6 +270,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_st->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_STREAMS, \
                                  VIR_ERR_INVALID_STREAM, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             goto label; \
@@ -271,6 +284,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_nw->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_NWFILTER, \
                                  VIR_ERR_INVALID_NWFILTER, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -285,6 +299,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_nw->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_NWFILTER, \
                                  VIR_ERR_INVALID_NWFILTER_BINDING, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -300,6 +315,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_snap->domain->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_DOMAIN_SNAPSHOT, \
                                  VIR_ERR_INVALID_DOMAIN_SNAPSHOT, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -358,6 +374,7 @@ extern virClassPtr virAdmClientClass;
     do { \
         if (!virObjectIsClass(obj, virAdmConnectClass)) { \
             virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -368,6 +385,7 @@ extern virClassPtr virAdmClientClass;
     do { \
         if (!virObjectIsClass(obj, virAdmConnectClass)) { \
             virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             goto label; \
@@ -380,6 +398,7 @@ extern virClassPtr virAdmClientClass;
         if (!virObjectIsClass(_srv, virAdmServerClass) || \
             !virObjectIsClass(_srv->conn, virAdmConnectClass)) { \
             virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -392,6 +411,7 @@ extern virClassPtr virAdmClientClass;
         if (!virObjectIsClass(_srv, virAdmServerClass) || \
             !virObjectIsClass(_srv->conn, virAdmConnectClass)) { \
             virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             goto label; \
@@ -405,6 +425,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_clt->srv, virAdmServerClass) || \
             !virObjectIsClass(_clt->srv->conn, virAdmConnectClass)) { \
             virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             virDispatchError(NULL); \
@@ -418,6 +439,7 @@ extern virClassPtr virAdmClientClass;
             !virObjectIsClass(_clt->srv, virAdmServerClass) || \
             !virObjectIsClass(_clt->srv->conn, virAdmConnectClass)) { \
             virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \
+                                 VIR_ERR_ERROR, \
                                  __FILE__, __FUNCTION__, __LINE__, \
                                  __FUNCTION__); \
             goto label; \
diff --git a/src/libvirt.c b/src/libvirt.c
index 0a738aefb1..3e0bb26b9f 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -988,6 +988,7 @@ virConnectOpenInternal(const char *name,
 #endif
              false)) {
             virReportErrorHelper(VIR_FROM_NONE, VIR_ERR_CONFIG_UNSUPPORTED,
+                                 VIR_ERR_ERROR,
                                  __FILE__, __FUNCTION__, __LINE__,
                                  _("libvirt was built without the '%s' driver"),
                                  ret->uri->scheme);
diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c
index 8a2108f2f2..6306b3f072 100644
--- a/src/util/virbuffer.c
+++ b/src/util/virbuffer.c
@@ -339,8 +339,8 @@ virBufferCheckErrorInternal(const virBuffer *buf,
         virReportOOMErrorFull(domcode, filename, funcname, linenr);
         errno = ENOMEM;
     } else {
-        virReportErrorHelper(domcode, VIR_ERR_INTERNAL_ERROR, filename,
-                             funcname, linenr, "%s",
+        virReportErrorHelper(domcode, VIR_ERR_INTERNAL_ERROR, VIR_ERR_ERROR,
+                             filename, funcname, linenr, "%s",
                              _("Invalid buffer API usage"));
         errno = EINVAL;
     }
diff --git a/src/util/virconf.c b/src/util/virconf.c
index 88a869517e..8a382e8b6e 100644
--- a/src/util/virconf.c
+++ b/src/util/virconf.c
@@ -110,10 +110,12 @@ virConfErrorHelper(const char *file, const char *func, size_t line,
 
     /* Construct the string 'filename:line: info' if we have that. */
     if (ctxt && ctxt->filename) {
-        virReportErrorHelper(VIR_FROM_CONF, error, file, func, line,
+        virReportErrorHelper(VIR_FROM_CONF, error, VIR_ERR_ERROR,
+                             file, func, line,
                              _("%s:%d: %s"), ctxt->filename, ctxt->line, info);
     } else {
-        virReportErrorHelper(VIR_FROM_CONF, error, file, func, line,
+        virReportErrorHelper(VIR_FROM_CONF, error, VIR_ERR_ERROR,
+                             file, func, line,
                              "%s", info);
     }
 }
diff --git a/src/util/virerror.c b/src/util/virerror.c
index 683e51aa19..517e0bde28 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -1518,6 +1518,7 @@ virErrorMsg(virErrorNumber error, const char *info)
  *
  * @domcode: the virErrorDomain indicating where it's coming from
  * @errorcode: the virErrorNumber code for the error
+ * @level: the virErrorLevel level for the error
  * @filename: Source file error is dispatched from
  * @funcname: Function error is dispatched from
  * @linenr: Line number error is dispatched from
@@ -1529,6 +1530,7 @@ virErrorMsg(virErrorNumber error, const char *info)
  */
 void virReportErrorHelper(int domcode,
                           int errorcode,
+                          virErrorLevel level,
                           const char *filename,
                           const char *funcname,
                           size_t linenr,
@@ -1549,7 +1551,7 @@ void virReportErrorHelper(int domcode,
 
     virerr = virErrorMsg(errorcode, (errorMessage[0] ? errorMessage : NULL));
     virRaiseErrorFull(filename, funcname, linenr,
-                      domcode, errorcode, VIR_ERR_ERROR,
+                      domcode, errorcode, level,
                       virerr, errorMessage, NULL,
                       -1, -1, virerr, errorMessage);
     errno = save_errno;
diff --git a/src/util/virerror.h b/src/util/virerror.h
index 31577c5c8c..6e089db0d0 100644
--- a/src/util/virerror.h
+++ b/src/util/virerror.h
@@ -51,11 +51,12 @@ void virRaiseErrorObject(const char *filename,
                          virErrorPtr err);
 
 void virReportErrorHelper(int domcode, int errcode,
+                          virErrorLevel level,
                           const char *filename,
                           const char *funcname,
                           size_t linenr,
                           const char *fmt, ...)
-  ATTRIBUTE_FMT_PRINTF(6, 7);
+  ATTRIBUTE_FMT_PRINTF(7, 8);
 
 void virReportSystemErrorFull(int domcode,
                               int theerrno,
@@ -160,10 +161,10 @@ void virReportSystemErrorFull(int domcode,
                       (fmt), __VA_ARGS__)
 
 # define virReportUnsupportedError() \
-    virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_NO_SUPPORT, \
+    virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_NO_SUPPORT, VIR_ERR_ERROR, \
                          __FILE__, __FUNCTION__, __LINE__, __FUNCTION__)
 # define virReportRestrictedError(...) \
-    virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_OPERATION_DENIED, \
+    virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_OPERATION_DENIED, VIR_ERR_ERROR, \
                          __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
 /* The sizeof(...) comparison here is a hack to catch typos
  * in the name of the enum by triggering a compile error, as well
@@ -171,7 +172,7 @@ void virReportSystemErrorFull(int domcode,
  * or struct type, instead of an enum. It should get optimized away
  * since sizeof() is known at compile time  */
 # define virReportEnumRangeError(typname, value) \
-    virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INTERNAL_ERROR, \
+    virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INTERNAL_ERROR, VIR_ERR_ERROR, \
                          __FILE__, __FUNCTION__, __LINE__, \
                          "Unexpected enum value %d for %s", \
                          value, sizeof((typname)1) != 0 ? #typname : #typname);
@@ -185,7 +186,7 @@ void virReportOOMErrorFull(int domcode,
     virReportOOMErrorFull(VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)
 
 # define virReportError(code, ...) \
-    virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \
+    virReportErrorHelper(VIR_FROM_THIS, code, VIR_ERR_ERROR, __FILE__, \
                          __FUNCTION__, __LINE__, __VA_ARGS__)
 
 # define virReportErrorObject(obj) \
diff --git a/src/util/virkeyfile.c b/src/util/virkeyfile.c
index 1006a88837..4a0a7f5ee8 100644
--- a/src/util/virkeyfile.c
+++ b/src/util/virkeyfile.c
@@ -93,10 +93,12 @@ virKeyFileErrorHelper(const char *file, const char *func, size_t line,
 {
     /* Construct the string 'filename:line: info' if we have that. */
     if (ctxt && ctxt->filename) {
-        virReportErrorHelper(VIR_FROM_CONF, error, file, func, line,
+        virReportErrorHelper(VIR_FROM_CONF, error, VIR_ERR_ERROR,
+                             file, func, line,
                              _("%s:%zu: %s '%s'"), ctxt->filename, ctxt->line, info, ctxt->cur);
     } else {
-        virReportErrorHelper(VIR_FROM_CONF, error, file, func, line,
+        virReportErrorHelper(VIR_FROM_CONF, error, VIR_ERR_ERROR,
+                             file, func, line,
                              "%s", info);
     }
 }
diff --git a/src/util/virxml.c b/src/util/virxml.c
index 998d974882..a5975e6665 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -37,7 +37,7 @@
 #define VIR_FROM_THIS VIR_FROM_XML
 
 #define virGenericReportError(from, code, ...) \
-        virReportErrorHelper(from, code, __FILE__, \
+        virReportErrorHelper(from, code, VIR_ERR_ERROR, __FILE__, \
                              __FUNCTION__, __LINE__, __VA_ARGS__)
 
 /* Internal data to be passed to SAX parser and used by error handler. */
-- 
2.17.1

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

  Powered by Linux