From a3739cbb3c19b255e196553ddf9f586bc1877773 Mon Sep 17 00:00:00 2001 From: Jan Fajerski Date: Tue, 30 Jan 2018 09:48:05 +0100 Subject: [PATCH] common/util: remove unit_to_bytesize, use strict_iecstrtoll instead Signed-off-by: Jan Fajerski --- src/common/util.cc | 67 ------------------------------------ src/include/util.h | 2 -- src/test/common/test_util.cc | 14 -------- 3 files changed, 83 deletions(-) diff --git a/src/common/util.cc b/src/common/util.cc index 51bd8b17ea9b2..6ba09be038635 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 03ba576212903..88eab27ad322d 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 64eace923c20b..b47bec688e769 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) { -- 2.39.5