mount: refuse copy, fallocate and handle attribute changes during the shutdown flush

copy_file_range, fallocate, and setattr/xattr on an open handle also
leave their result only in the handle. One that lands after the shutdown
flush has passed its handle was acknowledged and then lost at exit, as
writes were before. Like Write, they now return EIO once the flush starts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-12-04 01:31:21 -08:00
1 parent 22919a8d21
commit a5877b3d62
6 files changed
+42 -4

No files matched your search

+2 -1
View File
@@ -237,7 +237,8 @@ type WFS struct {
// asyncFlushWg tracks pending background flush work items for writebackCache mode.
// Must be waited on before unmount cleanup to prevent data loss.
asyncFlushWg sync.WaitGroup
// shuttingDown refuses writes once the shutdown flush has begun.
// shuttingDown refuses changes an open handle would hold in memory once
// the shutdown flush has begun.
shuttingDown atomic.Bool
// metaFollowWg tracks the metadata subscription goroutine and
+3
View File
@@ -121,6 +121,9 @@ func (wfs *WFS) SetAttr(cancel <-chan struct{}, input *fuse.SetAttrIn, out *fuse
}
active := wfs.fhLockTable.AcquireLock("SetAttr", fh.fh, util.ExclusiveLock)
defer wfs.fhLockTable.ReleaseLock(fh.fh, active)
if wfs.shuttingDown.Load() {
return fuse.EIO
}
fh.entryLock.Lock()
defer fh.entryLock.Unlock()
// entry is the handle's shared LockedEntry.Entry. Async upload workers
+3
View File
@@ -95,6 +95,9 @@ func (wfs *WFS) CopyFileRange(cancel <-chan struct{}, in *fuse.CopyFileRangeIn)
// lock source and target file handles
unlockHandles := lockCopyFileRangeHandles(fhIn, fhOut)
defer unlockHandles()
if wfs.shuttingDown.Load() {
return 0, fuse.EIO
}
if fhOut.entry == nil {
return 0, fuse.ENOENT
+3
View File
@@ -32,6 +32,9 @@ func (wfs *WFS) Fallocate(cancel <-chan struct{}, in *fuse.FallocateIn) (code fu
fhActiveLock := fh.wfs.fhLockTable.AcquireLock("Fallocate", fh.fh, util.ExclusiveLock)
defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock)
if wfs.shuttingDown.Load() {
return fuse.EIO
}
entry := fh.GetEntry().GetEntry()
if entry == nil {
@@ -7,7 +7,7 @@ import (
)
// Shutdown uploads the bytes an open file still buffers and commits them, then
// refuses further writes instead of acknowledging data it cannot keep.
// refuses further changes instead of acknowledging data it cannot keep.
func TestFlushOpenFilesUploadsBufferedWrites(t *testing.T) {
cluster := newProofCluster()
_, addr := newProofFiler(t, cluster, newVolumeStub(t))
@@ -23,7 +23,29 @@ func TestFlushOpenFilesUploadsBufferedWrites(t *testing.T) {
if fh.dirtyMetadata {
t.Fatal("handle still dirty after the shutdown flush")
}
if _, code := wfs.Write(nil, &fuse.WriteIn{Fh: uint64(fh.fh), Size: 1}, []byte("x")); code != fuse.EIO {
t.Fatalf("write after the shutdown flush = %v, want EIO", code)
wfs.copyBufferPool.New = func() any { return make([]byte, 1024) }
in := fuse.InHeader{NodeId: fh.inode}
for name, change := range map[string]func() fuse.Status{
"write": func() fuse.Status {
_, code := wfs.Write(nil, &fuse.WriteIn{Fh: uint64(fh.fh), Size: 1}, []byte("x"))
return code
},
"copy_file_range": func() fuse.Status {
_, code := wfs.CopyFileRange(nil, &fuse.CopyFileRangeIn{FhIn: uint64(fh.fh), OffIn: 1 << 20, FhOut: uint64(fh.fh), Len: 1})
return code
},
"fallocate": func() fuse.Status {
return wfs.Fallocate(nil, &fuse.FallocateIn{Fh: uint64(fh.fh), Length: 1 << 20})
},
"truncate": func() fuse.Status {
return wfs.SetAttr(nil, &fuse.SetAttrIn{SetAttrInCommon: fuse.SetAttrInCommon{InHeader: in, Valid: fuse.FATTR_SIZE | fuse.FATTR_FH, Fh: uint64(fh.fh), Size: 1}}, &fuse.AttrOut{})
},
} {
if code := change(); code != fuse.EIO {
t.Errorf("%s after the shutdown flush = %v, want EIO", name, code)
}
}
if fh.dirtyMetadata {
t.Fatal("a refused change left the handle dirty")
}
}
+6
View File
@@ -160,6 +160,9 @@ func (wfs *WFS) SetXAttr(cancel <-chan struct{}, input *fuse.SetXAttrIn, attr st
if fh != nil {
active := wfs.fhLockTable.AcquireLock("xattr", fh.fh, util.ExclusiveLock)
defer wfs.fhLockTable.ReleaseLock(fh.fh, active)
if wfs.shuttingDown.Load() {
return fuse.EIO
}
fh.entryLock.Lock()
defer fh.entryLock.Unlock()
// Readers take only the LockedEntry lock. Re-read the entry under
@@ -265,6 +268,9 @@ func (wfs *WFS) RemoveXAttr(cancel <-chan struct{}, header *fuse.InHeader, attr
if fh != nil {
active := wfs.fhLockTable.AcquireLock("xattr", fh.fh, util.ExclusiveLock)
defer wfs.fhLockTable.ReleaseLock(fh.fh, active)
if wfs.shuttingDown.Load() {
return fuse.EIO
}
fh.entryLock.Lock()
defer fh.entryLock.Unlock()
// Readers take only the LockedEntry lock. Re-read the entry under