From: Yan, Zheng Date: Fri, 27 Jul 2018 01:17:04 +0000 (+0800) Subject: mds: make CInode::get_dirfrags container agnostic X-Git-Tag: v13.2.3~115^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6669fed4171cdf7d79591cd3d36cb2c11f7f1fc1;p=ceph.git mds: make CInode::get_dirfrags container agnostic Signed-off-by: "Yan, Zheng" (cherry picked from commit 6538dae2c1c6392a86e2e66a113656b475f482a6) --- diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index fb9b010b8742..7b754df51873 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -698,31 +698,6 @@ CDir *CInode::get_approx_dirfrag(frag_t fg) return NULL; } -void CInode::get_dirfrags(std::list& ls) const -{ - // 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 e0e37e9644c9..4a96d48c05b7 100644 --- a/src/mds/CInode.h +++ b/src/mds/CInode.h @@ -558,9 +558,38 @@ public: } bool get_dirfrags_under(frag_t fg, std::list& ls); CDir* get_approx_dirfrag(frag_t fg); - void get_dirfrags(std::list& ls) const; - void get_nested_dirfrags(std::list& ls); - void get_subtree_dirfrags(std::list& ls); + + template + void get_dirfrags(Container& ls) const { + // all dirfrags + if constexpr (std::is_same_v>) + ls.reserve(ls.size() + dirfrags.size()); + for (const auto &p : dirfrags) + ls.push_back(p.second); + } + template + void get_nested_dirfrags(Container& ls) const { + // dirfrags in same subtree + if constexpr (std::is_same_v>) + ls.reserve(ls.size() + dirfrags.size() - num_subtree_roots); + 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 + if constexpr (std::is_same_v>) + ls.reserve(ls.size() + num_subtree_roots); + 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);