public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 06/11] VFS: introduce done_lookup_and_lock()
Date: Fri, 20 Dec 2024 13:54:24 +1100	[thread overview]
Message-ID: <20241220030830.272429-7-neilb@suse.de> (raw)
In-Reply-To: <20241220030830.272429-1-neilb@suse.de>

Callers of kern_path_locked() and user_path_locked_at() should now call
done_lookup_and_lock() to unlock the directory and dput() the
dentry.

This will allow the locking rules to be changed in a central place.

Signed-off-by: NeilBrown <neilb@suse.de>
---
 drivers/base/devtmpfs.c |  7 +++----
 fs/bcachefs/fs-ioctl.c  |  3 +--
 fs/namei.c              | 10 ++++++++--
 include/linux/namei.h   |  1 +
 kernel/audit_fsnotify.c |  3 +--
 kernel/audit_watch.c    |  3 +--
 6 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
index c9e34842139f..bb6d26338b6c 100644
--- a/drivers/base/devtmpfs.c
+++ b/drivers/base/devtmpfs.c
@@ -251,8 +251,8 @@ static int dev_rmdir(const char *name)
 	else
 		err = -EPERM;
 
-	dput(dentry);
-	inode_unlock(d_inode(parent.dentry));
+	done_lookup_and_lock(parent.dentry, dentry);
+
 	path_put(&parent);
 	return err;
 }
@@ -339,8 +339,7 @@ static int handle_remove(const char *nodename, struct device *dev)
 		if (!err || err == -ENOENT)
 			deleted = 1;
 	}
-	dput(dentry);
-	inode_unlock(d_inode(parent.dentry));
+	done_lookup_and_lock(parent.dentry, dentry);
 
 	path_put(&parent);
 	if (deleted && strchr(nodename, '/'))
diff --git a/fs/bcachefs/fs-ioctl.c b/fs/bcachefs/fs-ioctl.c
index c5464219b23f..d51c86e24bef 100644
--- a/fs/bcachefs/fs-ioctl.c
+++ b/fs/bcachefs/fs-ioctl.c
@@ -522,8 +522,7 @@ static long bch2_ioctl_subvolume_destroy(struct bch_fs *c, struct file *filp,
 		d_delete(victim);
 	}
 err:
-	inode_unlock(dir);
-	dput(victim);
+	done_lookup_and_lock(path.dentry, victim);
 	path_put(&path);
 	return ret;
 }
diff --git a/fs/namei.c b/fs/namei.c
index 8780406cb4d7..29f86df4b9dc 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2773,6 +2773,13 @@ struct dentry *user_path_locked_at(int dfd, const char __user *name, struct path
 }
 EXPORT_SYMBOL(user_path_locked_at);
 
+void done_lookup_and_lock(struct dentry *parent, struct dentry *child)
+{
+	dput(child);
+	inode_unlock(d_inode(parent));
+}
+EXPORT_SYMBOL(done_lookup_and_lock);
+
 int kern_path(const char *name, unsigned int flags, struct path *path)
 {
 	struct filename *filename = getname_kernel(name);
@@ -4146,8 +4153,7 @@ EXPORT_SYMBOL(kern_path_create);
 
 void done_path_create(struct path *path, struct dentry *dentry)
 {
-	dput(dentry);
-	inode_unlock(path->dentry->d_inode);
+	done_lookup_and_lock(path->dentry, dentry);
 	mnt_drop_write(path->mnt);
 	path_put(path);
 }
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 15118992f745..898fc8ba37e1 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -65,6 +65,7 @@ extern struct dentry *user_path_create(int, const char __user *, struct path *,
 extern void done_path_create(struct path *, struct dentry *);
 extern struct dentry *kern_path_locked(const char *, struct path *);
 extern struct dentry *user_path_locked_at(int , const char __user *, struct path *);
+extern void done_lookup_and_lock(struct dentry *parent, struct dentry *child);
 int vfs_path_parent_lookup(struct filename *filename, unsigned int flags,
 			   struct path *parent, struct qstr *last, int *type,
 			   const struct path *root);
diff --git a/kernel/audit_fsnotify.c b/kernel/audit_fsnotify.c
index c565fbf66ac8..db2c03caa74d 100644
--- a/kernel/audit_fsnotify.c
+++ b/kernel/audit_fsnotify.c
@@ -86,7 +86,6 @@ struct audit_fsnotify_mark *audit_alloc_mark(struct audit_krule *krule, char *pa
 	if (IS_ERR(dentry))
 		return ERR_CAST(dentry); /* returning an error */
 	inode = path.dentry->d_inode;
-	inode_unlock(inode);
 
 	audit_mark = kzalloc(sizeof(*audit_mark), GFP_KERNEL);
 	if (unlikely(!audit_mark)) {
@@ -107,7 +106,7 @@ struct audit_fsnotify_mark *audit_alloc_mark(struct audit_krule *krule, char *pa
 		audit_mark = ERR_PTR(ret);
 	}
 out:
-	dput(dentry);
+	done_lookup_and_lock(path.dentry, dentry);
 	path_put(&path);
 	return audit_mark;
 }
diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c
index e3130675ee6b..e1137ea9294b 100644
--- a/kernel/audit_watch.c
+++ b/kernel/audit_watch.c
@@ -354,8 +354,7 @@ static int audit_get_nd(struct audit_watch *watch, struct path *parent)
 	watch->dev = d->d_sb->s_dev;
 	watch->ino = d_backing_inode(d)->i_ino;
 
-	inode_unlock(d_backing_inode(parent->dentry));
-	dput(d);
+	done_lookup_and_lock(parent->dentry, d);
 	return 0;
 }
 
-- 
2.47.0


  parent reply	other threads:[~2024-12-20  3:09 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-20  2:54 [PATCH 00/11 RFC] Allow concurrent changes in a directory NeilBrown
2024-12-20  2:54 ` [PATCH 01/11] VFS: introduce vfs_mkdir_return() NeilBrown
2024-12-23  5:04   ` Al Viro
2024-12-23  7:26     ` NeilBrown
2024-12-20  2:54 ` [PATCH 02/11] VFS: add _shared versions of the various directory modifying inode_operations NeilBrown
2024-12-23  5:08   ` Al Viro
2024-12-20  2:54 ` [PATCH 03/11] VFS: use global wait-queue table for d_alloc_parallel() NeilBrown
2024-12-20  2:54 ` [PATCH 04/11] VFS: use d_alloc_parallel() in lookup_one_qstr_excl() NeilBrown
2024-12-20  2:54 ` [PATCH 05/11] VFS: change kern_path_locked() and user_path_locked_at() to never return negative dentry NeilBrown
2024-12-20  2:54 ` NeilBrown [this message]
2024-12-20  2:54 ` [PATCH 07/11] VFS: introduce lookup_and_lock() NeilBrown
2024-12-20  2:54 ` [PATCH 08/11] VFS: add inode_dir_lock/unlock NeilBrown
2024-12-21  1:21   ` Hillf Danton
2024-12-23  3:10     ` NeilBrown
2024-12-23 11:12       ` Hillf Danton
2024-12-23 20:36         ` NeilBrown
2024-12-24 10:26           ` Hillf Danton
2024-12-20  2:54 ` [PATCH 09/11] VFS: re-pack DENTRY_ flags NeilBrown
2024-12-20  2:54 ` [PATCH 10/11] VFS: take a shared lock for create/remove directory operations NeilBrown
2024-12-23  5:19   ` Al Viro
2024-12-23  7:11     ` NeilBrown
2024-12-23  7:26       ` Al Viro
2024-12-23 20:40         ` NeilBrown
2024-12-20  2:54 ` [PATCH 11/11] nfsd: use lookup_and_lock_one() NeilBrown
2024-12-20 20:55 ` [PATCH 00/11 RFC] Allow concurrent changes in a directory Andreas Dilger
2024-12-23  5:22 ` Al Viro

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=20241220030830.272429-7-neilb@suse.de \
    --to=neilb@suse.de \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /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