]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/PGMap: let pg_string_state() return boost::optional<>
authorKefu Chai <kchai@redhat.com>
Tue, 10 Oct 2017 12:32:08 +0000 (20:32 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 11 Oct 2017 03:14:55 +0000 (11:14 +0800)
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 <kchai@redhat.com>
(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
src/osd/osd_types.cc
src/osd/osd_types.h

index 431783d4a6788f0ba05a98735b7968b083cf4dfe..e07143383a71c93cde0319672a7bb0ab200ce39e 100644 (file)
@@ -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();
index 393cd7097d23fdb9483949fd2571e506fc31f629..e0de890adc648f4d21bf6987dff5a1858de72c0c 100644 (file)
@@ -854,9 +854,9 @@ std::string pg_state_string(int state)
   return ret;
 }
 
-int pg_string_state(const std::string& state)
+boost::optional<uint64_t> pg_string_state(const std::string& state)
 {
-  int type;
+  boost::optional<uint64_t> 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;
 }
 
index 43d9a98e73753ea8bb14c45ba32f01ea19a24d0b..150a6666632f505df579896bca448901037b36ee 100644 (file)
@@ -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<int32_t> &a);
-int pg_string_state(const std::string& state);
+boost::optional<uint64_t> pg_string_state(const std::string& state);
 
 
 /*