From: Jeff Layton <jlayton@kernel.org>
To: Al Viro <viro@zeniv.linux.org.uk>, linux-fsdevel@vger.kernel.org
Cc: chuck.lever@oracle.com, linux-nfs@vger.kernel.org,
neil@brown.name, torvalds@linux-foundation.org,
trondmy@kernel.org
Subject: Re: [PATCH 02/17] new helper: simple_start_creating()
Date: Fri, 13 Jun 2025 14:31:56 -0400 [thread overview]
Message-ID: <84376c8a7753a8242e9f5730128f0eaea7863b61.camel@kernel.org> (raw)
In-Reply-To: <20250613073432.1871345-2-viro@zeniv.linux.org.uk>
On Fri, 2025-06-13 at 08:34 +0100, Al Viro wrote:
> Set the things up for kernel-initiated creation of object in
> a tree-in-dcache filesystem. With respect to locking it's
> an equivalent of filename_create() - we either get a negative
> dentry with locked parent, or ERR_PTR() and no locks taken.
>
> tracefs and debugfs had that open-coded as part of their
> object creation machinery; switched to calling new helper.
>
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
> fs/debugfs/inode.c | 21 ++-------------------
> fs/libfs.c | 25 +++++++++++++++++++++++++
> fs/tracefs/inode.c | 15 ++-------------
> include/linux/fs.h | 1 +
> 4 files changed, 30 insertions(+), 32 deletions(-)
>
> diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
> index 30c4944e1862..08638e39bd12 100644
> --- a/fs/debugfs/inode.c
> +++ b/fs/debugfs/inode.c
> @@ -384,26 +384,9 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)
> if (!parent)
> parent = debugfs_mount->mnt_root;
>
> - inode_lock(d_inode(parent));
> - if (unlikely(IS_DEADDIR(d_inode(parent))))
> - dentry = ERR_PTR(-ENOENT);
> - else
> - dentry = lookup_noperm(&QSTR(name), parent);
> - if (!IS_ERR(dentry) && d_really_is_positive(dentry)) {
> - if (d_is_dir(dentry))
> - pr_err("Directory '%s' with parent '%s' already present!\n",
> - name, parent->d_name.name);
> - else
> - pr_err("File '%s' in directory '%s' already present!\n",
> - name, parent->d_name.name);
Any chance we could keep a pr_err() for this case? I was doing some
debugfs work recently, and found it helpful.
> - dput(dentry);
> - dentry = ERR_PTR(-EEXIST);
> - }
> -
> - if (IS_ERR(dentry)) {
> - inode_unlock(d_inode(parent));
> + dentry = simple_start_creating(parent, name);
> + if (IS_ERR(dentry))
> simple_release_fs(&debugfs_mount, &debugfs_mount_count);
> - }
>
> return dentry;
> }
> diff --git a/fs/libfs.c b/fs/libfs.c
> index 42e226af6095..833ad5ed10f5 100644
> --- a/fs/libfs.c
> +++ b/fs/libfs.c
> @@ -2260,3 +2260,28 @@ void stashed_dentry_prune(struct dentry *dentry)
> */
> cmpxchg(stashed, dentry, NULL);
> }
> +
> +/* parent must be held exclusive */
> +struct dentry *simple_start_creating(struct dentry *parent, const char *name)
> +{
> + struct dentry *dentry;
> + struct inode *dir = d_inode(parent);
> +
> + inode_lock(dir);
> + if (unlikely(IS_DEADDIR(dir))) {
> + inode_unlock(dir);
> + return ERR_PTR(-ENOENT);
> + }
> + dentry = lookup_noperm(&QSTR(name), parent);
> + if (IS_ERR(dentry)) {
> + inode_unlock(dir);
> + return dentry;
> + }
> + if (dentry->d_inode) {
> + dput(dentry);
> + inode_unlock(dir);
> + return ERR_PTR(-EEXIST);
> + }
> + return dentry;
> +}
> +EXPORT_SYMBOL(simple_start_creating);
> diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c
> index a3fd3cc591bd..4e5d091e9263 100644
> --- a/fs/tracefs/inode.c
> +++ b/fs/tracefs/inode.c
> @@ -551,20 +551,9 @@ struct dentry *tracefs_start_creating(const char *name, struct dentry *parent)
> if (!parent)
> parent = tracefs_mount->mnt_root;
>
> - inode_lock(d_inode(parent));
> - if (unlikely(IS_DEADDIR(d_inode(parent))))
> - dentry = ERR_PTR(-ENOENT);
> - else
> - dentry = lookup_noperm(&QSTR(name), parent);
> - if (!IS_ERR(dentry) && d_inode(dentry)) {
> - dput(dentry);
> - dentry = ERR_PTR(-EEXIST);
> - }
> -
> - if (IS_ERR(dentry)) {
> - inode_unlock(d_inode(parent));
> + dentry = simple_start_creating(parent, name);
> + if (IS_ERR(dentry))
> simple_release_fs(&tracefs_mount, &tracefs_mount_count);
> - }
>
> return dentry;
> }
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 96c7925a6551..9f75f8836bbd 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -3619,6 +3619,7 @@ extern int simple_fill_super(struct super_block *, unsigned long,
> const struct tree_descr *);
> extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count);
> extern void simple_release_fs(struct vfsmount **mount, int *count);
> +struct dentry *simple_start_creating(struct dentry *, const char *);
>
> extern ssize_t simple_read_from_buffer(void __user *to, size_t count,
> loff_t *ppos, const void *from, size_t available);
--
Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2025-06-13 18:31 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-13 7:31 [PATCHES][RFC][CFT] rpc_pipefs cleanups Al Viro
2025-06-13 7:34 ` [PATCH 01/17] simple_recursive_removal(): saner interaction with fsnotify Al Viro
2025-06-13 7:34 ` [PATCH 02/17] new helper: simple_start_creating() Al Viro
2025-06-13 18:31 ` Jeff Layton [this message]
2025-06-13 22:36 ` Al Viro
2025-06-13 23:46 ` Jeff Layton
2025-06-13 7:34 ` [PATCH 03/17] rpc_pipe: clean failure exits in fill_super Al Viro
2025-06-13 7:34 ` [PATCH 04/17] rpc_{rmdir_,}depopulate(): use simple_recursive_removal() instead Al Viro
2025-06-13 7:34 ` [PATCH 05/17] rpc_unlink(): use simple_recursive_removal() Al Viro
2025-06-13 7:34 ` [PATCH 06/17] rpc_populate(): lift cleanup into callers Al Viro
2025-06-13 7:34 ` [PATCH 07/17] rpc_unlink(): saner calling conventions Al Viro
2025-06-13 7:34 ` [PATCH 08/17] rpc_mkpipe_dentry(): " Al Viro
2025-06-13 7:34 ` [PATCH 09/17] rpc_pipe: don't overdo directory locking Al Viro
2025-06-13 7:34 ` [PATCH 10/17] rpc_pipe: saner primitive for creating subdirectories Al Viro
2025-06-13 7:34 ` [PATCH 11/17] rpc_pipe: saner primitive for creating regular files Al Viro
2025-06-13 7:34 ` [PATCH 12/17] rpc_mkpipe_dentry(): switch to start_creating() Al Viro
2025-06-13 19:27 ` Jeff Layton
2025-06-16 19:26 ` Al Viro
2025-06-13 7:34 ` [PATCH 13/17] rpc_gssd_dummy_populate(): don't bother with rpc_populate() Al Viro
2025-06-13 7:34 ` [PATCH 14/17] rpc_pipe: expand the calls of rpc_mkdir_populate() Al Viro
2025-06-13 7:34 ` [PATCH 15/17] rpc_new_dir(): the last argument is always NULL Al Viro
2025-06-13 7:34 ` [PATCH 16/17] rpc_create_client_dir(): don't bother with rpc_populate() Al Viro
2025-06-13 7:34 ` [PATCH 17/17] rpc_create_client_dir(): return 0 or -E Al Viro
2025-06-13 8:19 ` [PATCH 01/17] simple_recursive_removal(): saner interaction with fsnotify Amir Goldstein
2025-06-13 19:32 ` [PATCHES][RFC][CFT] rpc_pipefs cleanups Jeff Layton
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=84376c8a7753a8242e9f5730128f0eaea7863b61.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=torvalds@linux-foundation.org \
--cc=trondmy@kernel.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