From: Yan, Zheng Date: Fri, 27 Jul 2018 01:17:04 +0000 (+0800) Subject: mds: make CInode::get_dirfrags container agnostic X-Git-Tag: v12.2.9~88^2~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e192b72b6d8b8f94398d7078af09c0e91fd5daa2;p=ceph.git mds: make CInode::get_dirfrags container agnostic Signed-off-by: "Yan, Zheng" (cherry picked from commit c2807b8ffea7d6b0075ac0f08641235b9b352ad2) Conflicts: src/mds/CInode.cc src/mds/CInode.h --- diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index af4b5c2a9a6..11d3344d0f3 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -604,31 +604,6 @@ CDir *CInode::get_approx_dirfrag(frag_t fg) return NULL; } -void CInode::get_dirfrags(std::list& ls) -{ - // all dirfrags - for (const auto &p : dirfrags) { - ls.push_back(p.second); - } -} -void CInode::get_nested_dirfrags(list& ls) -{ - // dirfrags in same subtree - for (const auto &p : dirfrags) { - if (!p.second->is_subtree_root()) - ls.push_back(p.second); - } -} -void CInode::get_subtree_dirfrags(list& ls) -{ - // dirfrags that are roots of new subtrees - for (const auto &p : dirfrags) { - if (p.second->is_subtree_root()) - ls.push_back(p.second); - } -} - - CDir *CInode::get_or_open_dirfrag(MDCache *mdcache, frag_t fg) { assert(is_dir()); diff --git a/src/mds/CInode.h b/src/mds/CInode.h index b27e29f797b..fa03a0a12eb 100644 --- a/src/mds/CInode.h +++ b/src/mds/CInode.h @@ -524,9 +524,32 @@ public: } bool get_dirfrags_under(frag_t fg, std::list& ls); CDir* get_approx_dirfrag(frag_t fg); - void get_dirfrags(std::list& ls); - void get_nested_dirfrags(std::list& ls); - void get_subtree_dirfrags(std::list& ls); + + template + void get_dirfrags(Container& ls) const { + // all dirfrags + for (const auto &p : dirfrags) + ls.push_back(p.second); + } + template + void get_nested_dirfrags(Container& ls) const { + // dirfrags in same subtree + for (const auto &p : dirfrags) { + typename Container::value_type dir = p.second; + if (!dir->is_subtree_root()) + ls.push_back(dir); + } + } + template + void get_subtree_dirfrags(Container& ls) { + // dirfrags that are roots of new subtrees + for (const auto &p : dirfrags) { + typename Container::value_type dir = p.second; + if (dir->is_subtree_root()) + ls.push_back(dir); + } + } + CDir *get_or_open_dirfrag(MDCache *mdcache, frag_t fg); CDir *add_dirfrag(CDir *dir); void close_dirfrag(frag_t fg);