Skip to content

fix(presenter-fuse): serve FUSE callbacks from fuser's thread - #100

Draft
Mearman wants to merge 20 commits into
mainfrom
fix/fuse-runtime-handle
Draft

Mearman wants to merge 20 commits into
mainfrom
fix/fuse-runtime-handle

Conversation

@Mearman

@Mearman Mearman commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

fuser calls every Filesystem method on its own session thread, which belongs to no Tokio runtime. read_dir_sync, read_sync and metadata_size_sync called Handle::current() there, so the first listing panicked the session thread and ls on the mount got an I/O error or hung.

The daemon now passes its runtime handle to FusePresenter, which hands it to FuseOps, and the helpers block on that handle. crates/presenter-fuse/clippy.toml disallows Handle::current and Handle::try_current in the crate, so the class fails clippy rather than a mount. Every FUSE callback that touches a backend goes through those helpers; the NFS handlers run inside block_in_place on runtime workers and the ProjFS provider already takes its handle explicitly, so neither has this problem.

With listing fixed, reads through the mount still returned nothing: lookup replied with size zero for every file, and the kernel bounds reads by that size and refreshes expired entries with LOOKUP alone. lookup and getattr now share one helper that takes the size from the backend's metadata. That is the second commit.

Evidence, from an unprivileged user in a privileged container with fuse3 and a local backend:

  • Released 0.1.144 (aarch64): ls: reading directory ...: Input/output error, find killed after 20 s, and the log shows thread 'fuser-0' panicked at crates/presenter-fuse/src/ops.rs:215:18: there is no reactor running.
  • This branch: ls and find list smoke/hello.txt and smoke/sub/inner.txt, stat reports size 11, cat returns pre-seeded, no panic in the log.
  • New unit test sync_helpers_serve_a_thread_outside_any_runtime calls the helpers from a plain thread while a runtime exists elsewhere. On main it fails with the same panic at ops.rs:215:18. The clippy config, applied to main's code, reports the three Handle::current calls.
  • cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings and cargo test --workspace pass.

CI: Tier 3 of the Linux smoke test ran ls -la "$SMOKE/mount/" || true, which is why it passed over this. It now lists $SMOKE/mount/smoke/, checks hello.txt is listed and reads it back, each under timeout 30. I ran the Prepare and Tier 3 steps from this ci.yml against both binaries: 0.1.144 fails at the ls with the I/O error, this branch passes. The smoke job only runs after a release, so this PR's own CI does not exercise it. #98 also edits the smoke job (the FUSE package install); this change is limited to the listing lines in Tier 3, a different hunk.

Fixes #99

Update 2026-12-01: sizes, range reads, call bound, Drive paging

Review found more on the same paths; each is a new commit.

  • lookup and getattr turned a failed metadata call, or a file with no size, into size 0, so the kernel read the file as empty and cp copied an empty file and succeeded. DirEntry now carries the listed size (None for directories and for files with no byte size; on Drive that is shortcuts and folders, while Google Docs editor files do report a size, per the Drive files resource). Both handlers take the size from the parent's listing and answer EIO when it is unknown or the listing fails, so lookup makes no metadata call.
  • Every kernel read downloaded the whole file. Reads now call read_range with the FileEntry the listing returned. Local, S3, Drive and P2P all implement it with an empty result at or past the end; S3 and Drive treat 416 that way and slice a full 200 response.
  • Each backend call on fuser's session thread is bounded by BACKEND_CALL_TIMEOUT (30 s), so one stalled request fails with EIO instead of leaving the mount unanswered.
  • GDriveBackend::metadata resolved each path component from the first listing page only. It now pages, as the other views do (gdrive: metadata finds a path component only on the first listing page #101).

New tests: read_sync_fetches_only_the_requested_range fails on the previous head (the read path called download). file_of_unknown_size_is_never_presented_as_empty, a_stalled_backend_call_fails_within_the_bound and merge_listing_carries_each_files_size cover APIs that did not exist before. metadata_resolves_component_on_a_later_listing_page failed before the Drive fix with "Path not found". In the container mount test cp of a mounted file now produces an identical copy, and the edited smoke steps pass on ubuntu:26.04.

Known limit: the kernel's file size comes from the last LOOKUP or GETATTR reply (1 s attribute TTL), while read_range reads the file's current content. A file that changes between the two can read short (it shrank) or truncated at the old size (it grew) until the attributes refresh. Closing it would need the content pinned per open file handle, which this change does not do.

Update 2026-12-01: second review

  • Same-named entries: a backend may list two files under one name (Drive allows it). The read cache kept the last while lookup and getattr took the first, so a read could serve one file's bytes at the other's size. A FUSE listing now keeps one entry per name, the one with the smallest ItemId, independent of listing order, and every handler uses it. Each listing replaces its directory's cached entries, so a removed file is forgotten, and readdir reports a failed listing as EIO.
  • P2P index: list_children matched with LIKE, so listing a_b also listed axb and A_B. It now compares the prefix byte for byte. This query also exists on main, which has moved on in this file since the branch point, so a merge may need this hunk carried across.
  • S3: S3Backend had no list_children and inherited an empty default, so an S3 mount listed empty and succeeded. It now lists the root or a folder prefix one level deep with paging, an object key is an error, and metadata resolves a key prefix with no object of its own as a folder. The trait default is gone: every backend implements list_children, and the null backend and test doubles say explicitly that they list nothing.
  • Drive: the request limiter started full and was only refilled by a test, so after 10,000 requests every call waited forever. It now regains tokens from elapsed time. The path walk stops at the first listing page that holds each component.
  • Partly written P2P blocks: already fixed on main by e668a88 (write to a temporary file, then rename), so this branch does not touch it.
  • Follow-ups filed: p2p: an unresponsive peer delays block failover by the full request timeout #105 (an unresponsive peer delays block failover by the full 30 s request timeout, the same as the FUSE call bound) and local backend hashes every file on each directory listing #106 (the local backend hashes every file on each listing).

New tests, each failing before its fix: list_children_matches_the_parent_exactly (p2p), three of the four in folder_listing.rs (S3: paging, folder by path, object key; the fourth, a missing path stays not found, guards the new folder probe and passed before too), rate_limiter_refills_as_time_passes and metadata_stops_at_the_page_holding_the_component (Drive), same_named_files_resolve_to_one_entry_everywhere and a_relisted_directory_forgets_removed_files (FUSE).

Update 2026-12-01: third review

  • Same-named directories: FUSE now lists a directory by the native id of the entry its parent's listing kept, never by resolving the path again, so a folder cannot list empty or show a same-named sibling's contents. The Drive path walk looks each component up with a name-filtered query through every page and picks by the same rule (smallest id, vfs::transfer::keep_one_per_name); a component followed by more path must be a folder. This replaces the earlier "stop at the first page" walk, which cannot apply a tie-break. The walk records shared-drive ids again.
  • Delete contract: Backend::delete removes a file or an empty directory and refuses a non-empty one with Conflict, as the local backend already did. Drive (whose trash is recursive) now refuses a non-empty folder, and P2P (which orphaned children) does so in fix(backend-p2p): move a directory with its contents, delete only empty #107; S3 refuses while any key sits under the prefix and otherwise deletes the marker. vfs::transfer::delete_tree empties a directory first and is used where the protocol defines delete as recursive: WebDAV DELETE, the FFI delete (Android deleteDocument, iOS recursive deleteItem) and the source side of a cross-backend move. cascade rm, NFS RMDIR and REMOVE, the web API (now 409 for a non-empty directory) and File Provider delete_item stay non-recursive.
  • Copy and move: vfs::transfer::copy_tree and move_across copy files and whole trees, never write a directory as a file, refuse a directory over a file or the reverse, read every copied file back to check its size, and delete a move's source only after the whole copy succeeds. Used by VfsTree::rename (and so NFS rename), cascade mv and cp, the FFI rename and WebDAV MOVE across backends; WebDAV COPY now copies through the backends instead of adding an in-memory item. S3 move_entry moves a folder key by key (copy and verify every key, then delete the sources); P2P move_entry moving a directory with all its rows is fix(backend-p2p): move a directory with its contents, delete only empty #107.
  • WebDAV lists a backend root by Backend::root_native_id (S3's is /). The other presenters already did: NFS (through VfsTree::read_dir) and the FFI go through resolve_listing_native_id, File Provider lists by ids taken from entries, and FUSE lists a root by root_native_id.
  • S3 listings decode XML entities (an unknown entity is an error) and leave out keys with a . or .. segment.

New tests, each run against the previous head and failing there: parse_list_response_decodes_entities_and_skips_dot_segments, parse_list_response_rejects_an_unknown_entity, deleting_a_non_empty_folder_is_refused_and_deletes_nothing and moving_a_folder_moves_every_key_under_it (S3), metadata_descends_into_the_chosen_folder_among_same_named_entries (Drive), expand_root_lists_the_backends_own_root_id (WebDAV), a_directory_lists_the_contents_of_the_entry_its_parent_chose (FUSE). The vfs::transfer tests (folder move across backends, a failed copy leaves the source, no folder over file or the reverse, overwrite, delete_tree, VfsTree::rename of a folder) cover an API that did not exist before. deleting_an_empty_folder_removes_its_marker passed before too.

The P2P directory move and non-recursive delete started on this branch but conflicted with main, which has since rewritten both functions around write_atomically, so they moved to #107 against main and this branch keeps only P2P metadata reporting NotFound (which cross-backend copies rely on). A trial merge of this branch with main is clean and passes fmt, clippy and the whole test suite, and #107 merges with this branch without conflict.

Update 2026-12-01: parked in favour of #117

This branch grew well past the mount crash, and the cross-backend copy, move and delete it adds can lose files. The read-only mount fix is now #117, rebuilt on main with no write-path changes, and this pull request stays a draft. What remains here is tracked in #110 (recursive delete of a mount root), #111 (folder move merging into existing folders, case collisions), #112 (move deleting files added during the copy), #114 (row-less and peer-created subfolders left behind), #115 (non-recursive delete breaking web API and File Provider folder deletes) and #116 (S3 folder listing).

Copilot AI balanced review requested due to automatic review settings December 1, 2026 09:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

fuser calls every Filesystem method on its own session thread,
which belongs to no Tokio runtime.
The listing, read and size helpers looked the runtime up with
Handle::current(),
so the first directory listing panicked that thread
and the mount answered ls with an I/O error or hung.

The daemon now passes its runtime handle to FusePresenter,
which hands it to FuseOps, and the helpers block on that handle.
A crate-level clippy.toml disallows Handle::current and try_current
in presenter-fuse so the class cannot return.
A unit test calls each helper from a plain thread
while a runtime exists elsewhere, as fuser does.

Fixes #99
lookup answered every file with size zero,
on the assumption that the kernel would ask getattr for the real one.
The kernel bounds page-cache reads by the size in the last LOOKUP
or GETATTR reply and refreshes an expired entry with LOOKUP alone,
so every read through the mount returned no data.

lookup and getattr now build file attributes through one helper
that takes the size from the owning backend's metadata.
Tier 3 ran ls on the mount with || true,
so a mount that answered the listing with an I/O error still passed.
It now lists the backend's directory, checks the seeded file is there
and reads it back, each under a timeout so a hung mount fails the step
instead of the job timing out.
@Mearman
Mearman force-pushed the fix/fuse-runtime-handle branch from 115587e to 3e70015 Compare December 1, 2026 09:32
Copilot AI balanced review requested due to automatic review settings December 1, 2026 09:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

metadata resolved each path component from the first page of its
parent's listing only, so an entry Drive returned on a later page
was reported as not found while list_children listed it.
The walk now uses list_files_all_pages, as the other views do.

Fixes #101
merge_listing dropped the size the backend listed, so a presenter
that needed it had to make a metadata call per entry, which for
Google Drive walks the whole path.
DirEntry now has size: Option<u64>, None for directories and for
files with no byte size, such as native Google documents.
lookup and getattr turned a failed metadata call, or a file with no
size, into size zero, so the kernel read it as empty and cp copied an
empty file and reported success. Both now take the size from the
parent's listing and answer EIO when it is unknown or the listing
fails; lookup no longer makes a metadata call.

A kernel read downloaded the whole file each time. Reads now go to
the backend's read_range with the FileEntry the listing returned.

Every backend call on fuser's session thread is bounded by
BACKEND_CALL_TIMEOUT, so one stalled request fails with EIO instead
of leaving the whole mount unanswered.
Copilot AI balanced review requested due to automatic review settings December 1, 2026 10:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

list_children matched child paths with LIKE, which treats _ and % as
wildcards and ignores ASCII case, so listing a_b also returned the
children of axb and A_B. The prefix is now compared byte for byte.
S3Backend had no list_children, so it inherited the trait default
that returns nothing: an S3 mount listed empty and looked healthy.

list_children now lists the root or a folder prefix one level deep
with a / delimiter, following continuation tokens through every page,
and an object key is an error rather than an empty folder. metadata
resolves a path with no object of its own as a folder when keys sit
under it, so presenters can open subfolders by path.
The default returned an empty listing, which is indistinguishable from
an empty directory, so a backend that forgot it mounted as empty. The
default is gone; the null backend and the test doubles now say
explicitly that they list nothing.
The limiter started with 10,000 tokens and only a test ever refilled
it, so after 10,000 requests every Drive call waited forever. Tokens
are now regained from the time elapsed since the last refill, at the
limiter's configured rate per 100 seconds.
Resolving a path fetched every page of each parent's listing before
looking for the component. The walk now stops at the first page that
holds it.
The read cache kept the last of several same-named entries while
lookup and getattr took the first, so a read could serve one file's
bytes at another's size. A listing now keeps one entry per name, the
one with the smallest ItemId, so every handler resolves the name the
same way. Each listing replaces its directory's cached entries, so a
removed file can no longer be read, and readdir reports a failed
listing as EIO rather than ENOTDIR.

The comments on size: None named Google Docs files; Drive gives those
a size and leaves it unset for shortcuts and folders.
Copilot AI balanced review requested due to automatic review settings December 1, 2026 11:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Cross-backend moves downloaded a directory as if it were a file, wrote
it to the destination as an empty file, possibly over an existing one,
and then deleted the source. The new vfs::transfer module copies a
file or a whole tree, never writes a directory as a file, refuses to
put a directory over a file or the reverse, reads every copied file
back to check its size, and deletes a move's source only after the
whole copy succeeded. delete_tree removes a directory with its
contents, and keep_one_per_name is the one rule for choosing among
same-named entries. VfsTree::rename uses move_across.

Backend::delete now states its contract: a file or an empty directory,
never recursive, with a non-empty directory refused as Conflict.
move_entry rewrote only the directory's own row, orphaning every row
under it, and delete tombstoned a directory while its children stayed
live. A directory now moves with all its descendants, a destination
of the other kind is refused, a non-empty directory is refused on
delete, and metadata reports a missing path as NotFound.
The path walk took the first entry with a matching name, which could
be a file or a different folder than the one presenters list, so a
folder could show another folder's contents. Each component is now
looked up with a name-filtered query, paged to the end, and the entry
with the smallest id is chosen, as keep_one_per_name does; a component
followed by more path must be a folder. The walk records shared-drive
ids again, reports a missing path as NotFound, and delete refuses a
folder that still lists anything, since trashing it is recursive.
ListObjectsV2 values were used without decoding XML entities, so a key
with & or < was listed under its escaped form; they are now decoded
and an unknown entity is an error. Keys with a . or .. segment are
left out of listings, since no path can name them.

delete of a folder sent one DELETE for its marker and reported success
with every key under it left behind. It is now refused while anything
sits under the prefix and removes only the marker once it is empty.
move_entry of a folder copied one key; it now copies every key under
the prefix, checks each copy's size, and only then deletes the source
keys, and it refuses a destination that already exists as a folder or
as the other kind.
cascade mv and cp, the FFI rename and the WebDAV MOVE across backends
now copy whole trees and delete the source only after the copy
verifies. WebDAV COPY copies through the backends instead of adding an
in-memory item. WebDAV DELETE and the FFI delete, which their
protocols define as recursive, use delete_tree; cascade rm, NFS RMDIR
and REMOVE, the web API and the File Provider keep the non-recursive
delete, and the web API answers a non-empty directory with 409.

WebDAV lists a backend's root by the backend's own root id, so an S3
root is no longer listed as empty.
Opening a directory resolved its path again through the backend, which
could pick a different same-named entry than the parent's listing kept,
or a file, so a folder listed empty or showed another folder. The FUSE
listing now records every entry it keeps and lists a directory by that
entry's native id; only a backend root is listed by its root id.
Copilot AI balanced review requested due to automatic review settings December 1, 2026 12:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

The P2P delete and move_entry changes conflict with main, which has
since rewritten both to write through write_atomically. They return
to their previous form here and are made against main separately, so
this branch keeps only P2P metadata reporting a missing path as
NotFound, which cross-backend copies rely on.
Copilot AI balanced review requested due to automatic review settings December 1, 2026 12:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

copy_tree built child paths with Path::join, which inserts a backslash
on Windows, so a copied tree landed under keys such as copied\a.jpg on
backends that take the path as written (S3 keys, P2P index paths).
Child paths are now joined with / explicitly.
Copilot AI balanced review requested due to automatic review settings December 1, 2026 13:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FUSE: first directory listing panics with no Tokio reactor

2 participants