Remove cache id from public API

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2019-07-20 15:52:06 +02:00
parent 259df7ace9
commit 1100cb0b4f
9 changed files with 6 additions and 157 deletions

View File

@ -100,15 +100,6 @@ struct ocf_cache_info {
*/ */
ocf_volume_t ocf_cache_get_volume(ocf_cache_t cache); ocf_volume_t ocf_cache_get_volume(ocf_cache_t cache);
/**
* @brief Get ID of given cache object
*
* @param[in] cache Cache object
*
* @retval Cache ID
*/
ocf_cache_id_t ocf_cache_get_id(ocf_cache_t cache);
/** /**
* @brief Set name of given cache object * @brief Set name of given cache object
* *

View File

@ -84,22 +84,6 @@ uint32_t ocf_mngt_cache_get_count(ocf_ctx_t ctx);
/* Cache instances getters */ /* Cache instances getters */
/**
* @brief Get OCF cache
*
* @note This function on success also increasing reference counter
* in given cache
*
* @param[in] ctx OCF context
* @param[in] id OCF cache ID
* @param[out] cache OCF cache handle
*
* @retval 0 Get cache successfully
* @retval -OCF_ERR_INV_CACHE_ID Cache ID out of range
* @retval -OCF_ERR_CACHE_NOT_EXIST Cache with given ID is not exist
*/
int ocf_mngt_cache_get_by_id(ocf_ctx_t ctx, ocf_cache_id_t id, ocf_cache_t *cache);
/** /**
* @brief Get OCF cache by name * @brief Get OCF cache by name
* *
@ -255,12 +239,6 @@ int ocf_mngt_cache_visit_reverse(ocf_ctx_t ctx, ocf_mngt_cache_visitor_t visitor
* @brief Cache start configuration * @brief Cache start configuration
*/ */
struct ocf_mngt_cache_config { struct ocf_mngt_cache_config {
/**
* @brief Cache ID. In case of setting this field to invalid cache
* id first available cache ID will be set
*/
ocf_cache_id_t id;
/** /**
* @brief Cache name * @brief Cache name
*/ */
@ -331,7 +309,6 @@ struct ocf_mngt_cache_config {
static inline void ocf_mngt_cache_config_set_default( static inline void ocf_mngt_cache_config_set_default(
struct ocf_mngt_cache_config *cfg) struct ocf_mngt_cache_config *cfg)
{ {
cfg->id = OCF_CACHE_ID_INVALID;
cfg->cache_mode = ocf_cache_mode_default; cfg->cache_mode = ocf_cache_mode_default;
cfg->eviction_policy = ocf_eviction_default; cfg->eviction_policy = ocf_eviction_default;
cfg->promotion_policy = ocf_promotion_default; cfg->promotion_policy = ocf_promotion_default;

View File

@ -59,8 +59,8 @@ struct ocf_event_cache_desc {
/** Event header */ /** Event header */
struct ocf_event_hdr hdr; struct ocf_event_hdr hdr;
/** Cache Id */ /** Cache name */
ocf_cache_id_t id; const char *name;
/** Cache line size */ /** Cache line size */
ocf_cache_line_size_t cache_line_size; ocf_cache_line_size_t cache_line_size;

View File

@ -12,11 +12,6 @@
#include "ocf_env_headers.h" #include "ocf_env_headers.h"
/**
* @brief cache id type (by default designated as 16 bit unsigned integer)
*/
typedef uint16_t ocf_cache_id_t;
/** /**
* @brief cache line type (by default designated as 32 bit unsigned integer) * @brief cache line type (by default designated as 32 bit unsigned integer)
*/ */

View File

@ -25,22 +25,6 @@
#define OCF_ASSERT_PLUGGED(cache) ENV_BUG_ON(!(cache)->device) #define OCF_ASSERT_PLUGGED(cache) ENV_BUG_ON(!(cache)->device)
static ocf_cache_t _ocf_mngt_get_cache(ocf_ctx_t owner,
ocf_cache_id_t cache_id)
{
ocf_cache_t iter = NULL;
ocf_cache_t cache = NULL;
list_for_each_entry(iter, &owner->caches, list) {
if (iter->cache_id == cache_id) {
cache = iter;
break;
}
}
return cache;
}
#define DIRTY_SHUTDOWN_ERROR_MSG "Please use --load option to restore " \ #define DIRTY_SHUTDOWN_ERROR_MSG "Please use --load option to restore " \
"previous cache state (Warning: data corruption may happen)" \ "previous cache state (Warning: data corruption may happen)" \
"\nOr initialize your cache using --force option. " \ "\nOr initialize your cache using --force option. " \
@ -55,9 +39,6 @@ static ocf_cache_t _ocf_mngt_get_cache(ocf_ctx_t owner,
struct ocf_cache_mngt_init_params { struct ocf_cache_mngt_init_params {
bool metadata_volatile; bool metadata_volatile;
ocf_cache_id_t id;
/*!< cache id */
ocf_ctx_t ctx; ocf_ctx_t ctx;
/*!< OCF context */ /*!< OCF context */
@ -175,18 +156,6 @@ struct ocf_cache_attach_context {
ocf_pipeline_t pipeline; ocf_pipeline_t pipeline;
}; };
static ocf_cache_id_t _ocf_mngt_cache_find_free_id(ocf_ctx_t owner)
{
ocf_cache_id_t id = OCF_CACHE_ID_INVALID;
for (id = OCF_CACHE_ID_MIN; id <= OCF_CACHE_ID_MAX; id++) {
if (!_ocf_mngt_get_cache(owner, id))
return id;
}
return OCF_CACHE_ID_INVALID;
}
static void __init_hash_table(ocf_cache_t cache) static void __init_hash_table(ocf_cache_t cache)
{ {
/* Initialize hash table*/ /* Initialize hash table*/
@ -614,9 +583,6 @@ static int _ocf_mngt_init_new_cache(struct ocf_cache_mngt_init_params *params)
/* start with freezed metadata ref counter to indicate detached device*/ /* start with freezed metadata ref counter to indicate detached device*/
ocf_refcnt_freeze(&cache->refcnt.metadata); ocf_refcnt_freeze(&cache->refcnt.metadata);
/* Copy all required initialization parameters */
cache->cache_id = params->id;
env_atomic_set(&(cache->last_access_ms), env_atomic_set(&(cache->last_access_ms),
env_ticks_to_msecs(env_get_tick_count())); env_ticks_to_msecs(env_get_tick_count()));
@ -697,24 +663,6 @@ static int _ocf_mngt_init_prepare_cache(struct ocf_cache_mngt_init_params *param
if (ret) if (ret)
return ret; return ret;
if (param->id == OCF_CACHE_ID_INVALID) {
/* ID was not specified, take first free id */
param->id = _ocf_mngt_cache_find_free_id(param->ctx);
if (param->id == OCF_CACHE_ID_INVALID) {
ret = -OCF_ERR_TOO_MANY_CACHES;
goto out;
}
cfg->id = param->id;
} else {
/* ID was set, check if cache exist with specified ID */
cache = _ocf_mngt_get_cache(param->ctx, param->id);
if (cache) {
/* Cache already exist */
ret = -OCF_ERR_CACHE_EXIST;
goto out;
}
}
/* 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, &cache);
if (!ret) { if (!ret) {
@ -1250,8 +1198,6 @@ static int _ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
ENV_BUG_ON(env_memset(&params, sizeof(params), 0)); ENV_BUG_ON(env_memset(&params, sizeof(params), 0));
params.id = cfg->id;
params.ctx = ctx; params.ctx = ctx;
params.metadata.cache_mode = cfg->cache_mode; params.metadata.cache_mode = cfg->cache_mode;
params.metadata.layout = cfg->metadata_layout; params.metadata.layout = cfg->metadata_layout;
@ -1634,9 +1580,6 @@ err_pipeline:
static int _ocf_mngt_cache_validate_cfg(struct ocf_mngt_cache_config *cfg) static int _ocf_mngt_cache_validate_cfg(struct ocf_mngt_cache_config *cfg)
{ {
if (cfg->id > OCF_CACHE_ID_MAX)
return -OCF_ERR_INVAL;
if (!cfg->name) if (!cfg->name)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;

View File

@ -139,50 +139,6 @@ void ocf_mngt_cache_put(ocf_cache_t cache)
} }
} }
int ocf_mngt_cache_get_by_id(ocf_ctx_t ocf_ctx, ocf_cache_id_t id, ocf_cache_t *cache)
{
int error = 0;
struct ocf_cache *instance = NULL;
struct ocf_cache *iter = NULL;
OCF_CHECK_NULL(ocf_ctx);
OCF_CHECK_NULL(cache);
*cache = NULL;
if ((id < OCF_CACHE_ID_MIN) || (id > OCF_CACHE_ID_MAX)) {
/* Cache id out of range */
return -OCF_ERR_INVAL;
}
/* Lock caches list */
env_rmutex_lock(&ocf_ctx->lock);
list_for_each_entry(iter, &ocf_ctx->caches, list) {
if (iter->cache_id == id) {
instance = iter;
break;
}
}
if (instance) {
/* if cache is either fully initialized or during recovery */
if (!ocf_refcnt_inc(&instance->refcnt.cache)) {
/* Cache not initialized yet */
instance = NULL;
}
}
env_rmutex_unlock(&ocf_ctx->lock);
if (!instance)
error = -OCF_ERR_CACHE_NOT_EXIST;
else
*cache = instance;
return error;
}
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,
ocf_cache_t *cache) ocf_cache_t *cache)
{ {

View File

@ -17,12 +17,6 @@ ocf_volume_t ocf_cache_get_volume(ocf_cache_t cache)
return cache->device ? &cache->device->volume : NULL; return cache->device ? &cache->device->volume : NULL;
} }
ocf_cache_id_t ocf_cache_get_id(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
return cache->cache_id;
}
int ocf_cache_set_name(ocf_cache_t cache, const char *src, size_t src_size) int ocf_cache_set_name(ocf_cache_t cache, const char *src, size_t src_size)
{ {
OCF_CHECK_NULL(cache); OCF_CHECK_NULL(cache);

View File

@ -112,8 +112,6 @@ struct ocf_cache {
ocf_eviction_t eviction_policy_init; ocf_eviction_t eviction_policy_init;
int cache_id;
struct { struct {
/* cache get/put counter */ /* cache get/put counter */
struct ocf_refcnt cache; struct ocf_refcnt cache;

View File

@ -48,7 +48,7 @@ static int _ocf_trace_cache_info(ocf_cache_t cache, ocf_queue_t io_queue)
env_ticks_to_nsecs(env_get_tick_count()), env_ticks_to_nsecs(env_get_tick_count()),
sizeof(cache_desc)); sizeof(cache_desc));
cache_desc.id = ocf_cache_get_id(cache); cache_desc.name = ocf_cache_get_name(cache);
cache_desc.cache_line_size = ocf_cache_get_line_size(cache); cache_desc.cache_line_size = ocf_cache_get_line_size(cache);
cache_desc.cache_mode = ocf_cache_get_mode(cache); cache_desc.cache_mode = ocf_cache_get_mode(cache);
@ -85,9 +85,7 @@ int ocf_mngt_start_trace(ocf_cache_t cache, void *trace_ctx,
return -EINVAL; return -EINVAL;
if (cache->trace.trace_callback) { if (cache->trace.trace_callback) {
ocf_cache_log(cache, log_err, ocf_cache_log(cache, log_err, "Tracing already started\n");
"Tracing already started for cache %u\n",
ocf_cache_get_id(cache));
return -EINVAL; return -EINVAL;
} }
@ -107,8 +105,7 @@ int ocf_mngt_start_trace(ocf_cache_t cache, void *trace_ctx,
} }
} }
ocf_cache_log(cache, log_info, ocf_cache_log(cache, log_info, "Tracing started\n");
"Tracing started for cache %u\n", ocf_cache_get_id(cache));
return result; return result;
} }
@ -120,9 +117,7 @@ int ocf_mngt_stop_trace(ocf_cache_t cache)
OCF_CHECK_NULL(cache); OCF_CHECK_NULL(cache);
if (!cache->trace.trace_callback) { if (!cache->trace.trace_callback) {
ocf_cache_log(cache, log_err, ocf_cache_log(cache, log_err, "Tracing not started\n");
"Tracing not started for cache %u\n",
ocf_cache_get_id(cache));
return -EINVAL; return -EINVAL;
} }