From 6dea605445c934bb1addd3fb4a9925c77c4a1901 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 14 Jul 2017 15:31:37 -0400 Subject: [PATCH] crush/CrushWrapper: detach_bucket uninline Signed-off-by: Sage Weil --- src/crush/CrushWrapper.cc | 52 ++++++++++++++++++++++++++++++++++++++- src/crush/CrushWrapper.h | 46 +--------------------------------- 2 files changed, 52 insertions(+), 46 deletions(-) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index c3e1c50e36422..b8cfc449aaed5 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -950,7 +950,9 @@ int CrushWrapper::insert_item( return -EINVAL; } -int CrushWrapper::move_bucket(CephContext *cct, int id, const map& loc) + +int CrushWrapper::move_bucket( + CephContext *cct, int id, const map& loc) { // sorry this only works for buckets if (id >= 0) @@ -969,6 +971,54 @@ int CrushWrapper::move_bucket(CephContext *cct, int id, const map return insert_item(cct, id, bucket_weight / (float)0x10000, id_name, loc); } +int CrushWrapper::detach_bucket(CephContext *cct, int item) +{ + if (!crush) + return (-EINVAL); + + if (item >= 0) + return (-EINVAL); + + // check that the bucket that we want to detach exists + assert(bucket_exists(item)); + + // get the bucket's weight + crush_bucket *b = get_bucket(item); + unsigned bucket_weight = b->weight; + + // get where the bucket is located + pair bucket_location = get_immediate_parent(item); + + // get the id of the parent bucket + int parent_id = get_item_id(bucket_location.second); + + // get the parent bucket + crush_bucket *parent_bucket = get_bucket(parent_id); + + if (!IS_ERR(parent_bucket)) { + // zero out the bucket weight + bucket_adjust_item_weight(cct, parent_bucket, item, 0); + adjust_item_weight(cct, parent_bucket->id, parent_bucket->weight); + + // remove the bucket from the parent + bucket_remove_item(parent_bucket, item); + } else if (PTR_ERR(parent_bucket) != -ENOENT) { + return PTR_ERR(parent_bucket); + } + + // check that we're happy + int test_weight = 0; + map test_location; + test_location[ bucket_location.first ] = (bucket_location.second); + + bool successful_detach = !(check_item_loc(cct, item, test_location, + &test_weight)); + assert(successful_detach); + assert(test_weight == 0); + + return bucket_weight; +} + int CrushWrapper::swap_bucket(CephContext *cct, int src, int dst) { if (src >= 0 || dst >= 0) diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index ba6ffdf5b8830..cd3d1f58f164e 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -1123,51 +1123,7 @@ private: * * returns the weight of the detached bucket **/ - int detach_bucket(CephContext *cct, int item){ - if (!crush) - return (-EINVAL); - - if (item >= 0) - return (-EINVAL); - - // check that the bucket that we want to detach exists - assert(bucket_exists(item)); - - // get the bucket's weight - crush_bucket *b = get_bucket(item); - unsigned bucket_weight = b->weight; - - // get where the bucket is located - pair bucket_location = get_immediate_parent(item); - - // get the id of the parent bucket - int parent_id = get_item_id(bucket_location.second); - - // get the parent bucket - crush_bucket *parent_bucket = get_bucket(parent_id); - - if (!IS_ERR(parent_bucket)) { - // zero out the bucket weight - bucket_adjust_item_weight(cct, parent_bucket, item, 0); - adjust_item_weight(cct, parent_bucket->id, parent_bucket->weight); - - // remove the bucket from the parent - bucket_remove_item(parent_bucket, item); - } else if (PTR_ERR(parent_bucket) != -ENOENT) { - return PTR_ERR(parent_bucket); - } - - // check that we're happy - int test_weight = 0; - map test_location; - test_location[ bucket_location.first ] = (bucket_location.second); - - bool successful_detach = !(check_item_loc(cct, item, test_location, &test_weight)); - assert(successful_detach); - assert(test_weight == 0); - - return bucket_weight; - } + int detach_bucket(CephContext *cct, int item); public: int get_max_buckets() const { -- 2.39.5