From 1a27b07f72019c9782f611efe744cd87a894cecb Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Mon, 13 Jun 2022 12:44:18 +0200 Subject: [PATCH 1/2] Pipeline conditional step Signed-off-by: Adam Rutkowski Signed-off-by: Piotr Debski --- src/metadata/metadata.c | 17 ++++++++++++++--- src/utils/utils_pipeline.c | 9 ++++++++- src/utils/utils_pipeline.h | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/metadata/metadata.c b/src/metadata/metadata.c index 5779aa2..803cbec 100644 --- a/src/metadata/metadata.c +++ b/src/metadata/metadata.c @@ -1118,7 +1118,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), @@ -1126,14 +1125,26 @@ struct ocf_pipeline_arg ocf_metadata_load_all_args[] = { OCF_PL_ARG_TERMINATOR(), }; +static bool ocf_metadata_check_disabled_segment(ocf_pipeline_t pipeline, + ocf_pipeline_arg_t arg) +{ + .... +} + 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_CONDITIONAL(ocf_metadata_load_segment, + metadata_segment_cleaning, + ocf_metadata_check_disabled_segment), OCF_PL_STEP_FOREACH(ocf_metadata_load_segment, - ocf_metadata_load_all_args), + ocf_metadata_load_all_args, + + // conditional sfor cleaning OCF_PL_STEP_FOREACH(ocf_metadata_check_crc, - ocf_metadata_load_all_args), + ocf_metadata_load_all_args, + checker), 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; From c448043b42598c6bd1c1caee8901a1608f901173 Mon Sep 17 00:00:00 2001 From: Piotr Debski Date: Tue, 14 Jun 2022 11:02:55 +0200 Subject: [PATCH 2/2] Conditional pipeline step for filtering invalid segments Signed-off-by: Piotr Debski --- src/metadata/metadata.c | 43 +++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/metadata/metadata.c b/src/metadata/metadata.c index 803cbec..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, @@ -1125,26 +1143,21 @@ struct ocf_pipeline_arg ocf_metadata_load_all_args[] = { OCF_PL_ARG_TERMINATOR(), }; -static bool ocf_metadata_check_disabled_segment(ocf_pipeline_t pipeline, - ocf_pipeline_arg_t arg) -{ - .... -} - 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_CONDITIONAL(ocf_metadata_load_segment, - metadata_segment_cleaning, - ocf_metadata_check_disabled_segment), + 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, - - // conditional sfor cleaning + 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, - checker), + ocf_metadata_load_all_args), OCF_PL_STEP_TERMINATOR(), }, };