]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/common/cmdparse.cc
update sources to v12.1.0
[ceph.git] / ceph / src / common / cmdparse.cc
index 3fdf94c73676600d72b084a39acd36fb490ede5d..5a8e78e08f22ca3e2a40a16d51d1a8a2568a9b67 100644 (file)
  *
  */
 
-#include <cxxabi.h>
-#include "common/cmdparse.h"
-#include "common/Formatter.h"
-#include "include/str_list.h"
 #include "json_spirit/json_spirit.h"
 #include "common/debug.h"
 
@@ -319,7 +315,7 @@ cmd_vartype_stringify(const cmd_vartype &v)
 
 
 void
-handle_bad_get(CephContext *cct, string k, const char *tname)
+handle_bad_get(CephContext *cct, const string& k, const char *tname)
 {
   ostringstream errstr;
   int status;
@@ -335,3 +331,47 @@ handle_bad_get(CephContext *cct, 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;
+}