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>
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();
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")
else if (state == "snaptrim_error")
type = PG_STATE_SNAPTRIM_ERROR;
else
- type = -1;
+ type = boost::none;
return type;
}
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);
/*