]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: build without "using namespace std"
authorKefu Chai <kchai@redhat.com>
Wed, 11 Aug 2021 03:47:21 +0000 (11:47 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 13 Aug 2021 04:21:39 +0000 (12:21 +0800)
* 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 <kchai@redhat.com>
src/client/Client.cc
src/client/Client.h
src/client/ClientSnapRealm.cc
src/client/ClientSnapRealm.h
src/client/Dentry.h
src/client/Dir.h
src/client/Inode.cc
src/client/Inode.h
src/client/MetaRequest.h
src/client/MetaSession.h
src/client/ObjecterWriteback.h

index 7b2e034307a34f186dd34d31ab2b848617381272..ddf42266a5c78a39e4afe348867eb2f3c65f80bf 100644 (file)
 #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<uint64_t, ceph_filelock>::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<uint64_t, ceph_filelock>::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);
index 42f8bc14c551b49ce03cdabf36b41ac2d74fff64..bbf1619fedfddf804f151a50993861b2b62f0206 100644 (file)
@@ -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<dentry> buffer;
+  std::vector<dentry> 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<string>& names,
+  int getdir(const char *relpath, std::list<std::string>& 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<entity_addr_t>& address);
-  int get_file_extent_osds(int fd, loff_t off, loff_t *len, vector<int>& osds);
+  int get_file_stripe_address(int fd, loff_t offset, std::vector<entity_addr_t>& address);
+  int get_file_extent_osds(int fd, loff_t off, loff_t *len, std::vector<int>& 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<pair<string, string> >& path);
+  std::string get_pool_name(int64_t pool);
+  int get_osd_crush_location(int id, std::vector<std::pair<std::string, std::string> >& path);
 
-  int enumerate_layout(int fd, vector<ObjectExtent>& result,
+  int enumerate_layout(int fd, std::vector<ObjectExtent>& 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<snapid_t>& snaps);
+                             std::vector<snapid_t>& snaps);
 
   void handle_quota(const MConstRef<MClientQuota>& m);
   void handle_snap(const MConstRef<MClientSnap>& 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<Context*>& ls);
-  void signal_context_list(list<Context*>& ls);
+  void wait_on_context_list(std::list<Context*>& ls);
+  void signal_context_list(std::list<Context*>& 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;
 
index 81154a17069cc543473c768810897987d9ba590b..2ddd86f8a3c45f42c57e9a076cead60a57c63d29 100644 (file)
@@ -4,6 +4,9 @@
 #include "ClientSnapRealm.h"
 #include "common/Formatter.h"
 
+using std::set;
+using std::vector;
+
 void SnapRealm::build_snap_context()
 {
   set<snapid_t> snaps;
index ccb129d78bf3bcafc4869c09087ceef19eae6043..730c87eec5fadfb789cbf13141e3ee31127077a2 100644 (file)
@@ -18,15 +18,15 @@ struct SnapRealm {
   
   inodeno_t parent;
   snapid_t parent_since;
-  vector<snapid_t> prior_parent_snaps;  // snaps prior to parent_since
-  vector<snapid_t> my_snaps;
+  std::vector<snapid_t> prior_parent_snaps;  // snaps prior to parent_since
+  std::vector<snapid_t> my_snaps;
 
   SnapRealm *pparent;
-  set<SnapRealm*> pchildren;
+  std::set<SnapRealm*> 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<Inode*> 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
index 483a31eccb324b56dd704f1931dbe1a68cea26e6..94722c5de70fde96ef25b92ab78e6ed891b7cb4a 100644 (file)
@@ -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;
index 731a2038ecb292ace8d04ef9d2409b5e10946ca9..f98782e4392d2f3e33168ec5b868836b98a97392 100644 (file)
@@ -1,15 +1,19 @@
 #ifndef CEPH_CLIENT_DIR_H
 #define CEPH_CLIENT_DIR_H
 
+#include <string>
+#include <vector>
+
+class Dentry;
 struct Inode;
 
 class Dir {
  public:
   Inode    *parent_inode;  // my inode
-  ceph::unordered_map<string, Dentry*> dentries;
+  ceph::unordered_map<std::string, Dentry*> dentries;
   unsigned num_null_dentries = 0;
 
-  vector<Dentry*> readdir_cache;
+  std::vector<Dentry*> readdir_cache;
 
   explicit Dir(Inode* in) { parent_inode = in; }
 
index efeedb1ef358b4d915b64611e8a1f8ed704cedd3..388062cf4f109f56007ccbe684444a528e821dd5 100644 (file)
 
 #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();
index 86c08871ac4ce9febe05e0e2eb3c990e9ca52440..eddfb6da9a69a4875b16aea15b7b819c6b59e0b3 100644 (file)
@@ -87,7 +87,7 @@ struct CapSnap {
   uint32_t   mode = 0;
   uid_t      uid = 0;
   gid_t      gid = 0;
-  map<string,bufferptr> xattrs;
+  std::map<std::string,bufferptr> 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<Inode*>::item snaprealm_item;
   InodeRef snapdir_parent;  // only if we are a snapdir inode
-  map<snapid_t,CapSnap> cap_snaps;   // pending flush to mds
+  std::map<snapid_t,CapSnap> cap_snaps;   // pending flush to mds
 
   //int open_by_mode[CEPH_FILE_MODE_NUM];
-  map<int,int> open_by_mode;
-  map<int,int> cap_refs;
+  std::map<int,int> open_by_mode;
+  std::map<int,int> 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<Dentry *> dentries; // if i'm linked to a dentry.
-  string    symlink;  // symlink content, if it's a symlink
-  map<string,bufferptr> xattrs;
-  map<frag_t,int> fragmap;  // known frag -> mds mappings
-  map<frag_t, std::vector<mds_rank_t>> frag_repmap; // non-auth mds mappings
+  std::string    symlink;  // symlink content, if it's a symlink
+  std::map<std::string,bufferptr> xattrs;
+  std::map<frag_t,int> fragmap;  // known frag -> mds mappings
+  std::map<frag_t, std::vector<mds_rank_t>> frag_repmap; // non-auth mds mappings
 
   std::list<ceph::condition_variable*> waitfor_caps;
   std::list<ceph::condition_variable*> waitfor_commit;
@@ -272,7 +272,7 @@ struct Inode : RefCountedObject {
       (flock_locks && !flock_locks->empty());
   }
 
-  list<Delegation> delegations;
+  std::list<Delegation> delegations;
 
   xlist<MetaRequest*> unsafe_ops;
 
@@ -356,6 +356,6 @@ private:
 
 };
 
-ostream& operator<<(ostream &out, const Inode &in);
+std::ostream& operator<<(std::ostream &out, const Inode &in);
 
 #endif
index db134a705832c9de039eedf53e9b5eb5e862d691..fa97bf0f31626b729a218081625c827c27e762ee 100644 (file)
@@ -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<MClientRequest::Release> cap_releases;
+  std::vector<MClientRequest::Release> 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<ceph::condition_variable*> waitfor_safe;
+  std::list<ceph::condition_variable*> waitfor_safe;
 
   InodeRef target;
   UserPerm perms;
index c28cd0b83b6e786725bc90d05121d57b3a443a41..775912b53a1a29261cb54edfe1c9043ed12eb889 100644 (file)
@@ -46,7 +46,7 @@ struct MetaSession {
   int mds_state = MDSMap::STATE_NULL;
   bool readonly = false;
 
-  list<Context*> waiting_for_open;
+  std::list<Context*> waiting_for_open;
 
   xlist<Cap*> caps;
   xlist<Inode*> flushing_caps;
index 7a159e80e9de0598cf77323531b1149cf232968a..867ef5aa081991e7c00312e371dd4eacddfe392e 100644 (file)
@@ -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<pair<uint64_t, bufferlist> >& io_vec,
+                           std::vector<std::pair<uint64_t, bufferlist> >& io_vec,
                           const SnapContext& snapc, ceph::real_time mtime,
                           uint64_t trunc_size, __u32 trunc_seq,
                           Context *oncommit) override {
     ObjectOperation op;
-    for (vector<pair<uint64_t, bufferlist> >::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),