linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: NeilBrown <neil@brown.name>
Cc: Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 7/8] VFS: use new dentry locking for create/remove/rename
Date: Tue, 10 Jun 2025 21:36:31 +0100	[thread overview]
Message-ID: <20250610203631.GF299672@ZenIV> (raw)
In-Reply-To: <20250609075950.159417-8-neil@brown.name>

On Mon, Jun 09, 2025 at 05:34:12PM +1000, NeilBrown wrote:
> After taking the directory lock (or locks) we now lock the target
> dentries.  This is pointless at present but will allow us to remove the
> taking of the directory lock in a future patch.
> 
> MORE WORDS

Such as "why doesn't it deadlock?", presumably, seeing that you have

> @@ -2003,7 +2003,14 @@ struct dentry *lookup_and_lock_hashed(struct qstr *last,
>  
>  	inode_lock_nested(base->d_inode, I_MUTEX_PARENT);
>  
> +retry:
>  	dentry = lookup_one_qstr(last, base, lookup_flags);
> +	if (!IS_ERR(dentry) &&
> +	    !dentry_lock(dentry, base, last, TASK_UNINTERRUPTIBLE)) {

... take dentry lock inside ->i_rwsem on parent and

>  bool lock_and_check_dentry(struct dentry *child, struct dentry *parent)
>  {
> -	inode_lock_nested(d_inode(parent), I_MUTEX_PARENT);
> -	if (child->d_parent == parent) {
> -		/* get the child to balance with dentry_unlock which puts it. */
> -		dget(child);
> -		return true;
> +	if (!dentry_lock(child, NULL, NULL, TASK_UNINTERRUPTIBLE))
> +		return false;
> +	if (child->d_parent != parent) {
> +		__dentry_unlock(child);
> +		return false;
>  	}
> -	inode_unlock(d_inode(parent));
> -	return false;
> +	/* get the child to balance with dentry_unlock() which puts it. */
> +	dget(child);
> +	inode_lock_nested(d_inode(parent), I_MUTEX_PARENT);

... do the same in opposite order?

How could that possibly work?

  reply	other threads:[~2025-06-10 20:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-09  7:34 [PATCH 0/8 preview] demonstrate proposed new locking strategy for directories NeilBrown
2025-06-09  7:34 ` [PATCH 1/8] VFS: use global wait-queue table for d_alloc_parallel() NeilBrown
2025-06-09  7:34 ` [PATCH 2/8] VFS: use d_alloc_parallel() in lookup_one_qstr_excl() NeilBrown
2025-06-09  7:34 ` [PATCH 3/8] fs/proc: take rcu_read_lock() in proc_sys_compare() NeilBrown
2025-06-09  7:34 ` [PATCH 4/8] VFS: Add ability to exclusively lock a dentry and use for open/create NeilBrown
2025-06-09  7:34 ` [PATCH 5/8] Introduce S_DYING which warns that S_DEAD might follow NeilBrown
2025-06-10 20:57   ` Al Viro
2025-06-11  1:00     ` NeilBrown
2025-06-11  1:13       ` Al Viro
2025-06-11  2:49         ` NeilBrown
2025-06-09  7:34 ` [PATCH 6/8] VFS: provide alternative to s_vfs_rename_mutex NeilBrown
2025-06-09  7:34 ` [PATCH 7/8] VFS: use new dentry locking for create/remove/rename NeilBrown
2025-06-10 20:36   ` Al Viro [this message]
2025-06-11  0:34     ` NeilBrown
2025-06-09  7:34 ` [PATCH 8/8] VFS: allow a filesystem to opt out of directory locking NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250610203631.GF299672@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=neil@brown.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).