提交 9ec935d5 编写于 作者: E Eric Blake

maint: improve VIR_ERR_INVALID_NODE_DEVICE usage

While all errors related to invalid node device appeared to be
consistent, we might as well continue the trend of using a
common macro.  For now, we don't need virCheckNodeDeviceGoto().

* src/datatypes.h (virCheckNodeDeviceReturn): New macro.
(VIR_IS_NODE_DEVICE, VIR_IS_CONNECTED_NODE_DEVICE): Drop
unused macros.
* src/libvirt.c: Use macro throughout.
(virLibNodeDeviceError): Drop unused macro.
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 2a6395aa
...@@ -164,10 +164,19 @@ extern virClassPtr virStoragePoolClass; ...@@ -164,10 +164,19 @@ extern virClassPtr virStoragePoolClass;
} \ } \
} while (0) } while (0)
# define VIR_IS_NODE_DEVICE(obj) \ # define virCheckNodeDeviceReturn(obj, retval) \
(virObjectIsClass((obj), virNodeDeviceClass)) do { \
# define VIR_IS_CONNECTED_NODE_DEVICE(obj) \ virNodeDevicePtr _node = (obj); \
(VIR_IS_NODE_DEVICE(obj) && virObjectIsClass((obj)->conn, virConnectClass)) if (!virObjectIsClass(_node, virNodeDeviceClass) || \
!virObjectIsClass(_node->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_NODEDEV, \
VIR_ERR_INVALID_NODE_DEVICE, \
__FILE__, __FUNCTION__, __LINE__, \
__FUNCTION__); \
virDispatchError(NULL); \
return retval; \
} \
} while (0)
# define VIR_IS_SECRET(obj) \ # define VIR_IS_SECRET(obj) \
(virObjectIsClass((obj), virSecretClass)) (virObjectIsClass((obj), virSecretClass))
......
...@@ -528,9 +528,6 @@ DllMain(HINSTANCE instance ATTRIBUTE_UNUSED, ...@@ -528,9 +528,6 @@ DllMain(HINSTANCE instance ATTRIBUTE_UNUSED,
#define virLibDomainError(code, ...) \ #define virLibDomainError(code, ...) \
virReportErrorHelper(VIR_FROM_DOM, code, __FILE__, \ virReportErrorHelper(VIR_FROM_DOM, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__) __FUNCTION__, __LINE__, __VA_ARGS__)
#define virLibNodeDeviceError(code, ...) \
virReportErrorHelper(VIR_FROM_NODEDEV, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__)
#define virLibSecretError(code, ...) \ #define virLibSecretError(code, ...) \
virReportErrorHelper(VIR_FROM_SECRET, code, __FILE__, \ virReportErrorHelper(VIR_FROM_SECRET, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__) __FUNCTION__, __LINE__, __VA_ARGS__)
...@@ -14385,11 +14382,7 @@ virNodeDeviceGetXMLDesc(virNodeDevicePtr dev, unsigned int flags) ...@@ -14385,11 +14382,7 @@ virNodeDeviceGetXMLDesc(virNodeDevicePtr dev, unsigned int flags)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) { virCheckNodeDeviceReturn(dev, NULL);
virLibNodeDeviceError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
virDispatchError(NULL);
return NULL;
}
if (dev->conn->nodeDeviceDriver && dev->conn->nodeDeviceDriver->nodeDeviceGetXMLDesc) { if (dev->conn->nodeDeviceDriver && dev->conn->nodeDeviceDriver->nodeDeviceGetXMLDesc) {
char *ret; char *ret;
...@@ -14422,11 +14415,7 @@ virNodeDeviceGetName(virNodeDevicePtr dev) ...@@ -14422,11 +14415,7 @@ virNodeDeviceGetName(virNodeDevicePtr dev)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) { virCheckNodeDeviceReturn(dev, NULL);
virLibNodeDeviceError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
virDispatchError(NULL);
return NULL;
}
return dev->name; return dev->name;
} }
...@@ -14448,11 +14437,7 @@ virNodeDeviceGetParent(virNodeDevicePtr dev) ...@@ -14448,11 +14437,7 @@ virNodeDeviceGetParent(virNodeDevicePtr dev)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) { virCheckNodeDeviceReturn(dev, NULL);
virLibNodeDeviceError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
virDispatchError(NULL);
return NULL;
}
if (!dev->parent) { if (!dev->parent) {
if (dev->conn->nodeDeviceDriver && dev->conn->nodeDeviceDriver->nodeDeviceGetParent) { if (dev->conn->nodeDeviceDriver && dev->conn->nodeDeviceDriver->nodeDeviceGetParent) {
...@@ -14482,11 +14467,7 @@ virNodeDeviceNumOfCaps(virNodeDevicePtr dev) ...@@ -14482,11 +14467,7 @@ virNodeDeviceNumOfCaps(virNodeDevicePtr dev)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) { virCheckNodeDeviceReturn(dev, -1);
virLibNodeDeviceError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
if (dev->conn->nodeDeviceDriver && dev->conn->nodeDeviceDriver->nodeDeviceNumOfCaps) { if (dev->conn->nodeDeviceDriver && dev->conn->nodeDeviceDriver->nodeDeviceNumOfCaps) {
int ret; int ret;
...@@ -14524,12 +14505,7 @@ virNodeDeviceListCaps(virNodeDevicePtr dev, ...@@ -14524,12 +14505,7 @@ virNodeDeviceListCaps(virNodeDevicePtr dev,
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) { virCheckNodeDeviceReturn(dev, -1);
virLibNodeDeviceError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virCheckNonNullArgGoto(names, error); virCheckNonNullArgGoto(names, error);
virCheckNonNegativeArgGoto(maxnames, error); virCheckNonNegativeArgGoto(maxnames, error);
...@@ -14565,11 +14541,8 @@ virNodeDeviceFree(virNodeDevicePtr dev) ...@@ -14565,11 +14541,8 @@ virNodeDeviceFree(virNodeDevicePtr dev)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) { virCheckNodeDeviceReturn(dev, -1);
virLibNodeDeviceError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virObjectUnref(dev); virObjectUnref(dev);
return 0; return 0;
} }
...@@ -14599,11 +14572,8 @@ virNodeDeviceRef(virNodeDevicePtr dev) ...@@ -14599,11 +14572,8 @@ virNodeDeviceRef(virNodeDevicePtr dev)
virResetLastError(); virResetLastError();
if ((!VIR_IS_CONNECTED_NODE_DEVICE(dev))) { virCheckNodeDeviceReturn(dev, -1);
virLibConnError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virObjectRef(dev); virObjectRef(dev);
return 0; return 0;
} }
...@@ -14640,12 +14610,7 @@ virNodeDeviceDettach(virNodeDevicePtr dev) ...@@ -14640,12 +14610,7 @@ virNodeDeviceDettach(virNodeDevicePtr dev)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) { virCheckNodeDeviceReturn(dev, -1);
virLibNodeDeviceError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virCheckReadOnlyGoto(dev->conn->flags, error); virCheckReadOnlyGoto(dev->conn->flags, error);
if (dev->conn->driver->nodeDeviceDettach) { if (dev->conn->driver->nodeDeviceDettach) {
...@@ -14702,12 +14667,7 @@ virNodeDeviceDetachFlags(virNodeDevicePtr dev, ...@@ -14702,12 +14667,7 @@ virNodeDeviceDetachFlags(virNodeDevicePtr dev,
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) { virCheckNodeDeviceReturn(dev, -1);
virLibNodeDeviceError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virCheckReadOnlyGoto(dev->conn->flags, error); virCheckReadOnlyGoto(dev->conn->flags, error);
if (dev->conn->driver->nodeDeviceDetachFlags) { if (dev->conn->driver->nodeDeviceDetachFlags) {
...@@ -14748,12 +14708,7 @@ virNodeDeviceReAttach(virNodeDevicePtr dev) ...@@ -14748,12 +14708,7 @@ virNodeDeviceReAttach(virNodeDevicePtr dev)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) { virCheckNodeDeviceReturn(dev, -1);
virLibNodeDeviceError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virCheckReadOnlyGoto(dev->conn->flags, error); virCheckReadOnlyGoto(dev->conn->flags, error);
if (dev->conn->driver->nodeDeviceReAttach) { if (dev->conn->driver->nodeDeviceReAttach) {
...@@ -14796,12 +14751,7 @@ virNodeDeviceReset(virNodeDevicePtr dev) ...@@ -14796,12 +14751,7 @@ virNodeDeviceReset(virNodeDevicePtr dev)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) { virCheckNodeDeviceReturn(dev, -1);
virLibNodeDeviceError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virCheckReadOnlyGoto(dev->conn->flags, error); virCheckReadOnlyGoto(dev->conn->flags, error);
if (dev->conn->driver->nodeDeviceReset) { if (dev->conn->driver->nodeDeviceReset) {
...@@ -14877,12 +14827,7 @@ virNodeDeviceDestroy(virNodeDevicePtr dev) ...@@ -14877,12 +14827,7 @@ virNodeDeviceDestroy(virNodeDevicePtr dev)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) { virCheckNodeDeviceReturn(dev, -1);
virLibNodeDeviceError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virCheckReadOnlyGoto(dev->conn->flags, error); virCheckReadOnlyGoto(dev->conn->flags, error);
if (dev->conn->nodeDeviceDriver && if (dev->conn->nodeDeviceDriver &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册