Skip to content

fix(presenter-fuse): list, stat and read through the Linux mount - #117

Open
Mearman wants to merge 10 commits into
mainfrom
fix/fuse-mount-listing
Open

Mearman wants to merge 10 commits into
mainfrom
fix/fuse-mount-listing

Conversation

@Mearman

@Mearman Mearman commented Dec 1, 2026

Copy link
Copy Markdown
Member

The Linux FUSE mount panicked on its first listing (#99): fuser calls every Filesystem method on its own session thread, which belongs to no Tokio runtime, and read_dir_sync, read_sync and metadata_size_sync called Handle::current() there. This is the read-only part of #100, rebuilt on main: what a mount needs to list, stat and read correctly, and nothing that writes.

  • The daemon passes its runtime handle to FusePresenter and FuseOps, and the helpers block on it. crates/presenter-fuse/clippy.toml disallows Handle::current and Handle::try_current in the crate.
  • DirEntry carries the size the backend listed. lookup and getattr take it from the parent's listing and answer EIO when it is unknown or the listing fails, so a file is never presented as empty and cp never copies an empty file and succeeds.
  • Kernel reads call Backend::read_range with the listed FileEntry, instead of downloading the whole file per read. Local, S3, Drive and P2P already implement it on main.
  • Each backend call from the session thread is bounded by BACKEND_CALL_TIMEOUT, so a stalled request fails with EIO instead of leaving the mount unanswered.
  • One same-named-entry rule: a listing keeps one entry per name (the smallest ItemId, independent of listing order), and readdir, lookup, getattr, read and opening a directory all use it. A directory is listed by the native id of the entry its parent's listing kept, never by resolving its path again. Each listing replaces its directory's cached entries, so a removed file is forgotten.
  • P2P FolderIndex::list_children compares the parent prefix byte for byte instead of with LIKE, which matched _ and % as wildcards and ignored ASCII case.
  • Drive's request limiter regains tokens as time passes; it started full and was only refilled by a test, so after 10,000 requests every call waited forever.
  • S3 has no folder listing and inherits list_children's empty default, so an S3 mount showed every folder as empty. Backend::lists_children() now says whether a listing is real; S3 returns false, and the FUSE listing fails with an error naming the backend (EIO in the shell, a warning in the daemon log). Only FUSE reads the flag: S3 list_children is unchanged, so every other presenter behaves as before. S3 folder listing itself is S3: list folders through list_children #116.
  • CI: Tier 3 of the Linux smoke test ran ls -la "$SMOKE/mount/" || true. It now lists $SMOKE/mount/smoke/, checks hello.txt is listed and reads it back, each under timeout 30.

No delete, move, copy or upload behaviour changes in any backend or presenter. I checked the diff against main: no write path is touched, and the only backend changes are the P2P listing query, the Drive limiter and S3's new lists_children flag, which nothing outside FUSE reads. The transfer module, recursive deletes and S3 folder delete and move from #100 are not here.

Evidence:

  • Real mount, as an unprivileged user in a privileged rust:1.96.0 container with fuse3 and a local backend holding hello.txt, sub/inner.txt and a 300,000-byte big.bin. Main's binary: ls of the backend directory fails with Input/output error, every later ls, stat, cat and cp hangs until killed after 20 s, and the log shows thread 'fuser-0' panicked at crates/presenter-fuse/src/ops.rs:215:18. This branch: both directories list, stat reports 11, 300000 and 11 bytes, both cats return their content, cp of big.bin matches the original under cmp, and the log has no panic.
  • Guard tests run against main's code with only the test added, each failing there: read_dir_sync_serves_a_thread_outside_any_runtime (panics at ops.rs:215:18), list_children_matches_the_parent_exactly (P2P), rate_limiter_refills_as_time_passes (Drive, never gets a token). The other new tests (sync_helpers_serve_a_thread_outside_any_runtime, read_sync_fetches_only_the_requested_range, file_of_unknown_size_is_never_presented_as_empty, a_stalled_backend_call_fails_within_the_bound, same_named_files_resolve_to_one_entry_everywhere, a_relisted_directory_forgets_removed_files, a_directory_lists_the_contents_of_the_entry_its_parent_chose, a_backend_without_a_listing_fails_instead_of_listing_empty, merge_listing_carries_each_files_size, and S3 declares_that_it_cannot_list_children) use APIs main does not have; the mount run above is their failing-on-main evidence.
  • cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, cargo clippy -p cascade-engine --no-default-features --features portable -- -D warnings, cargo test --workspace, cargo doc --workspace --no-deps --document-private-items with warnings denied, and gitlint pass.

Known limit, as in #100: the kernel's file size comes from the last LOOKUP or GETATTR reply (1 s attribute TTL) while read_range reads current content, so a file that changes in between can read short or truncated until the attributes refresh.

Fixes #99

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.
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.
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.
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.
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.
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.
S3Backend has no list_children and inherits the empty default, so a
FUSE mount of an S3 backend showed every folder as empty and looked
healthy. Backend::lists_children now says whether a listing is real;
S3 says it is not, and the FUSE listing fails with an error naming the
backend, so the mount answers EIO and logs why.

Only the FUSE mount reads the new flag. S3 list_children is unchanged,
so no other presenter and no delete, move, copy or upload path changes.
Copilot AI balanced review requested due to automatic review settings December 1, 2026 14: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.

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