From 8fb2388d82b9f6591b7598b44f0560a6b646a90e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 17 Apr 2014 21:05:49 -0700 Subject: [PATCH] osd_types: pg_t: add get_ancestor() method Give us the ancestor for when the pool had a past value for pg_num. Signed-off-by: Sage Weil --- src/osd/osd_types.cc | 9 +++++++++ src/osd/osd_types.h | 1 + src/test/osd/types.cc | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index dca7bbf605f..33b1b9c3459 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -393,6 +393,15 @@ ostream& operator<<(ostream& out, const spg_t &pg) return out; } +pg_t pg_t::get_ancestor(unsigned old_pg_num) const +{ + int old_bits = pg_pool_t::calc_bits_of(old_pg_num); + int old_mask = (1 << old_bits) - 1; + pg_t ret = *this; + ret.m_seed = ceph_stable_mod(m_seed, old_pg_num, old_mask); + return ret; +} + bool pg_t::is_split(unsigned old_pg_num, unsigned new_pg_num, set *children) const { assert(m_seed < old_pg_num); diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 4154d42fcfb..7874977ea92 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -311,6 +311,7 @@ struct pg_t { } pg_t get_parent() const; + pg_t get_ancestor(unsigned old_pg_num) const; int print(char *o, int maxlen) const; bool parse(const char *s); diff --git a/src/test/osd/types.cc b/src/test/osd/types.cc index 6380211cf81..ac218fa80d3 100644 --- a/src/test/osd/types.cc +++ b/src/test/osd/types.cc @@ -558,6 +558,18 @@ TEST(pg_interval_t, check_new_interval) } } +TEST(pg_t, get_ancestor) +{ + ASSERT_EQ(pg_t(0, 0, -1), pg_t(16, 0, -1).get_ancestor(16)); + ASSERT_EQ(pg_t(1, 0, -1), pg_t(17, 0, -1).get_ancestor(16)); + ASSERT_EQ(pg_t(0, 0, -1), pg_t(16, 0, -1).get_ancestor(8)); + ASSERT_EQ(pg_t(16, 0, -1), pg_t(16, 0, -1).get_ancestor(80)); + ASSERT_EQ(pg_t(16, 0, -1), pg_t(16, 0, -1).get_ancestor(83)); + ASSERT_EQ(pg_t(1, 0, -1), pg_t(1321, 0, -1).get_ancestor(123).get_ancestor(8)); + ASSERT_EQ(pg_t(3, 0, -1), pg_t(1323, 0, -1).get_ancestor(123).get_ancestor(8)); + ASSERT_EQ(pg_t(3, 0, -1), pg_t(1323, 0, -1).get_ancestor(8)); +} + TEST(pg_t, split) { pg_t pgid(0, 0, -1);