linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Why does d_splice_alias need to check IS_ROOT?
@ 2018-05-26 16:33 Lei Chen
  2018-05-26 17:12 ` Al Viro
  0 siblings, 1 reply; 3+ messages in thread
From: Lei Chen @ 2018-05-26 16:33 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-kernel, viro

Hello list,

I'm insteresting in how hard link and denry lookup work and their
implementation.

I know that this interface tries to connect an inode to a dentry, but
why does it need
to check whether the inode alias IS_ROOT if the inode represents a directory?
And the code process in different way according to check result.  What
occasions
are they used for?

struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
{
    if (S_ISDIR(inode->i_mode)) {
        struct dentry *new = __d_find_any_alias(inode);
        if (unlikely(new)) {
            if (unlikely(d_ancestor(new, dentry))) {
                /*the code here is to forbidden ancestor hard link*/
            } else if (!IS_ROOT(new)) {
                __d_unalias(inode, dentry, new);
            } else {
                __d_move(new, dentry, false);
            }

        }


    }
}

Thanks in advance.

Regards,
Larry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Why does d_splice_alias need to check IS_ROOT?
  2018-05-26 16:33 Why does d_splice_alias need to check IS_ROOT? Lei Chen
@ 2018-05-26 17:12 ` Al Viro
  2018-05-27 11:09   ` Lei Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Al Viro @ 2018-05-26 17:12 UTC (permalink / raw)
  To: Lei Chen; +Cc: linux-fsdevel, linux-kernel

On Sun, May 27, 2018 at 12:33:40AM +0800, Lei Chen wrote:
> Hello list,
> 
> I'm insteresting in how hard link and denry lookup work and their
> implementation.
> 
> I know that this interface tries to connect an inode to a dentry, but
> why does it need
> to check whether the inode alias IS_ROOT if the inode represents a directory?
> And the code process in different way according to check result.  What
> occasions
> are they used for?

If it's disconnected (and not an ancestor of the place where we want it),
we can just move it in place, no questions asked.  If it is *NOT*
disconnected, the only thing we can do is to detach it from where it
is and move it over.  Which takes a lot more care wrt locking.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Why does d_splice_alias need to check IS_ROOT?
  2018-05-26 17:12 ` Al Viro
@ 2018-05-27 11:09   ` Lei Chen
  0 siblings, 0 replies; 3+ messages in thread
From: Lei Chen @ 2018-05-27 11:09 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-fsdevel, linux-kernel

Al Viro <viro@zeniv.linux.org.uk> 于2018年5月27日周日 上午1:12写道:

> On Sun, May 27, 2018 at 12:33:40AM +0800, Lei Chen wrote:
> > Hello list,
> >
> > I'm insteresting in how hard link and denry lookup work and their
> > implementation.
> >
> > I know that this interface tries to connect an inode to a dentry, but
> > why does it need
> > to check whether the inode alias IS_ROOT if the inode represents a
directory?
> > And the code process in different way according to check result.  What
> > occasions
> > are they used for?

> If it's disconnected (and not an ancestor of the place where we want it),
> we can just move it in place, no questions asked.  If it is *NOT*
> disconnected, the only thing we can do is to detach it from where it
> is and move it over.  Which takes a lot more care wrt locking.

Thanks for your reply.

But why does it mean "disconnected" if IS_ROOT returns true??
Why not use hlist_unhashed(&entry->d_u.d_alias) or d_is_negative to
determine whether a dentry is connected to an inode??

I found that when we allocate a new dentry struct, its parent is not
always itself.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-05-27 11:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-26 16:33 Why does d_splice_alias need to check IS_ROOT? Lei Chen
2018-05-26 17:12 ` Al Viro
2018-05-27 11:09   ` Lei Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).