mount: Fix read flushing - fixes #638

This commit is contained in:
Nick Craig-Wood 2016-09-10 22:32:30 +01:00
parent 265f5b77a7
commit 392a86f585
2 changed files with 18 additions and 12 deletions

View File

@ -116,17 +116,23 @@ func (fh *ReadFileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) err
fh.mu.Lock() fh.mu.Lock()
defer fh.mu.Unlock() defer fh.mu.Unlock()
fs.Debug(fh.o, "ReadFileHandle.Flush") fs.Debug(fh.o, "ReadFileHandle.Flush")
// If Read hasn't been called then ignore the Flush - Release
// will pick it up
if !fh.readCalled {
fs.Debug(fh.o, "ReadFileHandle.Flush ignoring flush on unread handle")
return nil
} // Ignore the Flush as there is nothing we can sensibly do and
err := fh.close() // it seems quite common for Flush to be called from
if err != nil { // different threads each of which have read some data.
fs.ErrorLog(fh.o, "ReadFileHandle.Flush error: %v", err) if false {
return err // If Read hasn't been called then ignore the Flush - Release
// will pick it up
if !fh.readCalled {
fs.Debug(fh.o, "ReadFileHandle.Flush ignoring flush on unread handle")
return nil
}
err := fh.close()
if err != nil {
fs.ErrorLog(fh.o, "ReadFileHandle.Flush error: %v", err)
return err
}
} }
fs.Debug(fh.o, "ReadFileHandle.Flush OK") fs.Debug(fh.o, "ReadFileHandle.Flush OK")
return nil return nil

View File

@ -72,9 +72,9 @@ func TestReadFileDoubleClose(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, 1, n) assert.Equal(t, 1, n)
// close the dup - should produce an error // close the dup - should not produce an error
err = syscall.Close(fd2) err = syscall.Close(fd2)
assert.Error(t, err, "input/output error") assert.NoError(t, err, "input/output error")
run.rm(t, "testdoubleclose") run.rm(t, "testdoubleclose")
} }