From: Sage Weil Date: Wed, 25 May 2011 04:05:47 +0000 (-0700) Subject: crushtool: fix remove-item X-Git-Tag: v0.29~35 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=dd89ff44200a626ce70a1f389919045ecf4daa9a;p=ceph.git crushtool: fix remove-item Scan all buckets instead of doing a tree traverse. Signed-off-by: Sage Weil --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 41becbcb2e2..84258122316 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -17,48 +17,32 @@ void CrushWrapper::find_roots(set& 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 roots; - find_roots(roots); - for (set::iterator p = roots.begin(); p != roots.end(); ++p) { - list 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; isize; ++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; isize; ++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; } diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index f70f52ab093..446cfcb9ad2 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -155,7 +155,7 @@ public: void find_roots(set& roots) const; int insert_device(int id, int weight, string name, map& 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)); diff --git a/src/crushtool.cc b/src/crushtool.cc index 0497c7ec822..392b9e088fd 100644 --- a/src/crushtool.cc +++ b/src/crushtool.cc @@ -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;