From 8a283f9164747bc2dda2b908b2d97228e1eab4eb Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 11 Aug 2021 11:47:21 +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/client/Client.cc | 14 +++++++-- src/client/Client.h | 53 +++++++++++++++++----------------- src/client/ClientSnapRealm.cc | 3 ++ src/client/ClientSnapRealm.h | 10 +++---- src/client/Dentry.h | 2 +- src/client/Dir.h | 8 +++-- src/client/Inode.cc | 6 ++++ src/client/Inode.h | 22 +++++++------- src/client/MetaRequest.h | 4 +-- src/client/MetaSession.h | 2 +- src/client/ObjecterWriteback.h | 8 ++--- 11 files changed, 76 insertions(+), 56 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 7b2e034307a..ddf42266a5c 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -149,6 +149,14 @@ #define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH) #endif +using std::dec; +using std::hex; +using std::list; +using std::oct; +using std::pair; +using std::string; +using std::vector; + using namespace TOPNSPC::common; namespace bs = boost::system; @@ -5616,7 +5624,7 @@ out: return r; } -ostream& operator<<(ostream &out, const UserPerm& perm) { +std::ostream& operator<<(std::ostream &out, const UserPerm& perm) { out << "UserPerm(uid: " << perm.uid() << ", gid: " << perm.gid() << ")"; return out; } @@ -11039,7 +11047,7 @@ void Client::_encode_filelocks(Inode *in, bufferlist& bl) encode(nr_fcntl_locks, bl); if (nr_fcntl_locks) { auto &lock_state = in->fcntl_locks; - for(multimap::iterator p = lock_state->held_locks.begin(); + for(auto p = lock_state->held_locks.begin(); p != lock_state->held_locks.end(); ++p) encode(p->second, bl); @@ -11049,7 +11057,7 @@ void Client::_encode_filelocks(Inode *in, bufferlist& bl) encode(nr_flock_locks, bl); if (nr_flock_locks) { auto &lock_state = in->flock_locks; - for(multimap::iterator p = lock_state->held_locks.begin(); + for(auto p = lock_state->held_locks.begin(); p != lock_state->held_locks.end(); ++p) encode(p->second, bl); diff --git a/src/client/Client.h b/src/client/Client.h index 42f8bc14c55..bbf1619fedf 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -107,10 +107,11 @@ class MDSCommandOp : public CommandOp /* getdir result */ struct DirEntry { - explicit DirEntry(const string &s) : d_name(s), stmask(0) {} - DirEntry(const string &n, struct stat& s, int stm) : d_name(n), st(s), stmask(stm) {} + explicit DirEntry(const std::string &s) : d_name(s), stmask(0) {} + DirEntry(const std::string &n, struct stat& s, int stm) + : d_name(n), st(s), stmask(stm) {} - string d_name; + std::string d_name; struct stat st; int stmask; }; @@ -215,7 +216,7 @@ struct dir_result_t { // ((frag value) << 28) | (the nth entry in frag); unsigned next_offset; // offset of next chunk (last_name's + 1) - string last_name; // last entry in previous chunk + std::string last_name; // last entry in previous chunk uint64_t release_count; uint64_t ordered_count; @@ -225,7 +226,7 @@ struct dir_result_t { frag_t buffer_frag; - vector buffer; + std::vector buffer; struct dirent de; }; @@ -350,7 +351,7 @@ public: int readdir_r(dir_result_t *dirp, struct dirent *de); int readdirplus_r(dir_result_t *dirp, struct dirent *de, struct ceph_statx *stx, unsigned want, unsigned flags, Inode **out); - int getdir(const char *relpath, list& names, + int getdir(const char *relpath, std::list& names, const UserPerm& perms); // get the whole dir at once. /** @@ -512,8 +513,8 @@ public: int describe_layout(const char *path, file_layout_t* layout, const UserPerm& perms); int fdescribe_layout(int fd, file_layout_t* layout); - int get_file_stripe_address(int fd, loff_t offset, vector& address); - int get_file_extent_osds(int fd, loff_t off, loff_t *len, vector& osds); + int get_file_stripe_address(int fd, loff_t offset, std::vector& address); + int get_file_extent_osds(int fd, loff_t off, loff_t *len, std::vector& osds); int get_osd_addr(int osd, entity_addr_t& addr); // expose mdsmap @@ -523,10 +524,10 @@ public: int get_local_osd(); int get_pool_replication(int64_t pool); int64_t get_pool_id(const char *pool_name); - string get_pool_name(int64_t pool); - int get_osd_crush_location(int id, vector >& path); + std::string get_pool_name(int64_t pool); + int get_osd_crush_location(int id, std::vector >& path); - int enumerate_layout(int fd, vector& result, + int enumerate_layout(int fd, std::vector& result, loff_t length, loff_t offset); int mksnap(const char *path, const char *name, const UserPerm& perm, @@ -714,7 +715,7 @@ public: int get_caps_used(Inode *in); void maybe_update_snaprealm(SnapRealm *realm, snapid_t snap_created, snapid_t snap_highwater, - vector& snaps); + std::vector& snaps); void handle_quota(const MConstRef& m); void handle_snap(const MConstRef& m); @@ -742,7 +743,7 @@ public: void finish_cap_snap(Inode *in, CapSnap &capsnap, int used); void _schedule_invalidate_dentry_callback(Dentry *dn, bool del); - void _async_dentry_invalidate(vinodeno_t dirino, vinodeno_t ino, string& name); + void _async_dentry_invalidate(vinodeno_t dirino, vinodeno_t ino, std::string& name); void _try_to_trim_inode(Inode *in, bool sched_inval); void _schedule_invalidate_callback(Inode *in, int64_t off, int64_t len); @@ -790,7 +791,7 @@ public: Inode *add_update_inode(InodeStat *st, utime_t ttl, MetaSession *session, const UserPerm& request_perms); - Dentry *insert_dentry_inode(Dir *dir, const string& dname, LeaseStat *dlease, + Dentry *insert_dentry_inode(Dir *dir, const std::string& dname, LeaseStat *dlease, Inode *in, utime_t from, MetaSession *session, Dentry *old_dentry = NULL); void update_dentry_lease(Dentry *dn, LeaseStat *dlease, utime_t from, MetaSession *session); @@ -989,8 +990,8 @@ protected: // helpers void wake_up_session_caps(MetaSession *s, bool reconnect); - void wait_on_context_list(list& ls); - void signal_context_list(list& ls); + void wait_on_context_list(std::list& ls); + void signal_context_list(std::list& ls); // -- metadata cache stuff @@ -1014,7 +1015,7 @@ protected: * leave dn set to default NULL unless you're trying to add * a new inode to a pre-created Dentry */ - Dentry* link(Dir *dir, const string& name, Inode *in, Dentry *dn); + Dentry* link(Dir *dir, const std::string& name, Inode *in, Dentry *dn); void unlink(Dentry *dn, bool keepdir, bool keepdentry); int fill_stat(Inode *in, struct stat *st, frag_info_t *dirstat=0, nest_info_t *rstat=0); @@ -1229,11 +1230,11 @@ private: * statistics and layout metadata. */ struct VXattr { - const string name; - size_t (Client::*getxattr_cb)(Inode *in, char *val, size_t size); - bool readonly; - bool (Client::*exists_cb)(Inode *in); - unsigned int flags; + const std::string name; + size_t (Client::*getxattr_cb)(Inode *in, char *val, size_t size); + bool readonly; + bool (Client::*exists_cb)(Inode *in); + unsigned int flags; }; enum { @@ -1292,10 +1293,10 @@ private: // internal interface // call these with client_lock held! - int _do_lookup(Inode *dir, const string& name, int mask, InodeRef *target, + int _do_lookup(Inode *dir, const std::string& name, int mask, InodeRef *target, const UserPerm& perms); - int _lookup(Inode *dir, const string& dname, int mask, InodeRef *target, + int _lookup(Inode *dir, const std::string& dname, int mask, InodeRef *target, const UserPerm& perm, std::string* alternate_name=nullptr); int _link(Inode *in, Inode *dir, const char *name, const UserPerm& perm, std::string alternate_name, @@ -1337,7 +1338,7 @@ private: int flags, const UserPerm& perms); int _setxattr(InodeRef &in, const char *name, const void *value, size_t len, int flags, const UserPerm& perms); - int _setxattr_check_data_pool(string& name, string& value, const OSDMap *osdmap); + int _setxattr_check_data_pool(std::string& name, std::string& value, const OSDMap *osdmap); void _setxattr_maybe_wait_for_osdmap(const char *name, const void *value, size_t len); int _removexattr(Inode *in, const char *nm, const UserPerm& perms); int _removexattr(InodeRef &in, const char *nm, const UserPerm& perms); @@ -1530,7 +1531,7 @@ private: utime_t last_auto_reconnect; // trace generation - ofstream traceout; + std::ofstream traceout; ceph::condition_variable mount_cond, sync_cond; diff --git a/src/client/ClientSnapRealm.cc b/src/client/ClientSnapRealm.cc index 81154a17069..2ddd86f8a3c 100644 --- a/src/client/ClientSnapRealm.cc +++ b/src/client/ClientSnapRealm.cc @@ -4,6 +4,9 @@ #include "ClientSnapRealm.h" #include "common/Formatter.h" +using std::set; +using std::vector; + void SnapRealm::build_snap_context() { set snaps; diff --git a/src/client/ClientSnapRealm.h b/src/client/ClientSnapRealm.h index ccb129d78bf..730c87eec5f 100644 --- a/src/client/ClientSnapRealm.h +++ b/src/client/ClientSnapRealm.h @@ -18,15 +18,15 @@ struct SnapRealm { inodeno_t parent; snapid_t parent_since; - vector prior_parent_snaps; // snaps prior to parent_since - vector my_snaps; + std::vector prior_parent_snaps; // snaps prior to parent_since + std::vector my_snaps; SnapRealm *pparent; - set pchildren; + std::set pchildren; private: SnapContext cached_snap_context; // my_snaps + parent snaps + past_parent_snaps - friend ostream& operator<<(ostream& out, const SnapRealm& r); + friend std::ostream& operator<<(std::ostream& out, const SnapRealm& r); public: xlist inodes_with_caps; @@ -49,7 +49,7 @@ public: void dump(Formatter *f) const; }; -inline ostream& operator<<(ostream& out, const SnapRealm& r) { +inline std::ostream& operator<<(std::ostream& out, const SnapRealm& r) { return out << "snaprealm(" << r.ino << " nref=" << r.nref << " c=" << r.created << " seq=" << r.seq << " parent=" << r.parent << " my_snaps=" << r.my_snaps diff --git a/src/client/Dentry.h b/src/client/Dentry.h index 483a31eccb3..94722c5de70 100644 --- a/src/client/Dentry.h +++ b/src/client/Dentry.h @@ -81,7 +81,7 @@ public: friend std::ostream &operator<<(std::ostream &oss, const Dentry &Dentry); Dir *dir; - const string name; + const std::string name; InodeRef inode; int ref = 1; // 1 if there's a dir beneath me. int64_t offset = 0; diff --git a/src/client/Dir.h b/src/client/Dir.h index 731a2038ecb..f98782e4392 100644 --- a/src/client/Dir.h +++ b/src/client/Dir.h @@ -1,15 +1,19 @@ #ifndef CEPH_CLIENT_DIR_H #define CEPH_CLIENT_DIR_H +#include +#include + +class Dentry; struct Inode; class Dir { public: Inode *parent_inode; // my inode - ceph::unordered_map dentries; + ceph::unordered_map dentries; unsigned num_null_dentries = 0; - vector readdir_cache; + std::vector readdir_cache; explicit Dir(Inode* in) { parent_inode = in; } diff --git a/src/client/Inode.cc b/src/client/Inode.cc index efeedb1ef35..388062cf4f1 100644 --- a/src/client/Inode.cc +++ b/src/client/Inode.cc @@ -12,6 +12,12 @@ #include "mds/flock.h" +using std::dec; +using std::list; +using std::oct; +using std::ostream; +using std::string; + Inode::~Inode() { delay_cap_item.remove_myself(); diff --git a/src/client/Inode.h b/src/client/Inode.h index 86c08871ac4..eddfb6da9a6 100644 --- a/src/client/Inode.h +++ b/src/client/Inode.h @@ -87,7 +87,7 @@ struct CapSnap { uint32_t mode = 0; uid_t uid = 0; gid_t gid = 0; - map xattrs; + std::map xattrs; version_t xattr_version = 0; bufferlist inline_data; @@ -174,7 +174,7 @@ struct Inode : RefCountedObject { return layout != file_layout_t(); } - __u32 hash_dentry_name(const string &dn) { + __u32 hash_dentry_name(const std::string &dn) { int which = dir_layout.dl_dir_hash; if (!which) which = CEPH_STR_HASH_LINUX; @@ -217,11 +217,11 @@ struct Inode : RefCountedObject { SnapRealm *snaprealm = 0; xlist::item snaprealm_item; InodeRef snapdir_parent; // only if we are a snapdir inode - map cap_snaps; // pending flush to mds + std::map cap_snaps; // pending flush to mds //int open_by_mode[CEPH_FILE_MODE_NUM]; - map open_by_mode; - map cap_refs; + std::map open_by_mode; + std::map cap_refs; ObjectCacher::ObjectSet oset; // ORDER DEPENDENCY: ino @@ -231,10 +231,10 @@ struct Inode : RefCountedObject { uint64_t ll_ref = 0; // separate ref count for ll client xlist dentries; // if i'm linked to a dentry. - string symlink; // symlink content, if it's a symlink - map xattrs; - map fragmap; // known frag -> mds mappings - map> frag_repmap; // non-auth mds mappings + std::string symlink; // symlink content, if it's a symlink + std::map xattrs; + std::map fragmap; // known frag -> mds mappings + std::map> frag_repmap; // non-auth mds mappings std::list waitfor_caps; std::list waitfor_commit; @@ -272,7 +272,7 @@ struct Inode : RefCountedObject { (flock_locks && !flock_locks->empty()); } - list delegations; + std::list delegations; xlist unsafe_ops; @@ -356,6 +356,6 @@ private: }; -ostream& operator<<(ostream &out, const Inode &in); +std::ostream& operator<<(std::ostream &out, const Inode &in); #endif diff --git a/src/client/MetaRequest.h b/src/client/MetaRequest.h index db134a70583..fa97bf0f316 100644 --- a/src/client/MetaRequest.h +++ b/src/client/MetaRequest.h @@ -37,7 +37,7 @@ public: int dentry_drop, dentry_unless; int old_dentry_drop, old_dentry_unless; int other_inode_drop, other_inode_unless; - vector cap_releases; + std::vector cap_releases; int regetattr_mask; // getattr mask if i need to re-stat after a traceless reply @@ -67,7 +67,7 @@ public: ceph::condition_variable *caller_cond; // who to take up ceph::condition_variable *dispatch_cond; // who to kick back - list waitfor_safe; + std::list waitfor_safe; InodeRef target; UserPerm perms; diff --git a/src/client/MetaSession.h b/src/client/MetaSession.h index c28cd0b83b6..775912b53a1 100644 --- a/src/client/MetaSession.h +++ b/src/client/MetaSession.h @@ -46,7 +46,7 @@ struct MetaSession { int mds_state = MDSMap::STATE_NULL; bool readonly = false; - list waiting_for_open; + std::list waiting_for_open; xlist caps; xlist flushing_caps; diff --git a/src/client/ObjecterWriteback.h b/src/client/ObjecterWriteback.h index 7a159e80e9d..867ef5aa081 100644 --- a/src/client/ObjecterWriteback.h +++ b/src/client/ObjecterWriteback.h @@ -48,15 +48,13 @@ class ObjecterWriteback : public WritebackHandler { bool can_scattered_write() override { return true; } using WritebackHandler::write; ceph_tid_t write(const object_t& oid, const object_locator_t& oloc, - vector >& io_vec, + std::vector >& io_vec, const SnapContext& snapc, ceph::real_time mtime, uint64_t trunc_size, __u32 trunc_seq, Context *oncommit) override { ObjectOperation op; - for (vector >::iterator p = io_vec.begin(); - p != io_vec.end(); - ++p) - op.write(p->first, p->second, trunc_size, trunc_seq); + for (auto& [offset, bl] : io_vec) + op.write(offset, bl, trunc_size, trunc_seq); return m_objecter->mutate(oid, oloc, op, snapc, mtime, 0, new C_OnFinisher(new C_Lock(m_lock, oncommit), -- 2.39.5