From 52c4864d849cbbb76d49d1a908025b77c7246bda Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Thu, 19 Nov 2026 20:53:14 +0100 Subject: fusefrontend: report mitigated corruptions via the context Replace the RootNode.MitigatedCorruptions channel with a callback that fsck attaches to the context of each operation via fusefrontend.WithCorruptionReporter(). The channel was needed when fsck went through the kernel, but now that fsck calls the node operations directly, the context is a better way: * Each report is attributed to the operation that caused it, so fsck no longer needs a watcher goroutine and the watchDone channel around every call. * reportMitigatedCorruption() no longer blocks for up to one second (and logs "BUG: reportCorruptItem: timeout") when nobody is listening. * A mounted filesystem has no reporter in the context, so reporting is a no-op there. readFileID() and doRead() now take a ctx. The write paths pass context.Background(), as fsck never writes. Co-Authored-By: Claude Opus 5.5 --- internal/fusefrontend/file.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'internal/fusefrontend/file.go') diff --git a/internal/fusefrontend/file.go b/internal/fusefrontend/file.go index feb40b5..8eee0f8 100644 --- a/internal/fusefrontend/file.go +++ b/internal/fusefrontend/file.go @@ -87,7 +87,9 @@ func (f *File) intFd() int { // readFileID loads the file header from disk and extracts the file ID. // Returns io.EOF if the file is empty. -func (f *File) readFileID() ([]byte, error) { +// +// ctx is only used to report mitigated corruptions, see WithCorruptionReporter. +func (f *File) readFileID(ctx context.Context) ([]byte, error) { // We read +1 byte to determine if the file has actual content // and not only the header. A header-only file will be considered empty. // This makes File ID poisoning more difficult. @@ -105,7 +107,7 @@ func (f *File) readFileID() ([]byte, error) { if err == io.EOF && n != 0 { tlog.Warn.Printf("readFileID %d: incomplete file, got %d instead of %d bytes", f.qIno.Ino, n, readLen) - f.rootNode.reportMitigatedCorruption(fmt.Sprint(f.qIno.Ino)) + reportMitigatedCorruption(ctx, fmt.Sprint(f.qIno.Ino)) } return nil, err } @@ -150,7 +152,10 @@ func (f *File) createHeader() (fileID []byte, err error) { // // Called by Read() for normal reading, // by Write() and Truncate() via doWrite() for Read-Modify-Write. -func (f *File) doRead(dst []byte, off uint64, length uint64) ([]byte, syscall.Errno) { +// +// ctx is only used to report mitigated corruptions, see WithCorruptionReporter. +// The write paths pass context.Background(), as fsck never writes. +func (f *File) doRead(ctx context.Context, dst []byte, off uint64, length uint64) ([]byte, syscall.Errno) { // Get the file ID, either from the open file table, or from disk. var fileID []byte f.fileTableEntry.IDLock.Lock() @@ -160,7 +165,7 @@ func (f *File) doRead(dst []byte, off uint64, length uint64) ([]byte, syscall.Er } else { // Not cached, we have to read it from disk. var err error - fileID, err = f.readFileID() + fileID, err = f.readFileID(ctx) if err != nil { f.fileTableEntry.IDLock.Unlock() if err == io.EOF { @@ -251,7 +256,7 @@ func (f *File) Read(ctx context.Context, buf []byte, off int64) (resultData fuse defer f.fileTableEntry.ContentLock.RUnlock() tlog.Debug.Printf("ino%d: FUSE Read: offset=%d length=%d", f.qIno.Ino, off, len(buf)) - out, errno := f.doRead(buf[:0], uint64(off), uint64(len(buf))) + out, errno := f.doRead(ctx, buf[:0], uint64(off), uint64(len(buf))) if errno != 0 { // With -sharedstorage, when we get a decryption error, we lock the // byte range and try again. @@ -266,7 +271,7 @@ func (f *File) Read(ctx context.Context, buf []byte, off int64) (resultData fuse } defer f.UnlockSharedStorage(int64(alignedOffset), int64(alignedLength)) - out, errno = f.doRead(buf[:0], uint64(off), uint64(len(buf))) + out, errno = f.doRead(ctx, buf[:0], uint64(off), uint64(len(buf))) if errno != 0 { return nil, errno } @@ -303,7 +308,7 @@ func (f *File) loadOrCreateFileID() (created bool, errno syscall.Errno) { } defer f.UnlockSharedStorage(0, contentenc.HeaderLen) - fileID, err := f.readFileID() + fileID, err := f.readFileID(context.Background()) // Write a new file header if the file is empty if err == io.EOF { fileID, err = f.createHeader() @@ -347,7 +352,7 @@ func (f *File) doWrite(data []byte, off int64) (uint32, syscall.Errno) { // Incomplete block -> Read-Modify-Write if b.IsPartial() { // Read - oldData, errno := f.doRead(nil, b.BlockPlainOff(), f.rootNode.contentEnc.PlainBS()) + oldData, errno := f.doRead(context.Background(), nil, b.BlockPlainOff(), f.rootNode.contentEnc.PlainBS()) if errno != 0 { tlog.Warn.Printf("ino%d fh%d: RMW read failed: errno=%d", f.qIno.Ino, f.intFd(), errno) return 0, errno -- cgit v1.2.3