提交 7d0a0ab7 编写于 作者: E Eric Blake

maint: improve VIR_ERR_INVALID_NWFILTER usage

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: NEric Blake <eblake@redhat.com>
上级 101f176a
......@@ -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))
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册