From: Sage Weil Date: Fri, 16 Feb 2018 03:13:27 +0000 (-0600) Subject: osd/osd_types: add pg_t::is_merge() method X-Git-Tag: v14.0.1~371^2~55 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=054049246120e15fd8ae7ba4efda526f81d2f0d3;p=ceph.git osd/osd_types: add pg_t::is_merge() method This checks if we are a merge *source*, and if so, who the parent (target) will be. Signed-off-by: Sage Weil --- diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 1f8db32480e94..7a5e7cfa3b8a3 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -558,6 +558,23 @@ unsigned pg_t::get_split_bits(unsigned pg_num) const { return p - 1; } +bool pg_t::is_merge(unsigned old_pg_num, unsigned new_pg_num, + pg_t *parent) const +{ + if (m_seed < old_pg_num && + m_seed >= new_pg_num) { + if (parent) { + pg_t t = *this; + while (t.m_seed >= new_pg_num) { + t = t.get_parent(); + } + *parent = t; + } + return true; + } + return false; +} + pg_t pg_t::get_parent() const { unsigned bits = cbits(m_seed); diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index e8422d851e256..91fa9e31653ff 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -412,6 +412,8 @@ struct pg_t { bool is_split(unsigned old_pg_num, unsigned new_pg_num, set *pchildren) const; + bool is_merge(unsigned old_pg_num, unsigned new_pg_num, pg_t *parent) const; + /** * Returns b such that for all object o: * ~((~0)<