From: Simon Gao Date: Sat, 27 Jun 2020 14:28:17 +0000 (+0800) Subject: tool: convert str to num using strtoull X-Git-Tag: wip-pdonnell-testing-20200918.022351~732^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fd861f27710f4e5ec6c378cf5d0df63825f80816;p=ceph-ci.git tool: convert str to num using strtoull Signed-off-by: Simon Gao --- diff --git a/src/tools/cephfs/MetaTool.cc b/src/tools/cephfs/MetaTool.cc index bde23f75990..128cfcad5a0 100644 --- a/src/tools/cephfs/MetaTool.cc +++ b/src/tools/cephfs/MetaTool.cc @@ -207,7 +207,7 @@ int MetaTool::process(string& mode, string& ino, string out, string in, bool con int MetaTool::show_fnode(string& ino, string& out) { if (ino != "0") { - inodeno_t i_ino = conv2hexino(ino.c_str()); + inodeno_t i_ino = std::stoull(ino.c_str(), nullptr, 0); meta_op op(_debug, out); meta_op::sub_op* nsop = new meta_op::sub_op(&op); nsop->sub_op_t = meta_op::OP_SHOW_FN; @@ -233,7 +233,7 @@ int MetaTool::amend_fnode(string& in, bool confirm) int MetaTool::amend_meta_info(string& ino, string& in, bool confirm) { if (ino != "0" && in != "") { - inodeno_t i_ino = conv2hexino(ino.c_str()); + inodeno_t i_ino = std::stoull(ino.c_str(), nullptr, 0); meta_op op(_debug, "", in, confirm); meta_op::sub_op* nsop = new meta_op::sub_op(&op); nsop->sub_op_t = meta_op::OP_AMEND; @@ -249,7 +249,7 @@ int MetaTool::amend_meta_info(string& ino, string& in, bool confirm) int MetaTool::list_meta_info(string& ino, string& out) { if (ino != "0") { - inodeno_t i_ino = conv2hexino(ino.c_str()); + inodeno_t i_ino = std::stoull(ino.c_str(), nullptr, 0); meta_op op(_debug, out); meta_op::sub_op* nsop = new meta_op::sub_op(&op); nsop->sub_op_t = meta_op::OP_LIST; @@ -265,7 +265,7 @@ int MetaTool::list_meta_info(string& ino, string& out) int MetaTool::show_meta_info(string& ino, string& out) { if (ino != "0") { - inodeno_t i_ino = conv2hexino(ino.c_str()); + inodeno_t i_ino = std::stoull(ino.c_str(), nullptr, 0); meta_op op(_debug, out); meta_op::sub_op* nsop = new meta_op::sub_op(&op); @@ -771,15 +771,6 @@ int MetaTool::list_meta(meta_op &op) } return 0; } -unsigned long long MetaTool::conv2hexino(const char* ino) -{ - unsigned long long iino = 0; - std::stringstream conv; - conv << ino; - conv >> iino; - printf("convert to hexadecimal ino %s => %llx \n", ino, iino); - return iino; -} int MetaTool::file_meta(meta_op &op) { diff --git a/src/tools/cephfs/MetaTool.h b/src/tools/cephfs/MetaTool.h index 809c8d9b6cf..041e223b7de 100644 --- a/src/tools/cephfs/MetaTool.h +++ b/src/tools/cephfs/MetaTool.h @@ -255,7 +255,6 @@ private: int _amend_meta(string &k, inode_meta_t& i, const string& fn, meta_op& op); int _show_fn(inode_meta_t& i, const string& fn); int _amend_fn(const string& fn, bool confirm); - static unsigned long long conv2hexino(const char* ino); void usage(); MetaTool(bool debug=false): _debug(debug) {} diff --git a/src/tools/cephfs/cephfs-meta-injection.cc b/src/tools/cephfs/cephfs-meta-injection.cc index 79ffbaea31c..5768d38693c 100644 --- a/src/tools/cephfs/cephfs-meta-injection.cc +++ b/src/tools/cephfs/cephfs-meta-injection.cc @@ -33,7 +33,7 @@ int main(int argc, const char **argv) ("debug", "show debug info") ("rank,r", po::value(&rank_str), "the rank of cephfs, default(0) (e.g. -r cephfs_a:0)") ("minfo", po::value(&minfo), "specify metapool, datapools and rank (e.g. cephfs_metadata_a:cephfs_data_a:0)") - ("ino,i", po::value(&ino), "specify inode. e.g. 1099511627776, you can find it with cmd, 'ls -i'") + ("ino,i", po::value(&ino), "specify inode. e.g. 1099511627776 or 0x10000000000, you can find it with cmd, 'ls -i'") ("out,o", po::value(&out), "output file") ("in", po::value(&in), "input file") ("yes-i-really-really-mean-it", "need by amend info") @@ -43,7 +43,6 @@ int main(int argc, const char **argv) po::options_description modeoptions("mode options"); modeoptions.add_options() ("mode", po::value(&mode), - "\tconv : convert decimal ino to hex\n" \ "\tlistc : list all obj of dir\n" \ "\tshowm : show the info of ino\n" \ "\tshowfn : show the fnode of dir\n" \ @@ -71,7 +70,7 @@ int main(int argc, const char **argv) if (vm.count("help")) { std::cout << version << std::endl; std::cout << "usage : \n" - << " cephfs-meta-injection -r -i " + << " cephfs-meta-injection -r -i " << std::endl; std::cout << "example : \n" << " amend info of inode(1099531628828)\n" @@ -83,11 +82,6 @@ int main(int argc, const char **argv) return 0; } - if (mode == "conv") { - MetaTool::conv2hexino(ino.c_str()); - return 0; - } - MetaTool mt(vm.count("debug")); int rc = mt.init(); if (rc != 0) {