]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
*: drop strict_iecstrtoll(const char *str,..) 42485/head
authorKefu Chai <kchai@redhat.com>
Mon, 26 Jul 2021 07:16:06 +0000 (15:16 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 26 Jul 2021 12:12:17 +0000 (20:12 +0800)
replace strict_iecstrtoll(const char *str,..) with
strict_iecstrtoll(std::string_view, ..). which is more convenient.
and both of them share the same implementation:

strict_iec_cast<uint64_t>(str, err);

so they are interchangeable.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/options.cc
src/common/strtol.cc
src/common/strtol.h
src/kv/RocksDBStore.cc
src/mon/OSDMonitor.cc
src/os/bluestore/BitmapFreelistManager.cc
src/test/objectstore_bench.cc
src/tools/ceph_dedup_tool.cc
src/tools/rbd/ArgumentTypes.cc
src/tools/rbd/action/Bench.cc

index 8c9b7418b6edc2b143c3ac5c8a5b60cc9d40f0d5..a68e2474a3dc45c6d1b7eec7d69f2e214cc11010 100644 (file)
@@ -196,7 +196,7 @@ int Option::parse_value(
     }
     *out = uuid;
   } else if (type == Option::TYPE_SIZE) {
-    Option::size_t sz{strict_iecstrtoll(val.c_str(), error_message)};
+    Option::size_t sz{strict_iecstrtoll(val, error_message)};
     if (!error_message->empty()) {
       return -EINVAL;
     }
index ff4040b18c21e7547a885cb49c8c7a0bb1b6f1ab..c9e982b63962ccbd093bd2708c07f9a3f96c7332 100644 (file)
@@ -220,11 +220,6 @@ uint64_t strict_iecstrtoll(std::string_view str, std::string *err)
   return strict_iec_cast<uint64_t>(str, err);
 }
 
-uint64_t strict_iecstrtoll(const char *str, std::string *err)
-{
-  return strict_iec_cast<uint64_t>(str, err);
-}
-
 template<typename T>
 T strict_si_cast(std::string_view str, std::string *err)
 {
index 92cca690de97148a5a7b3d61f4f08f12b6e4fae7..2183137b1edf9c6bd1e27cf8692d18e518402d02 100644 (file)
@@ -79,7 +79,7 @@ double strict_strtod(std::string_view str, std::string *err);
 
 float strict_strtof(std::string_view str, std::string *err);
 
-uint64_t strict_iecstrtoll(const char *str, std::string *err);
+uint64_t strict_iecstrtoll(std::string_view str, std::string *err);
 
 template<typename T>
 T strict_iec_cast(std::string_view str, std::string *err);
index 05ad8844cb017a3664910ef8a6762ef124b1bea3..18cba3e517a9530ca63ee6bd7ad3d1dd21764a56 100644 (file)
@@ -319,14 +319,14 @@ int RocksDBStore::tryInterpret(const string &key, const string &val, rocksdb::Op
 {
   if (key == "compaction_threads") {
     std::string err;
-    int f = strict_iecstrtoll(val.c_str(), &err);
+    int f = strict_iecstrtoll(val, &err);
     if (!err.empty())
       return -EINVAL;
     //Low priority threadpool is used for compaction
     opt.env->SetBackgroundThreads(f, rocksdb::Env::Priority::LOW);
   } else if (key == "flusher_threads") {
     std::string err;
-    int f = strict_iecstrtoll(val.c_str(), &err);
+    int f = strict_iecstrtoll(val, &err);
     if (!err.empty())
       return -EINVAL;
     //High priority threadpool is used for flusher
@@ -960,7 +960,7 @@ int RocksDBStore::verify_sharding(const rocksdb::Options& opt,
       size_t cache_size = cct->_conf->rocksdb_cache_size;
       if (auto it = cache_options_map.find("size"); it !=cache_options_map.end()) {
        std::string error;
-       cache_size = strict_iecstrtoll(it->second.c_str(), &error);
+       cache_size = strict_iecstrtoll(it->second, &error);
        if (!error.empty()) {
          derr << __func__ << " invalid size: '" << it->second << "'" << dendl;
        }
index d7ece669c34f1b8700438934dab6e599d8d86464..8fd947510ce42df688fd163a07c0d47258e8cd65 100644 (file)
@@ -7346,7 +7346,7 @@ int OSDMonitor::normalize_profile(const string& profilename,
   auto it = profile.find("stripe_unit");
   if (it != profile.end()) {
     string err_str;
-    uint32_t stripe_unit = strict_iecstrtoll(it->second.c_str(), &err_str);
+    uint32_t stripe_unit = strict_iecstrtoll(it->second, &err_str);
     if (!err_str.empty()) {
       *ss << "could not parse stripe_unit '" << it->second
          << "': " << err_str << std::endl;
@@ -7644,7 +7644,7 @@ int OSDMonitor::prepare_pool_stripe_width(const unsigned pool_type,
       auto it = profile.find("stripe_unit");
       if (it != profile.end()) {
        string err_str;
-       stripe_unit = strict_iecstrtoll(it->second.c_str(), &err_str);
+       stripe_unit = strict_iecstrtoll(it->second, &err_str);
        ceph_assert(err_str.empty());
       }
       *stripe_width = data_chunks *
@@ -13435,7 +13435,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
     if (field == "max_objects") {
       value = strict_si_cast<uint64_t>(val, &tss);
     } else if (field == "max_bytes") {
-      value = strict_iecstrtoll(val.c_str(), &tss);
+      value = strict_iecstrtoll(val, &tss);
     } else {
       ceph_abort_msg("unrecognized option");
     }
index 315a6bb8c43cf465ab351e70992c941a75ce45cd..edc489b6851b15c19283d1adedb0e4ce54850d30 100644 (file)
@@ -260,7 +260,7 @@ int BitmapFreelistManager::_read_cfg(
     string val;
     int r = cfg_reader(keys[i], &val);
     if (r == 0) {
-      *(vals[i]) = strict_iecstrtoll(val.c_str(), &err);
+      *(vals[i]) = strict_iecstrtoll(val, &err);
       if (!err.empty()) {
         derr << __func__ << " Failed to parse - "
           << keys[i] << ":" << val
index bc25c5a8f7f4c639beab4eb83f31cefe221e3252..7bcc7b2af08dece50a1e03df88e89b6540c8d3e8 100644 (file)
@@ -47,7 +47,7 @@ struct byte_units {
 
 bool byte_units::parse(const std::string &val, std::string *err)
 {
-  v = strict_iecstrtoll(val.c_str(), err);
+  v = strict_iecstrtoll(val, err);
   return err->empty();
 }
 
index fff2943748d945c0f8984ded4042bece664f8c47..e215fbe3887b43e9e5ce2fefccbc0f4f42ce5d09 100644 (file)
@@ -147,7 +147,7 @@ void usage()
 template <typename I, typename T>
 static int rados_sistrtoll(I &i, T *val) {
   std::string err;
-  *val = strict_iecstrtoll(i->second.c_str(), &err);
+  *val = strict_iecstrtoll(i->second, &err);
   if (err != "") {
     cerr << "Invalid value for " << i->first << ": " << err << std::endl;
     return -EINVAL;
index 7b111b811a3b792a3be4bcd3b4753160f11e5f65..caf2820dd331364c3eb5d8da6be3c83c45fe8068 100644 (file)
@@ -382,7 +382,7 @@ void validate(boost::any& v, const std::vector<std::string>& values,
   const std::string &s = po::validators::get_single_string(values);
 
   std::string parse_error;
-  uint64_t size = strict_iecstrtoll(s.c_str(), &parse_error);
+  uint64_t size = strict_iecstrtoll(s, &parse_error);
   if (!parse_error.empty()) {
     throw po::validation_error(po::validation_error::invalid_option_value);
   }
@@ -416,7 +416,7 @@ void validate(boost::any& v, const std::vector<std::string>& values,
   const std::string &s = po::validators::get_single_string(values);
 
   std::string parse_error;
-  uint64_t objectsize = strict_iecstrtoll(s.c_str(), &parse_error);
+  uint64_t objectsize = strict_iecstrtoll(s, &parse_error);
   if (!parse_error.empty()) {
     throw po::validation_error(po::validation_error::invalid_option_value);
   }
@@ -500,7 +500,7 @@ void validate(boost::any& v, const std::vector<std::string>& values,
   const std::string &s = po::validators::get_single_string(values);
 
   std::string parse_error;
-  uint64_t size = strict_iecstrtoll(s.c_str(), &parse_error);
+  uint64_t size = strict_iecstrtoll(s, &parse_error);
   if (parse_error.empty() && (size >= (1 << 12)) && (size <= (1 << 26))) {
     v = boost::any(size);
     return;
@@ -527,7 +527,7 @@ void validate(boost::any& v, const std::vector<std::string>& values,
   const std::string &s = po::validators::get_single_string(values);
 
   std::string parse_error;
-  uint64_t format = strict_iecstrtoll(s.c_str(), &parse_error);
+  uint64_t format = strict_iecstrtoll(s, &parse_error);
   if (!parse_error.empty() || (format != 1 && format != 2)) {
     throw po::validation_error(po::validation_error::invalid_option_value);
   }
index 304b5c22918793cb57a0767c5090ffa40f0a616c..cca1ba5879598d016b5b67ab142fdc6897228965 100644 (file)
@@ -59,7 +59,7 @@ void validate(boost::any& v, const std::vector<std::string>& values,
   const std::string &s = po::validators::get_single_string(values);
 
   std::string parse_error;
-  uint64_t size = strict_iecstrtoll(s.c_str(), &parse_error);
+  uint64_t size = strict_iecstrtoll(s, &parse_error);
   if (!parse_error.empty()) {
     throw po::validation_error(po::validation_error::invalid_option_value);
   }