mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
virstorageobj: Move virStoragePoolObjIsDuplicate up
This function is going to be made static in used in virStoragePoolObjAssignDef(). Therefore move it a few lines up. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
16f5abb2f8
commit
db867c6bfd
@ -1047,6 +1047,68 @@ virStoragePoolObjVolumeListExport(virConnectPtr conn,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* virStoragePoolObjIsDuplicate:
|
||||
* @doms : virStoragePoolObjListPtr to search
|
||||
* @def : virStoragePoolDefPtr definition of pool to lookup
|
||||
* @check_active: If true, ensure that pool is not active
|
||||
*
|
||||
* Returns: -1 on error
|
||||
* 0 if pool is new
|
||||
* 1 if pool is a duplicate
|
||||
*/
|
||||
int
|
||||
virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
|
||||
virStoragePoolDefPtr def,
|
||||
bool check_active)
|
||||
{
|
||||
int ret = -1;
|
||||
virStoragePoolObjPtr obj = NULL;
|
||||
|
||||
/* See if a Pool with matching UUID already exists */
|
||||
obj = virStoragePoolObjFindByUUID(pools, def->uuid);
|
||||
if (obj) {
|
||||
/* UUID matches, but if names don't match, refuse it */
|
||||
if (STRNEQ(obj->def->name, def->name)) {
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
virUUIDFormat(obj->def->uuid, uuidstr);
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("pool '%s' is already defined with uuid %s"),
|
||||
obj->def->name, uuidstr);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (check_active) {
|
||||
/* UUID & name match, but if Pool is already active, refuse it */
|
||||
if (virStoragePoolObjIsActive(obj)) {
|
||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||
_("pool is already active as '%s'"),
|
||||
obj->def->name);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
} else {
|
||||
/* UUID does not match, but if a name matches, refuse it */
|
||||
obj = virStoragePoolObjFindByName(pools, def->name);
|
||||
if (obj) {
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
virUUIDFormat(obj->def->uuid, uuidstr);
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("pool '%s' already exists with uuid %s"),
|
||||
def->name, uuidstr);
|
||||
goto cleanup;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virStoragePoolObjEndAPI(&obj);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virStoragePoolObjAssignDef:
|
||||
* @pools: Storage Pool object list pointer
|
||||
@ -1452,68 +1514,6 @@ virStoragePoolObjGetNames(virStoragePoolObjListPtr pools,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* virStoragePoolObjIsDuplicate:
|
||||
* @doms : virStoragePoolObjListPtr to search
|
||||
* @def : virStoragePoolDefPtr definition of pool to lookup
|
||||
* @check_active: If true, ensure that pool is not active
|
||||
*
|
||||
* Returns: -1 on error
|
||||
* 0 if pool is new
|
||||
* 1 if pool is a duplicate
|
||||
*/
|
||||
int
|
||||
virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
|
||||
virStoragePoolDefPtr def,
|
||||
bool check_active)
|
||||
{
|
||||
int ret = -1;
|
||||
virStoragePoolObjPtr obj = NULL;
|
||||
|
||||
/* See if a Pool with matching UUID already exists */
|
||||
obj = virStoragePoolObjFindByUUID(pools, def->uuid);
|
||||
if (obj) {
|
||||
/* UUID matches, but if names don't match, refuse it */
|
||||
if (STRNEQ(obj->def->name, def->name)) {
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
virUUIDFormat(obj->def->uuid, uuidstr);
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("pool '%s' is already defined with uuid %s"),
|
||||
obj->def->name, uuidstr);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (check_active) {
|
||||
/* UUID & name match, but if Pool is already active, refuse it */
|
||||
if (virStoragePoolObjIsActive(obj)) {
|
||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||
_("pool is already active as '%s'"),
|
||||
obj->def->name);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
} else {
|
||||
/* UUID does not match, but if a name matches, refuse it */
|
||||
obj = virStoragePoolObjFindByName(pools, def->name);
|
||||
if (obj) {
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
virUUIDFormat(obj->def->uuid, uuidstr);
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("pool '%s' already exists with uuid %s"),
|
||||
def->name, uuidstr);
|
||||
goto cleanup;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virStoragePoolObjEndAPI(&obj);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
getSCSIHostNumber(virStorageAdapterSCSIHostPtr scsi_host,
|
||||
unsigned int *hostnum)
|
||||
|
Loading…
Reference in New Issue
Block a user