Skip to content

Commit

Permalink
mds: cleanup CDir freezing/frozen tree check
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 15, 2018
1 parent c1a43ca commit 4ecf91d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
32 changes: 12 additions & 20 deletions src/mds/CDir.cc
Expand Up @@ -2948,34 +2948,26 @@ void CDir::unfreeze_tree()
}
}

bool CDir::is_freezing_tree() const
pair<bool,bool> CDir::is_freezing_or_frozen_tree() const
{
if (num_freezing_trees == 0)
return false;
const CDir *dir = this;
while (1) {
if (dir->is_freezing_tree_root()) return true;
if (dir->is_subtree_root()) return false;
if (dir->inode->parent)
dir = dir->inode->parent->dir;
else
return false; // root on replica
}
}
if (!num_freezing_trees && !num_frozen_trees)
return make_pair(false, false);

bool CDir::is_frozen_tree() const
{
if (num_frozen_trees == 0)
return false;
bool freezing, frozen;
const CDir *dir = this;
while (1) {
if (dir->is_frozen_tree_root()) return true;
if (dir->is_subtree_root()) return false;
freezing = dir->is_freezing_tree_root();
frozen = dir->is_frozen_tree_root();
if (freezing || frozen)
break;
if (dir->is_subtree_root())
break;
if (dir->inode->parent)
dir = dir->inode->parent->dir;
else
return false; // root on replica
break; // root on replica
}
return make_pair(freezing, frozen);
}

CDir *CDir::get_frozen_tree_root()
Expand Down
27 changes: 23 additions & 4 deletions src/mds/CDir.h
Expand Up @@ -709,7 +709,16 @@ class CDir : public MDSCacheObject, public Counter<CDir> {
void abort_import();

// -- auth pins --
bool can_auth_pin() const override { return is_auth() && !(is_frozen() || is_freezing()); }
bool can_auth_pin() const override {
if (!is_auth())
return false;
if (is_freezing_dir() || is_frozen_dir())
return false;
auto p = is_freezing_or_frozen_tree();
if (p.first || p.second)
return false;
return true;
}
int get_cum_auth_pins() const { return auth_pins + nested_auth_pins; }
int get_auth_pins() const { return auth_pins; }
int get_nested_auth_pins() const { return nested_auth_pins; }
Expand All @@ -731,13 +740,23 @@ class CDir : public MDSCacheObject, public Counter<CDir> {

void maybe_finish_freeze();

bool is_freezing() const override { return is_freezing_tree() || is_freezing_dir(); }
bool is_freezing_tree() const;
pair<bool,bool> is_freezing_or_frozen_tree() const;

bool is_freezing() const override { return is_freezing_dir() || is_freezing_tree(); }
bool is_freezing_tree() const {
if (!num_freezing_trees)
return false;
return is_freezing_or_frozen_tree().first;
}
bool is_freezing_tree_root() const { return state & STATE_FREEZINGTREE; }
bool is_freezing_dir() const { return state & STATE_FREEZINGDIR; }

bool is_frozen() const override { return is_frozen_dir() || is_frozen_tree(); }
bool is_frozen_tree() const;
bool is_frozen_tree() const {
if (!num_frozen_trees)
return false;
return is_freezing_or_frozen_tree().second;
}
bool is_frozen_tree_root() const { return state & STATE_FROZENTREE; }
bool is_frozen_dir() const { return state & STATE_FROZENDIR; }

Expand Down

0 comments on commit 4ecf91d

Please sign in to comment.