]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: use smart pointer to track 'cwd' and 'root_parents'
authorYan, Zheng <zyan@redhat.com>
Wed, 24 Jun 2015 07:54:31 +0000 (15:54 +0800)
committerYan, Zheng <zyan@redhat.com>
Thu, 12 Nov 2015 07:41:53 +0000 (15:41 +0800)
Signed-off-by: Yan, Zheng <zyan@redhat.com>
(cherry picked from commit 8c45ae1239c934b6727071398a1cfccb6277069e)

src/client/Client.cc
src/client/Client.h

index b8e3ac9490ce91e869e260d97311c3524ad2f204..334ebbecaaa58f5b20e9da24f263c1d1bf69305e 100644 (file)
@@ -184,8 +184,6 @@ Client::Client(Messenger *m, MonClient *mc)
   last_tid = 0;
   last_flush_seq = 0;
 
-  cwd = NULL;
-
   //
   root = 0;
 
@@ -271,11 +269,8 @@ void Client::tear_down_cache()
     delete root;
     root = 0;
     root_ancestor = 0;
-    while (!root_parents.empty()) {
-      Inode *in = root_parents.begin()->second;
+    while (!root_parents.empty())
       root_parents.erase(root_parents.begin());
-      delete in;
-    }
     inode_map.clear();
   }
 
@@ -566,11 +561,8 @@ void Client::trim_cache()
     delete root;
     root = 0;
     root_ancestor = 0;
-    while (!root_parents.empty()) {
-      Inode *in = root_parents.begin()->second;
+    while (!root_parents.empty())
       root_parents.erase(root_parents.begin());
-      delete in;
-    }
     inode_map.clear();
   }
 }
@@ -745,11 +737,9 @@ Inode * Client::add_update_inode(InodeStat *st, utime_t from,
       root = in;
       root_ancestor = in;
       cwd = root;
-      cwd->get();
     } else if (!mounted) {
       root_parents[root_ancestor] = in;
       root_ancestor = in;
-      in->get();
     }
 
     // immutable bits
@@ -2472,11 +2462,8 @@ void Client::put_inode(Inode *in, int n)
     if (in == root) {
       root = 0;
       root_ancestor = 0;
-      while (!root_parents.empty()) {
-        Inode *in = root_parents.begin()->second;
+      while (!root_parents.empty())
         root_parents.erase(root_parents.begin());
-        put_inode(in);
-      }
     }
 
     if (!in->oset.objects.empty()) {
@@ -4691,9 +4678,7 @@ void Client::unmount()
     timer.cancel_event(tick_event);
   tick_event = 0;
 
-  if (cwd)
-    put_inode(cwd);
-  cwd = NULL;
+  cwd.reset();
 
   // clean up any unclosed files
   while (!fd_map.empty()) {
@@ -7584,11 +7569,8 @@ int Client::chdir(const char *relpath)
   int r = path_walk(path, &in);
   if (r < 0)
     return r;
-  if (cwd != in.get()) {
-    put_inode(cwd);
-    cwd = in.get();
-    cwd->get();
-  }
+  if (cwd != in)
+    cwd.swap(in);
   ldout(cct, 3) << "chdir(" << relpath << ")  cwd now " << cwd->ino << dendl;
   return 0;
 }
@@ -7598,7 +7580,7 @@ void Client::getcwd(string& dir)
   filepath path;
   ldout(cct, 10) << "getcwd " << *cwd << dendl;
 
-  Inode *in = cwd;
+  Inode *in = cwd.get();
   while (in != root) {
     assert(in->dn_set.size() < 2); // dirs can't be hard-linked
     Dentry *dn = in->get_first_parent();
@@ -7615,7 +7597,7 @@ void Client::getcwd(string& dir)
 
       // start over
       path = filepath();
-      in = cwd;
+      in = cwd.get();
       continue;
     }
     path.push_front_dentry(dn->name);
@@ -10497,7 +10479,7 @@ Inode *Client::get_quota_root(Inode *in)
     if (!in->dn_set.empty())
       in = in->get_first_parent()->dir->parent_inode;
     else if (root_parents.count(in))
-      in = root_parents[in];
+      in = root_parents[in].get();
     else
       in = NULL;
   }
index af6b5ce969d07fc00d6c211aa96ef5ad8d5ecc71..964c71c780a4b7ab247de88ec4924e748f789493 100644 (file)
@@ -345,7 +345,7 @@ protected:
   // cache
   ceph::unordered_map<vinodeno_t, Inode*> inode_map;
   Inode*                 root;
-  map<Inode*, Inode*>    root_parents;
+  map<Inode*, InodeRef>  root_parents;
   Inode*                 root_ancestor;
   LRU                    lru;    // lru list of Dentry's in our local metadata cache.
 
@@ -436,7 +436,7 @@ protected:
   void unlink(Dentry *dn, bool keepdir, bool keepdentry);
 
   // path traversal for high-level interface
-  Inode *cwd;
+  InodeRef cwd;
   int path_walk(const filepath& fp, InodeRef *end, bool followsym=true);
   int fill_stat(Inode *in, struct stat *st, frag_info_t *dirstat=0, nest_info_t *rstat=0);
   int fill_stat(InodeRef& in, struct stat *st, frag_info_t *dirstat=0, nest_info_t *rstat=0) {