Store cache name in metadata

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2019-07-20 14:32:58 +02:00
parent b73b2857dd
commit eb4272afa9
5 changed files with 28 additions and 26 deletions

View File

@ -32,18 +32,16 @@ int ocf_metadata_init(struct ocf_cache *cache,
ENV_BUG_ON(cache->metadata.iface_priv);
ret = ocf_metadata_io_init(cache);
if (ret)
return ret;
*iface = *metadata_hash_get_iface();
ret = cache->metadata.iface.init(cache, cache_line_size);
if (ret)
if (ret) {
ocf_metadata_io_deinit(cache);
return ret;
}
ocf_metadata_concurrency_init(cache);
return ret;
return 0;
}
int ocf_metadata_init_variable_size(struct ocf_cache *cache, uint64_t device_size,

View File

@ -6,6 +6,7 @@
#ifndef __METADATA_SUPERBLOCK_H__
#define __METADATA_SUPERBLOCK_H__
#include <ocf/ocf_def.h>
#include <ocf/ocf_def.h>
#define CACHE_MAGIC_NUMBER 0x187E1CA6
@ -26,6 +27,8 @@ struct ocf_superblock_config {
/* Currently set cache mode */
ocf_cache_mode_t cache_mode;
char name[OCF_CACHE_NAME_SIZE];
ocf_cache_line_t cachelines;
uint32_t valid_parts_no;

View File

@ -701,7 +701,6 @@ static int _ocf_mngt_init_prepare_cache(struct ocf_cache_mngt_init_params *param
struct ocf_mngt_cache_config *cfg)
{
ocf_cache_t cache;
char cache_name[OCF_CACHE_NAME_SIZE];
int ret = 0;
ret = env_rmutex_lock_interruptible(&param->ctx->lock);
@ -735,12 +734,7 @@ static int _ocf_mngt_init_prepare_cache(struct ocf_cache_mngt_init_params *param
goto out;
}
ret = env_strncpy(cache_name, sizeof(cache_name),
cfg->name, sizeof(cache_name));
if (ret)
goto out;
ocf_log(param->ctx, log_info, "Inserting cache %s\n", cache_name);
ocf_log(param->ctx, log_info, "Inserting cache %s\n", cfg->name);
ret = _ocf_mngt_init_new_cache(param);
if (ret)
@ -748,10 +742,6 @@ static int _ocf_mngt_init_prepare_cache(struct ocf_cache_mngt_init_params *param
cache = param->cache;
ret = ocf_cache_set_name(cache, cache_name, sizeof(cache_name));
if (ret)
goto out;
cache->backfill.max_queue_size = cfg->backfill.max_queue_size;
cache->backfill.queue_unblock_size = cfg->backfill.queue_unblock_size;
@ -1265,6 +1255,7 @@ static int _ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
struct ocf_mngt_cache_config *cfg)
{
struct ocf_cache_mngt_init_params params;
ocf_cache_t tmp_cache;
int result;
ENV_BUG_ON(env_memset(&params, sizeof(params), 0));
@ -1284,21 +1275,30 @@ static int _ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
if (result)
goto _cache_mngt_init_instance_ERROR;
*cache = params.cache;
tmp_cache = params.cache;
/*
* Initialize metadata selected segments of metadata in memory
*/
result = ocf_metadata_init(*cache, params.metadata.line_size);
result = ocf_metadata_init(tmp_cache, params.metadata.line_size);
if (result) {
result = -OCF_ERR_START_CACHE_FAIL;
goto _cache_mngt_init_instance_ERROR;
}
ocf_log(ctx, log_debug, "Metadata initialized\n");
params.flags.metadata_inited = true;
_ocf_mngt_cache_init(*cache, &params);
result = ocf_cache_set_name(tmp_cache, cfg->name, OCF_CACHE_NAME_SIZE);
if (result)
goto _cache_mngt_init_instance_ERROR;
result = ocf_metadata_io_init(tmp_cache);
if (result)
goto _cache_mngt_init_instance_ERROR;
ocf_cache_log(tmp_cache, log_debug, "Metadata initialized\n");
_ocf_mngt_cache_init(tmp_cache, &params);
ocf_ctx_get(ctx);
@ -1306,10 +1306,12 @@ static int _ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
/* User did not request to lock cache instance after creation -
unlock it here since we have acquired the lock to
perform management operations. */
ocf_mngt_cache_unlock(*cache);
ocf_mngt_cache_unlock(tmp_cache);
params.flags.cache_locked = false;
}
*cache = tmp_cache;
return 0;
_cache_mngt_init_instance_ERROR:

View File

@ -26,13 +26,14 @@ ocf_cache_id_t ocf_cache_get_id(ocf_cache_t cache)
int ocf_cache_set_name(ocf_cache_t cache, const char *src, size_t src_size)
{
OCF_CHECK_NULL(cache);
return env_strncpy(cache->name, OCF_CACHE_NAME_SIZE - 1, src, src_size);
return env_strncpy(cache->conf_meta->name, OCF_CACHE_NAME_SIZE,
src, src_size);
}
const char *ocf_cache_get_name(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
return cache->name;
return cache->conf_meta->name;
}
bool ocf_cache_is_incomplete(ocf_cache_t cache)

View File

@ -114,8 +114,6 @@ struct ocf_cache {
int cache_id;
char name[OCF_CACHE_NAME_SIZE];
struct {
/* cache get/put counter */
struct ocf_refcnt cache;