Return error status from ocf_freelist_init

Signed-off-by: Rafal Stefanowski <rafal.stefanowski@intel.com>
This commit is contained in:
Rafal Stefanowski 2020-12-23 02:20:55 +01:00
parent d3b61e474c
commit 57d4aaf7c9
7 changed files with 41 additions and 36 deletions

View File

@ -995,9 +995,9 @@ static void _ocf_mngt_attach_prepare_metadata(ocf_pipeline_t pipeline,
context->flags.attached_metadata_inited = true;
cache->freelist = ocf_freelist_init(cache);
if (!cache->freelist)
OCF_PL_FINISH_RET(pipeline, -OCF_ERR_START_CACHE_FAIL);
ret = ocf_freelist_init(&cache->freelist, cache);
if (ret)
OCF_PL_FINISH_RET(pipeline, ret);
context->flags.freelist_inited = true;

View File

@ -365,48 +365,53 @@ void ocf_freelist_put_cache_line(ocf_freelist_t freelist,
env_put_execution_context(ctx);
}
ocf_freelist_t ocf_freelist_init(struct ocf_cache *cache)
int ocf_freelist_init(ocf_freelist_t *freelist, struct ocf_cache *cache)
{
uint32_t num;
int i;
ocf_freelist_t freelist;
int result;
ocf_freelist_t tmp_freelist;
ocf_cache_line_t line_entries = ocf_metadata_collision_table_entries(
cache);
freelist = env_vzalloc(sizeof(*freelist));
if (!freelist)
return NULL;
tmp_freelist = env_vzalloc(sizeof(*tmp_freelist));
if (!tmp_freelist)
return -OCF_ERR_NO_MEM;
num = env_get_execution_context_count();
freelist->cache = cache;
freelist->count = num;
env_atomic64_set(&freelist->total_free, 0);
freelist->lock = env_vzalloc(sizeof(freelist->lock[0]) * num);
freelist->part = env_vzalloc(sizeof(freelist->part[0]) * num);
tmp_freelist->cache = cache;
tmp_freelist->count = num;
env_atomic64_set(&tmp_freelist->total_free, 0);
tmp_freelist->lock = env_vzalloc(sizeof(tmp_freelist->lock[0]) * num);
tmp_freelist->part = env_vzalloc(sizeof(tmp_freelist->part[0]) * num);
if (!freelist->lock || !freelist->part)
if (!tmp_freelist->lock || !tmp_freelist->part) {
result = -OCF_ERR_NO_MEM;
goto free_allocs;
for (i = 0; i < num; i++) {
if (env_spinlock_init(&freelist->lock[i]))
goto spinlock_err;
freelist->part[i].head = line_entries;
freelist->part[i].tail = line_entries;
env_atomic64_set(&freelist->part[i].curr_size, 0);
}
return freelist;
for (i = 0; i < num; i++) {
result = env_spinlock_init(&tmp_freelist->lock[i]);
if (result)
goto spinlock_err;
tmp_freelist->part[i].head = line_entries;
tmp_freelist->part[i].tail = line_entries;
env_atomic64_set(&tmp_freelist->part[i].curr_size, 0);
}
*freelist = tmp_freelist;
return 0;
spinlock_err:
while (i--)
env_spinlock_destroy(&freelist->lock[i]);
env_spinlock_destroy(&tmp_freelist->lock[i]);
free_allocs:
env_vfree(freelist->lock);
env_vfree(freelist->part);
env_vfree(freelist);
return NULL;
env_vfree(tmp_freelist->lock);
env_vfree(tmp_freelist->part);
env_vfree(tmp_freelist);
return result;
}
void ocf_freelist_deinit(ocf_freelist_t freelist)

View File

@ -13,7 +13,7 @@ struct ocf_freelist;
typedef struct ocf_freelist *ocf_freelist_t;
/* Init / deinit freelist runtime structures */
ocf_freelist_t ocf_freelist_init(struct ocf_cache *cache);
int ocf_freelist_init(ocf_freelist_t *freelist, struct ocf_cache *cache);
void ocf_freelist_deinit(ocf_freelist_t freelist);
/* Assign unused cachelines to freelist */

View File

@ -122,7 +122,7 @@ static void ocf_freelist_get_cache_line_get_fast(void **state)
will_return_maybe(__wrap_env_get_execution_context_count, num_ctxts);
will_return_maybe(__wrap_metadata_test_valid_any, false);
freelist = ocf_freelist_init(NULL);
ocf_freelist_init(&freelist, NULL);
ocf_freelist_populate(freelist, num_cls);
@ -224,7 +224,7 @@ static void ocf_freelist_get_cache_line_get_slow(void **state)
/* always return exec ctx 0 */
will_return_maybe(__wrap_env_get_execution_context, 0);
freelist = ocf_freelist_init(NULL);
ocf_freelist_init(&freelist, NULL);
ocf_freelist_populate(freelist, num_cls);
@ -308,7 +308,7 @@ static void ocf_freelist_get_cache_line_put(void **state)
will_return_maybe(__wrap_env_get_execution_context_count, num_ctxts);
will_return_maybe(__wrap_metadata_test_valid_any, false);
freelist = ocf_freelist_init(NULL);
ocf_freelist_init(&freelist, NULL);
ocf_freelist_populate(freelist, num_cls);

View File

@ -50,7 +50,7 @@ static void ocf_freelist_init_test01(void **state)
expect_function_call(__wrap_env_get_execution_context_count);
will_return(__wrap_env_get_execution_context_count, num_ctxts);
freelist = ocf_freelist_init(cache);
ocf_freelist_init(&freelist, cache);
assert(freelist != NULL);
ocf_freelist_deinit(freelist);

View File

@ -136,7 +136,7 @@ static void ocf_freelist_get_put_locks(void **state)
/* simulate context 1 for the entire test duration */
will_return_maybe(__wrap_env_get_execution_context, 1);
freelist = ocf_freelist_init(NULL);
ocf_freelist_init(&freelist, NULL);
ocf_freelist_populate(freelist, num_cls);

View File

@ -76,7 +76,7 @@ static void ocf_freelist_populate_test01(void **state)
will_return_maybe(__wrap_env_get_execution_context_count, num_ctxts);
will_return_maybe(__wrap_metadata_test_valid_any, false);
freelist = ocf_freelist_init(NULL);
ocf_freelist_init(&freelist, NULL);
expect_set_info(0, PARTITION_INVALID, 1 , num_cls);
expect_set_info(1, PARTITION_INVALID, 2 , 0);
@ -104,7 +104,7 @@ static void ocf_freelist_populate_test02(void **state)
will_return_maybe(__wrap_ocf_metadata_collision_table_entries, num_cls);
will_return_maybe(__wrap_env_get_execution_context_count, num_ctxts);
freelist = ocf_freelist_init(NULL);
ocf_freelist_init(&freelist, NULL);
/* simulate only cachelines 2, 3, 4, 7 invalid */
will_return(__wrap_metadata_test_valid_any, true);