From 598696bc32004eacb99064a4e114a2306ee1ec1e Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Tue, 2 Jun 2020 01:16:38 +0800 Subject: [PATCH] [thin_pool] Implement synchronous mapping insertion and removal --- thin-provisioning/thin_pool.cc | 37 ++++++++++++++++++++++++++++++++++ thin-provisioning/thin_pool.h | 4 ++++ 2 files changed, 41 insertions(+) diff --git a/thin-provisioning/thin_pool.cc b/thin-provisioning/thin_pool.cc index 302a5e9..cea270e 100644 --- a/thin-provisioning/thin_pool.cc +++ b/thin-provisioning/thin_pool.cc @@ -16,6 +16,7 @@ // with thin-provisioning-tools. If not, see // . +#include "persistent-data/math_utils.h" #include "thin-provisioning/thin_pool.h" #include @@ -336,3 +337,39 @@ thin_pool::write_changed_details() } //---------------------------------------------------------------- + +void +thin_provisioning::process_read(thin::ptr td, thin_pool::ptr tp, + sector_t offset) +{ + block_address blocknr = base::div_up(offset, tp->get_data_block_size()); + td->lookup(blocknr); +} + +void +thin_provisioning::process_write(thin::ptr td, thin_pool::ptr tp, + sector_t offset) +{ + block_address blocknr = base::div_up(offset, tp->get_data_block_size()); + thin::maybe_address result = td->lookup(blocknr); + if (!!result && !result->shared_) + return; + // TODO: handle out-of-space errors + block_address data_block = tp->alloc_data_block(); + td->insert(blocknr, data_block); +} + +void +thin_provisioning::process_discard(thin::ptr td, thin_pool::ptr tp, + sector_t offset) +{ + block_address blocknr = base::div_up(offset, tp->get_data_block_size()); + thin::maybe_address result = td->lookup(blocknr); + if (!result) + return; + td->remove(blocknr); + if (!result->shared_) + tp->free_data_block(result->block_); +} + +//---------------------------------------------------------------- diff --git a/thin-provisioning/thin_pool.h b/thin-provisioning/thin_pool.h index 6151677..ce6e18e 100644 --- a/thin-provisioning/thin_pool.h +++ b/thin-provisioning/thin_pool.h @@ -109,6 +109,10 @@ namespace thin_provisioning { metadata::ptr md_; device_map thin_devices_; }; + + void process_read(thin::ptr td, thin_pool::ptr tp, sector_t offset); + void process_write(thin::ptr td, thin_pool::ptr tp, sector_t offset); + void process_discard(thin::ptr td, thin_pool::ptr tp, sector_t offset); }; //----------------------------------------------------------------