Commit c76ff170 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Make go-fuse TSAN clean.

parent 92961189
...@@ -130,7 +130,7 @@ func NewFile() *MutableDataFile { ...@@ -130,7 +130,7 @@ func NewFile() *MutableDataFile {
return &MutableDataFile{} return &MutableDataFile{}
} }
func setupFAttrTest(t *testing.T, fs FileSystem) (dir string, clean func()) { func setupFAttrTest(t *testing.T, fs FileSystem) (dir string, clean func(), sync func()) {
dir, err := ioutil.TempDir("", "go-fuse") dir, err := ioutil.TempDir("", "go-fuse")
CheckSuccess(err) CheckSuccess(err)
nfs := NewPathNodeFs(fs, nil) nfs := NewPathNodeFs(fs, nil)
...@@ -150,12 +150,14 @@ func setupFAttrTest(t *testing.T, fs FileSystem) (dir string, clean func()) { ...@@ -150,12 +150,14 @@ func setupFAttrTest(t *testing.T, fs FileSystem) (dir string, clean func()) {
if state.Unmount() == nil { if state.Unmount() == nil {
os.RemoveAll(dir) os.RemoveAll(dir)
} }
}, func() {
state.ThreadSanitizerSync()
} }
} }
func TestDataReadLarge(t *testing.T) { func TestDataReadLarge(t *testing.T) {
fs := &FSetAttrFs{} fs := &FSetAttrFs{}
dir, clean := setupFAttrTest(t, fs) dir, clean, _ := setupFAttrTest(t, fs)
defer clean() defer clean()
content := RandomData(385 * 1023) content := RandomData(385 * 1023)
...@@ -170,7 +172,7 @@ func TestDataReadLarge(t *testing.T) { ...@@ -170,7 +172,7 @@ func TestDataReadLarge(t *testing.T) {
func TestFSetAttr(t *testing.T) { func TestFSetAttr(t *testing.T) {
fs := &FSetAttrFs{} fs := &FSetAttrFs{}
dir, clean := setupFAttrTest(t, fs) dir, clean, sync := setupFAttrTest(t, fs)
defer clean() defer clean()
fn := dir + "/file" fn := dir + "/file"
...@@ -184,6 +186,7 @@ func TestFSetAttr(t *testing.T) { ...@@ -184,6 +186,7 @@ func TestFSetAttr(t *testing.T) {
_, err = f.WriteString("hello") _, err = f.WriteString("hello")
CheckSuccess(err) CheckSuccess(err)
sync()
code := syscall.Ftruncate(int(f.Fd()), 3) code := syscall.Ftruncate(int(f.Fd()), 3)
if code != nil { if code != nil {
t.Error("truncate retval", os.NewSyscallError("Ftruncate", code)) t.Error("truncate retval", os.NewSyscallError("Ftruncate", code))
......
...@@ -47,6 +47,24 @@ type MountState struct { ...@@ -47,6 +47,24 @@ type MountState struct {
loops sync.WaitGroup loops sync.WaitGroup
} }
// Use this method to make synchronization between accessing a
// filesystem object through the operating system, and accessing a
// filesystem internally, so thread-sanitizer does not get confused.
//
// fs := SomeFSObj{ReadCalled: false}
// ms := NewMountState(fs)
// ms.Mount("/mnt", nil)
// ..
// ioutil.ReadFile("/mnt/file")
//
// mountstate.ThreadSanitizerSync()
// if fs.ReadCalled { ... // no race condition here.
//
func (ms *MountState) ThreadSanitizerSync() {
ms.reqMu.Lock()
ms.reqMu.Unlock()
}
func (ms *MountState) KernelSettings() raw.InitIn { func (ms *MountState) KernelSettings() raw.InitIn {
return ms.kernelSettings return ms.kernelSettings
} }
......
...@@ -912,6 +912,7 @@ func TestUnionFsDisappearing(t *testing.T) { ...@@ -912,6 +912,7 @@ func TestUnionFsDisappearing(t *testing.T) {
CheckSuccess(err) CheckSuccess(err)
oldRoot := wrFs.Root oldRoot := wrFs.Root
state.ThreadSanitizerSync()
wrFs.Root = "/dev/null" wrFs.Root = "/dev/null"
time.Sleep((3 * entryTtl) / 2) time.Sleep((3 * entryTtl) / 2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment