From fc8ea3f2d6e56da6ca0bed1774a65fe70a065e36 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 17 Aug 2015 11:52:10 -0400 Subject: [PATCH] osd/osd_types: add pg_t::get_hobj_{start,end} methods Convenience methods to easily get the bounds of the object range that are managed by a given PG. Note that this is a function of the pool pg_num because otherwise the pg_t id only gives us the start position. Signed-off-by: Sage Weil --- src/osd/osd_types.cc | 24 ++++++++++++++++++++++++ src/osd/osd_types.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 464cb197cb02..b60ff9312772 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -522,6 +522,30 @@ pg_t pg_t::get_parent() const return retval; } +hobject_t pg_t::get_hobj_start() const +{ + return hobject_t(object_t(), string(), CEPH_NOSNAP, m_seed, m_pool, + string()); +} + +hobject_t pg_t::get_hobj_end(unsigned pg_num) const +{ + // note: this assumes a bitwise sort; with the legacy nibblewise + // sort a PG did not always cover a single contiguous range of the + // (bit-reversed) hash range. + unsigned bits = get_split_bits(pg_num); + uint64_t rev_start = hobject_t::_reverse_bits(m_seed); + uint64_t rev_end = (rev_start | (0xffffffff >> bits)) + 1; + if (rev_end >= 0x100000000) { + assert(rev_end == 0x100000000); + return hobject_t::get_max(); + } else { + return hobject_t(object_t(), string(), CEPH_NOSNAP, + hobject_t::_reverse_bits(rev_end), m_pool, + string()); + } +} + void pg_t::dump(Formatter *f) const { f->dump_unsigned("pool", m_pool); diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 9810e6b76dc4..836f99144862 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -348,6 +348,9 @@ struct pg_t { return oid.match(bits, ps()); } + hobject_t get_hobj_start() const; + hobject_t get_hobj_end(unsigned pg_num) const; + void encode(bufferlist& bl) const { __u8 v = 1; ::encode(v, bl); -- 2.47.3