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.
This commit is contained in:
Jakob Unterwurzacher 2016-05-08 23:16:40 +02:00
parent 4b6cf43521
commit ba7c798418

View File

@ -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)