提交 8add79a9 编写于 作者: E Eric Blake

maint: improve VIR_ERR_INVALID_STORAGE_POOL usage

virStoragePoolBuild reported an invalid pool as if it were an
invalid network.  Likewise, we weren't consistent on whether to
use VIR_FROM_NONE or VIR_FROM_STORAGE.  Similar to previous
patches, use a common macro to make it nicer.  Furthermore, just
as in commit 6e130ddc, the difference between VIR_IS_STORAGE_POOL
and VIR_IS_CONNECTED_STORAGE_POOL is moot (due to reference
counting, any valid pool must be tied to a valid connection).
For now, we don't need virCheckStoragePoolGoto().

* src/datatypes.h (virCheckStoragePoolReturn): New macro.
(VIR_IS_STORAGE_POOL, VIR_IS_CONNECTED_STORAGE_POOL): Drop
unused macros.
* src/libvirt.c: Use macro throughout.
(virLibStoragePoolError): Drop unused macro.
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 e0933512
...@@ -124,10 +124,19 @@ extern virClassPtr virStoragePoolClass; ...@@ -124,10 +124,19 @@ extern virClassPtr virStoragePoolClass;
} \ } \
} while (0) } while (0)
# define VIR_IS_STORAGE_POOL(obj) \ # define virCheckStoragePoolReturn(obj, retval) \
(virObjectIsClass((obj), virStoragePoolClass)) do { \
# define VIR_IS_CONNECTED_STORAGE_POOL(obj) \ virStoragePoolPtr _pool = (obj); \
(VIR_IS_STORAGE_POOL(obj) && virObjectIsClass((obj)->conn, virConnectClass)) if (!virObjectIsClass(_pool, virStoragePoolClass) || \
!virObjectIsClass(_pool->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_STORAGE, \
VIR_ERR_INVALID_STORAGE_POOL, \
__FILE__, __FUNCTION__, __LINE__, \
__FUNCTION__); \
virDispatchError(NULL); \
return retval; \
} \
} while (0)
# define VIR_IS_STORAGE_VOL(obj) \ # define VIR_IS_STORAGE_VOL(obj) \
(virObjectIsClass((obj), virStorageVolClass)) (virObjectIsClass((obj), virStorageVolClass))
......
...@@ -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 virLibStoragePoolError(code, ...) \
virReportErrorHelper(VIR_FROM_STORAGE, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__)
#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__)
...@@ -12183,11 +12180,8 @@ virStoragePoolGetConnect(virStoragePoolPtr pool) ...@@ -12183,11 +12180,8 @@ virStoragePoolGetConnect(virStoragePoolPtr pool)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, NULL);
virLibStoragePoolError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return NULL;
}
return pool->conn; return pool->conn;
} }
...@@ -12732,12 +12726,9 @@ virStoragePoolBuild(virStoragePoolPtr pool, ...@@ -12732,12 +12726,9 @@ virStoragePoolBuild(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibStoragePoolError(VIR_ERR_INVALID_NETWORK, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
conn = pool->conn; conn = pool->conn;
virCheckReadOnlyGoto(conn->flags, error); virCheckReadOnlyGoto(conn->flags, error);
if (conn->storageDriver && conn->storageDriver->storagePoolBuild) { if (conn->storageDriver && conn->storageDriver->storagePoolBuild) {
...@@ -12772,12 +12763,9 @@ virStoragePoolUndefine(virStoragePoolPtr pool) ...@@ -12772,12 +12763,9 @@ virStoragePoolUndefine(virStoragePoolPtr pool)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibStoragePoolError(VIR_ERR_INVALID_NETWORK, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
conn = pool->conn; conn = pool->conn;
virCheckReadOnlyGoto(conn->flags, error); virCheckReadOnlyGoto(conn->flags, error);
if (conn->storageDriver && conn->storageDriver->storagePoolUndefine) { if (conn->storageDriver && conn->storageDriver->storagePoolUndefine) {
...@@ -12814,12 +12802,9 @@ virStoragePoolCreate(virStoragePoolPtr pool, ...@@ -12814,12 +12802,9 @@ virStoragePoolCreate(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibStoragePoolError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
conn = pool->conn; conn = pool->conn;
virCheckReadOnlyGoto(conn->flags, error); virCheckReadOnlyGoto(conn->flags, error);
if (conn->storageDriver && conn->storageDriver->storagePoolCreate) { if (conn->storageDriver && conn->storageDriver->storagePoolCreate) {
...@@ -12858,13 +12843,9 @@ virStoragePoolDestroy(virStoragePoolPtr pool) ...@@ -12858,13 +12843,9 @@ virStoragePoolDestroy(virStoragePoolPtr pool)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibStoragePoolError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
conn = pool->conn; conn = pool->conn;
virCheckReadOnlyGoto(conn->flags, error); virCheckReadOnlyGoto(conn->flags, error);
if (conn->storageDriver && conn->storageDriver->storagePoolDestroy) { if (conn->storageDriver && conn->storageDriver->storagePoolDestroy) {
...@@ -12903,13 +12884,9 @@ virStoragePoolDelete(virStoragePoolPtr pool, ...@@ -12903,13 +12884,9 @@ virStoragePoolDelete(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibStoragePoolError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
conn = pool->conn; conn = pool->conn;
virCheckReadOnlyGoto(conn->flags, error); virCheckReadOnlyGoto(conn->flags, error);
if (conn->storageDriver && conn->storageDriver->storagePoolDelete) { if (conn->storageDriver && conn->storageDriver->storagePoolDelete) {
...@@ -12944,11 +12921,8 @@ virStoragePoolFree(virStoragePoolPtr pool) ...@@ -12944,11 +12921,8 @@ virStoragePoolFree(virStoragePoolPtr pool)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibStoragePoolError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virObjectUnref(pool); virObjectUnref(pool);
return 0; return 0;
...@@ -12979,11 +12953,8 @@ virStoragePoolRef(virStoragePoolPtr pool) ...@@ -12979,11 +12953,8 @@ virStoragePoolRef(virStoragePoolPtr pool)
virResetLastError(); virResetLastError();
if ((!VIR_IS_CONNECTED_STORAGE_POOL(pool))) { virCheckStoragePoolReturn(pool, -1);
virLibConnError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virObjectRef(pool); virObjectRef(pool);
return 0; return 0;
} }
...@@ -13009,13 +12980,9 @@ virStoragePoolRefresh(virStoragePoolPtr pool, ...@@ -13009,13 +12980,9 @@ virStoragePoolRefresh(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibStoragePoolError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
conn = pool->conn; conn = pool->conn;
virCheckReadOnlyGoto(conn->flags, error); virCheckReadOnlyGoto(conn->flags, error);
if (conn->storageDriver && conn->storageDriver->storagePoolRefresh) { if (conn->storageDriver && conn->storageDriver->storagePoolRefresh) {
...@@ -13049,11 +13016,8 @@ virStoragePoolGetName(virStoragePoolPtr pool) ...@@ -13049,11 +13016,8 @@ virStoragePoolGetName(virStoragePoolPtr pool)
virResetLastError(); virResetLastError();
if (!VIR_IS_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, NULL);
virLibStoragePoolError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return NULL;
}
return pool->name; return pool->name;
} }
...@@ -13075,11 +13039,7 @@ virStoragePoolGetUUID(virStoragePoolPtr pool, ...@@ -13075,11 +13039,7 @@ virStoragePoolGetUUID(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibStoragePoolError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virCheckNonNullArgGoto(uuid, error); virCheckNonNullArgGoto(uuid, error);
memcpy(uuid, &pool->uuid[0], VIR_UUID_BUFLEN); memcpy(uuid, &pool->uuid[0], VIR_UUID_BUFLEN);
...@@ -13109,11 +13069,7 @@ virStoragePoolGetUUIDString(virStoragePoolPtr pool, ...@@ -13109,11 +13069,7 @@ virStoragePoolGetUUIDString(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibStoragePoolError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virCheckNonNullArgGoto(buf, error); virCheckNonNullArgGoto(buf, error);
virUUIDFormat(pool->uuid, buf); virUUIDFormat(pool->uuid, buf);
...@@ -13144,11 +13100,7 @@ virStoragePoolGetInfo(virStoragePoolPtr pool, ...@@ -13144,11 +13100,7 @@ virStoragePoolGetInfo(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibStoragePoolError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virCheckNonNullArgGoto(info, error); virCheckNonNullArgGoto(info, error);
memset(info, 0, sizeof(virStoragePoolInfo)); memset(info, 0, sizeof(virStoragePoolInfo));
...@@ -13191,12 +13143,7 @@ virStoragePoolGetXMLDesc(virStoragePoolPtr pool, ...@@ -13191,12 +13143,7 @@ virStoragePoolGetXMLDesc(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, NULL);
virLibStoragePoolError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return NULL;
}
conn = pool->conn; conn = pool->conn;
if (conn->storageDriver && conn->storageDriver->storagePoolGetXMLDesc) { if (conn->storageDriver && conn->storageDriver->storagePoolGetXMLDesc) {
...@@ -13234,11 +13181,7 @@ virStoragePoolGetAutostart(virStoragePoolPtr pool, ...@@ -13234,11 +13181,7 @@ virStoragePoolGetAutostart(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibStoragePoolError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virCheckNonNullArgGoto(autostart, error); virCheckNonNullArgGoto(autostart, error);
conn = pool->conn; conn = pool->conn;
...@@ -13277,16 +13220,11 @@ virStoragePoolSetAutostart(virStoragePoolPtr pool, ...@@ -13277,16 +13220,11 @@ virStoragePoolSetAutostart(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibStoragePoolError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virCheckReadOnlyGoto(pool->conn->flags, error);
conn = pool->conn; conn = pool->conn;
virCheckReadOnlyGoto(conn->flags, error);
if (conn->storageDriver && conn->storageDriver->storagePoolSetAutostart) { if (conn->storageDriver && conn->storageDriver->storagePoolSetAutostart) {
int ret; int ret;
ret = conn->storageDriver->storagePoolSetAutostart(pool, autostart); ret = conn->storageDriver->storagePoolSetAutostart(pool, autostart);
...@@ -13330,11 +13268,7 @@ virStoragePoolListAllVolumes(virStoragePoolPtr pool, ...@@ -13330,11 +13268,7 @@ virStoragePoolListAllVolumes(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibConnError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
if (pool->conn->storageDriver && if (pool->conn->storageDriver &&
pool->conn->storageDriver->storagePoolListAllVolumes) { pool->conn->storageDriver->storagePoolListAllVolumes) {
...@@ -13368,11 +13302,7 @@ virStoragePoolNumOfVolumes(virStoragePoolPtr pool) ...@@ -13368,11 +13302,7 @@ virStoragePoolNumOfVolumes(virStoragePoolPtr pool)
virResetLastError(); virResetLastError();
if (!VIR_IS_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibConnError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
if (pool->conn->storageDriver && pool->conn->storageDriver->storagePoolNumOfVolumes) { if (pool->conn->storageDriver && pool->conn->storageDriver->storagePoolNumOfVolumes) {
int ret; int ret;
...@@ -13412,12 +13342,7 @@ virStoragePoolListVolumes(virStoragePoolPtr pool, ...@@ -13412,12 +13342,7 @@ virStoragePoolListVolumes(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibConnError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
virCheckNonNullArgGoto(names, error); virCheckNonNullArgGoto(names, error);
virCheckNonNegativeArgGoto(maxnames, error); virCheckNonNegativeArgGoto(maxnames, error);
...@@ -13485,12 +13410,7 @@ virStorageVolLookupByName(virStoragePoolPtr pool, ...@@ -13485,12 +13410,7 @@ virStorageVolLookupByName(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, NULL);
virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
virDispatchError(NULL);
return NULL;
}
virCheckNonNullArgGoto(name, error); virCheckNonNullArgGoto(name, error);
if (pool->conn->storageDriver && pool->conn->storageDriver->storageVolLookupByName) { if (pool->conn->storageDriver && pool->conn->storageDriver->storageVolLookupByName) {
...@@ -13660,14 +13580,8 @@ virStorageVolCreateXML(virStoragePoolPtr pool, ...@@ -13660,14 +13580,8 @@ virStorageVolCreateXML(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, NULL);
virLibConnError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return NULL;
}
virCheckNonNullArgGoto(xmlDesc, error); virCheckNonNullArgGoto(xmlDesc, error);
virCheckReadOnlyGoto(pool->conn->flags, error); virCheckReadOnlyGoto(pool->conn->flags, error);
if (pool->conn->storageDriver && pool->conn->storageDriver->storageVolCreateXML) { if (pool->conn->storageDriver && pool->conn->storageDriver->storageVolCreateXML) {
...@@ -13716,11 +13630,7 @@ virStorageVolCreateXMLFrom(virStoragePoolPtr pool, ...@@ -13716,11 +13630,7 @@ virStorageVolCreateXMLFrom(virStoragePoolPtr pool,
virResetLastError(); virResetLastError();
if (!VIR_IS_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, NULL);
virLibConnError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
virDispatchError(NULL);
return NULL;
}
if (!VIR_IS_STORAGE_VOL(clonevol)) { if (!VIR_IS_STORAGE_VOL(clonevol)) {
virLibConnError(VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
...@@ -16748,11 +16658,8 @@ virStoragePoolIsActive(virStoragePoolPtr pool) ...@@ -16748,11 +16658,8 @@ virStoragePoolIsActive(virStoragePoolPtr pool)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
if (pool->conn->storageDriver->storagePoolIsActive) { if (pool->conn->storageDriver->storagePoolIsActive) {
int ret; int ret;
ret = pool->conn->storageDriver->storagePoolIsActive(pool); ret = pool->conn->storageDriver->storagePoolIsActive(pool);
...@@ -16784,11 +16691,8 @@ virStoragePoolIsPersistent(virStoragePoolPtr pool) ...@@ -16784,11 +16691,8 @@ virStoragePoolIsPersistent(virStoragePoolPtr pool)
virResetLastError(); virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { virCheckStoragePoolReturn(pool, -1);
virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
if (pool->conn->storageDriver->storagePoolIsPersistent) { if (pool->conn->storageDriver->storagePoolIsPersistent) {
int ret; int ret;
ret = pool->conn->storageDriver->storagePoolIsPersistent(pool); ret = pool->conn->storageDriver->storagePoolIsPersistent(pool);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册