*
*/
-#include <regex>
-#include <locale>
-#include <sstream>
#include <algorithm>
-
#include <boost/algorithm/string.hpp>
-#include <boost/algorithm/string/predicate.hpp>
+#include <locale>
+#include <sstream>
#include "mon/OSDMonitor.h"
#include "mon/Monitor.h"
} // anonymous namespace
-// Helpers for parsing commands:
-namespace {
-
-inline std::string make_ws_trimmed(const std::string& input)
-{
- return input.substr(
- input.find_first_not_of(" \t\n\r"),
- input.find_last_not_of(" \t\n\r"));
-}
-
-// A shame we don't have std::string_view, but this should not be /too/ high-overhead:
-inline bool cmd_match(const string cmd_string, const string cmd_prefix, bool matching_fn(const string))
-try
-{
- if(std::string::npos == cmd_string.find(cmd_prefix))
- return false;
-
- return matching_fn(make_ws_trimmed(
- cmd_string.substr(cmd_prefix.size(), cmd_string.size())));
-}
-catch(std::out_of_range&)
-{
- return false;
-}
-
-inline bool cmd_match(const string cmd_string, const string cmd_prefix, const string match_str)
-try
-{
- if(std::string::npos == cmd_string.find(cmd_prefix))
- return false;
-
- return match_str == make_ws_trimmed(
- cmd_string.substr(cmd_prefix.size(), cmd_string.size()));
-}
-catch(std::out_of_range&)
-{
- return false;
-}
-
-// Matches the tail of a command, starting after cmd_prefix:
-inline bool cmd_match_any(const string, const string)
-{
- return false;
-}
-
-template <typename MatchT, typename ...MatchTS>
-inline bool cmd_match_any(const string cmd_string, const string cmd_prefix, MatchT match_with, MatchTS ...match_ts)
-{
- return cmd_match(cmd_string, cmd_prefix, match_with) || cmd_match_any(cmd_string, cmd_prefix, match_ts...);
-}
-
-// Note that ValueT is not defined in terms of value_type:
-template <typename ValueT>
-inline bool equal_to_any_in(const ValueT v, const std::vector<std::string>&& xs)
-{
- using namespace std;
-
- return any_of(begin(xs), end(xs),
- [&v](const ValueT cand) { return v == cand; });
-}
-
-template <typename ValueT>
-inline bool ends_with_any_in(const ValueT v, const std::vector<std::string>&& xs)
-{
- using namespace std;
-
- return any_of(begin(xs), end(xs), [&v](const ValueT cand) {
- return boost::algorithm::ends_with(v, cand);
- });
-}
-
-bool match_cmd_delete_remove(const std::string cmd)
-{
- return equal_to_any_in(cmd, { "rm", "remove", "del", "delete" });
-}
-
-constexpr auto cmd_delete_remove_strings { "(rm|remove|del|delete)" };
-
-// Pretty half-baked, but should make life easier in several situations:
-// Helps handle the form "osd del-foo":
-auto match_remove_cmd_in(const string prefix, const string alternatives)
-{
- // Synthesize a regular expression such as:
- // osd\s+(rm|remove|del|delete)+\-(noup|nodown|noin|noout)($|(\s+.*))
- string regex_pattern = prefix + R"(\s+)"
- + cmd_delete_remove_strings + '+'
- + R"(\-)"
- + '(' + alternatives + ')'
- + R"(($|(\s+.*)))"
- ;
-
- return regex { regex_pattern };
-}
-
-bool matches_cmd_delete_remove(const std::string input, const std::string prefix, const std::string alternatives)
-{
- return regex_match(input,
- match_remove_cmd_in(prefix, "noup|nodown|noin|noout"));
-}
-
-} // anonymous namespace
-
void LastEpochClean::Lec::report(ps_t ps, epoch_t last_epoch_clean)
{
if (epoch_by_pg.size() <= ps) {
p.application_metadata[app][key] = value;
ss << "set application '" << app << "' key '" << key << "' to '"
<< value << "' on pool '" << pool_name << "'";
- } else if (ends_with_any_in(prefix, { "rm", "remove", "del", "delete" })) {
+ } else if (boost::algorithm::ends_with(prefix, "rm")) {
if (!app_exists) {
ss << "application '" << app << "' is not enabled on pool '" << pool_name
<< "'";
newcrush.encode(pending_inc.crush, mon->get_quorum_con_features());
goto update;
- } else if (cmd_match_any(prefix, "osd crush weight-set", &match_cmd_delete_remove, "rm-compat")) {
+ } else if (prefix == "osd crush weight-set rm" ||
+ prefix == "osd crush weight-set rm-compat") {
CrushWrapper newcrush;
_get_pending_crush(newcrush);
int64_t pool;
- if (cmd_match(prefix, "osd crush weight-set", &match_cmd_delete_remove)) { // eg. not "rm-compat"
+ if (prefix == "osd crush weight-set rm") {
string poolname;
cmd_getval(cct, cmdmap, "pool", poolname);
pool = osdmap.lookup_pg_pool_name(poolname.c_str());
wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, err, ss.str(),
get_last_committed() + 1));
return true;
- } else if (cmd_match(prefix, "osd crush", "rm|remove|del|delete|unlink")) {
+ } else if (prefix == "osd crush rm" ||
+ prefix == "osd crush remove" ||
+ prefix == "osd crush unlink") {
do {
// osd crush rm <id> [ancestor]
CrushWrapper newcrush;
get_last_committed() + 1));
return true;
- } else if (cmd_match_any(prefix, "osd erasure-code-profile", &match_cmd_delete_remove)) {
+ } else if (prefix == "osd erasure-code-profile rm") {
string name;
cmd_getval(cct, cmdmap, "name", name);
get_last_committed() + 1));
return true;
- } else if (cmd_match_any(prefix, "osd crush rule", &match_cmd_delete_remove)) {
+ } else if (prefix == "osd crush rule rm") {
string name;
cmd_getval(cct, cmdmap, "name", name);
} else if (prefix == "osd down" ||
prefix == "osd out" ||
prefix == "osd in" ||
- cmd_match_any(prefix, "osd", &match_cmd_delete_remove)) {
+ prefix == "osd rm") {
bool any = false;
bool stop = false;
ss << "marked in osd." << osd << ". ";
any = true;
}
- } else if (cmd_match_any(prefix, "osd", &match_cmd_delete_remove)) {
+ } else if (prefix == "osd rm") {
err = prepare_command_osd_remove(osd);
if (err == -EBUSY) {
get_last_committed() + 1));
return true;
}
- } else if (matches_cmd_delete_remove(prefix, "osd", "noup|nodown|noin|noout")) {
+ } else if (prefix == "osd rm-noup" ||
+ prefix == "osd rm-nodown" ||
+ prefix == "osd rm-noin" ||
+ prefix == "osd rm-noout") {
enum {
OP_NOUP,
wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs,
get_last_committed() + 1));
return true;
- } else if (match_cmd_delete_remove(blacklistop)) {
+ } else if (blacklistop == "rm") {
if (osdmap.is_blacklisted(addr) ||
pending_inc.new_blacklist.count(addr)) {
if (osdmap.is_blacklisted(addr))
get_last_committed() + 1));
return true;
- } else if (cmd_match_any(prefix, "osd pool", &match_cmd_delete_remove)) {
+ } else if (prefix == "osd pool delete" ||
+ prefix == "osd pool rm") {
// osd pool delete/rm <poolname> <poolname again> --yes-i-really-really-mean-it
string poolstr, poolstr2, sure;
cmd_getval(cct, cmdmap, "pool", poolstr);
wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, ss.str(),
get_last_committed() + 1));
return true;
- } else if (cmd_match_any(prefix, "osd tier", &match_cmd_delete_remove)) {
+ } else if (prefix == "osd tier remove" ||
+ prefix == "osd tier rm") {
string poolstr;
cmd_getval(cct, cmdmap, "pool", poolstr);
int64_t pool_id = osdmap.lookup_pg_pool_name(poolstr);
wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, ss.str(),
get_last_committed() + 1));
return true;
- } else if (cmd_match_any(prefix, "osd tier",
- "remove-overlay", "rm-overlay",
- "delete-overlay", "del-overlay")) {
+ } else if (prefix == "osd tier remove-overlay" ||
+ prefix == "osd tier rm-overlay") {
string poolstr;
cmd_getval(cct, cmdmap, "pool", poolstr);
int64_t pool_id = osdmap.lookup_pg_pool_name(poolstr);
} else if (prefix == "osd pool application enable" ||
prefix == "osd pool application disable" ||
prefix == "osd pool application set" ||
- cmd_match_any(prefix, "osd pool application", &match_cmd_delete_remove)) {
+ prefix == "osd pool application rm") {
err = prepare_command_pool_application(prefix, cmdmap, ss);
if (err == -EAGAIN)
goto wait;