From c286041f2595c50ced44987343c81a34d7698c23 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Mon, 16 Aug 2021 18:16:29 +0800 Subject: [PATCH 1/5] [thin_repair/thin_dump] Fix sorting of data mapping candidates - Fix the references for sorting. The timestamp statistics is stored in node_info corresponding to the second element. - Fix the timestamp comparison routine. The mapping root with more recent blocks should have higher priority. --- thin-provisioning/metadata_dumper.cc | 37 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/thin-provisioning/metadata_dumper.cc b/thin-provisioning/metadata_dumper.cc index 665c762..37c6969 100644 --- a/thin-provisioning/metadata_dumper.cc +++ b/thin-provisioning/metadata_dumper.cc @@ -252,26 +252,33 @@ namespace { bool cmp_time_counts(pair const &lhs_pair, pair const &rhs_pair) { - auto const &lhs = lhs_pair.first.time_counts; - auto const &rhs = rhs_pair.first.time_counts; + auto const &lhs = lhs_pair.second.time_counts; + auto const &rhs = rhs_pair.second.time_counts; - for (auto lhs_it = lhs.crbegin(); lhs_it != lhs.crend(); lhs_it++) { - for (auto rhs_it = rhs.crbegin(); rhs_it != rhs.crend(); rhs_it++) { - if (lhs_it->first > rhs_it->first) - return true; - else if (rhs_it->first > lhs_it->first) - return false; + auto lhs_it = lhs.crbegin(); + auto rhs_it = rhs.crbegin(); + while (lhs_it != lhs.crend() && rhs_it != rhs.crend()) { - else if (lhs_it->second > rhs_it->second) - return true; + auto lhs_time = lhs_it->first; + auto rhs_time = rhs_it->first; + auto lhs_count = lhs_it->second; + auto rhs_count = rhs_it->second; - else if (rhs_it->second > lhs_it->second) - return false; - } - } + if (lhs_time > rhs_time) + return true; + else if (rhs_time > lhs_time) + return false; + else if (lhs_count > rhs_count) + return true; + else if (rhs_count > lhs_count) + return false; - return true; + lhs_it++; + rhs_it++; + } + + return (lhs_it != lhs.crend()) ? true : false; } class gatherer { From c2e6db74b9588c38d996943fdf7608adba4aef0a Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Tue, 17 Aug 2021 16:20:20 +0800 Subject: [PATCH 2/5] [thin_repair/thin_dump] Remove unused function parameter --- thin-provisioning/metadata_dumper.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thin-provisioning/metadata_dumper.cc b/thin-provisioning/metadata_dumper.cc index 37c6969..0811ef3 100644 --- a/thin-provisioning/metadata_dumper.cc +++ b/thin-provisioning/metadata_dumper.cc @@ -790,7 +790,7 @@ namespace { void emit_trees_(block_manager::ptr bm, superblock_detail::superblock const &sb, - emitter::ptr e, override_options const &ropts) + emitter::ptr e) { metadata md(bm, sb); dump_options opts; @@ -882,7 +882,7 @@ namespace { !get_map_ids(*tm, msb->data_mapping_root_)) find_better_roots_(bm, *msb); - emit_trees_(bm, *msb, e, opts); + emit_trees_(bm, *msb, e); } } From d1e8168fb65e363caac3cc4cc2cf1f8b38a1ae1c Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Thu, 19 Aug 2021 18:38:23 +0800 Subject: [PATCH 3/5] [thin_repair/thin_dump] Change the label type for empty leaves Empty leaves now are treated as bottom-level leaves, so that empty devices could be recovered. --- thin-provisioning/metadata_dumper.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/thin-provisioning/metadata_dumper.cc b/thin-provisioning/metadata_dumper.cc index 0811ef3..da4eef5 100644 --- a/thin-provisioning/metadata_dumper.cc +++ b/thin-provisioning/metadata_dumper.cc @@ -438,6 +438,14 @@ namespace { // in the bottom 24 bits. This means every block/time apart from block 0 // will result in a value that's outside the range of the metadata device. bool is_top_level(node_ref &n) { + // A leaf node of value-size 8 and without mappings should be + // treated as a bottom-level leaf, so that it could be referenced + // by top-level nodes, if any. On the other hand, an empty + // top-level leaf doesn't help repairing. + if (!n.get_nr_entries()) { + return false; + } + auto nr_metadata_blocks = bm_.get_nr_blocks(); for (unsigned i = 0; i < n.get_nr_entries(); i++) From d2d6ab79266fb8778c67b803d654eefdc94791f6 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Tue, 24 Aug 2021 16:20:50 +0800 Subject: [PATCH 4/5] [thin_repair/thin_dump] Check consistency of thin_ids before running a regular dump --- thin-provisioning/metadata_dumper.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/thin-provisioning/metadata_dumper.cc b/thin-provisioning/metadata_dumper.cc index da4eef5..b62d131 100644 --- a/thin-provisioning/metadata_dumper.cc +++ b/thin-provisioning/metadata_dumper.cc @@ -412,6 +412,9 @@ namespace { if (rhs == ms.end()) continue; + if (lhs->second != rhs->second) + continue; + filtered.push_back(make_pair(p.first.b, p.second.b)); } @@ -886,8 +889,9 @@ namespace { auto tm = open_tm(bm, superblock_detail::SUPERBLOCK_LOCATION); - if (!get_dev_ids(*tm, msb->device_details_root_) || - !get_map_ids(*tm, msb->data_mapping_root_)) + auto maybe_dev_ids = get_dev_ids(*tm, msb->device_details_root_); + auto maybe_map_ids = get_map_ids(*tm, msb->data_mapping_root_); + if (!maybe_dev_ids || !maybe_map_ids || (*maybe_dev_ids) != (*maybe_map_ids)) find_better_roots_(bm, *msb); emit_trees_(bm, *msb, e); From e6f17d4b4f8bb23bf4f48e66eddd7110260790b6 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Tue, 24 Aug 2021 20:59:47 +0800 Subject: [PATCH 5/5] [thin_repair/thin_dump] Exclude unwanted btree nodes --- thin-provisioning/metadata_dumper.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/thin-provisioning/metadata_dumper.cc b/thin-provisioning/metadata_dumper.cc index b62d131..d80359e 100644 --- a/thin-provisioning/metadata_dumper.cc +++ b/thin-provisioning/metadata_dumper.cc @@ -597,6 +597,8 @@ namespace { info.nr_mappings = n.get_nr_entries(); } + } else { + fail(info, "not the value size of interest"); } return info;