Re: [PATCH v2 10/11] fhandle, pidfs: support open_by_handle_at() purely based on file handle

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jun 24, 2025 at 11:30 AM Jan Kara <jack@xxxxxxx> 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@xxxxxxxxxx>
> > ---
> >  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;

Thanks,
Amir.





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux