From: Yan, Zheng Date: Wed, 24 Jun 2015 07:54:31 +0000 (+0800) Subject: client: use smart pointer to track 'cwd' and 'root_parents' X-Git-Tag: v0.94.7~24^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fa79bd978f646001365b14009efe9fa5c562f681;p=ceph.git client: use smart pointer to track 'cwd' and 'root_parents' Signed-off-by: Yan, Zheng (cherry picked from commit 8c45ae1239c934b6727071398a1cfccb6277069e) --- diff --git a/src/client/Client.cc b/src/client/Client.cc index b8e3ac9490ce..334ebbecaaa5 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -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; } diff --git a/src/client/Client.h b/src/client/Client.h index af6b5ce969d0..964c71c780a4 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -345,7 +345,7 @@ protected: // cache ceph::unordered_map inode_map; Inode* root; - map root_parents; + map 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) {