From d5084f3f863d2812be6defb0209be256f7d23d4b Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Tue, 16 Sep 2014 11:27:54 +0200 Subject: [PATCH] mon: add the get_crush_ruleset helper By factoring a code snippet from prepare_pool_crush_ruleset with no modification. Signed-off-by: Loic Dachary --- src/mon/OSDMonitor.cc | 51 +++++++++++++++++++++++++------------------ src/mon/OSDMonitor.h | 3 +++ 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 25a5bc7fc05cf..b2fda0e0df76b 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -3405,27 +3405,7 @@ int OSDMonitor::prepare_pool_crush_ruleset(const unsigned pool_type, return *crush_ruleset; } } else { - int ret; - ret = osdmap.crush->get_rule_id(ruleset_name); - if (ret != -ENOENT) { - // found it, use it - *crush_ruleset = ret; - } else { - CrushWrapper newcrush; - _get_pending_crush(newcrush); - - ret = newcrush.get_rule_id(ruleset_name); - if (ret != -ENOENT) { - // found it, wait for it to be proposed - dout(20) << "prepare_pool_crush_ruleset: ruleset " - << ruleset_name << " is pending, try again" << dendl; - return -EAGAIN; - } else { - //Cannot find it , return error - ss << "Specified ruleset " << ruleset_name << " doesn't exist"; - return ret; - } - } + return get_crush_ruleset(ruleset_name, crush_ruleset, ss); } } break; @@ -3464,6 +3444,35 @@ int OSDMonitor::prepare_pool_crush_ruleset(const unsigned pool_type, return 0; } + +int OSDMonitor::get_crush_ruleset(const string &ruleset_name, + int *crush_ruleset, + stringstream &ss) +{ + int ret; + ret = osdmap.crush->get_rule_id(ruleset_name); + if (ret != -ENOENT) { + // found it, use it + *crush_ruleset = ret; + } else { + CrushWrapper newcrush; + _get_pending_crush(newcrush); + + ret = newcrush.get_rule_id(ruleset_name); + if (ret != -ENOENT) { + // found it, wait for it to be proposed + dout(20) << __func__ << ": ruleset " << ruleset_name + << " try again" << dendl; + return -EAGAIN; + } else { + //Cannot find it , return error + ss << "specified ruleset " << ruleset_name << " doesn't exist"; + return ret; + } + } + return 0; +} + /** * @param name The name of the new pool * @param auid The auid of the pool owner. Can be -1 diff --git a/src/mon/OSDMonitor.h b/src/mon/OSDMonitor.h index e28efba40229f..44aa02f6fc120 100644 --- a/src/mon/OSDMonitor.h +++ b/src/mon/OSDMonitor.h @@ -257,6 +257,9 @@ private: const string &profile, int *ruleset, stringstream &ss); + int get_crush_ruleset(const string &ruleset_name, + int *crush_ruleset, + stringstream &ss); int get_erasure_code(const string &erasure_code_profile, ErasureCodeInterfaceRef *erasure_code, stringstream &ss) const; -- 2.39.5