From d946124a01c39939e133557d6ea11aa7656700a9 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Wed, 22 Jul 2020 22:40:41 +0200 Subject: [PATCH] Calculate CRC for runtime metadata sections only on clean load During recovery procedure there is no guarantee that checksums of runtime sections were flushed correctly before dirty shutdown. Signed-off-by: Robert Baldyga --- src/metadata/metadata_hash.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/metadata/metadata_hash.c b/src/metadata/metadata_hash.c index 9f4b971..b9f1b4b 100644 --- a/src/metadata/metadata_hash.c +++ b/src/metadata/metadata_hash.c @@ -1273,8 +1273,8 @@ static void ocf_medatata_hash_check_crc_sb_config(ocf_pipeline_t pipeline, ocf_pipeline_next(pipeline); } -static void ocf_medatata_hash_check_crc(ocf_pipeline_t pipeline, - void *priv, ocf_pipeline_arg_t arg) +static void ocf_medatata_hash_check_crc_skip(ocf_pipeline_t pipeline, + void *priv, ocf_pipeline_arg_t arg, bool skip_on_dirty_shutdown) { struct ocf_metadata_hash_context *context = priv; int segment = ocf_pipeline_arg_get_int(arg); @@ -1286,6 +1286,9 @@ static void ocf_medatata_hash_check_crc(ocf_pipeline_t pipeline, ctrl = (struct ocf_metadata_hash_ctrl *)cache->metadata.iface_priv; sb_config = METADATA_MEM_POOL(ctrl, metadata_segment_sb_config); + if (!sb_config->clean_shutdown && skip_on_dirty_shutdown) + OCF_PL_NEXT_RET(pipeline); + crc = ocf_metadata_raw_checksum(cache, &(ctrl->raw_desc[segment])); if (crc != sb_config->checksum[segment]) { @@ -1299,6 +1302,18 @@ static void ocf_medatata_hash_check_crc(ocf_pipeline_t pipeline, ocf_pipeline_next(pipeline); } +static void ocf_medatata_hash_check_crc(ocf_pipeline_t pipeline, + void *priv, ocf_pipeline_arg_t arg) +{ + ocf_medatata_hash_check_crc_skip(pipeline, priv, arg, false); +} + +static void ocf_medatata_hash_check_crc_if_clean(ocf_pipeline_t pipeline, + void *priv, ocf_pipeline_arg_t arg) +{ + ocf_medatata_hash_check_crc_skip(pipeline, priv, arg, true); +} + static void ocf_medatata_hash_load_superblock_post(ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg) { @@ -1409,14 +1424,18 @@ struct ocf_pipeline_arg ocf_metadata_hash_load_sb_load_segment_args[] = { }; struct ocf_pipeline_arg ocf_metadata_hash_load_sb_check_crc_args[] = { - OCF_PL_ARG_INT(metadata_segment_sb_runtime), OCF_PL_ARG_INT(metadata_segment_part_config), - OCF_PL_ARG_INT(metadata_segment_part_runtime), OCF_PL_ARG_INT(metadata_segment_core_config), OCF_PL_ARG_INT(metadata_segment_core_uuid), OCF_PL_ARG_TERMINATOR(), }; +struct ocf_pipeline_arg ocf_metadata_hash_load_sb_check_crc_args_clean[] = { + OCF_PL_ARG_INT(metadata_segment_sb_runtime), + OCF_PL_ARG_INT(metadata_segment_part_runtime), + OCF_PL_ARG_TERMINATOR(), +}; + struct ocf_pipeline_properties ocf_metadata_hash_load_sb_pipeline_props = { .priv_size = sizeof(struct ocf_metadata_hash_context), .finish = ocf_metadata_hash_load_superblock_finish, @@ -1428,6 +1447,8 @@ struct ocf_pipeline_properties ocf_metadata_hash_load_sb_pipeline_props = { OCF_PL_STEP(ocf_medatata_hash_check_crc_sb_config), OCF_PL_STEP_FOREACH(ocf_medatata_hash_check_crc, ocf_metadata_hash_load_sb_check_crc_args), + OCF_PL_STEP_FOREACH(ocf_medatata_hash_check_crc_if_clean, + ocf_metadata_hash_load_sb_check_crc_args_clean), OCF_PL_STEP(ocf_medatata_hash_load_superblock_post), OCF_PL_STEP_TERMINATOR(), },