]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: move parse_* helpers into cmdparse
authorSage Weil <sage@redhat.com>
Fri, 19 May 2017 14:25:43 +0000 (10:25 -0400)
committerSage Weil <sage@redhat.com>
Fri, 2 Jun 2017 17:02:47 +0000 (13:02 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/cmdparse.cc
src/common/cmdparse.h
src/mon/Monitor.cc
src/mon/Monitor.h
src/mon/OSDMonitor.cc
src/mon/OSDMonitor.h

index c396b8ada48ed671deabe6173898c70486607385..5a8e78e08f22ca3e2a40a16d51d1a8a2568a9b67 100644 (file)
@@ -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;
+}
index 236b1f51a0ffc99ad41e4610143ce7e807f4eda9..7de4cbf67c4671d545350a797cc7f9aad514edb2 100644 (file)
@@ -4,7 +4,9 @@
 #define CEPH_COMMON_CMDPARSE_H
 
 #include <boost/variant.hpp>
-
+#include <vector>
+#include <stdexcept>
+#include <ostream>
 #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
index 8a93389dac02abeafab6a6673c391ed89f0759c2..13994bab1138ed7823cc0547e24b7dcaf8812730 100644 (file)
@@ -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;
index 47beafb4bd0ad3a4f270deda9d29399919c20534..0d3a9080e812c560de47e2cfd7df1dedf704e438 100644 (file)
@@ -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;
index 4fc513a319795f7446636829ff3e67f6042c7402..3a6d6ab31fedefa21fa4a339df6ceac9812058d4 100644 (file)
@@ -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<string,cmd_vartype> &cmdmap,
                                          stringstream& ss)
 {
index 992ecdb2d012011947a2c2a76ad0976501b8ca0a..b87a5af6036d7a449ec628da2229608fa919ce8a 100644 (file)
@@ -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<pair<health_status_t,string> >& summary,
                  list<pair<health_status_t,string> > *detail,
                  CephContext *cct) const override;