Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/mngt/ocf_mngt_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ static void _ocf_mngt_deinit_added_cores(
ocf_core_seq_cutoff_deinit(core);
ocf_core_seq_detect_deinit(core);

if (core->counters)
env_refcnt_deinit(&core->refcnt);
env_free(core->counters);
core->counters = NULL;
core->added = false;
Expand Down Expand Up @@ -511,6 +513,13 @@ static void _ocf_mngt_load_add_cores(ocf_pipeline_t pipeline,
if (!core->counters)
goto err;

ret = env_refcnt_init(&core->refcnt, "core", sizeof("core"));
if (ret) {
env_free(core->counters);
core->counters = NULL;
goto err;
}

ret = ocf_core_seq_detect_init(core);
if (ret < 0)
goto err;
Expand Down
1 change: 1 addition & 0 deletions src/mngt/ocf_mngt_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void cache_mngt_core_remove_from_cache(ocf_core_t core)
ocf_prefetch_deinit(cache, core);
ocf_core_seq_cutoff_deinit(core);
ocf_core_seq_detect_deinit(core);
env_refcnt_deinit(&core->refcnt);
env_free(core->counters);
core->counters = NULL;
core->added = false;
Expand Down
25 changes: 25 additions & 0 deletions src/mngt/ocf_mngt_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ static void _ocf_mngt_cache_add_core_handle_error(
core->added = false;
core->opened = false;

env_refcnt_deinit(&core->refcnt);
env_free(core->counters);
core->counters = NULL;
}
Expand Down Expand Up @@ -497,6 +498,13 @@ static void ocf_mngt_cache_add_core_insert(ocf_pipeline_t pipeline,
if (!core->counters)
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_NO_MEM);

result = env_refcnt_init(&core->refcnt, "core", sizeof("core"));
if (result) {
env_free(core->counters);
core->counters = NULL;
OCF_PL_FINISH_RET(context->pipeline, result);
}

context->flags.counters_allocated = true;

/* When adding new core to cache, reset all core/cache statistics */
Expand Down Expand Up @@ -665,6 +673,7 @@ struct ocf_mngt_cache_remove_core_context {
ocf_core_t core;
const char *core_name;
struct ocf_cleaner_wait_context cleaner_wait;
bool core_frozen;
};

static void ocf_mngt_cache_remove_core_finish(ocf_pipeline_t pipeline,
Expand All @@ -681,6 +690,9 @@ static void ocf_mngt_cache_remove_core_finish(ocf_pipeline_t pipeline,
context->core_name);
}

if (context->core_frozen)
env_refcnt_unfreeze(&context->core->refcnt);

if (ocf_cache_is_device_attached(cache)) {
ocf_cleaner_refcnt_unfreeze(cache);
}
Expand Down Expand Up @@ -741,6 +753,7 @@ static void _ocf_mngt_cache_remove_core(ocf_pipeline_t pipeline, void *priv,
cache_mngt_core_remove_from_cleaning_pol(core);

cache_mngt_core_remove_from_meta(core);
context->core_frozen = false;
cache_mngt_core_remove_from_cache(core);
cache_mngt_core_deinit(core);

Expand All @@ -752,6 +765,17 @@ static void _ocf_mngt_cache_remove_core(ocf_pipeline_t pipeline, void *priv,
context);
}

static void ocf_mngt_cache_remove_core_wait_requests(ocf_pipeline_t pipeline,
void *priv, ocf_pipeline_arg_t arg)
{
struct ocf_mngt_cache_remove_core_context *context = priv;
ocf_core_t core = context->core;

env_refcnt_freeze(&core->refcnt);
context->core_frozen = true;
ocf_pipeline_continue_on_zero_refcnt(pipeline, &core->refcnt);
}

static void ocf_mngt_cache_remove_core_wait_cleaning_complete(void *priv)
{
ocf_pipeline_t pipeline = priv;
Expand All @@ -778,6 +802,7 @@ struct ocf_pipeline_properties ocf_mngt_cache_remove_core_pipeline_props = {
.finish = ocf_mngt_cache_remove_core_finish,
.steps = {
OCF_PL_STEP(ocf_mngt_cache_remove_core_wait_cleaning),
OCF_PL_STEP(ocf_mngt_cache_remove_core_wait_requests),
OCF_PL_STEP(_ocf_mngt_cache_remove_core_mapping),
OCF_PL_STEP(_ocf_mngt_cache_remove_core),
OCF_PL_STEP_TERMINATOR(),
Expand Down
2 changes: 2 additions & 0 deletions src/ocf_core_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ struct ocf_core {

struct ocf_counters_core *counters;

struct env_refcnt refcnt;

void *priv;
};

Expand Down
9 changes: 9 additions & 0 deletions src/ocf_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ struct ocf_request *ocf_req_new(ocf_queue_t queue, ocf_core_t core,

ENV_BUG_ON(ocf_queue_is_mngt(queue));

if (!env_refcnt_inc(&core->refcnt))
return NULL;

ocf_queue_get(queue);

if (!env_refcnt_inc(&cache->refcnt.metadata)) {
Expand All @@ -205,6 +208,7 @@ struct ocf_request *ocf_req_new(ocf_queue_t queue, ocf_core_t core,
req = ocf_req_new_d2c(queue, core, addr, bytes, rw);
if (unlikely(!req)) {
ocf_queue_put(queue);
env_refcnt_dec(&core->refcnt);
return NULL;
}
return req;
Expand All @@ -229,6 +233,7 @@ struct ocf_request *ocf_req_new(ocf_queue_t queue, ocf_core_t core,
if (unlikely(!req)) {
env_refcnt_dec(&cache->refcnt.metadata);
ocf_queue_put(queue);
env_refcnt_dec(&core->refcnt);
return NULL;
}

Expand Down Expand Up @@ -304,6 +309,7 @@ struct ocf_request *ocf_req_new_cache(ocf_cache_t cache, ocf_queue_t queue,
ocf_req_init(req, cache, queue, NULL, addr, bytes, rw);

req->lock_idx = ocf_metadata_concurrency_next_idx(queue);
req->is_cache = true;

return req;
}
Expand Down Expand Up @@ -398,6 +404,9 @@ void ocf_req_put(struct ocf_request *req)
else if (!req->is_mngt || req->cleaner)
env_refcnt_dec(&req->cache->refcnt.metadata);

if (!req->is_mngt && !req->cleaner && !req->is_cache)
env_refcnt_dec(&req->core->refcnt);

if (unlikely(req->is_mngt)) {
env_free(req);
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/ocf_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ struct ocf_request {
uint8_t is_mngt : 1;
/* !< It's a management path request */

uint8_t is_cache : 1;
/* !< It's a cache volume request */

ocf_req_cache_mode_t cache_mode;

ocf_queue_t io_queue;
Expand Down
Loading