Simplify data object API
Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
@@ -131,7 +131,7 @@ struct ocf_cachemng_attach_params {
|
||||
bool device_alloc : 1;
|
||||
/*!< data structure allocated */
|
||||
|
||||
bool uuid_alloc : 1;
|
||||
bool data_obj_inited : 1;
|
||||
/*!< uuid for cache device is allocated */
|
||||
|
||||
bool attached_metadata_inited : 1;
|
||||
@@ -436,10 +436,8 @@ static int _ocf_mngt_init_instance_add_cores(
|
||||
* Attach bottom device to core structure
|
||||
* in cache
|
||||
*/
|
||||
core->obj.type = tobj->type;
|
||||
core->obj.priv = tobj->priv;
|
||||
ocf_mngt_core_pool_remove(ocf_cache_get_ctx(cache),
|
||||
tobj);
|
||||
ocf_dobj_move(&core->obj, tobj);
|
||||
ocf_mngt_core_pool_remove(cache->owner, tobj);
|
||||
|
||||
core->opened = true;
|
||||
ocf_cache_log(cache, log_info,
|
||||
@@ -623,6 +621,7 @@ static int _ocf_mngt_init_new_cache(struct ocf_cachemng_init_params *params)
|
||||
static int _ocf_mngt_attach_cache_device(struct ocf_cache *cache,
|
||||
struct ocf_cachemng_attach_params *attach_params)
|
||||
{
|
||||
ocf_data_obj_type_t type;
|
||||
int ret;
|
||||
|
||||
cache->device = env_vzalloc(sizeof(*cache->device));
|
||||
@@ -633,18 +632,19 @@ static int _ocf_mngt_attach_cache_device(struct ocf_cache *cache,
|
||||
cache->device->obj.cache = cache;
|
||||
|
||||
/* Prepare UUID of cache data object */
|
||||
cache->device->obj.type = ocf_ctx_get_data_obj_type(cache->owner,
|
||||
type = ocf_ctx_get_data_obj_type(cache->owner,
|
||||
attach_params->device_type);
|
||||
if (!cache->device->obj.type) {
|
||||
if (!type) {
|
||||
ret = -OCF_ERR_INVAL_DATA_OBJ_TYPE;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ocf_uuid_cache_set(cache, &attach_params->uuid)) {
|
||||
ret = -OCF_ERR_INVAL;
|
||||
ret = ocf_dobj_init(&cache->device->obj, type,
|
||||
&attach_params->uuid, true);
|
||||
if (ret)
|
||||
goto err;
|
||||
}
|
||||
attach_params->flags.uuid_alloc = true;
|
||||
|
||||
attach_params->flags.data_obj_inited = true;
|
||||
|
||||
/*
|
||||
* Open cache device, It has to be done first because metadata service
|
||||
@@ -1098,8 +1098,8 @@ static void _ocf_mngt_attach_handle_error(
|
||||
if (attach_params->flags.concurrency_inited)
|
||||
ocf_concurrency_deinit(cache);
|
||||
|
||||
if (attach_params->flags.uuid_alloc)
|
||||
ocf_uuid_cache_clear(cache);
|
||||
if (attach_params->flags.data_obj_inited)
|
||||
ocf_dobj_deinit(&cache->device->obj);
|
||||
|
||||
if (attach_params->flags.device_alloc)
|
||||
env_vfree(cache->device);
|
||||
@@ -1572,7 +1572,7 @@ static int _ocf_mngt_cache_unplug(ocf_cache_t cache, bool stop)
|
||||
ocf_metadata_deinit_variable_size(cache);
|
||||
ocf_concurrency_deinit(cache);
|
||||
|
||||
ocf_uuid_cache_clear(cache);
|
||||
ocf_dobj_deinit(&cache->device->obj);
|
||||
|
||||
env_vfree(cache->device);
|
||||
cache->device = NULL;
|
||||
|
@@ -96,7 +96,7 @@ void cache_mng_core_remove_from_meta(struct ocf_cache *cache, int core_id)
|
||||
cache->core_conf_meta[core_id].added = false;
|
||||
|
||||
/* Clear UUID of core */
|
||||
ocf_uuid_core_clear(cache, &cache->core[core_id]);
|
||||
ocf_metadata_clear_core_uuid(&cache->core[core_id]);
|
||||
cache->core_conf_meta[core_id].seq_no = OCF_SEQ_NO_INVALID;
|
||||
|
||||
OCF_METADATA_UNLOCK_WR();
|
||||
|
@@ -64,12 +64,14 @@ error_out:
|
||||
static int _ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
|
||||
struct ocf_mngt_core_config *cfg)
|
||||
{
|
||||
int result = 0;
|
||||
ocf_core_t tmp_core;
|
||||
struct ocf_data_obj_uuid new_uuid;
|
||||
ocf_data_obj_t obj;
|
||||
ocf_data_obj_type_t type;
|
||||
ocf_seq_no_t core_sequence_no;
|
||||
ocf_cleaning_t clean_type;
|
||||
uint64_t length;
|
||||
int result = 0;
|
||||
|
||||
tmp_core = &cache->core[cfg->core_id];
|
||||
obj = &tmp_core->obj;
|
||||
@@ -77,14 +79,20 @@ static int _ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
|
||||
tmp_core->obj.cache = cache;
|
||||
|
||||
/* Set uuid */
|
||||
ocf_uuid_core_set(cache, tmp_core, &cfg->uuid);
|
||||
result = ocf_metadata_set_core_uuid(tmp_core, &cfg->uuid, &new_uuid);
|
||||
if (result)
|
||||
return -OCF_ERR_INVAL;
|
||||
|
||||
obj->type = ocf_ctx_get_data_obj_type(cache->owner, cfg->data_obj_type);
|
||||
if (!obj->type) {
|
||||
type = ocf_ctx_get_data_obj_type(cache->owner, cfg->data_obj_type);
|
||||
if (!type) {
|
||||
result = -OCF_ERR_INVAL_DATA_OBJ_TYPE;
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
result = ocf_dobj_init(obj, type, &new_uuid, false);
|
||||
if (result)
|
||||
goto error_out;
|
||||
|
||||
if (cfg->user_metadata.data && cfg->user_metadata.size > 0) {
|
||||
result = ocf_core_set_user_metadata_raw(tmp_core,
|
||||
cfg->user_metadata.data,
|
||||
@@ -184,7 +192,7 @@ error_after_clean_pol:
|
||||
error_after_open:
|
||||
ocf_dobj_close(obj);
|
||||
error_out:
|
||||
ocf_uuid_core_clear(cache, tmp_core);
|
||||
ocf_metadata_clear_core_uuid(tmp_core);
|
||||
*core = NULL;
|
||||
return result;
|
||||
}
|
||||
@@ -336,17 +344,22 @@ static int _ocf_mngt_find_core_id(ocf_cache_t cache,
|
||||
int ocf_mngt_core_init_front_dobj(ocf_core_t core)
|
||||
{
|
||||
ocf_cache_t cache = ocf_core_get_cache(core);
|
||||
ocf_data_obj_t front_obj;
|
||||
ocf_data_obj_type_t type;
|
||||
struct ocf_data_obj_uuid uuid = {
|
||||
.data = core,
|
||||
.size = sizeof(core),
|
||||
};
|
||||
int ret;
|
||||
|
||||
front_obj = &core->front_obj;
|
||||
front_obj->uuid.data = core;
|
||||
front_obj->uuid.size = sizeof(core);
|
||||
|
||||
front_obj->type = ocf_ctx_get_data_obj_type(cache->owner, 0);
|
||||
if (!front_obj->type)
|
||||
type = ocf_ctx_get_data_obj_type(cache->owner, 0);
|
||||
if (!type)
|
||||
return -OCF_ERR_INVAL;
|
||||
|
||||
return ocf_dobj_open(front_obj);
|
||||
ret = ocf_dobj_init(&core->front_obj, type, &uuid, false);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return ocf_dobj_open(&core->front_obj);
|
||||
}
|
||||
|
||||
int ocf_mngt_cache_add_core_nolock(ocf_cache_t cache, ocf_core_t *core,
|
||||
|
Reference in New Issue
Block a user