Re: FUSE passthrough: fd lifetime?

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

 



On Tue, Aug 27, 2024 at 11:42 AM Han-Wen Nienhuys <hanwenn@xxxxxxxxx> wrote:
>
> Hi folks,

Hi Han-Wen,

For future reference, please CC FUSE and libfuse maintainers
and FUSE passthrough developer (me) if you want to make sure
that you got our attention.

>
> I am implementing passthrough support for go-fuse. It seems to be
> working now (code:
> https://review.gerrithub.io/c/hanwen/go-fuse/+/1199984 and
> predecessors), but I am unsure of the correct lifetimes for the file
> descriptors.
>
> The passthrough_hp example seems to do:
>
> Open:
>   backing_fd = ..
>   backing_id = ioctl(fuse_device_fd,
>      FUSE_DEV_IOC_BACKING_OPEN, backing_fd)
>
> Release:
>   ioctl(fuse_device_fd,
>      FUSE_DEV_IOC_BACKING_CLOSE, backing_id)
>   close(backing_fd)
>

If you look closer, that is not exactly what passthough_hp does.
What it does is:

Open #1:
   backing_fd1 = ..
   backing_id = ioctl(fuse_device_fd,
      FUSE_DEV_IOC_BACKING_OPEN, backing_fd1)

Open #2 (of the same inode):
   backing_fd2 = ..
   /* No ioctl, reusing existing backing_id for inode */

Release #1:
   /* No ioctl */
   close(backing_fd1)

Release #2:
   ioctl(fuse_device_fd,
      FUSE_DEV_IOC_BACKING_CLOSE, backing_id)
   close(backing_fd2)

Not necessary.

passthrough_hp needs to keep backing_fd open because of
operations that are not passthrough.
It does not do that for keeping the backing_fd object alive.
Only the ioctls manage the lifetime of the backing fd object in the kernel.

> In the case of go-fuse, the backing_fd is managed by client
> code, so I can't ensure it is kept open long enough. I can work around
> this by doing
>
> Open:
>    new_backing_fd = ioctl(backing_fd, DUP_FD, 0)
>    backing_id = ioctl(fuse_device_fd,
>      FUSE_DEV_IOC_BACKING_OPEN, new_backing_fd)
>
> Release:
>   ioctl(fuse_device_fd,
>      FUSE_DEV_IOC_BACKING_CLOSE, backing_id)
>   close(new_backing_fd)
>
> but it would double the number of FDs the process uses.
>
> I tried simply closing the backing FD right after obtaining the
> backing ID, and it seems to work. Is this permitted?

Yes.

BTW, since you are one of the first (publicly announced) users of
FUSE passthrough, it would be helpful to get feedback about API,
which could change down the road and about your wish list.

Specifically, I have WIP patches for
- readdir() passthrough
- stat()/getxattr()/listxattr() passthrough

and users feedback could help me decide how to prioritize between
those (and other) FUSE passthrough efforts.

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