[thin_pool] Implement synchronous mapping insertion and removal

This commit is contained in:
Ming-Hung Tsai 2020-06-02 01:16:38 +08:00
parent 383ae78871
commit 598696bc32
2 changed files with 41 additions and 0 deletions

View File

@ -16,6 +16,7 @@
// with thin-provisioning-tools. If not, see
// <http://www.gnu.org/licenses/>.
#include "persistent-data/math_utils.h"
#include "thin-provisioning/thin_pool.h"
#include <stdexcept>
@ -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<sector_t>(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<sector_t>(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<sector_t>(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_);
}
//----------------------------------------------------------------

View File

@ -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);
};
//----------------------------------------------------------------