From 8894c5041d2dbd7408b428e5c2b3434aae2d697f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 3 May 2013 15:26:22 -0700 Subject: [PATCH] crush: return -1 on error from get_type_id So we can distinguish between a bad type name and type 0. Fix both callers, too. Signed-off-by: Sage Weil --- src/crush/CrushWrapper.cc | 3 ++- src/crush/CrushWrapper.h | 2 +- src/mon/OSDMonitor.cc | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 1fc86893e1d..e8058d60a57 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -641,8 +641,9 @@ int CrushWrapper::add_simple_rule(string name, string root_name, string failure_ int type = 0; if (failure_domain_name.length()) { type = get_type_id(failure_domain_name); - if (type <= 0) // bah, returns 0 on error; but its ok, device isn't a domain really + if (type < 0) { return -EINVAL; + } } int ruleset = 0; diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 9109156d066..ac936336125 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -166,7 +166,7 @@ public: build_rmaps(); if (type_rmap.count(name)) return type_rmap[name]; - return 0; + return -1; } const char *get_type_name(int t) const { std::map::const_iterator p = type_map.find(t); diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index d46c28f6ff2..75105cadadf 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2557,7 +2557,7 @@ bool OSDMonitor::prepare_command(MMonCommand *m) err = 0; } else { int type = newcrush.get_type_id(m->cmd[4]); - if (type <= 0) { + if (type < 0) { ss << "type '" << m->cmd[4] << "' does not exist"; err = -EINVAL; break; -- 2.47.3