Skip to content

C4-1: Implement Unlink and Rmdir in the FUSE layer #163

Closed

Description

@scttfrdmn

Summary

Implement Unlink and Rmdir so rm and rmdir work on a mount. Both are currently absent
from internal/fuse/filesystem.go, so the operations fail at the kernel boundary.

Background

DirectoryNode implements only Lookup, Readdir, Mkdir, and Create. Without Unlink
the mount is effectively append-only: files can be created but never removed.

The backend primitives already exist — Backend.DeleteObject and Backend.ListObjects — and
Mkdir/Create establish the object-key conventions to follow (directories are zero-byte
objects at the directory path).

Note the tier deletion embargo: TierValidator.ValidateDelete rejects deletes before the
tier's minimum storage period on GLACIER (90d) and DEEP_ARCHIVE (180d). That is a real AWS
billing constraint, unlike the write-size gate, so Unlink must surface it as a sensible
errno rather than a generic failure.

Implementation

Unlink — delete the object at the child path, invalidate the cache entry, and remove any
buffered writes for that path so a pending flush cannot resurrect the file. Map a missing
object to ENOENT and an embargo rejection to EPERM.

Rmdir — POSIX requires refusing a non-empty directory with ENOTEMPTY. Check emptiness
with a prefix ListObjects limited to a small result count; do not list the whole subtree.
Then delete the directory marker object.

Care needed on two points:

  • Implicit directories. A prefix can exist with no marker object (created by another tool
    writing a/b/c directly). Rmdir on such a prefix should succeed if empty rather than
    returning ENOENT for the absent marker.
  • Cache and buffer coherence. Deleting an object whose data is still in the write buffer
    or read cache must invalidate both, or subsequent reads will serve a deleted file.

Acceptance Criteria

  • touch f && rm f succeeds; the object is gone from S3
  • mkdir d && rmdir d succeeds
  • rmdir on a non-empty directory returns ENOTEMPTY
  • rm on a nonexistent path returns ENOENT
  • Emptiness checking does not list the entire subtree
  • Deleting a file with pending buffered writes does not resurrect it
  • A cached file is invalidated on delete; a subsequent read returns ENOENT
  • Rmdir works on an implicit prefix with no marker object
  • A GLACIER embargo rejection surfaces as EPERM, not a generic error
  • go test -race ./internal/fuse/... passes
  • AWS_PROFILE=aws AWS_REGION=us-west-2 go test -race -tags=integration ./internal/fuse/... passes

Dependencies

None — needs no persisted attributes. First of the v0.14.0 sequence. cgofuse parity is tracked
separately.

Activity

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

    @scttfrdmn
    OwnerAuthor

    Correction: severity is understated — rm returns success today while the object survives

    This issue describes the missing operations as failing at the kernel boundary. That is wrong for Unlink and Rmdir, and the actual behavior is considerably worse.

    go-fuse defaults both to success. From go-fuse/[email protected]/fs/api.go:

    // Unlink should remove a child from this directory.  If the
    // return status is OK, the Inode is removed as child in the
    // FS tree automatically. Default is to return success.
    type NodeUnlinker interface {
    	Unlink(ctx context.Context, name string) syscall.Errno
    }
    
    // Rmdir is like Unlink but for directories.
    // Default is to return success.
    type NodeRmdirer interface {
    	Rmdir(ctx context.Context, name string) syscall.Errno
    }

    Since internal/fuse/filesystem.go implements neither, rm and rmdir return exit code 0 and the kernel drops the inode from its tree — while the S3 object is never deleted. The user sees a successful deletion. The file is gone from the mount's view until the cache entry expires or the mount is restarted, at which point it reappears.

    This is silent false-success: data the user believes deleted is still present and still billing. For anyone using the mount to clear space or to remove sensitive data before decommissioning, the failure is invisible at exactly the moment it matters. Contrast Rename, which genuinely does default to ENOTSUP (same file, line 573) and therefore fails loudly and honestly — #164 is correctly characterized.

    Adjustments

    1. Re-prioritize. priority: critical is defensible on the silent-data-retention argument; at minimum reflect that this is a wrong-result bug, not an unimplemented-feature gap.
    2. Consider whether type: bug fits better than the enhancement framing, since current behavior actively misreports.
    3. Add a regression test asserting the pre-fix behavior is impossible afterward: Unlink must return an error when the backend DeleteObject fails, and must never return 0 without a confirmed delete.
    4. Interim mitigation worth considering ahead of the full implementation: stub Unlink/Rmdir to return syscall.EROFS. A loud, honest failure is strictly safer than a false success, and it is a few lines — plausibly worth landing in v0.10.1 rather than waiting for v0.14.0.
    5. The Rmdir emptiness check specified here needs C0-12: Paginate ListObjects so directories with more than 1000 entries are not silently truncated #171 (ListObjects pagination) — an unpaginated list cannot reliably determine whether a large prefix is empty.

    The same default applies to the cgofuse build (#168), which also implements neither.

  3. scttfrdmn commented on Jul 30, 2026

    @scttfrdmn
    OwnerAuthor

    Interim mitigation landed (issue stays open)

    DirectoryNode now implements Unlink and Rmdir in internal/fuse/filesystem.go. Both log a warning and return EROFS. This is not the fix this issue asks for — it converts a silent lie into a visible error while the real implementation is scheduled.

    Why it could not wait: go-fuse's NodeUnlinker and NodeRmdirer defaults return success when unimplemented. So rm file and rmdir dir reported success, the shell exited 0, and the S3 objects were untouched — a following ls showed the files again. Any script that deleted a file and checked the exit status was silently wrong. EROFS makes rm print an error and exit non-zero, which is truthful.

    Note this is a different failure mode from Rename (defaults to ENOTSUP) and Create (defaults to EROFS) — those already fail loudly, which is why only the two delete operations needed a stub.

    internal/fuse/delete_stub_test.go covers it, with compile-time guards:

    var _ gofuse.NodeUnlinker = (*DirectoryNode)(nil)
    var _ gofuse.NodeRmdirer  = (*DirectoryNode)(nil)

    Those assertions are the load-bearing part — a method whose signature drifts from the interface stops being called by go-fuse and silently reverts to the permissive default, with no compile error at the call site. The test also asserts a non-zero errno, so when the real DeleteObject implementation lands it will need updating; that is intended, and the test says so.

    The cgofuse build (internal/fuse/cgofuse_filesystem.go) is unaffected — it does not register delete operations at all, so the kernel rejects them before ObjectFS is consulted.

  4. added
    effort: medium
    on Aug 3, 2026
  5. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    First in v0.11.0. Promoted from v0.14.0, because rm not working is a larger gap than the distributed-consensus work that used to lead the next release — go list -deps ./cmd/objectfs shows no internal/distributed package links into the binary, so none of that could affect a mount.

    Current state confirmed: DirectoryNode.Unlink and Rmdir (internal/fuse/filesystem.go:628,636) return EROFS with the rationale recorded in place, and attributes.go:63-64 asserts both interfaces specifically so go-fuse cannot default them — go-fuse defaults an unimplemented NodeUnlinker to success, which is how the cgofuse subset reported rm succeeding while the object survived. Failing loudly is the right stub; it is still a stub.

    Blocks #164 (Rename needs a working delete half) and gates #162 (correcting the POSIX claim should follow the surface becoming true, not precede it).

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: fuseeffort: mediumpriority: hightype: enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions