return NULL;
}
-bool CInode::is_projected_ancestor_of(CInode *other)
+bool CInode::is_ancestor_of(const CInode *other) const
{
while (other) {
if (other == this)
return true;
- if (!other->get_projected_parent_dn())
+ const CDentry *pdn = other->get_oldest_parent_dn();
+ if (!pdn) {
+ assert(other->is_base());
break;
- other = other->get_projected_parent_dn()->get_dir()->get_inode();
+ }
+ other = pdn->get_dir()->get_inode();
+ }
+ return false;
+}
+
+bool CInode::is_projected_ancestor_of(const CInode *other) const
+{
+ while (other) {
+ if (other == this)
+ return true;
+ const CDentry *pdn = other->get_projected_parent_dn();
+ if (!pdn) {
+ assert(other->is_base());
+ break;
+ }
+ other = pdn->get_dir()->get_inode();
}
return false;
}
{
const CInode *cur = this;
while (!cur->snaprealm) {
- if (cur->get_parent_dn())
- cur = cur->get_parent_dn()->get_dir()->get_inode();
- else if (get_projected_parent_dn())
- cur = cur->get_projected_parent_dn()->get_dir()->get_inode();
- else
+ const CDentry *pdn = cur->get_oldest_parent_dn();
+ if (!pdn)
break;
+ cur = pdn->get_dir()->get_inode();
}
return cur->snaprealm;
}
inode_t& get_inode() { return inode; }
CDentry* get_parent_dn() { return parent; }
const CDentry* get_parent_dn() const { return parent; }
- const CDentry* get_projected_parent_dn() const { return !projected_parent.empty() ? projected_parent.back() : parent; }
CDentry* get_projected_parent_dn() { return !projected_parent.empty() ? projected_parent.back() : parent; }
+ const CDentry* get_projected_parent_dn() const { return !projected_parent.empty() ? projected_parent.back() : parent; }
+ const CDentry* get_oldest_parent_dn() const {
+ if (parent)
+ return parent;
+ return !projected_parent.empty() ? projected_parent.front(): NULL;
+ }
CDir *get_parent_dir();
const CDir *get_projected_parent_dir() const;
CDir *get_projected_parent_dir();
}
// -- misc --
- bool is_projected_ancestor_of(CInode *other);
+ bool is_ancestor_of(const CInode *other) const;
+ bool is_projected_ancestor_of(const CInode *other) const;
void make_path_string(std::string& s, bool projected=false, const CDentry *use_parent=NULL) const;
void make_path(filepath& s, bool projected=false) const;
p != open_children.end(); ) {
SnapRealm *realm = *p;
if (realm != child &&
- child->inode->is_projected_ancestor_of(realm->inode)) {
+ child->inode->is_ancestor_of(realm->inode)) {
dout(20) << " child gets child realm " << *realm << " on " << *realm->inode << dendl;
realm->parent = child;
child->open_children.insert(realm);
}
// split inodes_with_caps
- elist<CInode*>::iterator p = inodes_with_caps.begin(member_offset(CInode, item_caps));
- while (!p.end()) {
+ for (elist<CInode*>::iterator p = inodes_with_caps.begin(member_offset(CInode, item_caps));
+ !p.end(); ) {
CInode *in = *p;
++p;
-
// does inode fall within the child realm?
- bool under_child = false;
-
- if (in == child->inode) {
- under_child = true;
- } else {
- CInode *t = in;
- while (t->get_parent_dn()) {
- t = t->get_parent_dn()->get_dir()->get_inode();
- if (t == child->inode) {
- under_child = true;
- break;
- }
- if (t == in)
- break;
- }
- }
- if (under_child) {
+ if (child->inode->is_ancestor_of(in)) {
dout(20) << " child gets " << *in << dendl;
in->move_to_realm(child);
} else {