]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush/CrushWrapper: simplify get_full_location_ordered()
authorSage Weil <sage@inktank.com>
Wed, 30 Oct 2013 16:00:52 +0000 (09:00 -0700)
committerSage Weil <sage@redhat.com>
Sat, 27 Sep 2014 01:09:15 +0000 (18:09 -0700)
Just ascend the hierarchy; it is much less complicated.

Signed-off-by: Sage Weil <sage@inktank.com>
(cherry picked from commit 746069ee62c74ecf04ed45988029d5c3382a38d2)

src/crush/CrushWrapper.cc

index d17166bc4a9fe7905e167b22e47dde8d504bc5d9..65e7df2860331b0e8af9e05a9afa7d0262213e7b 100644 (file)
@@ -241,32 +241,16 @@ map<string, string> CrushWrapper::get_full_location(int id)
 
 int CrushWrapper::get_full_location_ordered(int id, vector<pair<string, string> >& path)
 {
-  int parent_id, ret;
-  pair<string, string> parent_coord;
-  parent_coord = get_immediate_parent(id, &ret);
-
-  // read the type map and get the name of the type with the largest ID
-  int high_type = 0;
-  for (map<int, string>::iterator it = type_map.begin(); it != type_map.end(); ++it){
-    if ( (*it).first > high_type )
-      high_type = (*it).first;
-  }
-
-  string high_type_name = type_map[high_type];
-
-  path.push_back(parent_coord);
-  parent_id = get_item_id(parent_coord.second);
-
-
-  while (parent_coord.first != high_type_name) {
-    parent_coord = get_immediate_parent(parent_id);
+  int cur = id;
+  int ret;
+  while (true) {
+    pair<string, string> parent_coord = get_immediate_parent(cur, &ret);
+    if (ret != 0)
+      break;
     path.push_back(parent_coord);
-    if ( parent_coord.first != high_type_name ){
-      parent_id = get_item_id(parent_coord.second);
-    }
+    cur = get_item_id(parent_coord.second);
   }
-
-  return ret;
+  return 0;
 }