From: Christian Brauner <brauner@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Jeff Layton <jlayton@kernel.org>,
Amir Goldstein <amir73il@gmail.com>,
Jens Axboe <axboe@kernel.dk>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
linux-fsdevel@vger.kernel.org,
Christian Brauner <brauner@kernel.org>
Subject: [PATCH RFC v3 07/47] namespace: convert fsmount() to FD_PREPARE()
Date: Fri, 21 Nov 2025 19:00:46 +0100 [thread overview]
Message-ID: <20251121-work-fd-prepare-v3-7-2c6444d13e0e@kernel.org> (raw)
In-Reply-To: <20251121-work-fd-prepare-v3-0-2c6444d13e0e@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/namespace.c | 56 ++++++++++++++++++++++----------------------------------
1 file changed, 22 insertions(+), 34 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index 74157dd471ee..8716aedada2c 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -4280,8 +4280,7 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
{
struct mnt_namespace *ns;
struct fs_context *fc;
- struct file *file;
- struct path newmount;
+ struct path newmount __free(path_put) = {};
struct mount *mnt;
unsigned int mnt_flags = 0;
long ret;
@@ -4319,33 +4318,32 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
fc = fd_file(f)->private_data;
- ret = mutex_lock_interruptible(&fc->uapi_mutex);
- if (ret < 0)
+ ACQUIRE(mutex_intr, uapi_mutex)(&fc->uapi_mutex);
+ ret = ACQUIRE_ERR(mutex_intr, &uapi_mutex);
+ if (ret)
return ret;
/* There must be a valid superblock or we can't mount it */
ret = -EINVAL;
if (!fc->root)
- goto err_unlock;
+ return ret;
ret = -EPERM;
if (mount_too_revealing(fc->root->d_sb, &mnt_flags)) {
errorfcp(fc, "VFS", "Mount too revealing");
- goto err_unlock;
+ return ret;
}
ret = -EBUSY;
if (fc->phase != FS_CONTEXT_AWAITING_MOUNT)
- goto err_unlock;
+ return ret;
if (fc->sb_flags & SB_MANDLOCK)
warn_mandlock();
newmount.mnt = vfs_create_mount(fc);
- if (IS_ERR(newmount.mnt)) {
- ret = PTR_ERR(newmount.mnt);
- goto err_unlock;
- }
+ if (IS_ERR(newmount.mnt))
+ return PTR_ERR(newmount.mnt);
newmount.dentry = dget(fc->root);
newmount.mnt->mnt_flags = mnt_flags;
@@ -4357,38 +4355,28 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
vfs_clean_context(fc);
ns = alloc_mnt_ns(current->nsproxy->mnt_ns->user_ns, true);
- if (IS_ERR(ns)) {
- ret = PTR_ERR(ns);
- goto err_path;
- }
+ if (IS_ERR(ns))
+ return PTR_ERR(ns);
mnt = real_mount(newmount.mnt);
ns->root = mnt;
ns->nr_mounts = 1;
mnt_add_to_ns(ns, mnt);
mntget(newmount.mnt);
- /* Attach to an apparent O_PATH fd with a note that we need to unmount
- * it, not just simply put it.
- */
- file = dentry_open(&newmount, O_PATH, fc->cred);
- if (IS_ERR(file)) {
+ FD_PREPARE(fdf, (flags & FSMOUNT_CLOEXEC) ? O_CLOEXEC : 0,
+ dentry_open(&newmount, O_PATH, fc->cred));
+ ret = ACQUIRE_ERR(fd_prepare, &fdf);
+ if (ret) {
dissolve_on_fput(newmount.mnt);
- ret = PTR_ERR(file);
- goto err_path;
+ return ret;
}
- file->f_mode |= FMODE_NEED_UNMOUNT;
-
- ret = get_unused_fd_flags((flags & FSMOUNT_CLOEXEC) ? O_CLOEXEC : 0);
- if (ret >= 0)
- fd_install(ret, file);
- else
- fput(file);
-err_path:
- path_put(&newmount);
-err_unlock:
- mutex_unlock(&fc->uapi_mutex);
- return ret;
+ /*
+ * Attach to an apparent O_PATH fd with a note that we
+ * need to unmount it, not just simply put it.
+ */
+ fd_prepare_file(fdf)->f_mode |= FMODE_NEED_UNMOUNT;
+ return fd_publish(fdf);
}
static inline int vfs_move_mount(const struct path *from_path,
--
2.47.3
next prev parent reply other threads:[~2025-11-21 18:01 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-21 18:00 [PATCH RFC v3 00/47] file: add and convert to FD_PREPARE() Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 01/47] file: add FD_PREPARE() Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 02/47] anon_inodes: convert __anon_inode_getfd() to FD_PREPARE() Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 03/47] eventfd: convert do_eventfd() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 04/47] fhandle: convert do_handle_open() " Christian Brauner
2025-11-21 18:42 ` Linus Torvalds
2025-11-21 18:00 ` [PATCH RFC v3 05/47] namespace: convert open_tree() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 06/47] namespace: convert open_tree_attr() " Christian Brauner
2025-11-21 18:00 ` Christian Brauner [this message]
2025-11-21 18:00 ` [PATCH RFC v3 08/47] fanotify: convert fanotify_init() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 09/47] nsfs: convert open_namespace() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 10/47] nsfs: convert ns_ioctl() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 11/47] autofs: convert autofs_dev_ioctl_open_mountpoint() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 12/47] eventpoll: convert do_epoll_create() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 13/47] open: convert do_sys_openat2() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 14/47] signalfd: convert do_signalfd4() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 15/47] timerfd: convert timerfd_create() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 16/47] userfaultfd: convert new_userfaultfd() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 17/47] xfs: convert xfs_open_by_handle() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 18/47] dma: convert dma_buf_fd() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 19/47] af_unix: convert unix_file_open() " Christian Brauner
2025-11-21 18:00 ` [PATCH RFC v3 20/47] dma: convert sync_file_ioctl_merge() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 21/47] exec: convert begin_new_exec() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 22/47] ipc: convert do_mq_open() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 23/47] bpf: convert bpf_iter_new_fd() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 24/47] bpf: convert bpf_token_create() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 25/47] memfd: convert memfd_create() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 26/47] secretmem: convert memfd_secret() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 27/47] net/handshake: convert handshake_nl_accept_doit() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 28/47] net/kcm: convert kcm_ioctl() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 29/47] net/sctp: convert sctp_getsockopt_peeloff_common() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 30/47] net/socket: convert sock_map_fd() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 31/47] net/socket: convert __sys_accept4_file() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 32/47] spufs: convert spufs_context_open() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 33/47] papr-hvpipe: convert papr_hvpipe_dev_create_handle() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 34/47] spufs: convert spufs_gang_open() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 35/47] pseries: convert papr_platform_dump_create_handle() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 36/47] pseries: port papr_rtas_setup_file_interface() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 37/47] dma: port sw_sync_ioctl_create_fence() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 38/47] gpio: convert linehandle_create() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 39/47] hv: convert mshv_ioctl_create_partition() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 40/47] media: convert media_request_alloc() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 41/47] ntsync: convert ntsync_obj_get_fd() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 42/47] tty: convert ptm_open_peer() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 43/47] vfio: convert vfio_group_ioctl_get_device_fd() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 44/47] file: convert replace_fd() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 45/47] io_uring: convert io_create_mock_file() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 46/47] kvm: convert kvm_arch_supports_gmem_init_shared() " Christian Brauner
2025-11-21 18:01 ` [PATCH RFC v3 47/47] kvm: convert kvm_vcpu_ioctl_get_stats_fd() " Christian Brauner
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=20251121-work-fd-prepare-v3-7-2c6444d13e0e@kernel.org \
--to=brauner@kernel.org \
--cc=amir73il@gmail.com \
--cc=axboe@kernel.dk \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@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;
as well as URLs for NNTP newsgroup(s).