]> xenbits.xensource.com Git - libvirt.git/commitdiff
maint: improve VIR_ERR_INVALID_NWFILTER usage
authorEric Blake <eblake@redhat.com>
Sat, 28 Dec 2013 01:12:05 +0000 (18:12 -0700)
committerEric Blake <eblake@redhat.com>
Thu, 9 Jan 2014 21:35:08 +0000 (14:35 -0700)
While all errors related to invalid nwfilters appeared to be
consistent, we might as well continue the trend of using a
common macro.  As in commit 6e130ddc, the difference between
VIR_IS_NWFILTER and VIR_IS_CONNECTED_NWFILTER is moot, since
reference counting means any valid nwfilter is also tied to
a valid connection.  For now, we don't need virCheckNWFilterGoto().

* src/datatypes.h (virCheckNWFilterReturn): New macro.
(VIR_IS_NWFILTER, VIR_IS_CONNECTED_NWFILTER): Drop unused macros.
* src/libvirt.c: Use macro throughout.
(virLibNWFilterError): Drop unused macro.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/datatypes.h
src/libvirt.c

index 74b4a97ead9840ee84c9ac21f987215241934df1..92e0810c1d15927d85acde22476599acb559bce1 100644 (file)
@@ -218,10 +218,19 @@ extern virClassPtr virStoragePoolClass;
         }                                                               \
     } while (0)
 
-# define VIR_IS_NWFILTER(obj) \
-    (virObjectIsClass((obj), virNWFilterClass))
-# define VIR_IS_CONNECTED_NWFILTER(obj) \
-    (VIR_IS_NWFILTER(obj) && virObjectIsClass((obj)->conn, virConnectClass))
+# define virCheckNWFilterReturn(obj, retval)                            \
+    do {                                                                \
+        virNWFilterPtr _nw = (obj);                                     \
+        if (!virObjectIsClass(_nw, virNWFilterClass) ||                 \
+            !virObjectIsClass(_nw->conn, virConnectClass)) {            \
+            virReportErrorHelper(VIR_FROM_NWFILTER,                     \
+                                 VIR_ERR_INVALID_NWFILTER,              \
+                                 __FILE__, __FUNCTION__, __LINE__,      \
+                                 __FUNCTION__);                         \
+            virDispatchError(NULL);                                     \
+            return retval;                                              \
+        }                                                               \
+    } while (0)
 
 # define VIR_IS_SNAPSHOT(obj) \
     (virObjectIsClass((obj), virDomainSnapshotClass))
index 153c1528e0f02f89749cc1dd5f7d3f09e905c4af..8fd0d8ac4efb7825055f8027bc4cc57192f885cb 100644 (file)
@@ -528,9 +528,6 @@ DllMain(HINSTANCE instance ATTRIBUTE_UNUSED,
 #define virLibDomainError(code, ...)                              \
     virReportErrorHelper(VIR_FROM_DOM, code, __FILE__,            \
                          __FUNCTION__, __LINE__, __VA_ARGS__)
-#define virLibNWFilterError(code, ...)                            \
-    virReportErrorHelper(VIR_FROM_NWFILTER, code, __FILE__,       \
-                         __FUNCTION__, __LINE__, __VA_ARGS__)
 #define virLibDomainSnapshotError(code, ...)                       \
     virReportErrorHelper(VIR_FROM_DOMAIN_SNAPSHOT, code, __FILE__, \
                          __FUNCTION__, __LINE__, __VA_ARGS__)
@@ -16750,11 +16747,7 @@ virNWFilterFree(virNWFilterPtr nwfilter)
 
     virResetLastError();
 
-    if (!VIR_IS_CONNECTED_NWFILTER(nwfilter)) {
-        virLibNWFilterError(VIR_ERR_INVALID_NWFILTER, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckNWFilterReturn(nwfilter, -1);
 
     virObjectUnref(nwfilter);
     return 0;
@@ -16777,11 +16770,8 @@ virNWFilterGetName(virNWFilterPtr nwfilter)
 
     virResetLastError();
 
-    if (!VIR_IS_NWFILTER(nwfilter)) {
-        virLibNWFilterError(VIR_ERR_INVALID_NWFILTER, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
+    virCheckNWFilterReturn(nwfilter, NULL);
+
     return nwfilter->name;
 }
 
@@ -16802,11 +16792,7 @@ virNWFilterGetUUID(virNWFilterPtr nwfilter, unsigned char *uuid)
 
     virResetLastError();
 
-    if (!VIR_IS_NWFILTER(nwfilter)) {
-        virLibNWFilterError(VIR_ERR_INVALID_NWFILTER, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckNWFilterReturn(nwfilter, -1);
     virCheckNonNullArgGoto(uuid, error);
 
     memcpy(uuid, &nwfilter->uuid[0], VIR_UUID_BUFLEN);
@@ -16836,11 +16822,7 @@ virNWFilterGetUUIDString(virNWFilterPtr nwfilter, char *buf)
 
     virResetLastError();
 
-    if (!VIR_IS_NWFILTER(nwfilter)) {
-        virLibNWFilterError(VIR_ERR_INVALID_NWFILTER, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckNWFilterReturn(nwfilter, -1);
     virCheckNonNullArgGoto(buf, error);
 
     virUUIDFormat(nwfilter->uuid, buf);
@@ -16907,13 +16889,9 @@ virNWFilterUndefine(virNWFilterPtr nwfilter)
 
     virResetLastError();
 
-    if (!VIR_IS_CONNECTED_NWFILTER(nwfilter)) {
-        virLibNWFilterError(VIR_ERR_INVALID_NWFILTER, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckNWFilterReturn(nwfilter, -1);
     conn = nwfilter->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);
 
     if (conn->nwfilterDriver && conn->nwfilterDriver->nwfilterUndefine) {
@@ -16951,12 +16929,7 @@ virNWFilterGetXMLDesc(virNWFilterPtr nwfilter, unsigned int flags)
 
     virResetLastError();
 
-    if (!VIR_IS_CONNECTED_NWFILTER(nwfilter)) {
-        virLibNWFilterError(VIR_ERR_INVALID_NWFILTER, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
-
+    virCheckNWFilterReturn(nwfilter, NULL);
     conn = nwfilter->conn;
 
     if (conn->nwfilterDriver && conn->nwfilterDriver->nwfilterGetXMLDesc) {
@@ -17000,11 +16973,8 @@ virNWFilterRef(virNWFilterPtr nwfilter)
 
     virResetLastError();
 
-    if ((!VIR_IS_CONNECTED_NWFILTER(nwfilter))) {
-        virLibConnError(VIR_ERR_INVALID_NWFILTER, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckNWFilterReturn(nwfilter, -1);
+
     virObjectRef(nwfilter);
     return 0;
 }