From: Jan Fajerski Date: Tue, 30 Jan 2018 08:48:05 +0000 (+0100) Subject: common/util: remove unit_to_bytesize, use strict_iecstrtoll instead X-Git-Tag: v13.1.0~258^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a3739cbb3c19b255e196553ddf9f586bc1877773;p=ceph.git common/util: remove unit_to_bytesize, use strict_iecstrtoll instead Signed-off-by: Jan Fajerski --- diff --git a/src/common/util.cc b/src/common/util.cc index 51bd8b17ea9b..6ba09be03863 100644 --- a/src/common/util.cc +++ b/src/common/util.cc @@ -38,73 +38,6 @@ #include -int64_t unit_to_bytesize(string val, ostream *pss) -{ - if (val.empty()) { - if (pss) - *pss << "value is empty!"; - return -EINVAL; - } - - char c = val[val.length()-1]; - int modifier = 0; - if (!::isdigit(c)) { - if (val.length() < 2) { - if (pss) - *pss << "invalid value: " << val; - return -EINVAL; - } - val = val.substr(0,val.length()-1); - switch (c) { - case 'B': - break; - case 'k': - case 'K': - modifier = 10; - break; - case 'M': - modifier = 20; - break; - case 'G': - modifier = 30; - break; - case 'T': - modifier = 40; - break; - case 'P': - modifier = 50; - break; - case 'E': - modifier = 60; - break; - default: - if (pss) - *pss << "unrecognized modifier '" << c << "'" << std::endl; - return -EINVAL; - } - } - - if (val[0] == '+' || val[0] == '-') { - if (pss) - *pss << "expected numerical value, got: " << val; - return -EINVAL; - } - - string err; - int64_t r = strict_strtoll(val.c_str(), 10, &err); - if ((r == 0) && !err.empty()) { - if (pss) - *pss << err; - return -1; - } - if (r < 0) { - if (pss) - *pss << "unable to parse positive integer '" << val << "'"; - return -1; - } - return (r * (1LL << modifier)); -} - int get_fs_stats(ceph_data_stats_t &stats, const char *path) { if (!path) diff --git a/src/include/util.h b/src/include/util.h index 03ba57621290..88eab27ad322 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -17,8 +17,6 @@ #include "common/Formatter.h" #include "include/types.h" -int64_t unit_to_bytesize(string val, ostream *pss); - std::string bytes2str(uint64_t count); struct ceph_data_stats diff --git a/src/test/common/test_util.cc b/src/test/common/test_util.cc index 64eace923c20..b47bec688e76 100644 --- a/src/test/common/test_util.cc +++ b/src/test/common/test_util.cc @@ -18,20 +18,6 @@ #include -TEST(util, unit_to_bytesize) -{ - ASSERT_EQ(1234ll, unit_to_bytesize("1234", &cerr)); - ASSERT_EQ(1024ll, unit_to_bytesize("1K", &cerr)); - ASSERT_EQ(1024ll, unit_to_bytesize("1k", &cerr)); - ASSERT_EQ(1048576ll, unit_to_bytesize("1M", &cerr)); - ASSERT_EQ(1073741824ll, unit_to_bytesize("1G", &cerr)); - ASSERT_EQ(1099511627776ll, unit_to_bytesize("1T", &cerr)); - ASSERT_EQ(1125899906842624ll, unit_to_bytesize("1P", &cerr)); - ASSERT_EQ(1152921504606846976ll, unit_to_bytesize("1E", &cerr)); - - ASSERT_EQ(65536ll, unit_to_bytesize(" 64K", &cerr)); -} - #if defined(__linux__) TEST(util, collect_sys_info) {