From 524de134a4468b8adab1c9a94a87cec5ac2e45e6 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Tue, 2 Jun 2020 19:07:13 +0800 Subject: [PATCH] [thin_pool] Support creating metadadata snapshot --- thin-provisioning/thin_pool.cc | 46 ++++++++++++++++++++++++++++++++++ thin-provisioning/thin_pool.h | 3 +++ 2 files changed, 49 insertions(+) diff --git a/thin-provisioning/thin_pool.cc b/thin-provisioning/thin_pool.cc index d9d9684..2b58e4d 100644 --- a/thin-provisioning/thin_pool.cc +++ b/thin-provisioning/thin_pool.cc @@ -227,6 +227,52 @@ thin_pool::get_transaction_id() const return md_->sb_.trans_id_; } +void +thin_pool::reserve_metadata_snap() +{ + if (md_->sb_.metadata_snap_) + throw std::runtime_error("pool metadata snapshot already exists."); + + commit(); + + md_->metadata_sm_->inc(superblock_detail::SUPERBLOCK_LOCATION); + transaction_manager::write_ref wr = md_->tm_->shadow( + superblock_detail::SUPERBLOCK_LOCATION, + superblock_validator()).first; + + superblock_detail::superblock sb; + superblock_detail::superblock_disk *sbd = reinterpret_cast(wr.data()); + superblock_detail::superblock_traits::unpack(*sbd, sb); + + memset(sb.data_space_map_root_, 0, superblock_detail::SPACE_MAP_ROOT_SIZE); + memset(sb.metadata_space_map_root_, 0, superblock_detail::SPACE_MAP_ROOT_SIZE); + md_->metadata_sm_->inc(sb.data_mapping_root_); + md_->metadata_sm_->inc(sb.device_details_root_); + + superblock_detail::superblock_traits::pack(sb, *sbd); + + md_->sb_.metadata_snap_ = wr.get_location(); +} + +void +thin_pool::release_metadata_snap() +{ + if (!md_->sb_.metadata_snap_) + throw std::runtime_error("No pool metadata snapshot found"); + + superblock_detail::superblock sb = read_superblock(md_->tm_->get_bm(), + md_->sb_.metadata_snap_); + device_tree dtree(*md_->tm_, sb.device_details_root_, + device_tree_detail::device_details_traits::ref_counter()); + dtree.destroy(); + mapping_tree mtree(*md_->tm_, sb.data_mapping_root_, + mapping_tree_detail::block_traits::ref_counter(md_->tm_->get_sm())); + mtree.destroy(); + md_->metadata_sm_->dec(md_->sb_.metadata_snap_); + + md_->sb_.metadata_snap_ = 0; +} + block_address thin_pool::get_metadata_snap() const { diff --git a/thin-provisioning/thin_pool.h b/thin-provisioning/thin_pool.h index 4dffc7b..62f6945 100644 --- a/thin-provisioning/thin_pool.h +++ b/thin-provisioning/thin_pool.h @@ -82,6 +82,9 @@ namespace thin_provisioning { void set_transaction_id(uint64_t id); uint64_t get_transaction_id() const; + // handling metadata snapshot + void reserve_metadata_snap(); + void release_metadata_snap(); block_address get_metadata_snap() const; block_address alloc_data_block();