From 4361b030be11f37dc3c553748dea689c79fed506 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 11 Aug 2021 16:00:32 +0800 Subject: [PATCH] client: 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 --- src/ceph_syn.cc | 2 ++ src/client/SyntheticClient.cc | 1 + src/client/SyntheticClient.h | 56 +++++++++++++++++------------------ src/client/fuse_ll.cc | 2 ++ src/include/Distribution.h | 4 +-- 5 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/ceph_syn.cc b/src/ceph_syn.cc index f67f5d5b34c..38268c438e8 100644 --- a/src/ceph_syn.cc +++ b/src/ceph_syn.cc @@ -34,6 +34,8 @@ #include #include +using namespace std; + extern int syn_filer_flags; int main(int argc, const char **argv, char *envp[]) diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index 9ef5ccf1993..3b408dd3f2d 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -43,6 +43,7 @@ #undef dout_prefix #define dout_prefix *_dout << "client." << (whoami >= 0 ? whoami:client->get_nodeid()) << " " +using namespace std; // traces //void trace_include(SyntheticClient *syn, Client *cl, string& prefix); //void trace_openssh(SyntheticClient *syn, Client *cl, string& prefix); diff --git a/src/client/SyntheticClient.h b/src/client/SyntheticClient.h index faec7e26d8a..2c160163732 100644 --- a/src/client/SyntheticClient.h +++ b/src/client/SyntheticClient.h @@ -94,7 +94,7 @@ -void parse_syn_options(vector& args); +void parse_syn_options(std::vector& args); extern int num_client; class SyntheticClient { @@ -109,11 +109,11 @@ class SyntheticClient { int get_op(); - filepath cwd; - map contents; - set subdirs; - bool did_readdir; - set open_files; + filepath cwd; + std::map contents; + std::set subdirs; + bool did_readdir; + std::set open_files; void up(); @@ -125,7 +125,7 @@ class SyntheticClient { int get_random_fh() { int r = rand() % open_files.size(); - set::iterator it = open_files.begin(); + std::set::iterator it = open_files.begin(); while (r--) ++it; return *it; } @@ -135,7 +135,7 @@ class SyntheticClient { const char *get_random_subdir() { ceph_assert(!subdirs.empty()); int r = ((rand() % subdirs.size()) + (rand() % subdirs.size())) / 2; // non-uniform distn - set::iterator it = subdirs.begin(); + std::set::iterator it = subdirs.begin(); while (r--) ++it; n1 = cwd; @@ -150,7 +150,7 @@ class SyntheticClient { r += cwd.last_dentry().c_str()[0]; // slightly permuted r %= contents.size(); - map::iterator it = contents.begin(); + std::map::iterator it = contents.begin(); while (r--) ++it; n2 = cwd; @@ -162,7 +162,7 @@ class SyntheticClient { char sub_s[50]; const char *make_sub(const char *base) { snprintf(sub_s, sizeof(sub_s), "%s.%d", base, rand() % 100); - string f = sub_s; + std::string f = sub_s; sub = cwd; sub.push_dentry(f); return sub.c_str(); @@ -191,16 +191,16 @@ class SyntheticClient { } // run() will do one of these things: - list modes; - list sargs; - list iargs; + std::list modes; + std::list sargs; + std::list iargs; utime_t run_start; utime_t run_until; client_t run_only; client_t exclude; - string get_sarg(int seq); + std::string get_sarg(int seq); int get_iarg() { int i = iargs.front(); iargs.pop_front(); @@ -209,24 +209,24 @@ class SyntheticClient { bool time_to_stop() { utime_t now = ceph_clock_now(); - if (0) cout << "time_to_stop .. now " << now - << " until " << run_until - << " start " << run_start - << std::endl; + if (0) std::cout << "time_to_stop .. now " << now + << " until " << run_until + << " start " << run_start + << std::endl; if (run_until.sec() && now > run_until) return true; else return false; } - string compose_path(string& prefix, char *rest) { + std::string compose_path(std::string& prefix, char *rest) { return prefix + rest; } - int full_walk(string& fromdir); + int full_walk(std::string& fromdir); int random_walk(int n); - int dump_placement(string& fn); + int dump_placement(std::string& fn); int make_dirs(const char *basedir, int dirs, int files, int depth); @@ -238,8 +238,8 @@ class SyntheticClient { int create_shared(int num); int open_shared(int num, int count); - int rm_file(string& fn); - int write_file(string& fn, int mb, loff_t chunk); + int rm_file(std::string& fn); + int write_file(std::string& fn, int mb, loff_t chunk); int write_fd(int fd, int size, int wrsize); int write_batch(int nfile, int mb, int chunk); @@ -249,15 +249,15 @@ class SyntheticClient { int object_rw(int nobj, int osize, int wrpc, int overlap, double rskew, double wskew); - int read_random(string& fn, int mb, int chunk); - int read_random_ex(string& fn, int mb, int chunk); + int read_random(std::string& fn, int mb, int chunk); + int read_random_ex(std::string& fn, int mb, int chunk); int overload_osd_0(int n, int sie, int wrsize); int check_first_primary(int fd); - int clean_dir(string& basedir); + int clean_dir(std::string& basedir); - int play_trace(Trace& t, string& prefix, bool metadata_only=false); + int play_trace(Trace& t, std::string& prefix, bool metadata_only=false); void make_dir_mess(const char *basedir, int n); void foo(); @@ -270,7 +270,7 @@ class SyntheticClient { const UserPerm& perms); int lookup_ino(inodeno_t ino, const UserPerm& perms); - int chunk_file(string &filename); + int chunk_file(std::string &filename); void mksnap(const char *base, const char *name, const UserPerm& perms); void rmsnap(const char *base, const char *name, const UserPerm& perms); diff --git a/src/client/fuse_ll.cc b/src/client/fuse_ll.cc index 3dbd0eda092..c2de8940fb7 100644 --- a/src/client/fuse_ll.cc +++ b/src/client/fuse_ll.cc @@ -53,6 +53,8 @@ #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK)) #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi)) +using namespace std; + static const ceph::unordered_map cephfs_errno_to_system_errno = { {CEPHFS_EBLOCKLISTED, ESHUTDOWN}, {CEPHFS_EPERM, EPERM}, diff --git a/src/include/Distribution.h b/src/include/Distribution.h index e4f0b30b129..56e998757c3 100644 --- a/src/include/Distribution.h +++ b/src/include/Distribution.h @@ -19,8 +19,8 @@ #include class Distribution { - vector p; - vector v; + std::vector p; + std::vector v; public: //Distribution() { -- 2.39.5