From b16ff123b7f2509940b16a2339b448163e7a07da Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Tue, 11 Aug 2020 22:42:32 +0800 Subject: [PATCH] [thin] Stop metadata counting on the first error --- thin-provisioning/metadata_checker.cc | 6 ++++-- thin-provisioning/metadata_counter.cc | 28 ++++++++++++++++++++------- thin-provisioning/metadata_counter.h | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/thin-provisioning/metadata_checker.cc b/thin-provisioning/metadata_checker.cc index b2101aa..23ce449 100644 --- a/thin-provisioning/metadata_checker.cc +++ b/thin-provisioning/metadata_checker.cc @@ -296,7 +296,8 @@ namespace { out << "checking space map counts" << end_message(); nested_output::nest _ = out.push(); - count_metadata(tm, sb, bc); + if (!count_metadata(tm, sb, bc)) + return FATAL; // Finally we need to check the metadata space map agrees // with the counts we've just calculated. @@ -358,6 +359,7 @@ namespace { options_(check_opts), out_(cerr, 2), info_out_(cout, 0), + expected_rc_(true), // set stop on the first error err_(NO_ERROR) { if (output_opts == OUTPUT_QUIET) { @@ -398,7 +400,7 @@ namespace { err_ << examine_metadata_space_map(tm, sb, options_.sm_opts_, out_, expected_rc_); // check the data space map - if (core_sm) + if (err_ != FATAL && core_sm) err_ << compare_space_maps(data_sm, *core_sm, out_); } else err_ << examine_data_mappings(tm, sb, options_.data_mapping_opts_, out_, diff --git a/thin-provisioning/metadata_counter.cc b/thin-provisioning/metadata_counter.cc index 95487d2..9014402 100644 --- a/thin-provisioning/metadata_counter.cc +++ b/thin-provisioning/metadata_counter.cc @@ -8,7 +8,7 @@ using namespace thin_provisioning; //---------------------------------------------------------------- namespace { - void count_trees(transaction_manager::ptr tm, + bool count_trees(transaction_manager::ptr tm, superblock_detail::superblock const &sb, block_counter &bc) { @@ -27,11 +27,15 @@ namespace { mapping_tree_detail::block_traits::ref_counter(space_map::ptr())); count_btree_blocks(mtree, bc, vc); } + + return true; } - void count_space_maps(transaction_manager::ptr tm, + bool count_space_maps(transaction_manager::ptr tm, superblock_detail::superblock const &sb, block_counter &bc) { + bool ret = true; + // Count the metadata space map (no-throw) try { persistent_space_map::ptr metadata_sm = @@ -39,36 +43,46 @@ namespace { metadata_sm->count_metadata(bc); } catch (std::exception &e) { cerr << e.what() << endl; + ret = false; } // Count the data space map (no-throw) - { + try { persistent_space_map::ptr data_sm = open_disk_sm(*tm, static_cast(&sb.data_space_map_root_)); data_sm->count_metadata(bc); + } catch (std::exception &e) { + cerr << e.what() << endl; + ret = false; } + + return ret; } } //---------------------------------------------------------------- -void thin_provisioning::count_metadata(transaction_manager::ptr tm, +bool thin_provisioning::count_metadata(transaction_manager::ptr tm, superblock_detail::superblock const &sb, block_counter &bc, bool skip_metadata_snap) { + bool ret = true; + // Count the superblock bc.inc(superblock_detail::SUPERBLOCK_LOCATION); - count_trees(tm, sb, bc); + ret &= count_trees(tm, sb, bc); // Count the metadata snap, if present if (!skip_metadata_snap && sb.metadata_snap_ != superblock_detail::SUPERBLOCK_LOCATION) { bc.inc(sb.metadata_snap_); superblock_detail::superblock snap = read_superblock(tm->get_bm(), sb.metadata_snap_); - count_trees(tm, snap, bc); + ret &= count_trees(tm, snap, bc); } - count_space_maps(tm, sb, bc); + ret &= count_space_maps(tm, sb, bc); + + return ret; } //---------------------------------------------------------------- diff --git a/thin-provisioning/metadata_counter.h b/thin-provisioning/metadata_counter.h index bc65ab9..c5916a6 100644 --- a/thin-provisioning/metadata_counter.h +++ b/thin-provisioning/metadata_counter.h @@ -7,7 +7,7 @@ //---------------------------------------------------------------- namespace thin_provisioning { - void count_metadata(transaction_manager::ptr tm, + bool count_metadata(transaction_manager::ptr tm, superblock_detail::superblock const &sb, block_counter &bc, bool skip_metadata_snap = false);