diff options
| author | Jakob Unterwurzacher | 2026-11-11 21:21:13 +0100 |
|---|---|---|
| committer | Jakob Unterwurzacher | 2026-11-11 21:21:13 +0100 |
| commit | 0363a138f8125604d75d9ca84be4092482b622df (patch) | |
| tree | af3e8fae13f8b17d8bfdb0e7a9f35b1398a3122d /internal/fusefrontend/file_allocate_truncate.go | |
| parent | 3bfeb314d993e9bf88e343b446f4b247dead3695 (diff) | |
fusefrontend: -sharedstorage: don't replace the header when growing a truncated file
With -sharedstorage, truncate to zero keeps the file header, because
other mounts may have the file ID cached. But a following truncate that
grows the file to a block-aligned size went through truncateGrowFile,
which saw plaintext size 0 and unconditionally called createHeader().
This replaced the file ID (without taking the header lock), and
everything the other mount wrote afterwards with its cached ID was
unreadable.
Factor the "read header or create it if the file is empty" logic out of
doWrite into loadOrCreateFileID() and use it in truncateGrowFile with
-sharedstorage.
Add TestGrowAfterTruncateKeepsHeader as a regression test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'internal/fusefrontend/file_allocate_truncate.go')
| -rw-r--r-- | internal/fusefrontend/file_allocate_truncate.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/internal/fusefrontend/file_allocate_truncate.go b/internal/fusefrontend/file_allocate_truncate.go index f4a078c..b7b2651 100644 --- a/internal/fusefrontend/file_allocate_truncate.go +++ b/internal/fusefrontend/file_allocate_truncate.go @@ -241,8 +241,15 @@ func (f *File) truncateGrowFile(oldPlainSz uint64, newPlainSz uint64) syscall.Er // The new size is block-aligned. In this case we can do everything ourselves // and avoid the call to doWrite. if newPlainSz%f.rootNode.contentEnc.PlainBS() == 0 { - // The file was empty, so it did not have a header. Create one. - if oldPlainSz == 0 { + if oldPlainSz == 0 && f.rootNode.args.SharedStorage { + // With -sharedstorage, truncate to zero keeps the header, and other + // mounts may have the file ID cached. Reuse the existing header if + // there is one, and only create one if the file is really empty. + if _, errno := f.loadOrCreateFileID(); errno != 0 { + return errno + } + } else if oldPlainSz == 0 { + // The file was empty, so it did not have a header. Create one. id, err := f.createHeader() if err != nil { return fs.ToErrno(err) |
