aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-05-08 23:16:40 +0200
committerJakob Unterwurzacher2016-05-08 23:21:20 +0200
commitba7c798418269e6d496af206bdebd2204a07155f (patch)
treeb1dcb3fc9d4219ddeaaf721339ee6d96a012e598
parent4b6cf43521a362ff36e38aa77b48ee06fdf11f71 (diff)
fusefrontend: fix panic due to concurrently unregistered wlock
Commit 730291feab properly freed wlock when the file descriptor is closed. However, concurrently running Write and Truncates may still want to lock it. Check if the fd has been closed first.
-rw-r--r--internal/fusefrontend/file.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/internal/fusefrontend/file.go b/internal/fusefrontend/file.go
index d9588e9..ac00b1d 100644
--- a/internal/fusefrontend/file.go
+++ b/internal/fusefrontend/file.go
@@ -278,6 +278,10 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) {
func (f *file) Write(data []byte, off int64) (uint32, fuse.Status) {
f.fdLock.RLock()
defer f.fdLock.RUnlock()
+ if f.fd.Fd() < 0 {
+ // The file descriptor has been closed concurrently.
+ return 0, fuse.EBADF
+ }
wlock.lock(f.ino)
defer wlock.unlock(f.ino)
@@ -337,6 +341,10 @@ func (f *file) Fsync(flags int) (code fuse.Status) {
func (f *file) Truncate(newSize uint64) fuse.Status {
f.fdLock.RLock()
defer f.fdLock.RUnlock()
+ if f.fd.Fd() < 0 {
+ // The file descriptor has been closed concurrently.
+ return fuse.EBADF
+ }
wlock.lock(f.ino)
defer wlock.unlock(f.ino)