From b0e2d0e6a054c1925695b02693863234745528a8 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Mon, 21 Mar 2016 17:17:57 +0000 Subject: [PATCH] [thin_repair, metadata] Try harder to get the number of data blocks when opening the metadata. --- thin-provisioning/metadata_dumper.cc | 28 +++++++++++++++++++++------- thin-provisioning/thin_repair.cc | 6 +----- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/thin-provisioning/metadata_dumper.cc b/thin-provisioning/metadata_dumper.cc index 0c0fbe4..7bb9361 100644 --- a/thin-provisioning/metadata_dumper.cc +++ b/thin-provisioning/metadata_dumper.cc @@ -185,8 +185,13 @@ namespace { d.creation_time_, d.snapshotted_time_); - emit_mappings(tree_root); - + try { + emit_mappings(tree_root); + } catch (exception &e) { + cerr << e.what(); + e_->end_device(); + throw; + } e_->end_device(); } else if (!repair_) { @@ -211,6 +216,19 @@ namespace { bool repair_; mapping_tree_detail::damage_visitor::ptr damage_policy_; }; + + block_address get_nr_blocks(metadata::ptr md) { + if (md->data_sm_) + return md->data_sm_->get_nr_blocks(); + + else if (md->sb_.blocknr_ == superblock_detail::SUPERBLOCK_LOCATION) + // grab from the root structure of the space map + return get_nr_blocks_in_data_sm(*md->tm_, &md->sb_.data_space_map_root_); + + else + // metadata snap, we really don't know + return 0ull; + } } //---------------------------------------------------------------- @@ -222,14 +240,10 @@ thin_provisioning::metadata_dump(metadata::ptr md, emitter::ptr e, bool repair) device_tree_detail::damage_visitor::ptr dd_policy(details_damage_policy(repair)); walk_device_tree(*md->details_, de, *dd_policy); - // metadata snap doesn't have the space maps so we don't know how - // many data blocks there are. - block_address nr_data_blocks = md->data_sm_ ? md->data_sm_->get_nr_blocks() : 0; - e->begin_superblock("", md->sb_.time_, md->sb_.trans_id_, md->sb_.data_block_size_, - nr_data_blocks, + get_nr_blocks(md), boost::optional()); { diff --git a/thin-provisioning/thin_repair.cc b/thin-provisioning/thin_repair.cc index d146ccd..2741b78 100644 --- a/thin-provisioning/thin_repair.cc +++ b/thin-provisioning/thin_repair.cc @@ -24,11 +24,7 @@ namespace { block_manager<>::ptr old_bm = open_bm(old_path, block_manager<>::READ_ONLY); - // we need to read the space maps to get the size - // of the data device. This is a shame, since any - // corruption in the sms will cause the repair to - // fail. - metadata::ptr old_md(new metadata(old_bm, true)); + metadata::ptr old_md(new metadata(old_bm, false)); metadata_dump(old_md, e, true); } catch (std::exception &e) {