Skip to content

C4-3: Implement Setattr and POSIX attribute persistence #165

Closed

Description

@scttfrdmn

Summary

Implement Setattr (chmod, chown, utimens, truncate) and the attribute-persistence layer it
requires. Getattr currently returns synthetic config defaults, so file modes and ownership
cannot be stored or retrieved at all.

Background

internal/fuse/filesystem.go Getattr fabricates everything:

out.Mode = f.fs.config.DefaultMode
out.Uid  = f.fs.config.DefaultUID
out.Gid  = f.fs.config.DefaultGID
// LastModified used for atime, mtime, and ctime alike

Every file reports the same mode and owner, and there is nowhere for a chmod to land. This is
the foundational issue of the milestone: xattr support (#TBD) builds on the same storage layer.

Storage strategy — metadata by default, annotations as a detected accelerator.

Default: POSIX attributes in S3 user metadata (x-amz-meta-objectfs-mode,
-objectfs-uid, -objectfs-gid, -objectfs-mtime). This works on MinIO, Ceph, and Wasabi,
all reachable through the existing Endpoint/ForcePathStyle config. Cost: metadata is
immutable, so a chmod requires CopyObject onto itself to rewrite it — expensive for large
objects and it rewrites storage-class and lifecycle state.

Accelerator: where S3 object annotations are available, chmod becomes a PutObjectAnnotation
with no object rewrite — mutable in place, 1 byte to 1 MiB, up to 1000 per object, conditional
via x-amz-object-if-match. Annotations are unavailable on directory buckets, on SSE-C
objects, and on non-AWS endpoints, hence the fallback.

Implementation

  1. Capability layer. Detect annotation support once per bucket at mount (not per
    operation), cache the result, and fall back to metadata on any error. Both backends must be
    behind one interface so Setattr and the later xattr work share it.
  2. Getattr. Read persisted attributes when present; fall back to the current config
    defaults when absent, so pre-existing objects and objects written by other tools still stat
    correctly.
  3. Setattr. Handle mode, uid/gid, and times. Honor the valid mask — only apply fields
    the kernel actually set; applying all four on every call would clobber unrelated state.
  4. Truncate. A distinct operation from the attribute work, despite arriving through the
    same call: shrinking is a range read plus rewrite; growing zero-fills to the new size;
    truncate to 0 is a plain empty PutObject. Coordinate with the write buffer so a pending
    flush cannot resurrect the old length.
  5. Directories. Marker objects need attributes too, or chmod on a directory silently
    does nothing.

Acceptance Criteria

  • chmod 600 f then stat reports 0600; the mode survives an unmount/remount cycle
  • chown persists uid/gid where the caller has permission
  • touch -t sets mtime and it persists
  • truncate -s 100 f on a 10-byte file zero-fills to 100 bytes
  • truncate -s 0 f empties the file
  • Shrinking truncate preserves the retained prefix byte-for-byte
  • Objects with no stored attributes stat with config defaults, not an error
  • chmod on a directory persists
  • Partial Setattr (mode only) does not clobber uid/gid/times
  • Annotation support is probed once per mount, not per operation
  • Verified on both paths: real AWS (annotations) and a non-AWS S3-compatible endpoint (metadata)
  • go test -race ./internal/fuse/... ./internal/storage/s3/... passes
  • AWS_PROFILE=aws AWS_REGION=us-west-2 go test -race -tags=integration ./internal/fuse/... passes

Dependencies

Blocks the xattr issue, which reuses the same capability layer. Independent of #163 and #164.

Activity

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

    @scttfrdmn
    OwnerAuthor

    Correction: annotations require an SDK bump this repo has not taken

    The annotations-as-accelerator design depends on API operations that do not exist in the pinned SDK. This is a hard prerequisite, not a detail.

    Version gate. go.mod:10 pins github.com/aws/aws-sdk-go-v2/service/s3 v1.88.4. Listing that module directory for annotation operations returns nothing. The operations first appear in v1.104.0:

    api_op_PutObjectAnnotation.go
    api_op_GetObjectAnnotation.go
    api_op_ListObjectAnnotations.go
    api_op_DeleteObjectAnnotation.go
    api_op_UpdateBucketMetadataAnnotationTableConfiguration.go
    

    So the annotations path cannot be written at all until service/s3 moves from v1.88.4 to >= v1.104.0, which pulls the core aws-sdk-go-v2 and smithy-go forward with it.

    MVS compatibility risk. CargoShip v0.13.0 pins service/s3 v1.82.0 and aws-sdk-go-v2 v1.41.0 ([email protected]/go.mod). Minimal version selection will resolve to our higher version, so it should build — but CargoShip is compiled against the older s3.Client surface, and this needs an actual go build ./... plus the CargoShip-path tests to confirm, not an assumption. Verify before committing to the annotations design.

    Semantic defect in the conditional-write plan. The issue proposes x-amz-object-if-match for safe concurrent attribute updates. Per the SDK:

    // If specified, the operation only succeeds if the object's ETag matches the
    // provided value.
    ObjectIfMatch *string

    It matches the parent object's ETag, not the annotation's. Two concurrent chmods against an unmodified object therefore both present the same valid ETag and both succeed — last writer wins, silently. Annotations give no compare-and-swap on the annotation value itself. If atomic attribute updates are a requirement, annotations alone cannot provide them; that needs a separate mechanism and should be designed explicitly rather than assumed.

    Payload constraint. Annotation values must be valid UTF-8; non-UTF-8 bytes are rejected with HTTP 415. This matters for #167 (xattrs) in particular, where setfattr values are arbitrary binary. Base64-encode xattr values on the annotations path, or the metadata fallback will be the only correct path for binary xattrs.

    Suggested adjustment

    1. File a prerequisite issue for the SDK bump (service/s3 -> >= v1.104.0, core -> v1.42.x, smithy-go -> v1.27.x) with a CargoShip build/test check as its acceptance criterion, and make this issue depend on it.
    2. Build the metadata fallback first and ship it standalone. It needs no SDK bump, works on MinIO/Ceph/Wasabi, and is the default path per the design decision already taken. Annotations then become a genuinely optional optimization layered on later.
    3. Drop the atomicity claim from the acceptance criteria, or replace it with an explicit last-writer-wins statement.
  3. scttfrdmn commented on Aug 2, 2026

    @scttfrdmn
    OwnerAuthor

    Status: substantially implemented in v0.10.1 — remaining scope is annotations and directory chmod

    This issue was filed against v0.10.0, where Getattr fabricated everything. That is no longer the state. Recording what landed so the milestone is not carrying work that is already done.

    Implemented (internal/fuse/attributes.go, internal/vfs/attr.go):

    • FileNode.Getattr (attributes.go:228) reads persisted attributes, falling back to config defaults when absent. The FileNode no longer caches an ObjectInfo at all — v0.10.0 captured one at Lookup and answered from it, so a file reported the size and mtime it had when its inode was created, for as long as the inode lived.
    • FileNode.Setattr (:264) handles size (via buffer.Truncate), mode, uid, and gid, honoring the valid mask through in.GetSize()/GetMode()/GetUID()/GetGID() rather than applying all fields unconditionally.
    • Metadata persistence (vfs/attr.go:178-185): objectfs-uid, objectfs-gid, objectfs-mode, objectfs-mtime. Exactly the default strategy this issue specifies. Absent-vs-zero is distinguished (attr.go:212), so an object with no objectfs-uid reports the mounting user rather than root.
    • DirectoryNode.Getattr (:395) — this was the defect that made v0.10.0 unmountable for non-root users. NullPermissions disabled go-fuse's mode backstop and, with no Getattr on the directory node, the bridge fell through to mode 0000: no execute bit, so no directory of the mount could be traversed.
    • Truncate including the O_TRUNC path. The kernel does not negotiate CAP_ATOMIC_O_TRUNC, so it issues a separate SETATTR with size 0 before Open — handled in Setattr, not Open.
    • setuid/setgid/sticky refused with ENOTSUP rather than stored, since vfs.Attr.Mode holds permission bits only and a setuid bit that appeared to persist would promise an escalation this filesystem cannot perform.

    Still open, and the honest remaining scope of this issue:

    1. DirectoryNode.Setattr returns ENOTSUP for chmod/chown (:418-436), and cites this issue in its warning. A directory is a key prefix with no object to hold metadata. Doing this properly means either a marker object that carries the attributes (and then deciding what happens to implicit prefixes that have no marker) or a sidecar. utimes on a directory is already accepted and stores nothing, deliberately — failing it would make every tar -x and cp -a report errors for an attribute with nowhere to go.
    2. S3 object annotations as a detected accelerator. Not started. The metadata path works but every chmod is a CopyObject onto itself, which rewrites the object and is expensive on large files. Worth noting the self-copy has a wrinkle the audit hit: a CopyObject to the same key with no changes returns 400 InvalidRequest, so the metadata rewrite must actually change something or be routed differently.
    3. The capability-detection layer (#167 depends on it). One interface, detected once per bucket at mount, cached, falling back to metadata on any error.

    Also worth carrying forward: chmod/chown/touch flush synchronously, because each takes a path rather than a descriptor — there is no handle whose release would later make the change durable, so a change not written immediately would never be written at all. Whatever the annotation path looks like, it has to preserve that.

    Suggest retitling to Directory attribute persistence and the annotation accelerator and keeping it on v0.14.0, or splitting item 1 out since it is independent of items 2-3 and is what a user actually notices (chmod on a directory failing).

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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions