]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
OSDMap: unify the pg_to_acting_osds and pg_to_up_acting_osds implementations
authorGreg Farnum <greg@inktank.com>
Fri, 13 Dec 2013 21:55:31 +0000 (13:55 -0800)
committerGreg Farnum <greg@inktank.com>
Thu, 16 Jan 2014 00:33:05 +0000 (16:33 -0800)
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 <greg@inktank.com>
src/osd/OSDMap.cc
src/osd/OSDMap.h

index ed341aa0cffb88345e26249633adf366e44bed74..55742d9fc7c1ce6ec17cf64792e8c2fbbc935e5b 100644 (file)
@@ -1177,18 +1177,6 @@ int OSDMap::pg_to_osds(pg_t pg, vector<int>& raw) const
   return _pg_to_osds(*pool, pg, raw);
 }
 
-int OSDMap::pg_to_acting_osds(pg_t pg, vector<int>& acting) const
-{
-  const pg_pool_t *pool = get_pg_pool(pg.pool());
-  if (!pool)
-    return 0;
-  vector<int> 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<int>& 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<int>& up) const
   _raw_to_up_osds(pg, raw, up);
 }
   
-void OSDMap::pg_to_up_acting_osds(pg_t pg, vector<int>& up, vector<int>& acting) const
+void OSDMap::_pg_to_up_acting_osds(pg_t pg, vector<int> *up, vector<int>& acting) const
 {
   const pg_pool_t *pool = get_pg_pool(pg.pool());
   if (!pool)
     return;
   vector<int> raw;
+  vector<int> *_up = (up ? up : new vector<int>);
   _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<int>& acting, int nrep)
index 056eca42168fe896895eee317915d9ee1bec0919..cfc9e0df4ca6bebcafeac94ed2e8f1668880be83 100644 (file)
@@ -506,6 +506,10 @@ private:
 
   bool _raw_to_temp_osds(const pg_pool_t& pool, pg_t pg, vector<int>& raw, vector<int>& 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<int> *up,
+                             vector<int>& 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<int>& raw) const;
   /// map a pg to its acting set. @return acting set size
-  int pg_to_acting_osds(pg_t pg, vector<int>& acting) const;
+  int pg_to_acting_osds(pg_t pg, vector<int>& 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<int>& up, vector<int>& acting) const;
+  void pg_to_up_acting_osds(pg_t pg, vector<int>& up,
+                            vector<int>& acting) const {
+    _pg_to_up_acting_osds(pg, &up, acting);
+  }
 
   int64_t lookup_pg_pool_name(const string& name) {
     if (name_pool.count(name))