diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 6f1e14ed3ed6cbf5b17f28625d9f2d192d9677f7..185822451bd64c7b97e8330462dfaec2b998e0fa 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -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)