From c62e5dac91d4df3d27ec50f02efabbeb2db4dc45 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 19 May 2017 10:25:43 -0400 Subject: [PATCH] mon: move parse_* helpers into cmdparse Signed-off-by: Sage Weil --- src/common/cmdparse.cc | 44 ++++++++++++++++++++++++++++++++++++++++++ src/common/cmdparse.h | 8 +++++++- src/mon/Monitor.cc | 23 ---------------------- src/mon/Monitor.h | 2 -- src/mon/OSDMonitor.cc | 22 --------------------- src/mon/OSDMonitor.h | 2 -- 6 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/common/cmdparse.cc b/src/common/cmdparse.cc index c396b8ada48ed..5a8e78e08f22c 100644 --- a/src/common/cmdparse.cc +++ b/src/common/cmdparse.cc @@ -331,3 +331,47 @@ handle_bad_get(CephContext *cct, const string& k, const char *tname) if (status == 0) free((char *)typestr); } + +long parse_pos_long(const char *s, std::ostream *pss) +{ + if (*s == '-' || *s == '+') { + if (pss) + *pss << "expected numerical value, got: " << s; + return -EINVAL; + } + + string err; + long r = strict_strtol(s, 10, &err); + if ((r == 0) && !err.empty()) { + if (pss) + *pss << err; + return -1; + } + if (r < 0) { + if (pss) + *pss << "unable to parse positive integer '" << s << "'"; + return -1; + } + return r; +} + +int parse_osd_id(const char *s, std::ostream *pss) +{ + // osd.NNN? + if (strncmp(s, "osd.", 4) == 0) { + s += 4; + } + + // NNN? + ostringstream ss; + long id = parse_pos_long(s, &ss); + if (id < 0) { + *pss << ss.str(); + return id; + } + if (id > 0xffff) { + *pss << "osd id " << id << " is too large"; + return -ERANGE; + } + return id; +} diff --git a/src/common/cmdparse.h b/src/common/cmdparse.h index 236b1f51a0ffc..7de4cbf67c467 100644 --- a/src/common/cmdparse.h +++ b/src/common/cmdparse.h @@ -4,7 +4,9 @@ #define CEPH_COMMON_CMDPARSE_H #include - +#include +#include +#include #include "common/Formatter.h" #include "common/BackTrace.h" @@ -73,4 +75,8 @@ cmd_putval(CephContext *cct, cmdmap_t& cmdmap, const std::string& k, const T& va { cmdmap[k] = val; } + +extern int parse_osd_id(const char *s, std::ostream *pss); +extern long parse_pos_long(const char *s, std::ostream *pss = NULL); + #endif diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 8a93389dac02a..13994bab1138e 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -125,29 +125,6 @@ MonCommand mon_commands[] = { }; -long parse_pos_long(const char *s, ostream *pss) -{ - if (*s == '-' || *s == '+') { - if (pss) - *pss << "expected numerical value, got: " << s; - return -EINVAL; - } - - string err; - long r = strict_strtol(s, 10, &err); - if ((r == 0) && !err.empty()) { - if (pss) - *pss << err; - return -1; - } - if (r < 0) { - if (pss) - *pss << "unable to parse positive integer '" << s << "'"; - return -1; - } - return r; -} - void C_MonContext::finish(int r) { if (mon->is_shutdown()) return; diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 47beafb4bd0ad..0d3a9080e812c 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -950,8 +950,6 @@ public: #define CEPH_MON_FEATURE_INCOMPAT_KRAKEN CompatSet::Feature(8, "support monmap features") // make sure you add your feature to Monitor::get_supported_features -long parse_pos_long(const char *s, ostream *pss = NULL); - struct MonCommand { string cmdstring; string helpstring; diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 4fc513a319795..3a6d6ab31fede 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -5873,28 +5873,6 @@ bool OSDMonitor::prepare_unset_flag(MonOpRequestRef op, int flag) return true; } -int OSDMonitor::parse_osd_id(const char *s, stringstream *pss) -{ - // osd.NNN? - if (strncmp(s, "osd.", 4) == 0) { - s += 4; - } - - // NNN? - ostringstream ss; - long id = parse_pos_long(s, &ss); - if (id < 0) { - *pss << ss.str(); - return id; - } - if (id > 0xffff) { - *pss << "osd id " << id << " is too large"; - return -ERANGE; - } - return id; -} - - int OSDMonitor::prepare_command_pool_set(map &cmdmap, stringstream& ss) { diff --git a/src/mon/OSDMonitor.h b/src/mon/OSDMonitor.h index 992ecdb2d0120..b87a5af6036d7 100644 --- a/src/mon/OSDMonitor.h +++ b/src/mon/OSDMonitor.h @@ -469,8 +469,6 @@ public: void tick() override; // check state, take actions - int parse_osd_id(const char *s, stringstream *pss); - void get_health(list >& summary, list > *detail, CephContext *cct) const override; -- 2.39.5