From a96869223e3f1ba15b4eb7b5005e2300c782a142 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 3 May 2013 15:54:19 -0700 Subject: [PATCH] mon: generate useful error msgs for 'osd crush rule create-simple ...' Signed-off-by: Sage Weil --- src/crush/CrushWrapper.cc | 15 ++++++++++++--- src/crush/CrushWrapper.h | 3 ++- src/mon/OSDMonitor.cc | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index e8058d60a57ef..8d07c5ec79577 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -631,17 +631,26 @@ void CrushWrapper::reweight(CephContext *cct) } } -int CrushWrapper::add_simple_rule(string name, string root_name, string failure_domain_name) +int CrushWrapper::add_simple_rule(string name, string root_name, string failure_domain_name, + ostream *err) { - if (rule_exists(name)) + if (rule_exists(name)) { + if (err) + *err << "rule " << name << " exists"; return -EEXIST; - if (!name_exists(root_name)) + } + if (!name_exists(root_name)) { + if (err) + *err << "root item " << root_name << " does not exist"; return -ENOENT; + } int root = get_item_id(root_name); int type = 0; if (failure_domain_name.length()) { type = get_type_id(failure_domain_name); if (type < 0) { + if (err) + *err << "unknown type " << failure_domain_name; return -EINVAL; } } diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index ac936336125cc..ce97b29ad9da9 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -575,7 +575,8 @@ public: return set_rule_step(ruleno, step, CRUSH_RULE_EMIT, 0, 0); } - int add_simple_rule(string name, string root_name, string failure_domain_type); + int add_simple_rule(string name, string root_name, string failure_domain_type, + ostream *err = 0); int remove_rule(int ruleno); diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 75105cadadf92..7c5ffce48ce62 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2861,7 +2861,7 @@ bool OSDMonitor::prepare_command(MMonCommand *m) ss << "rule " << name << " already exists"; err = 0; } else { - int rule = newcrush.add_simple_rule(name, root, type); + int rule = newcrush.add_simple_rule(name, root, type, &ss); if (rule < 0) { err = rule; goto out; -- 2.39.5