From aeb3a8f447928d248d44a5c572eb099f707eedd8 Mon Sep 17 00:00:00 2001 From: Caleb Miles Date: Sun, 3 Jun 2012 15:25:09 -0700 Subject: [PATCH] crush: check_item_present True if id is present in the map. Signed-off-by: Caleb Miles --- src/crush/CrushWrapper.cc | 16 ++++++++++++++++ src/crush/CrushWrapper.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 1476286c72919..fd86f36186189 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -240,6 +240,22 @@ int CrushWrapper::adjust_item_weight(CephContext *cct, int id, int weight) return -ENOENT; } +bool CrushWrapper::check_item_present(int id) +{ + bool found = false; + + for (int bidx = 0; bidx < crush->max_buckets; bidx++) { + crush_bucket *b = crush->buckets[bidx]; + if (b == 0) + continue; + for (unsigned i = 0; i < b->size; i++) + if (b->items[i] == id) + found = true; + } + return found; +} + + void CrushWrapper::reweight(CephContext *cct) { set roots; diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 7f843cc0feb3b..fd48e64c76d3e 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -253,6 +253,10 @@ public: } void reweight(CephContext *cct); + /// check if item id is present in the map hierarchy + bool check_item_present(int id); + + /*** devices ***/ int get_max_devices() const { if (!crush) return 0; -- 2.39.5