diff options
author | Jakob Unterwurzacher | 2018-07-15 12:40:23 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2018-07-15 12:40:23 +0200 |
commit | 55bb22bad6c196f363ad27fbedad4f5360c4879f (patch) | |
tree | f7796ca9222e4e1c61ff767240ca498b9901fa83 /internal | |
parent | bbf5b72fff8b07251faacce9e77dd427a4379081 (diff) |
fusefrontend: doWrite: no need to take HeaderLock.RLock()
Other writers are blocked by ContentLock already.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/fusefrontend/file.go | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/internal/fusefrontend/file.go b/internal/fusefrontend/file.go index bad9bfc..1ae3386 100644 --- a/internal/fusefrontend/file.go +++ b/internal/fusefrontend/file.go @@ -266,13 +266,13 @@ func (f *File) Read(buf []byte, off int64) (resultData fuse.ReadResult, code fus // // Empty writes do nothing and are allowed. func (f *File) doWrite(data []byte, off int64) (uint32, fuse.Status) { - // Read header from disk, create a new one if the file is empty - f.fileTableEntry.HeaderLock.RLock() + // If the file ID is not cached, read it from disk if f.fileTableEntry.ID == nil { - f.fileTableEntry.HeaderLock.RUnlock() - // Somebody else may write the header here, but this would do no harm. + // Block other readers while we mess with the file header. Other writers + // are blocked by ContentLock already. f.fileTableEntry.HeaderLock.Lock() tmpID, err := f.readFileID() + // Write a new file header if the file is empty if err == io.EOF { tmpID, err = f.createHeader() } @@ -282,11 +282,7 @@ func (f *File) doWrite(data []byte, off int64) (uint32, fuse.Status) { } f.fileTableEntry.ID = tmpID f.fileTableEntry.HeaderLock.Unlock() - // The file ID may change in here. This does no harm because we - // re-read it after the RLock(). - f.fileTableEntry.HeaderLock.RLock() } - defer f.fileTableEntry.HeaderLock.RUnlock() // Handle payload data dataBuf := bytes.NewBuffer(data) blocks := f.contentEnc.ExplodePlainRange(uint64(off), uint64(len(data))) |