Introduce OCF_CMPL_RET() macro

This simplifies cases when we want to call completion callback
and immediately return from void-returning function, by allowing
to explicitly express programmers intent. That way we can avoid
cases when return statement is missing by mistake (this patch
fixes at least one bug related to this).

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga
2019-05-02 15:43:38 +02:00
parent bcb2e670f3
commit 1373471af7
9 changed files with 114 additions and 192 deletions

View File

@@ -1631,10 +1631,8 @@ static void _ocf_mngt_cache_attach(ocf_cache_t cache,
result = ocf_pipeline_create(&pipeline, cache,
&_ocf_mngt_cache_attach_pipeline_properties);
if (result) {
cmpl(cache, priv1, priv2, -OCF_ERR_NO_MEM);
return;
}
if (result)
OCF_CMPL_RET(cache, priv1, priv2, -OCF_ERR_NO_MEM);
context = ocf_pipeline_get_priv(pipeline);
@@ -1675,7 +1673,7 @@ err_uuid:
env_vfree(data);
err_pipeline:
ocf_pipeline_destroy(pipeline);
cmpl(cache, priv1, priv2, result);
OCF_CMPL_RET(cache, priv1, priv2, result);
}
static int _ocf_mngt_cache_validate_cfg(struct ocf_mngt_cache_config *cfg)
@@ -1794,7 +1792,7 @@ static void _ocf_mngt_cache_attach_complete(ocf_cache_t cache, void *priv1,
"failed\n");
}
cmpl(cache, priv2, error);
OCF_CMPL_RET(cache, priv2, error);
}
void ocf_mngt_cache_attach(ocf_cache_t cache,
@@ -1807,10 +1805,8 @@ void ocf_mngt_cache_attach(ocf_cache_t cache,
OCF_CHECK_NULL(cfg);
result = _ocf_mngt_cache_validate_device_cfg(cfg);
if (result) {
cmpl(cache, priv, result);
return;
}
if (result)
OCF_CMPL_RET(cache, priv, result);
_ocf_mngt_cache_attach(cache, cfg, false,
_ocf_mngt_cache_attach_complete, cmpl, priv);
@@ -1927,15 +1923,13 @@ static void _ocf_mngt_cache_load_complete(ocf_cache_t cache, void *priv1,
{
ocf_mngt_cache_load_end_t cmpl = priv1;
if (error) {
cmpl(cache, priv2, error);
return;
}
if (error)
OCF_CMPL_RET(cache, priv2, error);
_ocf_mng_cache_set_valid(cache);
_ocf_mngt_cache_load_log(cache);
cmpl(cache, priv2, 0);
OCF_CMPL_RET(cache, priv2, 0);
}
void ocf_mngt_cache_load(ocf_cache_t cache,
@@ -1949,13 +1943,11 @@ void ocf_mngt_cache_load(ocf_cache_t cache,
/* Load is not allowed in volatile metadata mode */
if (cache->metadata.is_volatile)
cmpl(cache, priv, -EINVAL);
OCF_CMPL_RET(cache, priv, -EINVAL);
result = _ocf_mngt_cache_validate_device_cfg(cfg);
if (result) {
cmpl(cache, priv, result);
return;
}
if (result)
OCF_CMPL_RET(cache, priv, result);
_ocf_mngt_cache_attach(cache, cfg, true,
_ocf_mngt_cache_load_complete, cmpl, priv);
@@ -2119,10 +2111,8 @@ void ocf_mngt_cache_stop(ocf_cache_t cache,
result = ocf_pipeline_create(&pipeline, cache,
&ocf_mngt_cache_stop_pipeline_properties);
if (result) {
cmpl(cache, priv, -OCF_ERR_NO_MEM);
return;
}
if (result)
OCF_CMPL_RET(cache, priv, -OCF_ERR_NO_MEM);
context = ocf_pipeline_get_priv(pipeline);
@@ -2136,8 +2126,7 @@ void ocf_mngt_cache_stop(ocf_cache_t cache,
ocf_cache_get_name(cache), sizeof(context->cache_name));
if (result) {
ocf_pipeline_destroy(pipeline);
cmpl(cache, priv, -OCF_ERR_NO_MEM);
return;
OCF_CMPL_RET(cache, priv, -OCF_ERR_NO_MEM);
}
ocf_cache_log(cache, log_info, "Stopping cache\n");
@@ -2200,10 +2189,8 @@ void ocf_mngt_cache_save(ocf_cache_t cache,
result = ocf_pipeline_create(&pipeline, cache,
&ocf_mngt_cache_save_pipeline_properties);
if (result) {
cmpl(cache, priv, result);
return;
}
if (result)
OCF_CMPL_RET(cache, priv, result);
context = ocf_pipeline_get_priv(pipeline);
@@ -2475,17 +2462,13 @@ void ocf_mngt_cache_detach(ocf_cache_t cache,
OCF_CHECK_NULL(cache);
if (!env_atomic_read(&cache->attached)) {
cmpl(cache, priv, -OCF_ERR_INVAL);
return;
}
if (!env_atomic_read(&cache->attached))
OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL);
result = ocf_pipeline_create(&pipeline, cache,
&ocf_mngt_cache_detach_pipeline_properties);
if (result) {
cmpl(cache, priv, -OCF_ERR_NO_MEM);
return;
}
if (result)
OCF_CMPL_RET(cache, priv, -OCF_ERR_NO_MEM);
context = ocf_pipeline_get_priv(pipeline);

View File

@@ -551,10 +551,8 @@ void ocf_mngt_cache_add_core(ocf_cache_t cache,
result = ocf_pipeline_create(&pipeline, cache,
&ocf_mngt_cache_add_core_pipeline_properties);
if (result) {
cmpl(cache, NULL, priv, -OCF_ERR_NO_MEM);
return;
}
if (result)
OCF_CMPL_RET(cache, NULL, priv, -OCF_ERR_NO_MEM);
context = ocf_pipeline_get_priv(pipeline);
@@ -585,7 +583,7 @@ err_uuid:
env_vfree(data);
err_pipeline:
ocf_pipeline_destroy(context->pipeline);
cmpl(cache, NULL, priv, result);
OCF_CMPL_RET(cache, NULL, priv, result);
}
/*
@@ -671,17 +669,13 @@ void ocf_mngt_cache_remove_core(ocf_core_t core,
core_id = ocf_core_get_id(core);
/* TODO: Make this asynchronous */
if (_ocf_cleaning_wait_for_finish(cache, 60 * 1000)) {
cmpl(priv, -OCF_ERR_CACHE_IN_USE);
return;
}
if (_ocf_cleaning_wait_for_finish(cache, 60 * 1000))
OCF_CMPL_RET(priv, -OCF_ERR_CACHE_IN_USE);
result = ocf_pipeline_create(&pipeline, cache,
&ocf_mngt_cache_remove_core_pipeline_props);
if (result) {
cmpl(priv, result);
return;
}
if (result)
OCF_CMPL_RET(priv, result);
context = ocf_pipeline_get_priv(pipeline);
@@ -738,10 +732,8 @@ void ocf_mngt_cache_detach_core(ocf_core_t core,
core_name = ocf_core_get_name(core);
/* TODO: Make this asynchronous */
if (_ocf_cleaning_wait_for_finish(cache, 60 * 1000)) {
cmpl(priv, -OCF_ERR_CACHE_IN_USE);
return;
}
if (_ocf_cleaning_wait_for_finish(cache, 60 * 1000))
OCF_CMPL_RET(priv, -OCF_ERR_CACHE_IN_USE);
ocf_core_log(core, log_debug, "Detaching core\n");
@@ -754,7 +746,7 @@ void ocf_mngt_cache_detach_core(ocf_core_t core,
core_name);
}
cmpl(priv, result);
OCF_CMPL_RET(priv, result);
}
int ocf_mngt_core_set_uuid(ocf_core_t core, const struct ocf_volume_uuid *uuid)

View File

@@ -671,30 +671,26 @@ void ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption,
if (!ocf_cache_is_device_attached(cache)) {
ocf_cache_log(cache, log_err, "Cannot flush cache - "
"cache device is detached\n");
cmpl(cache, priv, -OCF_ERR_INVAL);
return;
OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL);
}
if (ocf_cache_is_incomplete(cache)) {
ocf_cache_log(cache, log_err, "Cannot flush cache - "
"cache is in incomplete state\n");
cmpl(cache, priv, -OCF_ERR_CACHE_IN_INCOMPLETE_STATE);
return;
OCF_CMPL_RET(cache, priv, -OCF_ERR_CACHE_IN_INCOMPLETE_STATE);
}
if (!cache->mngt_queue) {
ocf_cache_log(cache, log_err,
"Cannot flush cache - no flush queue set\n");
cmpl(cache, priv, -OCF_ERR_INVAL);
return;
OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL);
}
result = ocf_pipeline_create(&pipeline, cache,
&_ocf_mngt_cache_flush_pipeline_properties);
if (result) {
cmpl(cache, priv, -OCF_ERR_NO_MEM);
return;
}
if (result)
OCF_CMPL_RET(cache, priv, -OCF_ERR_NO_MEM);
context = ocf_pipeline_get_priv(pipeline);
context->pipeline = pipeline;
@@ -767,30 +763,26 @@ void ocf_mngt_core_flush(ocf_core_t core, bool interruption,
if (!ocf_cache_is_device_attached(cache)) {
ocf_cache_log(cache, log_err, "Cannot flush core - "
"cache device is detached\n");
cmpl(core, priv, -OCF_ERR_INVAL);
return;
OCF_CMPL_RET(core, priv, -OCF_ERR_INVAL);
}
if (!core->opened) {
ocf_core_log(core, log_err, "Cannot flush - core is in "
"inactive state\n");
cmpl(core, priv, -OCF_ERR_CORE_IN_INACTIVE_STATE);
return;
OCF_CMPL_RET(core, priv, -OCF_ERR_CORE_IN_INACTIVE_STATE);
}
if (!cache->mngt_queue) {
ocf_core_log(core, log_err,
"Cannot flush core - no flush queue set\n");
cmpl(core, priv, -OCF_ERR_INVAL);
return;
OCF_CMPL_RET(core, priv, -OCF_ERR_INVAL);
}
result = ocf_pipeline_create(&pipeline, cache,
&_ocf_mngt_core_flush_pipeline_properties);
if (result) {
cmpl(core, priv, -OCF_ERR_NO_MEM);
return;
}
if (result)
OCF_CMPL_RET(core, priv, -OCF_ERR_NO_MEM);
context = ocf_pipeline_get_priv(pipeline);
context->pipeline = pipeline;
@@ -846,16 +838,14 @@ void ocf_mngt_cache_purge(ocf_cache_t cache,
if (!cache->mngt_queue) {
ocf_cache_log(cache, log_err,
"Cannot purge cache - no flush queue set\n");
cmpl(cache, priv, -OCF_ERR_INVAL);
return;
OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL);
}
result = ocf_pipeline_create(&pipeline, cache,
&_ocf_mngt_cache_purge_pipeline_properties);
if (result) {
cmpl(cache, priv, -OCF_ERR_NO_MEM);
return;
}
if (result)
OCF_CMPL_RET(cache, priv, -OCF_ERR_NO_MEM);
context = ocf_pipeline_get_priv(pipeline);
context->pipeline = pipeline;
@@ -900,18 +890,15 @@ void ocf_mngt_core_purge(ocf_core_t core,
if (!cache->mngt_queue) {
ocf_core_log(core, log_err,
"Cannot purge core - no flush queue set\n");
cmpl(core, priv, -OCF_ERR_INVAL);
return;
OCF_CMPL_RET(core, priv, -OCF_ERR_INVAL);
}
core_size = ocf_volume_get_length(&cache->core[core_id].volume);
result = ocf_pipeline_create(&pipeline, cache,
&_ocf_mngt_core_purge_pipeline_properties);
if (result) {
cmpl(core, priv, -OCF_ERR_NO_MEM);
return;
}
if (result)
OCF_CMPL_RET(core, priv, -OCF_ERR_NO_MEM);
context = ocf_pipeline_get_priv(pipeline);