From: Christian Brauner <brauner@kernel.org>
To: Erin Shepherd <erin.shepherd@e43.eu>,
Amir Goldstein <amir73il@gmail.com>,
Jeff Layton <jlayton@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
Chuck Lever <chuck.lever@oracle.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-nfs@vger.kernel.org
Subject: [PATCH RFC 2/6] fhandle: simplify error handling
Date: Fri, 29 Nov 2024 14:38:01 +0100 [thread overview]
Message-ID: <20241129-work-pidfs-file_handle-v1-2-87d803a42495@kernel.org> (raw)
In-Reply-To: <20241129-work-pidfs-file_handle-v1-0-87d803a42495@kernel.org>
Rely on our cleanup infrastructure.
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/fhandle.c | 39 +++++++++++++++++----------------------
1 file changed, 17 insertions(+), 22 deletions(-)
diff --git a/fs/fhandle.c b/fs/fhandle.c
index ec9145047dfc9d25e109e72d210987bbf6b36a20..c00d88fb14e16654b5cbbb71760c0478eac20384 100644
--- a/fs/fhandle.c
+++ b/fs/fhandle.c
@@ -261,19 +261,20 @@ static int do_handle_to_path(struct file_handle *handle, struct path *path,
{
int handle_dwords;
struct vfsmount *mnt = ctx->root.mnt;
+ struct dentry *dentry;
/* change the handle size to multiple of sizeof(u32) */
handle_dwords = handle->handle_bytes >> 2;
- path->dentry = exportfs_decode_fh_raw(mnt,
- (struct fid *)handle->f_handle,
- handle_dwords, handle->handle_type,
- ctx->fh_flags,
- vfs_dentry_acceptable, ctx);
- if (IS_ERR_OR_NULL(path->dentry)) {
- if (path->dentry == ERR_PTR(-ENOMEM))
+ dentry = exportfs_decode_fh_raw(mnt, (struct fid *)handle->f_handle,
+ handle_dwords, handle->handle_type,
+ ctx->fh_flags, vfs_dentry_acceptable,
+ ctx);
+ if (IS_ERR_OR_NULL(dentry)) {
+ if (dentry == ERR_PTR(-ENOMEM))
return -ENOMEM;
return -ESTALE;
}
+ path->dentry = dentry;
path->mnt = mntget(mnt);
return 0;
}
@@ -398,29 +399,23 @@ static long do_handle_open(int mountdirfd, struct file_handle __user *ufh,
int open_flag)
{
long retval = 0;
- struct path path;
+ struct path path __free(path_put) = {};
struct file *file;
- int fd;
retval = handle_to_path(mountdirfd, ufh, &path, open_flag);
if (retval)
return retval;
- fd = get_unused_fd_flags(open_flag);
- if (fd < 0) {
- path_put(&path);
+ CLASS(get_unused_fd, fd)(O_CLOEXEC);
+ if (fd < 0)
return fd;
- }
+
file = file_open_root(&path, "", open_flag, 0);
- if (IS_ERR(file)) {
- put_unused_fd(fd);
- retval = PTR_ERR(file);
- } else {
- retval = fd;
- fd_install(fd, file);
- }
- path_put(&path);
- return retval;
+ if (IS_ERR(file))
+ return PTR_ERR(file);
+
+ fd_install(fd, file);
+ return take_fd(fd);
}
/**
--
2.45.2
next prev parent reply other threads:[~2024-11-29 13:39 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-29 13:02 [PATCH RFC v2 0/3] pidfs: file handle preliminaries Christian Brauner
2024-11-29 13:02 ` [PATCH RFC v2 1/3] pidfs: rework inode number allocation Christian Brauner
2024-12-02 15:15 ` Jan Kara
2024-11-29 13:02 ` [PATCH RFC v2 2/3] pidfs: remove 32bit inode number handling Christian Brauner
2024-12-02 15:18 ` Jan Kara
2024-11-29 13:02 ` [PATCH RFC v2 3/3] pidfs: support FS_IOC_GETVERSION Christian Brauner
2024-12-02 15:35 ` Jan Kara
2024-11-29 13:37 ` [PATCH RFC 0/6] pidfs: implement file handle support Christian Brauner
2024-11-29 13:38 ` [PATCH RFC 1/6] pseudofs: add support for export_ops Christian Brauner
2024-12-02 15:59 ` Jan Kara
2024-11-29 13:38 ` Christian Brauner [this message]
2024-12-02 15:58 ` [PATCH RFC 2/6] fhandle: simplify error handling Jan Kara
2024-11-29 13:38 ` [PATCH RFC 3/6] exportfs: add open method Christian Brauner
2024-12-02 16:05 ` Jan Kara
2024-11-29 13:38 ` [PATCH RFC 4/6] fhandle: pull CAP_DAC_READ_SEARCH check into may_decode_fh() Christian Brauner
2024-12-02 16:01 ` Jan Kara
2024-11-29 13:38 ` [PATCH RFC 5/6] exportfs: add permission method Christian Brauner
2024-12-02 16:04 ` Jan Kara
2024-11-29 13:38 ` [PATCH RFC 6/6] pidfs: implement file handle support Christian Brauner
2024-11-29 14:52 ` Amir Goldstein
2024-11-30 12:22 ` [PATCH RFC 0/6] " Amir Goldstein
2024-12-01 8:43 ` Christian Brauner
2024-12-01 12:09 ` Amir Goldstein
2024-12-01 12:44 ` Christian Brauner
2024-11-29 14:27 ` [PATCH RFC v2 0/3] pidfs: file handle preliminaries Jeff Layton
2024-11-29 14:34 ` Amir Goldstein
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=20241129-work-pidfs-file_handle-v1-2-87d803a42495@kernel.org \
--to=brauner@kernel.org \
--cc=amir73il@gmail.com \
--cc=chuck.lever@oracle.com \
--cc=erin.shepherd@e43.eu \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.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
all inboxes | Powered by JetHome®