From 69a2ec27f060ded8ebf97ef4a67d73baf635e71c Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Fri, 13 Dec 2013 13:55:31 -0800 Subject: [PATCH] OSDMap: unify the pg_to_acting_osds and pg_to_up_acting_osds implementations These were the same except for a call to _raw_to_up_osds(). Move the existing pg_to_up_acting_osds into a private function taking a pointer, only fill in the up vector if it's a non-NULL pointer, and call it via the obvious header implementations. Signed-off-by: Greg Farnum --- src/osd/OSDMap.cc | 21 ++++++--------------- src/osd/OSDMap.h | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index ed341aa0cffb8..55742d9fc7c1c 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -1177,18 +1177,6 @@ int OSDMap::pg_to_osds(pg_t pg, vector& raw) const return _pg_to_osds(*pool, pg, raw); } -int OSDMap::pg_to_acting_osds(pg_t pg, vector& acting) const -{ - const pg_pool_t *pool = get_pg_pool(pg.pool()); - if (!pool) - return 0; - vector raw; - _pg_to_osds(*pool, pg, raw); - if (!_raw_to_temp_osds(*pool, pg, raw, acting)) - _raw_to_up_osds(pg, raw, acting); - return acting.size(); -} - void OSDMap::pg_to_raw_up(pg_t pg, vector& up) const { const pg_pool_t *pool = get_pg_pool(pg.pool()); @@ -1199,16 +1187,19 @@ void OSDMap::pg_to_raw_up(pg_t pg, vector& up) const _raw_to_up_osds(pg, raw, up); } -void OSDMap::pg_to_up_acting_osds(pg_t pg, vector& up, vector& acting) const +void OSDMap::_pg_to_up_acting_osds(pg_t pg, vector *up, vector& acting) const { const pg_pool_t *pool = get_pg_pool(pg.pool()); if (!pool) return; vector raw; + vector *_up = (up ? up : new vector); _pg_to_osds(*pool, pg, raw); - _raw_to_up_osds(pg, raw, up); + _raw_to_up_osds(pg, raw, *up); if (!_raw_to_temp_osds(*pool, pg, raw, acting)) - acting = up; + acting = *_up; + if (_up != up) + delete _up; } int OSDMap::calc_pg_rank(int osd, vector& acting, int nrep) diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index 056eca42168fe..cfc9e0df4ca6b 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -506,6 +506,10 @@ private: bool _raw_to_temp_osds(const pg_pool_t& pool, pg_t pg, vector& raw, vector& temp) const; + /// map to up and acting. Only provides up if pointer is non-NULL + void _pg_to_up_acting_osds(pg_t pg, vector *up, + vector& acting) const; + public: /*** * This is suitable only for looking at raw CRUSH outputs. It skips @@ -514,7 +518,10 @@ public: */ int pg_to_osds(pg_t pg, vector& raw) const; /// map a pg to its acting set. @return acting set size - int pg_to_acting_osds(pg_t pg, vector& acting) const; + int pg_to_acting_osds(pg_t pg, vector& acting) const { + _pg_to_up_acting_osds(pg, NULL, acting); + return acting.size(); + } /** * This does not apply temp overrides and should not be used * by anybody for data mapping purposes. @@ -526,7 +533,10 @@ public: * also find the up set useful for things like deciding what to * set as pg_temp. */ - void pg_to_up_acting_osds(pg_t pg, vector& up, vector& acting) const; + void pg_to_up_acting_osds(pg_t pg, vector& up, + vector& acting) const { + _pg_to_up_acting_osds(pg, &up, acting); + } int64_t lookup_pg_pool_name(const string& name) { if (name_pool.count(name)) -- 2.39.5