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

index b3ec334a728daedbe2cc8166de4d3953381e3672..0b6d3480497e7d4260bf88c68aaa9303b05af373 100644 (file)
@@ -2959,13 +2959,13 @@ int process_pg_map_command(
         state = -1;
         break;
       } else {
-        int64_t 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 5f32dc7ea4458b022fa79f7c98e69295e80be6d6..ceced3cb40b7e1d65b05d378810bef197eb3dddc 100644 (file)
@@ -853,9 +853,9 @@ std::string pg_state_string(uint64_t state)
   return ret;
 }
 
-int64_t pg_string_state(const std::string& state)
+boost::optional<uint64_t> pg_string_state(const std::string& state)
 {
-  int64_t type;
+  boost::optional<uint64_t> type;
   if (state == "active")
     type = PG_STATE_ACTIVE;
   else if (state == "clean")
@@ -909,7 +909,7 @@ int64_t 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 57acf95900ca5801a11c9783d1380073701e7123..33583e216393846c15dc5f46b6096a043c7d2646 100644 (file)
@@ -1008,7 +1008,7 @@ inline ostream& operator<<(ostream& out, const osd_stat_t& s) {
 
 std::string pg_state_string(uint64_t state);
 std::string pg_vector_string(const vector<int32_t> &a);
-int64_t pg_string_state(const std::string& state);
+boost::optional<uint64_t> pg_string_state(const std::string& state);
 
 
 /*