Files
seaweedfs/weed/mount/weedfs_xattr_test.go
T
c2b2ed769b fix(mount): preserve appended chunks during stale attribute updates (#12593)
* fix(mount): preserve acknowledged chunks during attribute updates

* mount: keep the WFS field block aligned

Adding the publication-lock fields inside the aligned block made gofmt
re-indent 25 unrelated lines. Put them in their own group after
dirIdleEvict, matching the enterprise layout, so syncs do not conflict there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: finish attribute saves through a FUSE interrupt

saveEntryAttributes derived its RPC context from the syscall's cancel
channel, so an interrupt while the conditional UpdateEntry was at the
owner returned EIO for an update the owner then applied, and skipped the
local install and retention. Keep the metadata deadline but drop the
cancellation, like the other metadata mutations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: map attribute CAS ids in place instead of cloning the entry

saveEntryAttributes cloned the whole entry three times per attempt only
to rewrite uid/gid for the filer, and each clone is as large as the
chunk list. Switch the ids in place and restore the exact local values
after the call, keeping one clone. The test now checks the reply carries
the local uid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: compare attribute updates against the filer's own uid/gid

With -map.uid/-map.gid, a filer id that is also a mapped local id reads
back unchanged and maps forward to another filer id. The IF_ENTRY_EQUAL
expected entry then never matched, so chmod, utimes and xattr changes on
such files failed with EAGAIN after three attempts, and an update would
have rewritten the owner. Keep the filer ids read with the entry for the
ids the syscall leaves alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(mount): align attribute retention with read lock order

* mount: take the handle lock before entryLock in the attribute snapshot

attributeEntrySnapshot held entryLock while it queued for the shared
handle lock. A Read holding that lock waits on entryLock, the snapshot
waits behind a queued exclusive (an invalidation or a Write), and the
exclusive waits on the Read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(mount): complete handle lock order and preserve explicit ID intent

* mount: re-read a refused attribute update from the file's owner filer

The filer checks the IF_ENTRY_EQUAL condition on the owner of the path's
write route key. The retry read any filer, so behind one that had not
applied the owner's latest update, every attempt sent the same stale base
and the syscall failed with EAGAIN. Read from the owner once the lock ring
is known, like lookupFilerEntry, but keep the filer's raw ids.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 16:28:47 -08:00

66 lines
2.2 KiB
Go

//go:build !freebsd
package mount
import (
"testing"
"github.com/seaweedfs/go-fuse/v2/fuse"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/util"
)
// TestSetXAttrCopiesValueBuffer reproduces the bug from
// https://github.com/seaweedfs/seaweedfs/discussions/9275 where `cp -a`
// of a file with an extended attribute leaves the destination with a
// corrupted value. The root cause is that go-fuse hands SetXAttr a
// `data` slice that aliases the per-request input buffer; when the
// buffer is returned to the pool and reused for another FUSE request,
// any reference still held by entry.Extended sees garbage.
//
// The bug only manifested when the file was open during setxattr (the
// open-fh path defers persistence to flush). We simulate that by
// mutating the caller-supplied buffer after SetXAttr returns.
func TestSetXAttrCopiesValueBuffer(t *testing.T) {
wfs := newCopyRangeTestWFS()
path := util.FullPath("/aaa.txt")
inode := wfs.inodeToPath.Lookup(path, 1, false, false, 0, true)
fh, _, _, _ := wfs.fhMap.AcquireFileHandle(wfs, inode, &filer_pb.Entry{
Name: "aaa.txt",
Attributes: &filer_pb.FuseAttributes{
FileMode: 0100644,
Inode: inode,
},
}, 0, 0)
fh.RememberPath(path)
// Model a newly copied file whose data has not reached the filer yet;
// this is the deferred persistence path whose buffer ownership we test.
fh.dirtyMetadata = true
// Caller buffer aliases a pool that the kernel will overwrite on
// the very next request. SetXAttr must defensively copy.
buf := []byte("test,in")
status := wfs.SetXAttr(make(chan struct{}), &fuse.SetXAttrIn{
InHeader: fuse.InHeader{NodeId: inode},
}, "user.xtags", buf)
if status != fuse.OK {
t.Fatalf("SetXAttr status = %v, want OK", status)
}
// Simulate the request buffer being recycled and reused for an
// unrelated payload.
for i := range buf {
buf[i] = 0xff
}
dest := make([]byte, 64)
n, status := wfs.GetXAttr(make(chan struct{}), &fuse.InHeader{NodeId: inode}, "user.xtags", dest)
if status != fuse.OK {
t.Fatalf("GetXAttr status = %v, want OK", status)
}
if got := string(dest[:n]); got != "test,in" {
t.Fatalf("GetXAttr value = %q, want %q (buffer aliasing leaked into stored xattr)", got, "test,in")
}
}