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 {
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")
CheckSuccess(err)
nfs := NewPathNodeFs(fs, nil)
......@@ -150,12 +150,14 @@ func setupFAttrTest(t *testing.T, fs FileSystem) (dir string, clean func()) {
if state.Unmount() == nil {
os.RemoveAll(dir)
}
}, func() {
state.ThreadSanitizerSync()
}
}
func TestDataReadLarge(t *testing.T) {
fs := &FSetAttrFs{}
dir, clean := setupFAttrTest(t, fs)
dir, clean, _ := setupFAttrTest(t, fs)
defer clean()
content := RandomData(385 * 1023)
......@@ -170,7 +172,7 @@ func TestDataReadLarge(t *testing.T) {
func TestFSetAttr(t *testing.T) {
fs := &FSetAttrFs{}
dir, clean := setupFAttrTest(t, fs)
dir, clean, sync := setupFAttrTest(t, fs)
defer clean()
fn := dir + "/file"
......@@ -184,6 +186,7 @@ func TestFSetAttr(t *testing.T) {
_, err = f.WriteString("hello")
CheckSuccess(err)
sync()
code := syscall.Ftruncate(int(f.Fd()), 3)
if code != nil {
t.Error("truncate retval", os.NewSyscallError("Ftruncate", code))
......
......@@ -47,6 +47,24 @@ type MountState struct {
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 {
return ms.kernelSettings
}
......
......@@ -912,6 +912,7 @@ func TestUnionFsDisappearing(t *testing.T) {
CheckSuccess(err)
oldRoot := wrFs.Root
state.ThreadSanitizerSync()
wrFs.Root = "/dev/null"
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