]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crushtool: clean up add-item a bit; don't add item to same bucket twice
authorSage Weil <sage.weil@dreamhost.com>
Wed, 25 May 2011 04:14:59 +0000 (21:14 -0700)
committerSage Weil <sage.weil@dreamhost.com>
Wed, 25 May 2011 04:14:59 +0000 (21:14 -0700)
Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h
src/crushtool.cc

index 84258122316cf54de4f3dc921a75115b72ceadda..3fb2d450ec3715e90bf999ee2aef367d134bccec 100644 (file)
@@ -60,18 +60,15 @@ int CrushWrapper::remove_item(int item)
   return ret;
 }
 
-int CrushWrapper::insert_device(int item, int weight, string name,
+int CrushWrapper::insert_item(int item, int weight, string name,
                                map<string,string>& loc)  // typename -> bucketname
 {
-  cout << "insert_device item " << item << " weight " << weight
+  cout << "insert_item item " << item << " weight " << weight
          << " name " << name << " loc " << loc << std::endl;
 
   if (name_exists(name.c_str())) {
-    cerr << "error: device name '" << name << "' already exists" << std::endl;
-    return -EEXIST;
-  }
-  if (item_exists(item)) {
-    cerr << "error: device id '" << item << "' already exists" << std::endl;
+    cerr << "error: device name '" << name << "' already exists as id "
+        << get_item_id(name.c_str()) << std::endl;
     return -EEXIST;
   }
 
@@ -90,7 +87,7 @@ int CrushWrapper::insert_device(int item, int weight, string name,
     int id = get_item_id(loc[p->second].c_str());
     if (!id) {
       // create the bucket
-      cout << "insert_device creating bucket " << loc[p->second] << std::endl;
+      cout << "insert_item creating bucket " << loc[p->second] << std::endl;
       int empty = 0;
       id = add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT, p->first, 1, &item, &empty);
       set_item_name(id, loc[p->second].c_str());
@@ -100,14 +97,22 @@ int CrushWrapper::insert_device(int item, int weight, string name,
 
     // add to an existing bucket
     if (!bucket_exists(id)) {
-      cout << "insert_device don't have bucket " << id << std::endl;
+      cout << "insert_item don't have bucket " << id << std::endl;
       return -EINVAL;
     }
-      
-    cout << "insert_device adding " << item << " weight " << weight
-           << " to bucket " << id << std::endl;
+
     crush_bucket *b = get_bucket(id);
     assert(b);
+
+    // make sure the item doesn't already exist in this bucket
+    for (unsigned j=0; j<b->size; j++)
+      if (b->items[j] == item) {
+       cerr << "insert_item " << item << " already exists in bucket " << b->id << std::endl;
+       return -EEXIST;
+      }
+    
+    cout << "insert_item adding " << item << " weight " << weight
+        << " to bucket " << id << std::endl;
     crush_bucket_add_item(b, item, 0);
     adjust_item_weight(item, weight);
     return 0;
index 446cfcb9ad20ff27424631c9b8f464b153b0acd7..53db4d3f379abc6feffbefc468623b5699edb71b 100644 (file)
@@ -154,7 +154,7 @@ public:
 
 
   void find_roots(set<int>& roots) const;
-  int insert_device(int id, int weight, string name, map<string,string>& loc);
+  int insert_item(int id, int weight, string name, map<string,string>& loc);
   int remove_item(int id);
   int adjust_item_weight(int id, int weight);
   int adjust_item_weightf(int id, float weight) {
index 392b9e088fdd56fb1f3678a39574e9f78d1f7cc9..c7f4e20b2b8f1c49d7b48a121757f1132d883124 100644 (file)
@@ -1087,7 +1087,7 @@ int main(int argc, const char **argv)
   if (add_item >= 0) {
     cout << me << " adding item " << add_item << " weight " << add_weight
         << " at " << add_loc << std::endl;
-    int r = crush.insert_device(add_item, (int)(add_weight * (float)0x10000), add_name, add_loc);
+    int r = crush.insert_item(add_item, (int)(add_weight * (float)0x10000), add_name, add_loc);
     if (r == 0)
       modified = true;
     else {