From 51c6f0def379ba013a82204398a021663f1b5d56 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 10 Oct 2017 20:32:08 +0800 Subject: [PATCH] mon/PGMap: let pg_string_state() return boost::optional<> better to be specific, so we don't run into the same problem even we are using the MSB of uint64_t for a pg state bit in future. we could, however use uint64_t(-1) to indicate the pg_string_state()'s failure to parse the state string, because pg_string_state() only translate a single state a time. but it's always better to be explicit than implicit. Fixes: http://tracker.ceph.com/issues/21609 Signed-off-by: Kefu Chai (cherry picked from commit 260f87a9f1c4e32ff3a596ea341ad07a901f44a9) Conflicts: src/mon/PGMap.cc src/osd/osd_types.cc src/osd/osd_types.h: trivial resolution --- src/mon/PGMap.cc | 6 +++--- src/osd/osd_types.cc | 6 +++--- src/osd/osd_types.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mon/PGMap.cc b/src/mon/PGMap.cc index 431783d4a678..e07143383a71 100644 --- a/src/mon/PGMap.cc +++ b/src/mon/PGMap.cc @@ -3885,13 +3885,13 @@ int process_pg_map_command( state = -1; break; } else { - int filter = pg_string_state(state_str); - if (filter < 0) { + auto filter = pg_string_state(state_str); + if (!filter) { *ss << "'" << state_str << "' is not a valid pg state," << " available choices: " << pg_state_string(0xFFFFFFFF); return -EINVAL; } - state |= filter; + state |= *filter; } states.pop_back(); diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 393cd7097d23..e0de890adc64 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -854,9 +854,9 @@ std::string pg_state_string(int state) return ret; } -int pg_string_state(const std::string& state) +boost::optional pg_string_state(const std::string& state) { - int type; + boost::optional type; if (state == "active") type = PG_STATE_ACTIVE; else if (state == "clean") @@ -910,7 +910,7 @@ int pg_string_state(const std::string& state) else if (state == "snaptrim_error") type = PG_STATE_SNAPTRIM_ERROR; else - type = -1; + type = boost::none; return type; } diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 43d9a98e7375..150a6666632f 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -1001,7 +1001,7 @@ inline ostream& operator<<(ostream& out, const osd_stat_t& s) { std::string pg_state_string(int state); std::string pg_vector_string(const vector &a); -int pg_string_state(const std::string& state); +boost::optional pg_string_state(const std::string& state); /* -- 2.47.3