env: change env_strncmp to take 4 args

Signed-off-by: Michal Rakowski <michal.rakowski@intel.com>
This commit is contained in:
Michal Rakowski 2019-09-30 16:31:56 +02:00
parent c65a25fff6
commit 325994074e
8 changed files with 22 additions and 17 deletions

2
env/posix/ocf_env.h vendored
View File

@ -621,7 +621,7 @@ static inline void env_sort(void *base, size_t num, size_t size,
})
#define env_strdup strndup
#define env_strnlen(s, smax) strnlen(s, smax)
#define env_strncmp strncmp
#define env_strncmp(s1, slen1, s2, slen2) strncmp(s1, s2, min(slen1, slen2))
#define env_strncpy(dest, dmax, src, slen) ({ \
strncpy(dest, src, min(dmax - 1, slen)); \
dest[dmax - 1] = '\0'; \

View File

@ -47,12 +47,13 @@ struct ocf_core_info {
*
* @param[in] cache OCF cache
* @param[in] name Core name
* @param[in] name_len Core name length
* @param[out] core OCF core handle
*
* @retval 0 Get cache successfully
* @retval -OCF_ERR_CORE_NOT_EXIST Core with given name doesn't exist
*/
int ocf_core_get_by_name(ocf_cache_t cache, const char *name,
int ocf_core_get_by_name(ocf_cache_t cache, const char *name, size_t name_len,
ocf_core_t *core);
/**

View File

@ -85,12 +85,13 @@ uint32_t ocf_mngt_cache_get_count(ocf_ctx_t ctx);
*
* @param[in] ctx OCF context
* @param[in] name OCF cache name
* @param[in] name_len Cache name length
* @param[out] cache OCF cache handle
*
* @retval 0 Get cache successfully
* @retval -OCF_ERR_CACHE_NOT_EXIST Cache with given name doesn't exist
*/
int ocf_mngt_cache_get_by_name(ocf_ctx_t ctx, const char* name,
int ocf_mngt_cache_get_by_name(ocf_ctx_t ctx, const char* name, size_t name_len,
ocf_cache_t *cache);
/**

View File

@ -662,7 +662,8 @@ static int _ocf_mngt_init_prepare_cache(struct ocf_cache_mngt_init_params *param
int ret = 0;
/* Check if cache with specified name exists */
ret = ocf_mngt_cache_get_by_name(param->ctx, cfg->name, &cache);
ret = ocf_mngt_cache_get_by_name(param->ctx, cfg->name,
OCF_CACHE_NAME_SIZE, &cache);
if (!ret) {
ocf_mngt_cache_put(cache);
/* Cache already exist */
@ -924,8 +925,8 @@ static void _ocf_mngt_attach_load_properties_end(void *priv, int error,
/*
* Check if name loaded from disk is the same as present one.
*/
if (env_strncmp(cache->conf_meta->name, properties->cache_name,
OCF_CACHE_NAME_SIZE)) {
if (env_strncmp(cache->conf_meta->name, OCF_CACHE_NAME_SIZE,
properties->cache_name, OCF_CACHE_NAME_SIZE)) {
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_CACHE_NAME_MISMATCH);
}

View File

@ -140,7 +140,7 @@ void ocf_mngt_cache_put(ocf_cache_t cache)
}
}
int ocf_mngt_cache_get_by_name(ocf_ctx_t ctx, const char *name,
int ocf_mngt_cache_get_by_name(ocf_ctx_t ctx, const char *name, size_t name_len,
ocf_cache_t *cache)
{
struct ocf_cache *instance = NULL;
@ -153,8 +153,8 @@ int ocf_mngt_cache_get_by_name(ocf_ctx_t ctx, const char *name,
env_rmutex_lock(&ctx->lock);
list_for_each_entry(iter, &ctx->caches, list) {
if (!env_strncmp(ocf_cache_get_name(iter), name,
OCF_CACHE_NAME_SIZE)) {
if (!env_strncmp(ocf_cache_get_name(iter), OCF_CACHE_NAME_SIZE,
name, name_len)) {
instance = iter;
break;
}

View File

@ -228,7 +228,8 @@ static void ocf_mngt_cache_try_add_core_prepare(ocf_pipeline_t pipeline,
ocf_ctx_t ctx = cache->owner;
int result;
result = ocf_core_get_by_name(cache, cfg->name, &core);
result = ocf_core_get_by_name(cache, cfg->name,
OCF_CORE_NAME_SIZE, &core);
if (result)
goto err;
@ -245,8 +246,8 @@ static void ocf_mngt_cache_try_add_core_prepare(ocf_pipeline_t pipeline,
goto err;
}
if (env_strncmp(volume->uuid.data, cfg->uuid.data,
OCF_MIN(volume->uuid.size, cfg->uuid.size))) {
if (env_strncmp(volume->uuid.data, volume->uuid.size, cfg->uuid.data,
cfg->uuid.size)) {
result = -OCF_ERR_INVAL;
goto err;
}
@ -304,7 +305,8 @@ static void ocf_mngt_cache_add_core_prepare(ocf_pipeline_t pipeline,
ocf_core_t core;
int result;
result = ocf_core_get_by_name(cache, cfg->name, &core);
result = ocf_core_get_by_name(cache, cfg->name,
OCF_CACHE_NAME_SIZE, &core);
if (!result)
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_CORE_EXIST);

View File

@ -82,7 +82,7 @@ ocf_volume_t ocf_mngt_core_pool_lookup(ocf_ctx_t ctx, ocf_uuid_t uuid,
list_for_each_entry(svolume, &ctx->core_pool.core_pool_head,
core_pool_item) {
if (svolume->type == type && !env_strncmp(svolume->uuid.data,
uuid->data, OCF_MIN(svolume->uuid.size, uuid->size))) {
svolume->uuid.size, uuid->data, uuid->size)) {
return svolume;
}
}

View File

@ -49,15 +49,15 @@ ocf_core_id_t ocf_core_get_id(ocf_core_t core)
return core_id;
}
int ocf_core_get_by_name(ocf_cache_t cache, const char *name,
int ocf_core_get_by_name(ocf_cache_t cache, const char *name, size_t name_len,
ocf_core_t *core)
{
ocf_core_t i_core;
ocf_core_id_t i_core_id;
for_each_core(cache, i_core, i_core_id) {
if (!env_strncmp(ocf_core_get_name(i_core), name,
OCF_CORE_NAME_SIZE)) {
if (!env_strncmp(ocf_core_get_name(i_core), OCF_CORE_NAME_SIZE,
name, name_len)) {
*core = i_core;
return 0;
}