mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
storage: Create helpers to perform FindByUUID and FindByName
Create a couple of helpers that will perform the same call sequence. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
babf148a94
commit
4a5d191e2a
@ -387,6 +387,56 @@ storageStateCleanup(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static virStoragePoolObjPtr
|
||||||
|
storagePoolObjFindByUUID(const unsigned char *uuid,
|
||||||
|
const char *name)
|
||||||
|
{
|
||||||
|
virStoragePoolObjPtr pool;
|
||||||
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
|
|
||||||
|
if (!(pool = virStoragePoolObjFindByUUID(&driver->pools, uuid))) {
|
||||||
|
virUUIDFormat(uuid, uuidstr);
|
||||||
|
if (name)
|
||||||
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
||||||
|
_("no storage pool with matching uuid '%s' (%s)"),
|
||||||
|
uuidstr, name);
|
||||||
|
else
|
||||||
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
||||||
|
_("no storage pool with matching uuid '%s'"),
|
||||||
|
uuidstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static virStoragePoolObjPtr
|
||||||
|
virStoragePoolObjFromStoragePool(virStoragePoolPtr pool)
|
||||||
|
{
|
||||||
|
virStoragePoolObjPtr ret;
|
||||||
|
|
||||||
|
storageDriverLock();
|
||||||
|
ret = storagePoolObjFindByUUID(pool->uuid, pool->name);
|
||||||
|
storageDriverUnlock();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static virStoragePoolObjPtr
|
||||||
|
storagePoolObjFindByName(const char *name)
|
||||||
|
{
|
||||||
|
virStoragePoolObjPtr pool;
|
||||||
|
|
||||||
|
storageDriverLock();
|
||||||
|
if (!(pool = virStoragePoolObjFindByName(&driver->pools, name)))
|
||||||
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
||||||
|
_("no storage pool with matching name '%s'"), name);
|
||||||
|
storageDriverUnlock();
|
||||||
|
|
||||||
|
return pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static virStoragePoolPtr
|
static virStoragePoolPtr
|
||||||
storagePoolLookupByUUID(virConnectPtr conn,
|
storagePoolLookupByUUID(virConnectPtr conn,
|
||||||
@ -396,16 +446,10 @@ storagePoolLookupByUUID(virConnectPtr conn,
|
|||||||
virStoragePoolPtr ret = NULL;
|
virStoragePoolPtr ret = NULL;
|
||||||
|
|
||||||
storageDriverLock();
|
storageDriverLock();
|
||||||
pool = virStoragePoolObjFindByUUID(&driver->pools, uuid);
|
pool = storagePoolObjFindByUUID(uuid, NULL);
|
||||||
storageDriverUnlock();
|
storageDriverUnlock();
|
||||||
|
if (!pool)
|
||||||
if (!pool) {
|
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
||||||
virUUIDFormat(uuid, uuidstr);
|
|
||||||
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
||||||
_("no storage pool with matching uuid '%s'"), uuidstr);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (virStoragePoolLookupByUUIDEnsureACL(conn, pool->def) < 0)
|
if (virStoragePoolLookupByUUIDEnsureACL(conn, pool->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -425,15 +469,8 @@ storagePoolLookupByName(virConnectPtr conn,
|
|||||||
virStoragePoolObjPtr pool;
|
virStoragePoolObjPtr pool;
|
||||||
virStoragePoolPtr ret = NULL;
|
virStoragePoolPtr ret = NULL;
|
||||||
|
|
||||||
storageDriverLock();
|
if (!(pool = storagePoolObjFindByName(name)))
|
||||||
pool = virStoragePoolObjFindByName(&driver->pools, name);
|
|
||||||
storageDriverUnlock();
|
|
||||||
|
|
||||||
if (!pool) {
|
|
||||||
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
||||||
_("no storage pool with matching name '%s'"), name);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (virStoragePoolLookupByNameEnsureACL(conn, pool->def) < 0)
|
if (virStoragePoolLookupByNameEnsureACL(conn, pool->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -452,16 +489,8 @@ storagePoolLookupByVolume(virStorageVolPtr vol)
|
|||||||
virStoragePoolObjPtr pool;
|
virStoragePoolObjPtr pool;
|
||||||
virStoragePoolPtr ret = NULL;
|
virStoragePoolPtr ret = NULL;
|
||||||
|
|
||||||
storageDriverLock();
|
if (!(pool = storagePoolObjFindByName(vol->pool)))
|
||||||
pool = virStoragePoolObjFindByName(&driver->pools, vol->pool);
|
|
||||||
storageDriverUnlock();
|
|
||||||
|
|
||||||
if (!pool) {
|
|
||||||
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
||||||
_("no storage pool with matching name '%s'"),
|
|
||||||
vol->pool);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (virStoragePoolLookupByVolumeEnsureACL(vol->conn, pool->def) < 0)
|
if (virStoragePoolLookupByVolumeEnsureACL(vol->conn, pool->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -584,25 +613,6 @@ storageConnectFindStoragePoolSources(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static virStoragePoolObjPtr
|
|
||||||
virStoragePoolObjFromStoragePool(virStoragePoolPtr pool)
|
|
||||||
{
|
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
||||||
virStoragePoolObjPtr ret;
|
|
||||||
|
|
||||||
storageDriverLock();
|
|
||||||
if (!(ret = virStoragePoolObjFindByUUID(&driver->pools, pool->uuid))) {
|
|
||||||
virUUIDFormat(pool->uuid, uuidstr);
|
|
||||||
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
||||||
_("no storage pool with matching uuid '%s' (%s)"),
|
|
||||||
uuidstr, pool->name);
|
|
||||||
}
|
|
||||||
storageDriverUnlock();
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int storagePoolIsActive(virStoragePoolPtr pool)
|
static int storagePoolIsActive(virStoragePoolPtr pool)
|
||||||
{
|
{
|
||||||
virStoragePoolObjPtr obj;
|
virStoragePoolObjPtr obj;
|
||||||
@ -809,14 +819,8 @@ storagePoolUndefine(virStoragePoolPtr obj)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
storageDriverLock();
|
storageDriverLock();
|
||||||
if (!(pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid))) {
|
if (!(pool = storagePoolObjFindByUUID(obj->uuid, obj->name)))
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
||||||
virUUIDFormat(obj->uuid, uuidstr);
|
|
||||||
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
||||||
_("no storage pool with matching uuid '%s' (%s)"),
|
|
||||||
uuidstr, obj->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (virStoragePoolUndefineEnsureACL(obj->conn, pool->def) < 0)
|
if (virStoragePoolUndefineEnsureACL(obj->conn, pool->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -995,14 +999,8 @@ storagePoolDestroy(virStoragePoolPtr obj)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
storageDriverLock();
|
storageDriverLock();
|
||||||
if (!(pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid))) {
|
if (!(pool = storagePoolObjFindByUUID(obj->uuid, obj->name)))
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
||||||
virUUIDFormat(obj->uuid, uuidstr);
|
|
||||||
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
||||||
_("no storage pool with matching uuid '%s' (%s)"),
|
|
||||||
uuidstr, obj->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (virStoragePoolDestroyEnsureACL(obj->conn, pool->def) < 0)
|
if (virStoragePoolDestroyEnsureACL(obj->conn, pool->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1129,14 +1127,8 @@ storagePoolRefresh(virStoragePoolPtr obj,
|
|||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
storageDriverLock();
|
storageDriverLock();
|
||||||
if (!(pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid))) {
|
if (!(pool = storagePoolObjFindByUUID(obj->uuid, obj->name)))
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
||||||
virUUIDFormat(obj->uuid, uuidstr);
|
|
||||||
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
||||||
_("no storage pool with matching uuid '%s' (%s)"),
|
|
||||||
uuidstr, obj->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (virStoragePoolRefreshEnsureACL(obj->conn, pool->def) < 0)
|
if (virStoragePoolRefreshEnsureACL(obj->conn, pool->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1279,16 +1271,8 @@ storagePoolSetAutostart(virStoragePoolPtr obj,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
storageDriverLock();
|
storageDriverLock();
|
||||||
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
if (!(pool = storagePoolObjFindByUUID(obj->uuid, obj->name)))
|
||||||
|
|
||||||
if (!pool) {
|
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
||||||
virUUIDFormat(obj->uuid, uuidstr);
|
|
||||||
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
||||||
_("no storage pool with matching uuid '%s' (%s)"),
|
|
||||||
uuidstr, obj->name);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (virStoragePoolSetAutostartEnsureACL(obj->conn, pool->def) < 0)
|
if (virStoragePoolSetAutostartEnsureACL(obj->conn, pool->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1707,18 +1691,8 @@ virStorageVolDefFromVol(virStorageVolPtr obj,
|
|||||||
{
|
{
|
||||||
virStorageVolDefPtr vol = NULL;
|
virStorageVolDefPtr vol = NULL;
|
||||||
|
|
||||||
*pool = NULL;
|
if (!(*pool = storagePoolObjFindByName(obj->pool)))
|
||||||
|
|
||||||
storageDriverLock();
|
|
||||||
*pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
|
|
||||||
storageDriverUnlock();
|
|
||||||
|
|
||||||
if (!*pool) {
|
|
||||||
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
||||||
_("no storage pool with matching name '%s'"),
|
|
||||||
obj->pool);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (!virStoragePoolObjIsActive(*pool)) {
|
if (!virStoragePoolObjIsActive(*pool)) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
|
Loading…
Reference in New Issue
Block a user