From 5fb4ea1a024c226ac4cc424c4e572abd283b8093 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 29 Sep 2016 17:43:04 -0400 Subject: [PATCH] os/bluestore/bluestore_types: uint64_t for ref_map We use this to track raw extents on disk for SharedBlob. We also use it for the in-memory Blob with the blob namespace, but using uint64_t intead of uint32_t doesn't hurt us there. Signed-off-by: Sage Weil --- src/os/bluestore/bluestore_types.cc | 40 +++++++++++++++-------------- src/os/bluestore/bluestore_types.h | 14 +++++----- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/os/bluestore/bluestore_types.cc b/src/os/bluestore/bluestore_types.cc index 3e1a0f35471..56752121df6 100644 --- a/src/os/bluestore/bluestore_types.cc +++ b/src/os/bluestore/bluestore_types.cc @@ -163,7 +163,8 @@ void bluestore_extent_ref_map_t::_check() const } } -void bluestore_extent_ref_map_t::_maybe_merge_left(map::iterator& p) +void bluestore_extent_ref_map_t::_maybe_merge_left( + map::iterator& p) { if (p == ref_map.begin()) return; @@ -177,9 +178,9 @@ void bluestore_extent_ref_map_t::_maybe_merge_left(map::itera } } -void bluestore_extent_ref_map_t::get(uint32_t offset, uint32_t length) +void bluestore_extent_ref_map_t::get(uint64_t offset, uint32_t length) { - map::iterator p = ref_map.lower_bound(offset); + auto p = ref_map.lower_bound(offset); if (p != ref_map.begin()) { --p; if (p->first + p->second.length <= offset) { @@ -195,9 +196,9 @@ void bluestore_extent_ref_map_t::get(uint32_t offset, uint32_t length) } if (p->first > offset) { // gap - uint32_t newlen = MIN(p->first - offset, length); + uint64_t newlen = MIN(p->first - offset, length); p = ref_map.insert( - map::value_type(offset, + map::value_type(offset, record_t(newlen, 1))).first; offset += newlen; length -= newlen; @@ -208,9 +209,9 @@ void bluestore_extent_ref_map_t::get(uint32_t offset, uint32_t length) if (p->first < offset) { // split off the portion before offset assert(p->first + p->second.length > offset); - uint32_t left = p->first + p->second.length - offset; + uint64_t left = p->first + p->second.length - offset; p->second.length = offset - p->first; - p = ref_map.insert(map::value_type( + p = ref_map.insert(map::value_type( offset, record_t(left, p->second.refs))).first; // continue below } @@ -235,10 +236,10 @@ void bluestore_extent_ref_map_t::get(uint32_t offset, uint32_t length) } void bluestore_extent_ref_map_t::put( - uint32_t offset, uint32_t length, + uint64_t offset, uint32_t length, vector *release) { - map::iterator p = ref_map.lower_bound(offset); + auto p = ref_map.lower_bound(offset); if (p == ref_map.end() || p->first > offset) { if (p == ref_map.begin()) { assert(0 == "put on missing extent (nothing before)"); @@ -249,9 +250,9 @@ void bluestore_extent_ref_map_t::put( } } if (p->first < offset) { - uint32_t left = p->first + p->second.length - offset; + uint64_t left = p->first + p->second.length - offset; p->second.length = offset - p->first; - p = ref_map.insert(map::value_type( + p = ref_map.insert(map::value_type( offset, record_t(left, p->second.refs))).first; } while (length > 0) { @@ -288,9 +289,9 @@ void bluestore_extent_ref_map_t::put( _check(); } -bool bluestore_extent_ref_map_t::contains(uint32_t offset, uint32_t length) const +bool bluestore_extent_ref_map_t::contains(uint64_t offset, uint32_t length) const { - map::const_iterator p = ref_map.lower_bound(offset); + auto p = ref_map.lower_bound(offset); if (p == ref_map.end() || p->first > offset) { if (p == ref_map.begin()) { return false; // nothing before @@ -307,7 +308,7 @@ bool bluestore_extent_ref_map_t::contains(uint32_t offset, uint32_t length) cons return false; if (p->first + p->second.length >= offset + length) return true; - uint32_t overlap = p->first + p->second.length - offset; + uint64_t overlap = p->first + p->second.length - offset; offset += overlap; length -= overlap; ++p; @@ -316,10 +317,10 @@ bool bluestore_extent_ref_map_t::contains(uint32_t offset, uint32_t length) cons } bool bluestore_extent_ref_map_t::intersects( - uint32_t offset, + uint64_t offset, uint32_t length) const { - map::const_iterator p = ref_map.lower_bound(offset); + auto p = ref_map.lower_bound(offset); if (p != ref_map.begin()) { --p; if (p->first + p->second.length <= offset) { @@ -341,10 +342,10 @@ void bluestore_extent_ref_map_t::encode(bufferlist& bl) const auto p = ref_map.begin(); small_encode_varint_lowz(p->first, bl); p->second.encode(bl); - int32_t pos = p->first; + int64_t pos = p->first; while (--n) { ++p; - small_encode_varint_lowz((int64_t)p->first - pos, bl); + small_encode_varint_lowz(p->first - pos, bl); p->second.encode(bl); pos = p->first; } @@ -381,7 +382,8 @@ void bluestore_extent_ref_map_t::dump(Formatter *f) const f->close_section(); } -void bluestore_extent_ref_map_t::generate_test_instances(list& o) +void bluestore_extent_ref_map_t::generate_test_instances( + list& o) { o.push_back(new bluestore_extent_ref_map_t); o.push_back(new bluestore_extent_ref_map_t); diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index f5d40014d36..6e09d114c97 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -151,7 +151,7 @@ struct bluestore_extent_ref_map_t { struct record_t { uint32_t length; uint32_t refs; - record_t(uint32_t l=0, uint32_t r=0) : length(l), refs(r) {} + record_t(uint64_t l=0, uint32_t r=0) : length(l), refs(r) {} void encode(bufferlist& bl) const { small_encode_varint_lowz(length, bl); small_encode_varint(refs, bl); @@ -163,10 +163,10 @@ struct bluestore_extent_ref_map_t { }; WRITE_CLASS_ENCODER(record_t) - map ref_map; + map ref_map; void _check() const; - void _maybe_merge_left(map::iterator& p); + void _maybe_merge_left(map::iterator& p); void clear() { ref_map.clear(); @@ -175,11 +175,11 @@ struct bluestore_extent_ref_map_t { return ref_map.empty(); } - void get(uint32_t offset, uint32_t len); - void put(uint32_t offset, uint32_t len, vector *release); + void get(uint64_t offset, uint32_t len); + void put(uint64_t offset, uint32_t len, vector *release); - bool contains(uint32_t offset, uint32_t len) const; - bool intersects(uint32_t offset, uint32_t len) const; + bool contains(uint64_t offset, uint32_t len) const; + bool intersects(uint64_t offset, uint32_t len) const; void encode(bufferlist& bl) const; void decode(bufferlist::iterator& p);