提交 459532b4 编写于 作者: E Eric Blake

maint: improve VIR_ERR_INVALID_INTERFACE usage

When checking for a valid interface, we weren't consistent on
whether we reported as VIR_FROM_NONE or VIR_FROM_INTERFACE.
Similar to previous patches, use a common macro to make it nicer.
Furthermore, just as in commit 6e130ddc, the difference between
VIR_IS_INTERFACE and VIR_IS_CONNECTED_INTERFACE is moot (due to
reference counting, any valid interface must be tied to a valid
connection).  For now, we don't need virCheckInterfaceGoto().

* src/datatypes.h (virCheckInterfaceReturn): New macro.
(VIR_IS_INTERFACE, VIR_IS_CONNECTED_INTERFACE): Drop unused
macros.
* src/libvirt.c: Use macro throughout.
(virLibInterfaceError): Drop unused macro.
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 6d8233fe
...@@ -110,10 +110,19 @@ extern virClassPtr virStoragePoolClass; ...@@ -110,10 +110,19 @@ extern virClassPtr virStoragePoolClass;
} \ } \
} while (0) } while (0)
# define VIR_IS_INTERFACE(obj) \ # define virCheckInterfaceReturn(obj, retval) \
(virObjectIsClass((obj), virInterfaceClass)) do { \
# define VIR_IS_CONNECTED_INTERFACE(obj) \ virInterfacePtr _iface = (obj); \
(VIR_IS_INTERFACE(obj) && virObjectIsClass((obj)->conn, virConnectClass)) if (!virObjectIsClass(_iface, virInterfaceClass) || \
!virObjectIsClass(_iface->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_INTERFACE, \
VIR_ERR_INVALID_INTERFACE, \
__FILE__, __FUNCTION__, __LINE__, \
__FUNCTION__); \
virDispatchError(NULL); \
return retval; \
} \
} while (0)
# define VIR_IS_STORAGE_POOL(obj) \ # define VIR_IS_STORAGE_POOL(obj) \
(virObjectIsClass((obj), virStoragePoolClass)) (virObjectIsClass((obj), virStoragePoolClass))
......
...@@ -534,9 +534,6 @@ DllMain(HINSTANCE instance ATTRIBUTE_UNUSED, ...@@ -534,9 +534,6 @@ DllMain(HINSTANCE instance ATTRIBUTE_UNUSED,
#define virLibStorageVolError(code, ...) \ #define virLibStorageVolError(code, ...) \
virReportErrorHelper(VIR_FROM_STORAGE, code, __FILE__, \ virReportErrorHelper(VIR_FROM_STORAGE, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__) __FUNCTION__, __LINE__, __VA_ARGS__)
#define virLibInterfaceError(code, ...) \
virReportErrorHelper(VIR_FROM_INTERFACE, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__)
#define virLibNodeDeviceError(code, ...) \ #define virLibNodeDeviceError(code, ...) \
virReportErrorHelper(VIR_FROM_NODEDEV, code, __FILE__, \ virReportErrorHelper(VIR_FROM_NODEDEV, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__) __FUNCTION__, __LINE__, __VA_ARGS__)
...@@ -11419,11 +11416,8 @@ virInterfaceGetConnect(virInterfacePtr iface) ...@@ -11419,11 +11416,8 @@ virInterfaceGetConnect(virInterfacePtr iface)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_INTERFACE(iface)) { virCheckInterfaceReturn(iface, NULL);
virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
virDispatchError(NULL);
return NULL;
}
return iface->conn; return iface->conn;
} }
...@@ -11730,11 +11724,8 @@ virInterfaceGetName(virInterfacePtr iface) ...@@ -11730,11 +11724,8 @@ virInterfaceGetName(virInterfacePtr iface)
virResetLastError(); virResetLastError();
if (!VIR_IS_INTERFACE(iface)) { virCheckInterfaceReturn(iface, NULL);
virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
virDispatchError(NULL);
return NULL;
}
return iface->name; return iface->name;
} }
...@@ -11757,11 +11748,8 @@ virInterfaceGetMACString(virInterfacePtr iface) ...@@ -11757,11 +11748,8 @@ virInterfaceGetMACString(virInterfacePtr iface)
virResetLastError(); virResetLastError();
if (!VIR_IS_INTERFACE(iface)) { virCheckInterfaceReturn(iface, NULL);
virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
virDispatchError(NULL);
return NULL;
}
return iface->mac; return iface->mac;
} }
...@@ -11792,12 +11780,7 @@ virInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags) ...@@ -11792,12 +11780,7 @@ virInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_INTERFACE(iface)) { virCheckInterfaceReturn(iface, NULL);
virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
virDispatchError(NULL);
return NULL;
}
conn = iface->conn; conn = iface->conn;
if (conn->interfaceDriver && conn->interfaceDriver->interfaceGetXMLDesc) { if (conn->interfaceDriver && conn->interfaceDriver->interfaceGetXMLDesc) {
...@@ -11890,12 +11873,9 @@ virInterfaceUndefine(virInterfacePtr iface) ...@@ -11890,12 +11873,9 @@ virInterfaceUndefine(virInterfacePtr iface)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_INTERFACE(iface)) { virCheckInterfaceReturn(iface, -1);
virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
conn = iface->conn; conn = iface->conn;
virCheckReadOnlyGoto(conn->flags, error); virCheckReadOnlyGoto(conn->flags, error);
if (conn->interfaceDriver && conn->interfaceDriver->interfaceUndefine) { if (conn->interfaceDriver && conn->interfaceDriver->interfaceUndefine) {
...@@ -11936,12 +11916,9 @@ virInterfaceCreate(virInterfacePtr iface, unsigned int flags) ...@@ -11936,12 +11916,9 @@ virInterfaceCreate(virInterfacePtr iface, unsigned int flags)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_INTERFACE(iface)) { virCheckInterfaceReturn(iface, -1);
virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
conn = iface->conn; conn = iface->conn;
virCheckReadOnlyGoto(conn->flags, error); virCheckReadOnlyGoto(conn->flags, error);
if (conn->interfaceDriver && conn->interfaceDriver->interfaceCreate) { if (conn->interfaceDriver && conn->interfaceDriver->interfaceCreate) {
...@@ -11986,13 +11963,9 @@ virInterfaceDestroy(virInterfacePtr iface, unsigned int flags) ...@@ -11986,13 +11963,9 @@ virInterfaceDestroy(virInterfacePtr iface, unsigned int flags)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_INTERFACE(iface)) { virCheckInterfaceReturn(iface, -1);
virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
conn = iface->conn; conn = iface->conn;
virCheckReadOnlyGoto(conn->flags, error); virCheckReadOnlyGoto(conn->flags, error);
if (conn->interfaceDriver && conn->interfaceDriver->interfaceDestroy) { if (conn->interfaceDriver && conn->interfaceDriver->interfaceDestroy) {
...@@ -12035,11 +12008,8 @@ virInterfaceRef(virInterfacePtr iface) ...@@ -12035,11 +12008,8 @@ virInterfaceRef(virInterfacePtr iface)
virResetLastError(); virResetLastError();
if ((!VIR_IS_CONNECTED_INTERFACE(iface))) { virCheckInterfaceReturn(iface, -1);
virLibConnError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virObjectRef(iface); virObjectRef(iface);
return 0; return 0;
} }
...@@ -12061,11 +12031,8 @@ virInterfaceFree(virInterfacePtr iface) ...@@ -12061,11 +12031,8 @@ virInterfaceFree(virInterfacePtr iface)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_INTERFACE(iface)) { virCheckInterfaceReturn(iface, -1);
virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virObjectUnref(iface); virObjectUnref(iface);
return 0; return 0;
} }
...@@ -17354,11 +17321,8 @@ virInterfaceIsActive(virInterfacePtr iface) ...@@ -17354,11 +17321,8 @@ virInterfaceIsActive(virInterfacePtr iface)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_INTERFACE(iface)) { virCheckInterfaceReturn(iface, -1);
virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
if (iface->conn->interfaceDriver->interfaceIsActive) { if (iface->conn->interfaceDriver->interfaceIsActive) {
int ret; int ret;
ret = iface->conn->interfaceDriver->interfaceIsActive(iface); ret = iface->conn->interfaceDriver->interfaceIsActive(iface);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册