Return error status from ocf_freelist_init
Signed-off-by: Rafal Stefanowski <rafal.stefanowski@intel.com>
This commit is contained in:
parent
d3b61e474c
commit
57d4aaf7c9
@ -995,9 +995,9 @@ static void _ocf_mngt_attach_prepare_metadata(ocf_pipeline_t pipeline,
|
|||||||
|
|
||||||
context->flags.attached_metadata_inited = true;
|
context->flags.attached_metadata_inited = true;
|
||||||
|
|
||||||
cache->freelist = ocf_freelist_init(cache);
|
ret = ocf_freelist_init(&cache->freelist, cache);
|
||||||
if (!cache->freelist)
|
if (ret)
|
||||||
OCF_PL_FINISH_RET(pipeline, -OCF_ERR_START_CACHE_FAIL);
|
OCF_PL_FINISH_RET(pipeline, ret);
|
||||||
|
|
||||||
context->flags.freelist_inited = true;
|
context->flags.freelist_inited = true;
|
||||||
|
|
||||||
|
@ -365,48 +365,53 @@ void ocf_freelist_put_cache_line(ocf_freelist_t freelist,
|
|||||||
env_put_execution_context(ctx);
|
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;
|
uint32_t num;
|
||||||
int i;
|
int i;
|
||||||
ocf_freelist_t freelist;
|
int result;
|
||||||
|
ocf_freelist_t tmp_freelist;
|
||||||
ocf_cache_line_t line_entries = ocf_metadata_collision_table_entries(
|
ocf_cache_line_t line_entries = ocf_metadata_collision_table_entries(
|
||||||
cache);
|
cache);
|
||||||
|
|
||||||
freelist = env_vzalloc(sizeof(*freelist));
|
tmp_freelist = env_vzalloc(sizeof(*tmp_freelist));
|
||||||
if (!freelist)
|
if (!tmp_freelist)
|
||||||
return NULL;
|
return -OCF_ERR_NO_MEM;
|
||||||
|
|
||||||
num = env_get_execution_context_count();
|
num = env_get_execution_context_count();
|
||||||
|
|
||||||
freelist->cache = cache;
|
tmp_freelist->cache = cache;
|
||||||
freelist->count = num;
|
tmp_freelist->count = num;
|
||||||
env_atomic64_set(&freelist->total_free, 0);
|
env_atomic64_set(&tmp_freelist->total_free, 0);
|
||||||
freelist->lock = env_vzalloc(sizeof(freelist->lock[0]) * num);
|
tmp_freelist->lock = env_vzalloc(sizeof(tmp_freelist->lock[0]) * num);
|
||||||
freelist->part = env_vzalloc(sizeof(freelist->part[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;
|
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:
|
spinlock_err:
|
||||||
while (i--)
|
while (i--)
|
||||||
env_spinlock_destroy(&freelist->lock[i]);
|
env_spinlock_destroy(&tmp_freelist->lock[i]);
|
||||||
free_allocs:
|
free_allocs:
|
||||||
env_vfree(freelist->lock);
|
env_vfree(tmp_freelist->lock);
|
||||||
env_vfree(freelist->part);
|
env_vfree(tmp_freelist->part);
|
||||||
env_vfree(freelist);
|
env_vfree(tmp_freelist);
|
||||||
return NULL;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ocf_freelist_deinit(ocf_freelist_t freelist)
|
void ocf_freelist_deinit(ocf_freelist_t freelist)
|
||||||
|
@ -13,7 +13,7 @@ struct ocf_freelist;
|
|||||||
typedef struct ocf_freelist *ocf_freelist_t;
|
typedef struct ocf_freelist *ocf_freelist_t;
|
||||||
|
|
||||||
/* Init / deinit freelist runtime structures */
|
/* 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);
|
void ocf_freelist_deinit(ocf_freelist_t freelist);
|
||||||
|
|
||||||
/* Assign unused cachelines to freelist */
|
/* Assign unused cachelines to freelist */
|
||||||
|
@ -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_env_get_execution_context_count, num_ctxts);
|
||||||
will_return_maybe(__wrap_metadata_test_valid_any, false);
|
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);
|
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 */
|
/* always return exec ctx 0 */
|
||||||
will_return_maybe(__wrap_env_get_execution_context, 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);
|
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_env_get_execution_context_count, num_ctxts);
|
||||||
will_return_maybe(__wrap_metadata_test_valid_any, false);
|
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);
|
ocf_freelist_populate(freelist, num_cls);
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ static void ocf_freelist_init_test01(void **state)
|
|||||||
expect_function_call(__wrap_env_get_execution_context_count);
|
expect_function_call(__wrap_env_get_execution_context_count);
|
||||||
will_return(__wrap_env_get_execution_context_count, num_ctxts);
|
will_return(__wrap_env_get_execution_context_count, num_ctxts);
|
||||||
|
|
||||||
freelist = ocf_freelist_init(cache);
|
ocf_freelist_init(&freelist, cache);
|
||||||
assert(freelist != NULL);
|
assert(freelist != NULL);
|
||||||
|
|
||||||
ocf_freelist_deinit(freelist);
|
ocf_freelist_deinit(freelist);
|
||||||
|
@ -136,7 +136,7 @@ static void ocf_freelist_get_put_locks(void **state)
|
|||||||
/* simulate context 1 for the entire test duration */
|
/* simulate context 1 for the entire test duration */
|
||||||
will_return_maybe(__wrap_env_get_execution_context, 1);
|
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);
|
ocf_freelist_populate(freelist, num_cls);
|
||||||
|
|
||||||
|
@ -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_env_get_execution_context_count, num_ctxts);
|
||||||
will_return_maybe(__wrap_metadata_test_valid_any, false);
|
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(0, PARTITION_INVALID, 1 , num_cls);
|
||||||
expect_set_info(1, PARTITION_INVALID, 2 , 0);
|
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_ocf_metadata_collision_table_entries, num_cls);
|
||||||
will_return_maybe(__wrap_env_get_execution_context_count, num_ctxts);
|
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 */
|
/* simulate only cachelines 2, 3, 4, 7 invalid */
|
||||||
will_return(__wrap_metadata_test_valid_any, true);
|
will_return(__wrap_metadata_test_valid_any, true);
|
||||||
|
Loading…
Reference in New Issue
Block a user