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

[libvirt] [PATCHv2 09/10] virterror: clean up VIR_ERR_INVALID_NETWORK usage



All uses of virLibNetworkError passed __FUNCTION__ as the info string;
avoid the duplication by factoring it into a macro which can contain
additional information (namely, the line number).

* src/util/virterror.c (virErrorMsg): Unify semantics.
* src/libvirt.c (virLibNetworkError): Convert to macro, and drop
extra parameter.  All callers simplified.
(virLibNetworkErrorHelper): Refactor function to take new parameters.
(virStoragePoolBuild, virStoragePoolUndefine): Use correct error
type.
---

This was 3/3 in v1.  Changes since then:
incorporate virErrorMsg change at the same time, which has the
nice effect of avoiding duplicate use of __FUNCTION__ in the
resulting output message.

 src/libvirt.c        |   58 ++++++++++++++++++++++++++-----------------------
 src/util/virterror.c |    7 +-----
 2 files changed, 32 insertions(+), 33 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index eb05337..54b9fb9 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -503,9 +503,11 @@ virLibDomainError(virDomainPtr domain, virErrorNumber error,
  *
  * Handle an error at the connection level
  */
+#define virLibNetworkError(net, error) \
+    virLibNetworkErrorHelper(net, error, __FILE__, __FUNCTION__, __LINE__)
 static void
-virLibNetworkError(virNetworkPtr network, virErrorNumber error,
-                   const char *info)
+virLibNetworkErrorHelper(virNetworkPtr network, virErrorNumber error,
+                         const char *file, const char *func, size_t line)
 {
     virConnectPtr conn = NULL;
     const char *errmsg;
@@ -513,12 +515,12 @@ virLibNetworkError(virNetworkPtr network, virErrorNumber error,
     if (error == VIR_ERR_OK)
         return;

-    errmsg = virErrorMsg(error, info);
+    errmsg = virErrorMsg(error, NULL);
     if (error != VIR_ERR_INVALID_NETWORK) {
         conn = network->conn;
     }
-    virRaiseError(conn, NULL, network, VIR_FROM_NET, error, VIR_ERR_ERROR,
-                  errmsg, info, NULL, 0, 0, errmsg, info);
+    virRaiseErrorFull(conn, file, func, line, VIR_FROM_NET, error,
+                      VIR_ERR_ERROR, errmsg, NULL, NULL, 0, 0, errmsg, NULL);
 }

 /**
@@ -5630,7 +5632,7 @@ virNetworkGetConnect (virNetworkPtr net)
     virResetLastError();

     if (!VIR_IS_CONNECTED_NETWORK (net)) {
-        virLibNetworkError (NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibNetworkError (NULL, VIR_ERR_INVALID_NETWORK);
         virDispatchError(NULL);
         return NULL;
     }
@@ -6028,13 +6030,13 @@ virNetworkUndefine(virNetworkPtr network) {
     virResetLastError();

     if (!VIR_IS_CONNECTED_NETWORK(network)) {
-        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK);
         virDispatchError(NULL);
         return (-1);
     }
     conn = network->conn;
     if (conn->flags & VIR_CONNECT_RO) {
-        virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        virLibNetworkError(network, VIR_ERR_OPERATION_DENIED);
         goto error;
     }

@@ -6071,13 +6073,13 @@ virNetworkCreate(virNetworkPtr network)
     virResetLastError();

     if (!VIR_IS_CONNECTED_NETWORK(network)) {
-        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK);
         virDispatchError(NULL);
         return (-1);
     }
     conn = network->conn;
     if (conn->flags & VIR_CONNECT_RO) {
-        virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        virLibNetworkError(network, VIR_ERR_OPERATION_DENIED);
         goto error;
     }

@@ -6116,14 +6118,14 @@ virNetworkDestroy(virNetworkPtr network)
     virResetLastError();

     if (!VIR_IS_CONNECTED_NETWORK(network)) {
-        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK);
         virDispatchError(NULL);
         return (-1);
     }

     conn = network->conn;
     if (conn->flags & VIR_CONNECT_RO) {
-        virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        virLibNetworkError(network, VIR_ERR_OPERATION_DENIED);
         goto error;
     }

@@ -6159,7 +6161,7 @@ virNetworkFree(virNetworkPtr network)
     virResetLastError();

     if (!VIR_IS_CONNECTED_NETWORK(network)) {
-        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK);
         virDispatchError(NULL);
         return (-1);
     }
@@ -6219,7 +6221,7 @@ virNetworkGetName(virNetworkPtr network)
     virResetLastError();

     if (!VIR_IS_NETWORK(network)) {
-        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK);
         virDispatchError(NULL);
         return (NULL);
     }
@@ -6243,12 +6245,12 @@ virNetworkGetUUID(virNetworkPtr network, unsigned char *uuid)
     virResetLastError();

     if (!VIR_IS_NETWORK(network)) {
-        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK);
         virDispatchError(NULL);
         return (-1);
     }
     if (uuid == NULL) {
-        virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibNetworkError(network, VIR_ERR_INVALID_ARG);
         goto error;
     }

@@ -6280,12 +6282,12 @@ virNetworkGetUUIDString(virNetworkPtr network, char *buf)
     virResetLastError();

     if (!VIR_IS_NETWORK(network)) {
-        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK);
         virDispatchError(NULL);
         return (-1);
     }
     if (buf == NULL) {
-        virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibNetworkError(network, VIR_ERR_INVALID_ARG);
         goto error;
     }

@@ -6320,12 +6322,12 @@ virNetworkGetXMLDesc(virNetworkPtr network, int flags)
     virResetLastError();

     if (!VIR_IS_CONNECTED_NETWORK(network)) {
-        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK);
         virDispatchError(NULL);
         return (NULL);
     }
     if (flags != 0) {
-        virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibNetworkError(network, VIR_ERR_INVALID_ARG);
         goto error;
     }

@@ -6365,7 +6367,7 @@ virNetworkGetBridgeName(virNetworkPtr network)
     virResetLastError();

     if (!VIR_IS_CONNECTED_NETWORK(network)) {
-        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK);
         virDispatchError(NULL);
         return (NULL);
     }
@@ -6408,12 +6410,12 @@ virNetworkGetAutostart(virNetworkPtr network,
     virResetLastError();

     if (!VIR_IS_CONNECTED_NETWORK(network)) {
-        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK);
         virDispatchError(NULL);
         return (-1);
     }
     if (!autostart) {
-        virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibNetworkError(network, VIR_ERR_INVALID_ARG);
         goto error;
     }

@@ -6454,13 +6456,13 @@ virNetworkSetAutostart(virNetworkPtr network,
     virResetLastError();

     if (!VIR_IS_CONNECTED_NETWORK(network)) {
-        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK);
         virDispatchError(NULL);
         return (-1);
     }

     if (network->conn->flags & VIR_CONNECT_RO) {
-        virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        virLibNetworkError(network, VIR_ERR_OPERATION_DENIED);
         goto error;
     }

@@ -7638,7 +7640,8 @@ virStoragePoolBuild(virStoragePoolPtr pool,
     virResetLastError();

     if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
-        virLibStoragePoolError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL,
+                               __FUNCTION__);
         virDispatchError(NULL);
         return (-1);
     }
@@ -7681,7 +7684,8 @@ virStoragePoolUndefine(virStoragePoolPtr pool)
     virResetLastError();

     if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
-        virLibStoragePoolError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL,
+                               __FUNCTION__);
         virDispatchError(NULL);
         return (-1);
     }
diff --git a/src/util/virterror.c b/src/util/virterror.c
index af865e0..a16b9f6 100644
--- a/src/util/virterror.c
+++ b/src/util/virterror.c
@@ -877,12 +877,7 @@ virErrorMsg(virErrorNumber error, const char *info)
             errmsg = _("parser error");
             break;
         case VIR_ERR_INVALID_NETWORK:
-            /* FIXME: Adjust all callers before unifying semantics.  */
-            if (info == NULL)
-                errmsg = _("invalid network pointer in");
-            else
-                errmsg = _("invalid network pointer in %s");
-            info = NULL;
+            errmsg = _("invalid network pointer");
             break;
         case VIR_ERR_NETWORK_EXIST:
             errmsg = _("network already exists");
-- 
1.7.0.1


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