[PATCHv2 10/10] virterror: clean up VIR_ERR_INVALID_INTERFACE usage

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

 



* src/util/virterror.c (virErrorMsg): Unify semantics.
* src/libvirt.c (virLibInterfaceError): Convert to macro, and drop
extra parameter.  All callers simplified.
(virLibInterfaceErrorHelper): Refactor function to take new
parameters.
---

There's still more that can be cleaned up, but I ran out of time
on this patch series today and thought I'd at least get this much
posted (and possible some of the earlier patches pushed, if they
get an ACK).

 src/libvirt.c        |   36 +++++++++++++++++++-----------------
 src/util/virterror.c |    7 +------
 2 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index 54b9fb9..003b8c6 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -531,9 +531,11 @@ virLibNetworkErrorHelper(virNetworkPtr network, virErrorNumber error,
  *
  * Handle an error at the connection level
  */
+#define virLibInterfaceError(iface, error) \
+    virLibInterfaceErrorHelper(iface, error, __FILE__, __FUNCTION__, __LINE__)
 static void
-virLibInterfaceError(virInterfacePtr iface, virErrorNumber error,
-                   const char *info)
+virLibInterfaceErrorHelper(virInterfacePtr iface, virErrorNumber error,
+                           const char *file, const char *func, size_t line)
 {
     virConnectPtr conn = NULL;
     const char *errmsg;
@@ -541,12 +543,12 @@ virLibInterfaceError(virInterfacePtr iface, virErrorNumber error,
     if (error == VIR_ERR_OK)
         return;

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

 /**
@@ -6505,7 +6507,7 @@ virInterfaceGetConnect (virInterfacePtr iface)
     virResetLastError();

     if (!VIR_IS_CONNECTED_INTERFACE (iface)) {
-        virLibInterfaceError (NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
+        virLibInterfaceError (NULL, VIR_ERR_INVALID_INTERFACE);
         virDispatchError(NULL);
         return NULL;
     }
@@ -6775,7 +6777,7 @@ virInterfaceGetName(virInterfacePtr iface)
     virResetLastError();

     if (!VIR_IS_INTERFACE(iface)) {
-        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
+        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE);
         virDispatchError(NULL);
         return (NULL);
     }
@@ -6801,7 +6803,7 @@ virInterfaceGetMACString(virInterfacePtr iface)
     virResetLastError();

     if (!VIR_IS_INTERFACE(iface)) {
-        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
+        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE);
         virDispatchError(NULL);
         return (NULL);
     }
@@ -6835,12 +6837,12 @@ virInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags)
     virResetLastError();

     if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
-        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
+        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE);
         virDispatchError(NULL);
         return (NULL);
     }
     if ((flags & ~VIR_INTERFACE_XML_INACTIVE) != 0) {
-        virLibInterfaceError(iface, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virLibInterfaceError(iface, VIR_ERR_INVALID_ARG);
         goto error;
     }

@@ -6924,13 +6926,13 @@ virInterfaceUndefine(virInterfacePtr iface) {
     virResetLastError();

     if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
-        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
+        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE);
         virDispatchError(NULL);
         return (-1);
     }
     conn = iface->conn;
     if (conn->flags & VIR_CONNECT_RO) {
-        virLibInterfaceError(iface, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        virLibInterfaceError(iface, VIR_ERR_OPERATION_DENIED);
         goto error;
     }

@@ -6967,13 +6969,13 @@ virInterfaceCreate(virInterfacePtr iface, unsigned int flags)
     virResetLastError();

     if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
-        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
+        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE);
         virDispatchError(NULL);
         return (-1);
     }
     conn = iface->conn;
     if (conn->flags & VIR_CONNECT_RO) {
-        virLibInterfaceError(iface, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        virLibInterfaceError(iface, VIR_ERR_OPERATION_DENIED);
         goto error;
     }

@@ -7012,14 +7014,14 @@ virInterfaceDestroy(virInterfacePtr iface, unsigned int flags)
     virResetLastError();

     if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
-        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
+        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE);
         virDispatchError(NULL);
         return (-1);
     }

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

@@ -7087,7 +7089,7 @@ virInterfaceFree(virInterfacePtr iface)
     virResetLastError();

     if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
-        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
+        virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE);
         virDispatchError(NULL);
         return (-1);
     }
diff --git a/src/util/virterror.c b/src/util/virterror.c
index a16b9f6..1eb7a3f 100644
--- a/src/util/virterror.c
+++ b/src/util/virterror.c
@@ -968,12 +968,7 @@ virErrorMsg(virErrorNumber error, const char *info)
             errmsg = _("interface not found");
             break;
         case VIR_ERR_INVALID_INTERFACE:
-            /* FIXME: Adjust all callers before unifying semantics.  */
-            if (info == NULL)
-                errmsg = _("invalid interface pointer in");
-            else
-                errmsg = _("invalid interface pointer in %s");
-            info = NULL;
+            errmsg = _("invalid interface pointer");
             break;
         case VIR_ERR_MULTIPLE_INTERFACES:
             errmsg = _("multiple matching interfaces found");
-- 
1.7.0.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]