[thin_ls] get it working with a metadata snap

This commit is contained in:
Joe Thornber 2016-01-20 14:45:38 +00:00
parent 8ec37aedd2
commit f385198cfc

View File

@ -46,8 +46,8 @@ using namespace thin_provisioning;
namespace { namespace {
class mapping_set { class mapping_set {
public: public:
mapping_set(block_address nr_blocks) mapping_set()
: bits_(nr_blocks * 2, false) { : bits_(10240, false) {
} }
enum block_state { enum block_state {
@ -57,15 +57,15 @@ namespace {
}; };
void inc(block_address b) { void inc(block_address b) {
if (bits_[b * 2]) if (get_bit(b * 2))
bits_[b * 2 + 1] = true; // shared set_bit(b * 2 + 1, true); // shared
else else
bits_[b * 2] = true; // exclusive set_bit(b * 2, true); // exclusive
} }
block_state get_state(block_address b) const { block_state get_state(block_address b) const {
if (bits_[b * 2]) { if (get_bit(b * 2)) {
if (bits_[b * 2 + 1]) if (get_bit(b * 2 + 1))
return SHARED; return SHARED;
else else
return EXCLUSIVE; return EXCLUSIVE;
@ -74,7 +74,27 @@ namespace {
} }
private: private:
vector<bool> bits_; void ensure_size(block_address bit) const {
if (bit >= bits_.size()) {
unsigned new_size = bits_.size() * 2;
while (new_size < bit)
new_size *= 2;
bits_.resize(new_size, false);
}
}
bool get_bit(block_address bit) const {
ensure_size(bit);
return bits_[bit];
}
void set_bit(block_address bit, bool v) {
ensure_size(bit);
bits_[bit] = v;
}
mutable vector<bool> bits_;
}; };
//------------------------------------------------ //------------------------------------------------
@ -289,7 +309,8 @@ namespace {
void ls_(string const &path, ostream &out, struct flags &flags) { void ls_(string const &path, ostream &out, struct flags &flags) {
grid_layout grid; grid_layout grid;
block_manager<>::ptr bm(open_bm(path, block_manager<>::READ_ONLY)); block_manager<>::ptr bm(open_bm(path, block_manager<>::READ_ONLY,
!flags.use_metadata_snap));
metadata::ptr md; metadata::ptr md;
if (flags.use_metadata_snap) if (flags.use_metadata_snap)
@ -303,7 +324,7 @@ namespace {
device_tree_detail::damage_visitor::ptr dd_policy(details_damage_policy()); device_tree_detail::damage_visitor::ptr dd_policy(details_damage_policy());
walk_device_tree(*md->details_, de, *dd_policy); walk_device_tree(*md->details_, de, *dd_policy);
mapping_set mappings(md->data_sm_->get_nr_blocks()); mapping_set mappings;
dd_map::const_iterator it; dd_map::const_iterator it;
dd_map const &map = de.get_details(); dd_map const &map = de.get_details();