From: Kefu Chai Date: Wed, 11 Aug 2021 10:44:08 +0000 (+0800) Subject: tools/cephfs: build without "using namespace std" X-Git-Tag: v17.1.0~1121^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=8a3a88804134be39ddcefea851ec0a62c68b50d9;p=ceph.git tools/cephfs: build without "using namespace std" * add "std::" prefix in headers * add "using" declarations in .cc files. so we don't rely on "using namespace std" in one or more included headers. Signed-off-by: Kefu Chai --- diff --git a/src/tools/cephfs/DataScan.cc b/src/tools/cephfs/DataScan.cc index 649e96b15ad3f..dd2e4417e09ba 100644 --- a/src/tools/cephfs/DataScan.cc +++ b/src/tools/cephfs/DataScan.cc @@ -35,6 +35,8 @@ #undef dout_prefix #define dout_prefix *_dout << "datascan." << __func__ << ": " +using namespace std; + void DataScan::usage() { std::cout << "Usage: \n" diff --git a/src/tools/cephfs/DataScan.h b/src/tools/cephfs/DataScan.h index 5c87fe2bdec4a..fe997f6632514 100644 --- a/src/tools/cephfs/DataScan.h +++ b/src/tools/cephfs/DataScan.h @@ -244,7 +244,7 @@ class DataScan : public MDSUtility, public MetadataTool RecoveryDriver *driver; fs_cluster_id_t fscid; - string metadata_pool_name; + std::string metadata_pool_name; std::vector data_pools; // IoCtx for data pool (where we scrape file backtraces from) @@ -291,7 +291,7 @@ class DataScan : public MDSUtility, public MetadataTool // Overwrite root objects even if they exist bool force_init; // Only scan inodes without this scrub tag - string filter_tag; + std::string filter_tag; /** * @param r set to error on valid key with invalid value diff --git a/src/tools/cephfs/Dumper.cc b/src/tools/cephfs/Dumper.cc index f3b07c5518141..68a190182dd03 100644 --- a/src/tools/cephfs/Dumper.cc +++ b/src/tools/cephfs/Dumper.cc @@ -34,6 +34,8 @@ #define HEADER_LEN 4096 +using namespace std; + int Dumper::init(mds_role_t role_, const std::string &type) { role = role_; diff --git a/src/tools/cephfs/JournalFilter.cc b/src/tools/cephfs/JournalFilter.cc index 266d7fccb578d..3a5e781a2db68 100644 --- a/src/tools/cephfs/JournalFilter.cc +++ b/src/tools/cephfs/JournalFilter.cc @@ -22,6 +22,7 @@ #define dout_context g_ceph_context #define dout_subsys ceph_subsys_mds +using namespace std; const string JournalFilter::range_separator(".."); diff --git a/src/tools/cephfs/JournalTool.cc b/src/tools/cephfs/JournalTool.cc index ec98609803a46..d972f8341f668 100644 --- a/src/tools/cephfs/JournalTool.cc +++ b/src/tools/cephfs/JournalTool.cc @@ -37,7 +37,7 @@ #undef dout_prefix #define dout_prefix *_dout << __func__ << ": " - +using namespace std; void JournalTool::usage() { diff --git a/src/tools/cephfs/MetaTool.cc b/src/tools/cephfs/MetaTool.cc index 527ae636fc0ff..baa0d498a2aa1 100644 --- a/src/tools/cephfs/MetaTool.cc +++ b/src/tools/cephfs/MetaTool.cc @@ -37,6 +37,7 @@ WRITE_RAW_ENCODER(unsigned char) #undef dout_prefix #define dout_prefix *_dout << __func__ << ": " +using namespace std; void MetaTool::meta_op::release() { diff --git a/src/tools/cephfs/MetaTool.h b/src/tools/cephfs/MetaTool.h index 510be6552a874..d36f7bba23c01 100644 --- a/src/tools/cephfs/MetaTool.h +++ b/src/tools/cephfs/MetaTool.h @@ -46,7 +46,7 @@ public: private: class meta_op { public: - meta_op(bool debug = false, string out = "", string in = "", bool confirm = false): + meta_op(bool debug = false, std::string out = "", std::string in = "", bool confirm = false): _debug(debug), _out(out), _in(in), @@ -68,8 +68,8 @@ private: INO_F } ino_type; - static string op_type_name(op_type& t) { - string name; + static std::string op_type_name(op_type& t) { + std::string name; switch (t) { case OP_LIST: name = "list dir"; @@ -97,8 +97,8 @@ private: } return name; } - static string ino_type_name(ino_type& t) { - string name; + static std::string ino_type_name(ino_type& t) { + std::string name; switch (t) { case INO_DIR: name = "dir"; @@ -121,7 +121,7 @@ private: void print() { std::cout << detail() << std::endl; } - string detail() { + std::string detail() { std::stringstream ds; ds << " [sub_op]" << op_type_name(sub_op_t) << "|" << ino_type_name(sub_ino_t) << "|" @@ -165,7 +165,7 @@ private: std::map ancestors; std::map inodes; - std::map okeys; + std::map okeys; void clear_sops() { while(!no_sops()) @@ -189,10 +189,10 @@ private: delete sop; sub_ops.pop(); } - string outfile() { + std::string outfile() { return _out; } - string infile() { + std::string infile() { return _in; } bool is_debug() { @@ -204,8 +204,8 @@ private: private: stack sub_ops; bool _debug; - string _out; - string _in; + std::string _out; + std::string _in; bool _confirm; }; MDSRoleSelector role_selector; @@ -236,12 +236,12 @@ private: meta_op* op = NULL ); - int process(string& mode, string& ino, string out, string in, bool confirm); - int show_meta_info(string& ino, string& out); - int list_meta_info(string& ino, string& out); - int amend_meta_info(string& ino, string& in, bool confirm); - int show_fnode(string& ino, string& out); - int amend_fnode(string& in, bool confirm); + int process(std::string& mode, std::string& ino, std::string out, std::string in, bool confirm); + int show_meta_info(std::string& ino, std::string& out); + int list_meta_info(std::string& ino, std::string& out); + int amend_meta_info(std::string& ino, std::string& in, bool confirm); + int show_fnode(std::string& ino, std::string& out); + int amend_fnode(std::string& in, bool confirm); int op_process(meta_op &op); int list_meta(meta_op &op); int file_meta(meta_op &op); @@ -251,21 +251,21 @@ private: int amend_fn(meta_op &op); public: int _file_meta(meta_op &op, librados::IoCtx& io); - int _show_meta(inode_meta_t& i, const string& fn); - 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); + int _show_meta(inode_meta_t& i, const std::string& fn); + int _amend_meta(std::string &k, inode_meta_t& i, const std::string& fn, meta_op& op); + int _show_fn(inode_meta_t& i, const std::string& fn); + int _amend_fn(const std::string& fn, bool confirm); void usage(); MetaTool(bool debug=false): _debug(debug) {} ~MetaTool() {} - int main(string& mode, - string& rank_str, - string& minfo, - string&ino, - string& out, - string& in, + int main(std::string& mode, + std::string& rank_str, + std::string& minfo, + std::string&ino, + std::string& out, + std::string& in, bool confirm = false ); }; diff --git a/src/tools/cephfs/Resetter.cc b/src/tools/cephfs/Resetter.cc index 278a48767cdfd..7c0aa30ab6a88 100644 --- a/src/tools/cephfs/Resetter.cc +++ b/src/tools/cephfs/Resetter.cc @@ -26,6 +26,8 @@ #define dout_context g_ceph_context #define dout_subsys ceph_subsys_mds +using namespace std; + int Resetter::init(mds_role_t role_, const std::string &type, bool hard) { role = role_; diff --git a/src/tools/cephfs/TableTool.cc b/src/tools/cephfs/TableTool.cc index e779b4b665e9d..dcd35a6241b7e 100644 --- a/src/tools/cephfs/TableTool.cc +++ b/src/tools/cephfs/TableTool.cc @@ -27,6 +27,8 @@ #undef dout_prefix #define dout_prefix *_dout << __func__ << ": " +using namespace std; + void TableTool::usage() { std::cout << "Usage: \n" diff --git a/src/tools/cephfs/cephfs-data-scan.cc b/src/tools/cephfs/cephfs-data-scan.cc index e6efff66c370b..f8241823f5c28 100644 --- a/src/tools/cephfs/cephfs-data-scan.cc +++ b/src/tools/cephfs/cephfs-data-scan.cc @@ -7,6 +7,7 @@ #include "DataScan.h" +using namespace std; int main(int argc, const char **argv) { diff --git a/src/tools/cephfs/cephfs-journal-tool.cc b/src/tools/cephfs/cephfs-journal-tool.cc index 290cb305ba527..1de11209bbdb8 100644 --- a/src/tools/cephfs/cephfs-journal-tool.cc +++ b/src/tools/cephfs/cephfs-journal-tool.cc @@ -23,10 +23,10 @@ int main(int argc, const char **argv) { - vector args; + std::vector args; argv_to_vec(argc, argv, args); if (args.empty()) { - cerr << argv[0] << ": -h or --help for usage" << std::endl; + std::cerr << argv[0] << ": -h or --help for usage" << std::endl; exit(1); } if (ceph_argparse_need_usage(args)) { diff --git a/src/tools/cephfs/cephfs-table-tool.cc b/src/tools/cephfs/cephfs-table-tool.cc index 47b475dd0f89b..120b4b3576baa 100644 --- a/src/tools/cephfs/cephfs-table-tool.cc +++ b/src/tools/cephfs/cephfs-table-tool.cc @@ -7,6 +7,7 @@ #include "TableTool.h" +using namespace std; int main(int argc, const char **argv) { diff --git a/src/tools/cephfs/type_helper.hpp b/src/tools/cephfs/type_helper.hpp index 06dfa0afe5e6b..2ec77c25cd74f 100644 --- a/src/tools/cephfs/type_helper.hpp +++ b/src/tools/cephfs/type_helper.hpp @@ -10,7 +10,7 @@ T1 conv_t(T2 s){ return target; } -void string_split(std::string str, vector& out, string split = ":"){ +void string_split(std::string str, std::vector& out, std::string split = ":") { std::cout << str << std::endl; auto pos = str.find(split); while(pos != std::string::npos){