Page MenuHomeFreeBSD

fusefs: change how poll() on /dev/fuse works on unmount
AcceptedPublic

Authored by asomers on Jun 12 2025, 10:28 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Jul 25, 10:48 PM
Unknown Object (File)
Fri, Jul 25, 3:48 PM
Unknown Object (File)
Fri, Jul 25, 12:21 PM
Unknown Object (File)
Fri, Jul 25, 7:58 AM
Unknown Object (File)
Thu, Jul 24, 6:18 PM
Unknown Object (File)
Thu, Jul 24, 5:32 AM
Unknown Object (File)
Tue, Jul 22, 6:41 PM
Unknown Object (File)
Thu, Jul 17, 9:46 AM
Subscribers

Details

Reviewers
arrowd
Summary

If the file system has been unmounted or is marked as dead due to server
misbehavior:

  • Don't return POLLIN or POLLRDNORM. We shouldn't, since a subsequent read() won't return any data.
  • Do return POLLHUP since we'll never again return data on read().
  • Don't return POLLOUT. According to poll(2), POLLHUP and POLLOUT should never be returned at the same time.

Don't MFC this change, as there's a small risk of breakage for fuse
servers that depend on the old behavior. Note that libfuse is not
affected; while it does use poll() it doesn't check revents. Nor are
any applications affect that use kqueue, select, or plain blocking
reads.

Reported by: arrowd
MFC after: Never
Sponsored by: ConnectWise

Test Plan

Test case added

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 64835
Build 61718: arc lint + arc unit

Event Timeline

sys/fs/fuse/fuse_device.c
284

I think, to be in line with that FreeBSD does for other descriptor types, this should be

revents = POLLHUP;

See my test program from this post: https://lists.freebsd.org/archives/freebsd-hackers/2025-June/004569.html

In that code I don't even request POLLHUP in events, but FreeBSD returns its nevertheless.

sys/fs/fuse/fuse_device.c
284

Yes, good catch. We should output POLLHUP regardless of the input events.

  • fixup: output POLLHUP regardless of the contents of events

LGTM, but you're still ORing POLLHUP into revents, not setting it. As I mentioned in comment, it seems that the FreeBSD way to report EOF is to return POLLHUP only.

This revision is now accepted and ready to land.Jun 16 2025, 5:01 AM

LGTM, but you're still ORing POLLHUP into revents, not setting it. As I mentioned in comment, it seems that the FreeBSD way to report EOF is to return POLLHUP only.

How about if I change it to return POLLIN if there are still any events to read, and only return POLLHUP once there are no more events _and_ the mountpoint is dead?