From 54c3e1b6880af065a53905872ba02ab4a9ee979a Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 26 Jul 2021 15:16:06 +0800 Subject: [PATCH] *: drop strict_iecstrtoll(const char *str,..) 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(str, err); so they are interchangeable. Signed-off-by: Kefu Chai --- src/common/options.cc | 2 +- src/common/strtol.cc | 5 ----- src/common/strtol.h | 2 +- src/kv/RocksDBStore.cc | 6 +++--- src/mon/OSDMonitor.cc | 6 +++--- src/os/bluestore/BitmapFreelistManager.cc | 2 +- src/test/objectstore_bench.cc | 2 +- src/tools/ceph_dedup_tool.cc | 2 +- src/tools/rbd/ArgumentTypes.cc | 8 ++++---- src/tools/rbd/action/Bench.cc | 2 +- 10 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/common/options.cc b/src/common/options.cc index 8c9b7418b6edc..a68e2474a3dc4 100644 --- a/src/common/options.cc +++ b/src/common/options.cc @@ -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; } diff --git a/src/common/strtol.cc b/src/common/strtol.cc index ff4040b18c21e..c9e982b63962c 100644 --- a/src/common/strtol.cc +++ b/src/common/strtol.cc @@ -220,11 +220,6 @@ uint64_t strict_iecstrtoll(std::string_view str, std::string *err) return strict_iec_cast(str, err); } -uint64_t strict_iecstrtoll(const char *str, std::string *err) -{ - return strict_iec_cast(str, err); -} - template T strict_si_cast(std::string_view str, std::string *err) { diff --git a/src/common/strtol.h b/src/common/strtol.h index 92cca690de971..2183137b1edf9 100644 --- a/src/common/strtol.h +++ b/src/common/strtol.h @@ -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 T strict_iec_cast(std::string_view str, std::string *err); diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index 05ad8844cb017..18cba3e517a95 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -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; } diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index d7ece669c34f1..8fd947510ce42 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -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(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"); } diff --git a/src/os/bluestore/BitmapFreelistManager.cc b/src/os/bluestore/BitmapFreelistManager.cc index 315a6bb8c43cf..edc489b6851b1 100644 --- a/src/os/bluestore/BitmapFreelistManager.cc +++ b/src/os/bluestore/BitmapFreelistManager.cc @@ -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 diff --git a/src/test/objectstore_bench.cc b/src/test/objectstore_bench.cc index bc25c5a8f7f4c..7bcc7b2af08de 100644 --- a/src/test/objectstore_bench.cc +++ b/src/test/objectstore_bench.cc @@ -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(); } diff --git a/src/tools/ceph_dedup_tool.cc b/src/tools/ceph_dedup_tool.cc index fff2943748d94..e215fbe3887b4 100644 --- a/src/tools/ceph_dedup_tool.cc +++ b/src/tools/ceph_dedup_tool.cc @@ -147,7 +147,7 @@ void usage() template 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; diff --git a/src/tools/rbd/ArgumentTypes.cc b/src/tools/rbd/ArgumentTypes.cc index 7b111b811a3b7..caf2820dd3313 100644 --- a/src/tools/rbd/ArgumentTypes.cc +++ b/src/tools/rbd/ArgumentTypes.cc @@ -382,7 +382,7 @@ void validate(boost::any& v, const std::vector& 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& 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& 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& 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); } diff --git a/src/tools/rbd/action/Bench.cc b/src/tools/rbd/action/Bench.cc index 304b5c2291879..cca1ba5879598 100644 --- a/src/tools/rbd/action/Bench.cc +++ b/src/tools/rbd/action/Bench.cc @@ -59,7 +59,7 @@ void validate(boost::any& v, const std::vector& 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); } -- 2.39.5