Skip to content

C4-4: Implement Statfs and Fsync #166

Closed

Description

@scttfrdmn

Summary

Implement Statfs and Fsync. df currently fails on a mount, and fsync/sync return an
error rather than flushing buffered writes — which matters for durability, not just tooling.

Background

Neither operation exists in internal/fuse/filesystem.go. Statfs is declared in
internal/filesystem/interface.go with only a test-mock implementation.

Fsync is the more consequential of the two. Applications that call fsync and check the
return value are entitled to assume their data is durable afterward. Today the call fails, so
either the application errors out or — worse, if it ignores the result — believes data is
durable when it is still in the write buffer.

Statfs is cosmetic by comparison, but df failing makes the mount look broken, and some
tools refuse to write to a filesystem they cannot stat.

Implementation

Fsync — flush the write buffer for the file's path and wait for the S3 PUT to complete
before returning. Reuse the existing buffer flush machinery rather than adding a parallel path.
Return the underlying error if the upload fails; do not report success on a failed flush. An
fsync on a file with nothing buffered is a no-op returning success.

Statfs — S3 has no size or inode limits to report, so the values are necessarily
synthetic. Report a large fixed capacity with proportional free space, a sane Bsize, and a
large Namelen (S3 keys allow 1024 bytes).

The one thing to get right: do not report zero free space, which causes tools to refuse
writes with ENOSPC. Pick a large capacity with most of it free and document the values as
synthetic.

Acceptance Criteria

  • df -h <mount> reports plausible non-zero total and available space
  • Statfs never reports zero available space
  • Namelen reflects the S3 key limit
  • fsync on a file with pending writes flushes to S3 before returning
  • fsync returns the underlying error when the flush fails
  • fsync on a file with no pending writes succeeds as a no-op
  • sync on the mount completes without error
  • After fsync returns success, the object is readable from S3 by an independent client
  • Synthetic Statfs values are documented
  • go test -race ./internal/fuse/... passes
  • AWS_PROFILE=aws AWS_REGION=us-west-2 go test -race -tags=integration ./internal/fuse/... passes

Dependencies

Independent of the attribute-storage work. Can land alongside #163 and #164.

Activity

  1. added
    type: enhancement
    priority: medium
    area: fuse
    on Jul 30, 2026
  2. scttfrdmn commented on Aug 2, 2026

    @scttfrdmn
    OwnerAuthor

    Status: implemented in v0.10.1 — this can likely close

    Both operations landed. Checking against the acceptance criteria:

    Fsync — FileNode.Fsync (internal/fuse/attributes.go:361) calls buffer.FlushContext(ctx, path), returns toErrno(err) on failure, invalidates the cache entry, and marks the handle clean. No-op returning success when there is no buffer. rawBridge.Fsync prefers NodeFsyncer over FileFsyncer, so the one implementation answers both fsync(2) and syncfs-style callers.

    One deliberate deviation from the issue: flags is ignored, so fdatasync and fsync are identical. That is not a shortcut — a PUT writes an object's data and its metadata in one request, so there is no cheaper data-only path to take.

    DirectoryNode.Fsync (:450) returns 0 without doing anything, and the reasoning is recorded at the method: a directory here is a key prefix, holds no state of its own, so no state of its own can be made durable. Databases and VCS tools fsync a directory to force a rename or create to disk, and both already complete synchronously on this filesystem — success is the accurate answer, not a convenient one.

    Statfs — implemented on both node types (:383, :455), both delegating to FileSystem.statfs (:485). Values (:471-477): Bsize 4096, Blocks 1<<38 (1 PiB), Bfree/Bavail equal to Blocks, Files/Ffree 1<<32, NameLen 255.

    Two notes where the implementation differs from the issue, both intentional:

    • NameLen is 255, not 1024. The issue asked for the S3 key limit. 255 is the POSIX NAME_MAX most tools expect for a single path component; the 1024-byte S3 limit is on the whole key, which is closer to PATH_MAX. Reporting 1024 would let a tool create a component the backend accepts but that no other filesystem could hold.
    • Free equals total. Reporting real usage would require a full bucket LIST on every statfs. Reporting zero free space would make install(1), dd, and most package managers refuse to write — which the issue correctly flagged as the one thing to get right.

    statfs existing at all is load-bearing beyond df: rawBridge.StatFs leaves StatfsOut entirely zeroed and returns success when the node does not implement NodeStatfser, and go-fuse's own documentation says an macOS filesystem must implement Statfs or the mount will not work. A zero block size is not a number df or the macOS VFS can do anything with.

    Not yet verified: the two criteria that need a live mount — df -h <mount> output, and after fsync returns success, the object is readable from S3 by an independent client. The unit-level behavior is covered; the end-to-end assertions want the real-S3 smoke test.

    Suggest closing once those two are checked against a live us-west-2 mount, rather than closing on code inspection — "fsync returned 0" and "the bytes are in S3" are different claims, and the gap between them is precisely the class of defect that made v0.10.0 unusable.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: fusepriority: mediumtype: enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions