From: Sage Weil Date: Wed, 25 May 2011 04:14:59 +0000 (-0700) Subject: crushtool: clean up add-item a bit; don't add item to same bucket twice X-Git-Tag: v0.29~34 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fe955881a835aca3a420ef7bcc17d44aa727749f;p=ceph.git crushtool: clean up add-item a bit; don't add item to same bucket twice Signed-off-by: Sage Weil --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 84258122316..3fb2d450ec3 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -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& 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; jsize; 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; diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 446cfcb9ad2..53db4d3f379 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -154,7 +154,7 @@ public: void find_roots(set& roots) const; - int insert_device(int id, int weight, string name, map& loc); + int insert_item(int id, int weight, string name, map& loc); int remove_item(int id); int adjust_item_weight(int id, int weight); int adjust_item_weightf(int id, float weight) { diff --git a/src/crushtool.cc b/src/crushtool.cc index 392b9e088fd..c7f4e20b2b8 100644 --- a/src/crushtool.cc +++ b/src/crushtool.cc @@ -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 {