While all errors related to invalid nwfilters appeared to be
consistent, we might as well continue the trend of using a
common macro. 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(a)redhat.com>
---
src/datatypes.h | 17 +++++++++++++----
src/libvirt.c | 50 ++++++++++----------------------------------------
2 files changed, 23 insertions(+), 44 deletions(-)
diff --git a/src/datatypes.h b/src/datatypes.h
index 6f092a7..7932a6c 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -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))
diff --git a/src/libvirt.c b/src/libvirt.c
index b460c00..9fb69ed 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -518,9 +518,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__)
@@ -16721,11 +16718,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;
@@ -16748,11 +16741,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;
}
@@ -16773,11 +16763,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);
@@ -16807,11 +16793,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);
@@ -16878,13 +16860,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)
{
@@ -16922,12 +16900,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) {
@@ -16971,11 +16944,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;
}
--
1.8.4.2