-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fusefrontend: sharedstorage: lock truncate agains concurrent access
Prevent reads and writes concurrent with the truncate operation. It's racy on tmpfs and ext4 ( https://lore.kernel.org/all/[email protected]/t/ ) as evident by TestOpenTruncate test failures: === RUN TestOpenTruncate cluster_test.go:209: POSIX compliance issue: non-exlusive create failed with err=file exists doRead 16384215: corrupt block #0: cipher: message authentication failed ino16384215 fh8: RMW read failed: errno=5 cluster_test.go:214: iteration 1: WriteAt: write /tmp/gocryptfs-test-parent-1026/1358464214/TestOpenTruncate.1788296708.mnt2/foo: input/output error --- FAIL: TestOpenTruncate (0.06s) FAIL exit status 1 FAIL github.com/rfjakob/gocryptfs/v2/tests/cluster 7.880s Relates-to: #56
- Loading branch information
Showing
4 changed files
with
24 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ import ( | |
"sync" | ||
"syscall" | ||
|
||
"golang.org/x/sys/unix" | ||
|
||
"github.com/rfjakob/gocryptfs/v2/internal/contentenc" | ||
|
||
"github.com/hanwen/go-fuse/v2/fs" | ||
|
@@ -109,6 +111,12 @@ func (f *File) truncate(newSize uint64) (errno syscall.Errno) { | |
f.fileTableEntry.ID = nil | ||
return 0 | ||
} else { | ||
// Prevent reads and writes concurrent with the truncate operation. It's | ||
// racy on tmpfs and ext4 ( https://lore.kernel.org/all/[email protected]/t/ ) | ||
// as evident by TestOpenTruncate test failures. | ||
f.LockSharedStorage(unix.F_WRLCK, 0, 0) | ||
defer f.LockSharedStorage(unix.F_UNLCK, 0, 0) | ||
|
||
// With -sharedstorage, we keep the on-disk file header. | ||
// Other mounts may have the file ID cached so we cannot mess with it. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters