From a93c86e525e7cd7e9e7315d275e5713d18569c78 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 26 May 2011 13:12:04 -0700 Subject: [PATCH] crushtool: fix --add-item weight being zero when parent bucket(s) created Signed-off-by: Sage Weil --- src/crush/CrushWrapper.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 3fb2d450ec371..796807ac453be 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -74,6 +74,8 @@ int CrushWrapper::insert_item(int item, int weight, string name, set_item_name(item, name.c_str()); + int cur = item; + for (map::iterator p = type_map.begin(); p != type_map.end(); p++) { if (p->first == 0) continue; @@ -89,9 +91,9 @@ int CrushWrapper::insert_item(int item, int weight, string name, // create the bucket 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); + id = add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT, p->first, 1, &cur, &empty); set_item_name(id, loc[p->second].c_str()); - item = id; + cur = id; continue; } @@ -106,14 +108,16 @@ int CrushWrapper::insert_item(int item, int weight, string name, // 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; + if (b->items[j] == cur) { + cerr << "insert_item " << cur << " already exists in bucket " << b->id << std::endl; return -EEXIST; } - cout << "insert_item adding " << item << " weight " << weight + cout << "insert_item adding " << cur << " weight " << weight << " to bucket " << id << std::endl; - crush_bucket_add_item(b, item, 0); + crush_bucket_add_item(b, cur, 0); + + // now that we've added the (0-weighted) item and any parent buckets, adjust the weight. adjust_item_weight(item, weight); return 0; } -- 2.39.5