Merge branch 'master' of github.com:jthornber/thin-provisioning-tools

This commit is contained in:
Joe Thornber 2017-09-07 15:42:31 +01:00
commit 3f8add4334

View File

@ -120,12 +120,7 @@ namespace {
ref_t lookup(unsigned b) const {
read_ref rr = tm_.read_lock(ie_.blocknr_, validator_);
void const *bits = bitmap_data(rr);
ref_t b1 = test_bit_le(bits, b * 2);
ref_t b2 = test_bit_le(bits, b * 2 + 1);
ref_t result = b2 ? 1 : 0;
result |= b1 ? 2 : 0;
return result;
return __lookup_raw(bitmap_data(rr), b);
}
void insert(unsigned b, ref_t n) {
@ -158,8 +153,10 @@ namespace {
}
boost::optional<unsigned> find_free(unsigned begin, unsigned end) {
read_ref rr = tm_.read_lock(ie_.blocknr_, validator_);
void const *bits = bitmap_data(rr);
for (unsigned i = max(begin, ie_.none_free_before_); i < end; i++)
if (lookup(i) == 0)
if (__lookup_raw(bits, i) == 0)
return boost::optional<unsigned>(i);
return boost::optional<unsigned>();
@ -193,6 +190,14 @@ namespace {
return h + 1;
}
ref_t __lookup_raw(void const *bits, unsigned b) const {
ref_t b1 = test_bit_le(bits, b * 2);
ref_t b2 = test_bit_le(bits, b * 2 + 1);
ref_t result = b2 ? 1 : 0;
result |= b1 ? 2 : 0;
return result;
}
transaction_manager &tm_;
bcache::validator::ptr validator_;