]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crushtool: fix remove-item
authorSage Weil <sage.weil@dreamhost.com>
Wed, 25 May 2011 04:05:47 +0000 (21:05 -0700)
committerSage Weil <sage.weil@dreamhost.com>
Wed, 25 May 2011 04:05:47 +0000 (21:05 -0700)
Scan all buckets instead of doing a tree traverse.

Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h
src/crushtool.cc

index 41becbcb2e20372f09da047a8a9c056cbbad6144..84258122316cf54de4f3dc921a75115b72ceadda 100644 (file)
@@ -17,48 +17,32 @@ void CrushWrapper::find_roots(set<int>& roots) const
 }
 
 
-int CrushWrapper::remove_device(int item)
+int CrushWrapper::remove_item(int item)
 {
-  cout << "remove_device item" << std::endl;
+  cout << "remove_item " << item << std::endl;
 
   crush_bucket *was_bucket = 0;
   int ret = -ENOENT;
 
-  set<int> roots;
-  find_roots(roots);
-  for (set<int>::iterator p = roots.begin(); p != roots.end(); ++p) {
-    list<int> q;
-    q.push_back(*p);
-    while (!q.empty()) {
-      int id = q.front();
-      q.pop_front();
-
-      if (id >= 0)
-       continue;  // it's a leaf.
-
-      crush_bucket *b = get_bucket(id);
-      if (!b) {
-       cout << "remove_device warning: bad reference to bucket " << id << std::endl;
-       continue;
-      }
-
-      for (unsigned i=0; i<b->size; ++i) {
-       int id = b->items[i];
-       if (id == item) {
-         if (item < 0) {
-           crush_bucket *t = get_bucket(item);
-           if (t && t->size) {
-             cout << "remove_device bucket " << item << " has " << t->size << " items, not empty" << std::endl;
-             return -ENOTEMPTY;
-           }       
-           was_bucket = t;
-         }
-         cout << "remove_device removing item " << item << " from bucket " << b->id << std::endl;
-         crush_bucket_remove_item(b, item);
-         ret = 0;
+  for (int i = 0; i < crush->max_buckets; i++) {
+    if (!crush->buckets[i])
+      continue;
+    crush_bucket *b = crush->buckets[i];
+
+    for (unsigned i=0; i<b->size; ++i) {
+      int id = b->items[i];
+      if (id == item) {
+       if (item < 0) {
+         crush_bucket *t = get_bucket(item);
+         if (t && t->size) {
+           cout << "remove_device bucket " << item << " has " << t->size << " items, not empty" << std::endl;
+           return -ENOTEMPTY;
+         }         
+         was_bucket = t;
        }
-       if (id < 0)
-         q.push_front(id);
+       cout << "remove_device removing item " << item << " from bucket " << b->id << std::endl;
+       crush_bucket_remove_item(b, item);
+       ret = 0;
       }
     }
   }
@@ -67,6 +51,11 @@ int CrushWrapper::remove_device(int item)
     cout << "remove_device removing bucket " << item << std::endl;
     crush_remove_bucket(crush, was_bucket);
   }
+  if (item >= 0 && name_map.count(item)) {
+    name_map.erase(item);
+    have_rmaps = false;
+    ret = 0;
+  }  
   
   return ret;
 }
index f70f52ab093c933ad224d2fad8aaea9854a00bec..446cfcb9ad20ff27424631c9b8f464b153b0acd7 100644 (file)
@@ -155,7 +155,7 @@ public:
 
   void find_roots(set<int>& roots) const;
   int insert_device(int id, int weight, string name, map<string,string>& loc);
-  int remove_device(int id);
+  int remove_item(int id);
   int adjust_item_weight(int id, int weight);
   int adjust_item_weightf(int id, float weight) {
     return adjust_item_weight(id, (int)(weight * (float)0x10000));
index 0497c7ec822391c37c839f2751afcef52e773c1f..392b9e088fdd56fb1f3678a39574e9f78d1f7cc9 100644 (file)
@@ -1075,7 +1075,7 @@ int main(int argc, const char **argv)
       r = -ENOENT;
     } else {
       int remove_item = crush.get_item_id(remove_name);
-      r = crush.remove_device(remove_item);
+      r = crush.remove_item(remove_item);
     }
     if (r == 0)
       modified = true;