Skip to content

Commit

Permalink
fusefrontend: sharedstorage: retry read-path on EIO error
Browse files Browse the repository at this point in the history
With -sharedstorage, when we get a decryption error, we lock the
byte range and try again.

This makes concurrent R/W safe agains torn writes.

#754
  • Loading branch information
rfjakob committed Jun 19, 2023
1 parent 751acc4 commit a97df85
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion internal/fusefrontend/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,20 @@ func (f *File) Read(ctx context.Context, buf []byte, off int64) (resultData fuse
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)))
if errno != 0 {
return nil, errno
// With -sharedstorage, when we get a decryption error, we lock the
// byte range and try again.
if !(f.rootNode.args.SharedStorage && errno == syscall.EIO) {
return nil, errno
}
blocks := f.contentEnc.ExplodePlainRange(uint64(off), uint64(len(buf)))
alignedOffset, alignedLength := blocks[0].JointCiphertextRange(blocks)
if err := f.LockSharedStorage(unix.F_RDLCK, int64(alignedOffset), int64(alignedLength)); err != nil {
return nil, fs.ToErrno(err)
}
out, errno = f.doRead(buf[:0], uint64(off), uint64(len(buf)))
if errno != 0 {
return nil, errno
}
}
tlog.Debug.Printf("ino%d: Read: errno=%d, returning %d bytes", f.qIno.Ino, errno, len(out))
return fuse.ReadResultData(out), errno
Expand Down

0 comments on commit a97df85

Please sign in to comment.