diff --git a/src/metadata/metadata.c b/src/metadata/metadata.c index 5779aa2..aa72c12 100644 --- a/src/metadata/metadata.c +++ b/src/metadata/metadata.c @@ -976,7 +976,6 @@ struct ocf_pipeline_arg ocf_metadata_flush_all_args[] = { OCF_PL_ARG_INT(metadata_segment_sb_runtime), OCF_PL_ARG_INT(metadata_segment_part_runtime), OCF_PL_ARG_INT(metadata_segment_core_runtime), - OCF_PL_ARG_INT(metadata_segment_cleaning), OCF_PL_ARG_INT(metadata_segment_lru), OCF_PL_ARG_INT(metadata_segment_collision), OCF_PL_ARG_INT(metadata_segment_list_info), @@ -984,12 +983,31 @@ struct ocf_pipeline_arg ocf_metadata_flush_all_args[] = { OCF_PL_ARG_TERMINATOR(), }; +/* + * Predicate function checking whether disable cleaner option is set + */ +static bool ocf_check_if_cleaner_enabled(ocf_pipeline_t pipeline, + void* priv, ocf_pipeline_arg_t arg) +{ + struct ocf_metadata_context *context = priv; + + return !context->cache->conf_meta->cleaner_disabled; +} + struct ocf_pipeline_properties ocf_metadata_flush_all_pipeline_props = { .priv_size = sizeof(struct ocf_metadata_context), .finish = ocf_metadata_flush_all_finish, .steps = { + + OCF_PL_STEP_COND_ARG_INT(ocf_check_if_cleaner_enabled, + ocf_metadata_flush_segment, + metadata_segment_cleaning), OCF_PL_STEP_FOREACH(ocf_metadata_flush_segment, ocf_metadata_flush_all_args), + + OCF_PL_STEP_COND_ARG_INT(ocf_check_if_cleaner_enabled, + ocf_metadata_calculate_crc, + metadata_segment_cleaning), OCF_PL_STEP_FOREACH(ocf_metadata_calculate_crc, ocf_metadata_flush_all_args), OCF_PL_STEP_ARG_INT(ocf_metadata_flush_all_set_status, @@ -1118,7 +1136,6 @@ out: struct ocf_pipeline_arg ocf_metadata_load_all_args[] = { OCF_PL_ARG_INT(metadata_segment_core_runtime), - OCF_PL_ARG_INT(metadata_segment_cleaning), OCF_PL_ARG_INT(metadata_segment_lru), OCF_PL_ARG_INT(metadata_segment_collision), OCF_PL_ARG_INT(metadata_segment_list_info), @@ -1130,8 +1147,15 @@ struct ocf_pipeline_properties ocf_metadata_load_all_pipeline_props = { .priv_size = sizeof(struct ocf_metadata_context), .finish = ocf_metadata_load_all_finish, .steps = { + OCF_PL_STEP_COND_ARG_INT(ocf_check_if_cleaner_enabled, + ocf_metadata_load_segment, + metadata_segment_cleaning), OCF_PL_STEP_FOREACH(ocf_metadata_load_segment, ocf_metadata_load_all_args), + + OCF_PL_STEP_COND_ARG_INT(ocf_check_if_cleaner_enabled, + ocf_metadata_check_crc, + metadata_segment_cleaning), OCF_PL_STEP_FOREACH(ocf_metadata_check_crc, ocf_metadata_load_all_args), OCF_PL_STEP_TERMINATOR(), diff --git a/src/utils/utils_pipeline.c b/src/utils/utils_pipeline.c index bb7cd04..5c4baef 100644 --- a/src/utils/utils_pipeline.c +++ b/src/utils/utils_pipeline.c @@ -1,5 +1,5 @@ /* - * Copyright(c) 2019-2021 Intel Corporation + * Copyright(c) 2019-2022 Intel Corporation * SPDX-License-Identifier: BSD-3-Clause */ @@ -39,6 +39,13 @@ static int _ocf_pipeline_run_step(struct ocf_request *req) pipeline->next_step++; step->hndl(pipeline, pipeline->priv, &step->arg); return 0; + case ocf_pipeline_step_conditional: + pipeline->next_step++; + if (step->pred(pipeline, pipeline->priv, &step->arg)) { + step->hndl(pipeline, pipeline->priv, &step->arg); + return 0; + } + continue; case ocf_pipeline_step_foreach: arg = &step->args[pipeline->next_arg++]; if (arg->type == ocf_pipeline_arg_terminator) { diff --git a/src/utils/utils_pipeline.h b/src/utils/utils_pipeline.h index 1b03ae3..bbf41c9 100644 --- a/src/utils/utils_pipeline.h +++ b/src/utils/utils_pipeline.h @@ -1,5 +1,5 @@ /* - * Copyright(c) 2019-2021 Intel Corporation + * Copyright(c) 2019-2022 Intel Corporation * SPDX-License-Identifier: BSD-3-Clause */ @@ -11,6 +11,7 @@ enum ocf_pipeline_step_type { ocf_pipeline_step_single, ocf_pipeline_step_foreach, + ocf_pipeline_step_conditional, ocf_pipeline_step_terminator, }; @@ -65,9 +66,13 @@ typedef void (*ocf_pipeline_step_hndl_t)(ocf_pipeline_t pipeline, typedef void (*ocf_pipeline_finish_t)(ocf_pipeline_t pipeline, void *priv, int error); +typedef bool (*ocf_pipeline_cond_step_predicate_t)(ocf_pipeline_t pipeline, + void *priv, ocf_pipeline_arg_t arg); + struct ocf_pipeline_step { enum ocf_pipeline_step_type type; ocf_pipeline_step_hndl_t hndl; + ocf_pipeline_cond_step_predicate_t pred; union { struct ocf_pipeline_arg arg; struct ocf_pipeline_arg *args; @@ -112,6 +117,35 @@ struct ocf_pipeline_step { .type = ocf_pipeline_step_terminator, \ } +#define OCF_PL_STEP_COND(_pred, _hndl) \ + { \ + .pred = _pred, \ + .type = ocf_pipeline_step_conditional, \ + .hndl = _hndl, \ + } + +#define OCF_PL_STEP_COND_ARG_INT(_pred, _hndl, _int) \ + { \ + .pred = _pred, \ + .type = ocf_pipeline_step_conditional, \ + .hndl = _hndl, \ + .arg = { \ + .type = ocf_pipeline_arg_int, \ + .val.i = _int, \ + } \ + } + +#define OCF_PL_STEP_COND_ARG_PTR(_pred, _hndl, _ptr) \ + { \ + .pred = _pred, \ + .type = ocf_pipeline_step_conditional, \ + .hndl = _hndl, \ + .arg = { \ + .type = ocf_pipeline_arg_ptr, \ + .val.p = _ptr, \ + } \ + } + struct ocf_pipeline_properties { uint32_t priv_size; ocf_pipeline_finish_t finish;