Skip to content

Commit

Permalink
mds: make CInode::get_dirfrags container agnostic
Browse files Browse the repository at this point in the history
Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
  • Loading branch information
ukernel committed Aug 17, 2018
1 parent efff5c6 commit 6538dae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
25 changes: 0 additions & 25 deletions src/mds/CInode.cc
Expand Up @@ -718,31 +718,6 @@ CDir *CInode::get_approx_dirfrag(frag_t fg)
return NULL;
}

void CInode::get_dirfrags(std::list<CDir*>& ls) const
{
// all dirfrags
for (const auto &p : dirfrags) {
ls.push_back(p.second);
}
}
void CInode::get_nested_dirfrags(list<CDir*>& 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<CDir*>& 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());
Expand Down
35 changes: 32 additions & 3 deletions src/mds/CInode.h
Expand Up @@ -559,9 +559,38 @@ class CInode : public MDSCacheObject, public InodeStoreBase, public Counter<CIno
}
bool get_dirfrags_under(frag_t fg, std::list<CDir*>& ls);
CDir* get_approx_dirfrag(frag_t fg);
void get_dirfrags(std::list<CDir*>& ls) const;
void get_nested_dirfrags(std::list<CDir*>& ls);
void get_subtree_dirfrags(std::list<CDir*>& ls);

template<typename Container>
void get_dirfrags(Container& ls) const {
// all dirfrags
if constexpr (std::is_same_v<Container, std::vector<CDir*>>)
ls.reserve(ls.size() + dirfrags.size());
for (const auto &p : dirfrags)
ls.push_back(p.second);
}
template<typename Container>
void get_nested_dirfrags(Container& ls) const {
// dirfrags in same subtree
if constexpr (std::is_same_v<Container, std::vector<CDir*>>)
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<typename Container>
void get_subtree_dirfrags(Container& ls) {
// dirfrags that are roots of new subtrees
if constexpr (std::is_same_v<Container, std::vector<CDir*>>)
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);
Expand Down

0 comments on commit 6538dae

Please sign in to comment.