From: Christian Brauner <brauner@kernel.org>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Jan Kara <jack@suse.cz>, Jeff Layton <jlayton@kernel.org>,
Chuck Lever <chuck.lever@oracle.com>,
Simona Vetter <simona@ffwll.ch>,
linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org
Subject: Re: [PATCH v2 10/11] fhandle, pidfs: support open_by_handle_at() purely based on file handle
Date: Tue, 24 Jun 2025 16:51:12 +0200 [thread overview]
Message-ID: <20250624-reinreden-museen-5b07804eaffe@brauner> (raw)
In-Reply-To: <CAOQ4uxjYGipMt4t+ZzYEQgn3EhWh327iEyoKyeoqKKGzwuHRsg@mail.gmail.com>
On Tue, Jun 24, 2025 at 04:28:50PM +0200, Amir Goldstein wrote:
> On Tue, Jun 24, 2025 at 12:53 PM Amir Goldstein <amir73il@gmail.com> wrote:
> >
> > On Tue, Jun 24, 2025 at 11:30 AM Jan Kara <jack@suse.cz> wrote:
> > >
> > > On Tue 24-06-25 10:29:13, Christian Brauner wrote:
> > > > Various filesystems such as pidfs (and likely drm in the future) have a
> > > > use-case to support opening files purely based on the handle without
> > > > having to require a file descriptor to another object. That's especially
> > > > the case for filesystems that don't do any lookup whatsoever and there's
> > > > zero relationship between the objects. Such filesystems are also
> > > > singletons that stay around for the lifetime of the system meaning that
> > > > they can be uniquely identified and accessed purely based on the file
> > > > handle type. Enable that so that userspace doesn't have to allocate an
> > > > object needlessly especially if they can't do that for whatever reason.
> > > >
> > > > Signed-off-by: Christian Brauner <brauner@kernel.org>
> > > > ---
> > > > fs/fhandle.c | 22 ++++++++++++++++++++--
> > > > fs/pidfs.c | 5 ++++-
> > > > 2 files changed, 24 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/fs/fhandle.c b/fs/fhandle.c
> > > > index ab4891925b52..54081e19f594 100644
> > > > --- a/fs/fhandle.c
> > > > +++ b/fs/fhandle.c
> > > > @@ -173,7 +173,7 @@ SYSCALL_DEFINE5(name_to_handle_at, int, dfd, const char __user *, name,
> > > > return err;
> > > > }
> > > >
> > > > -static int get_path_anchor(int fd, struct path *root)
> > > > +static int get_path_anchor(int fd, struct path *root, int handle_type)
> > > > {
> > > > if (fd >= 0) {
> > > > CLASS(fd, f)(fd);
> > > > @@ -193,6 +193,24 @@ static int get_path_anchor(int fd, struct path *root)
> > > > return 0;
> > > > }
> > > >
> > > > + /*
> > > > + * Only autonomous handles can be decoded without a file
> > > > + * descriptor.
> > > > + */
> > > > + if (!(handle_type & FILEID_IS_AUTONOMOUS))
> > > > + return -EOPNOTSUPP;
> > >
> > > This somewhat ties to my comment to patch 5 that if someone passed invalid
> > > fd < 0 before, we'd be returning -EBADF and now we'd be returning -EINVAL
> > > or -EOPNOTSUPP based on FILEID_IS_AUTONOMOUS setting. I don't care that
> > > much about it so feel free to ignore me but I think the following might be
> > > more sensible error codes:
> > >
> > > if (!(handle_type & FILEID_IS_AUTONOMOUS)) {
> > > if (fd == FD_INVALID)
> > > return -EOPNOTSUPP;
> > > return -EBADF;
> > > }
> > >
> > > if (fd != FD_INVALID)
> > > return -EBADF; (or -EINVAL no strong preference here)
> >
> > FWIW, I like -EBADF better.
> > it makes the error more descriptive and keeps the flow simple:
> >
> > + /*
> > + * Only autonomous handles can be decoded without a file
> > + * descriptor and only when FD_INVALID is provided.
> > + */
> > + if (fd != FD_INVALID)
> > + return -EBADF;
> > +
> > + if (!(handle_type & FILEID_IS_AUTONOMOUS))
> > + return -EOPNOTSUPP;
> >
>
> Thinking about it some more, as I am trying to address your concerns
> about crafting autonomous file handles by systemd, as you already
> decided to define a range for kernel reserved values for fd, why not,
> instead of requiring FD_INVALID for autonomous file handle, that we
> actually define a kernel fd value that translates to "the root of pidfs":
>
> + /*
> + * Autonomous handles can be decoded with a special file
> + * descriptor value that describes the filesystem.
> + */
> + switch (fd) {
> + case FD_PIDFS_ROOT:
> + pidfs_get_root(root);
> + break;
> + default:
> + return -EBADF;
> + }
> +
>
> Then you can toss all my old ideas, including FILEID_IS_AUTONOMOUS,
> and EXPORT_OP_AUTONOMOUS_HANDLES and you do not even need
> to define FILEID_PIDFS anymore, just keep exporting FILEID_KERNFS
> as before (you can also keep the existing systemd code) and when you want
> to open file by handle you just go
> open_by_handle_at(FD_PIDFS, &handle, 0)
> and that's it.
>
> In the end, my one and only concern with autonomous file handles is that
> there should be a user opt-in to request them.
>
> Sorry for taking the long road to get to this simpler design.
> WDYT?
And simply place FD_PIDFS_ROOT into the -10000 range?
Sounds good to me.
next prev parent reply other threads:[~2025-06-24 14:51 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-24 8:29 [PATCH v2 00/11] fhandle, pidfs: allow open_by_handle_at() purely based on file handle Christian Brauner
2025-06-24 8:29 ` [PATCH v2 01/11] fhandle: raise FILEID_IS_DIR in handle_type Christian Brauner
2025-06-24 9:31 ` Jan Kara
2025-06-24 8:29 ` [PATCH v2 02/11] fhandle: hoist copy_from_user() above get_path_from_fd() Christian Brauner
2025-06-24 9:31 ` Jan Kara
2025-06-24 8:29 ` [PATCH v2 03/11] fhandle: rename to get_path_anchor() Christian Brauner
2025-06-24 9:31 ` Jan Kara
2025-06-24 8:29 ` [PATCH v2 04/11] pidfs: add pidfs_root_path() helper Christian Brauner
2025-06-24 9:31 ` Jan Kara
2025-06-24 8:29 ` [PATCH v2 05/11] fhandle: reflow get_path_anchor() Christian Brauner
2025-06-24 9:16 ` Jan Kara
2025-06-24 10:16 ` Christian Brauner
2025-06-24 8:29 ` [PATCH v2 06/11] uapi/fcntl: mark range as reserved Christian Brauner
2025-06-24 9:16 ` Jan Kara
2025-06-24 10:57 ` Amir Goldstein
2025-06-24 13:47 ` Christian Brauner
2025-06-24 8:29 ` [PATCH v2 07/11] uapi/fcntl: add FD_INVALID Christian Brauner
2025-06-24 9:17 ` Jan Kara
2025-06-24 8:29 ` [PATCH v2 08/11] exportfs: add FILEID_PIDFS Christian Brauner
2025-06-24 9:17 ` Jan Kara
2025-06-24 13:15 ` Amir Goldstein
2025-06-24 13:43 ` Christian Brauner
2025-06-24 14:20 ` Amir Goldstein
2025-06-24 8:29 ` [PATCH v2 09/11] fhandle: add EXPORT_OP_AUTONOMOUS_HANDLES marker Christian Brauner
2025-06-24 9:18 ` Jan Kara
2025-06-24 9:20 ` Jan Kara
2025-06-24 10:16 ` Christian Brauner
2025-06-24 8:29 ` [PATCH v2 10/11] fhandle, pidfs: support open_by_handle_at() purely based on file handle Christian Brauner
2025-06-24 9:30 ` Jan Kara
2025-06-24 10:15 ` Christian Brauner
2025-06-24 10:53 ` Amir Goldstein
2025-06-24 14:28 ` Amir Goldstein
2025-06-24 14:51 ` Christian Brauner [this message]
2025-06-24 15:07 ` Amir Goldstein
2025-06-24 15:23 ` Christian Brauner
2025-06-24 17:45 ` Jan Kara
2025-06-24 19:23 ` Amir Goldstein
2025-06-25 7:52 ` Christian Brauner
2025-06-24 23:07 ` Al Viro
2025-06-25 7:52 ` Christian Brauner
2025-06-24 8:29 ` [PATCH v2 11/11] selftests/pidfd: decode pidfd file handles withou having to specify an fd Christian Brauner
2025-06-24 9:39 ` Jan Kara
2025-06-24 10:58 ` [PATCH v2 00/11] fhandle, pidfs: allow open_by_handle_at() purely based on file handle Amir Goldstein
2025-06-24 10:59 ` Christian Brauner
2025-06-24 14:15 ` Jan Kara
2025-06-24 14:34 ` Amir Goldstein
2025-06-24 14:39 ` 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=20250624-reinreden-museen-5b07804eaffe@brauner \
--to=brauner@kernel.org \
--cc=amir73il@gmail.com \
--cc=chuck.lever@oracle.com \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=simona@ffwll.ch \
/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