env: change env_strncmp to take 4 args
Signed-off-by: Michal Rakowski <michal.rakowski@intel.com>
This commit is contained in:
parent
c65a25fff6
commit
325994074e
2
env/posix/ocf_env.h
vendored
2
env/posix/ocf_env.h
vendored
@ -621,7 +621,7 @@ static inline void env_sort(void *base, size_t num, size_t size,
|
|||||||
})
|
})
|
||||||
#define env_strdup strndup
|
#define env_strdup strndup
|
||||||
#define env_strnlen(s, smax) strnlen(s, smax)
|
#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) ({ \
|
#define env_strncpy(dest, dmax, src, slen) ({ \
|
||||||
strncpy(dest, src, min(dmax - 1, slen)); \
|
strncpy(dest, src, min(dmax - 1, slen)); \
|
||||||
dest[dmax - 1] = '\0'; \
|
dest[dmax - 1] = '\0'; \
|
||||||
|
@ -47,12 +47,13 @@ struct ocf_core_info {
|
|||||||
*
|
*
|
||||||
* @param[in] cache OCF cache
|
* @param[in] cache OCF cache
|
||||||
* @param[in] name Core name
|
* @param[in] name Core name
|
||||||
|
* @param[in] name_len Core name length
|
||||||
* @param[out] core OCF core handle
|
* @param[out] core OCF core handle
|
||||||
*
|
*
|
||||||
* @retval 0 Get cache successfully
|
* @retval 0 Get cache successfully
|
||||||
* @retval -OCF_ERR_CORE_NOT_EXIST Core with given name doesn't exist
|
* @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);
|
ocf_core_t *core);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,12 +85,13 @@ uint32_t ocf_mngt_cache_get_count(ocf_ctx_t ctx);
|
|||||||
*
|
*
|
||||||
* @param[in] ctx OCF context
|
* @param[in] ctx OCF context
|
||||||
* @param[in] name OCF cache name
|
* @param[in] name OCF cache name
|
||||||
|
* @param[in] name_len Cache name length
|
||||||
* @param[out] cache OCF cache handle
|
* @param[out] cache OCF cache handle
|
||||||
*
|
*
|
||||||
* @retval 0 Get cache successfully
|
* @retval 0 Get cache successfully
|
||||||
* @retval -OCF_ERR_CACHE_NOT_EXIST Cache with given name doesn't exist
|
* @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);
|
ocf_cache_t *cache);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -662,7 +662,8 @@ static int _ocf_mngt_init_prepare_cache(struct ocf_cache_mngt_init_params *param
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
/* Check if cache with specified name exists */
|
/* 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) {
|
if (!ret) {
|
||||||
ocf_mngt_cache_put(cache);
|
ocf_mngt_cache_put(cache);
|
||||||
/* Cache already exist */
|
/* 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.
|
* Check if name loaded from disk is the same as present one.
|
||||||
*/
|
*/
|
||||||
if (env_strncmp(cache->conf_meta->name, properties->cache_name,
|
if (env_strncmp(cache->conf_meta->name, OCF_CACHE_NAME_SIZE,
|
||||||
OCF_CACHE_NAME_SIZE)) {
|
properties->cache_name, OCF_CACHE_NAME_SIZE)) {
|
||||||
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_CACHE_NAME_MISMATCH);
|
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_CACHE_NAME_MISMATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
ocf_cache_t *cache)
|
||||||
{
|
{
|
||||||
struct ocf_cache *instance = NULL;
|
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);
|
env_rmutex_lock(&ctx->lock);
|
||||||
|
|
||||||
list_for_each_entry(iter, &ctx->caches, list) {
|
list_for_each_entry(iter, &ctx->caches, list) {
|
||||||
if (!env_strncmp(ocf_cache_get_name(iter), name,
|
if (!env_strncmp(ocf_cache_get_name(iter), OCF_CACHE_NAME_SIZE,
|
||||||
OCF_CACHE_NAME_SIZE)) {
|
name, name_len)) {
|
||||||
instance = iter;
|
instance = iter;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,8 @@ static void ocf_mngt_cache_try_add_core_prepare(ocf_pipeline_t pipeline,
|
|||||||
ocf_ctx_t ctx = cache->owner;
|
ocf_ctx_t ctx = cache->owner;
|
||||||
int result;
|
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)
|
if (result)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
@ -245,8 +246,8 @@ static void ocf_mngt_cache_try_add_core_prepare(ocf_pipeline_t pipeline,
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env_strncmp(volume->uuid.data, cfg->uuid.data,
|
if (env_strncmp(volume->uuid.data, volume->uuid.size, cfg->uuid.data,
|
||||||
OCF_MIN(volume->uuid.size, cfg->uuid.size))) {
|
cfg->uuid.size)) {
|
||||||
result = -OCF_ERR_INVAL;
|
result = -OCF_ERR_INVAL;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@ -304,7 +305,8 @@ static void ocf_mngt_cache_add_core_prepare(ocf_pipeline_t pipeline,
|
|||||||
ocf_core_t core;
|
ocf_core_t core;
|
||||||
int result;
|
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)
|
if (!result)
|
||||||
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_CORE_EXIST);
|
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_CORE_EXIST);
|
||||||
|
|
||||||
|
@ -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,
|
list_for_each_entry(svolume, &ctx->core_pool.core_pool_head,
|
||||||
core_pool_item) {
|
core_pool_item) {
|
||||||
if (svolume->type == type && !env_strncmp(svolume->uuid.data,
|
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;
|
return svolume;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,15 +49,15 @@ ocf_core_id_t ocf_core_get_id(ocf_core_t core)
|
|||||||
return core_id;
|
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 *core)
|
||||||
{
|
{
|
||||||
ocf_core_t i_core;
|
ocf_core_t i_core;
|
||||||
ocf_core_id_t i_core_id;
|
ocf_core_id_t i_core_id;
|
||||||
|
|
||||||
for_each_core(cache, i_core, i_core_id) {
|
for_each_core(cache, i_core, i_core_id) {
|
||||||
if (!env_strncmp(ocf_core_get_name(i_core), name,
|
if (!env_strncmp(ocf_core_get_name(i_core), OCF_CORE_NAME_SIZE,
|
||||||
OCF_CORE_NAME_SIZE)) {
|
name, name_len)) {
|
||||||
*core = i_core;
|
*core = i_core;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user