Skip to content

Commit

Permalink
fuse: remove race conditions on fsh
Browse files Browse the repository at this point in the history
remove race conditions as seen with `go test -race` on FileSystemHost
members
  • Loading branch information
Steven Falken committed Jan 19, 2021
1 parent e0e91bc commit 92831e3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion fuse/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type FileSystemHost struct {
sigc chan os.Signal

capCaseInsensitive, capReaddirPlus bool
sync.RWMutex
}

var (
Expand Down Expand Up @@ -421,6 +422,8 @@ func hostInit(conn0 *c_struct_fuse_conn_info) (user_data unsafe.Pointer) {
fctx := c_fuse_get_context()
user_data = fctx.private_data
host := hostHandleGet(user_data)
host.Lock()
defer host.Unlock()
host.fuse = fctx.fuse
c_hostAsgnCconninfo(conn0,
c_bool(host.capCaseInsensitive),
Expand All @@ -441,6 +444,8 @@ func hostDestroy(user_data unsafe.Pointer) {
}
host := hostHandleGet(user_data)
host.fsop.Destroy()
host.RLock()
defer host.RUnlock()
if nil != host.sigc {
signal.Stop(host.sigc)
}
Expand Down Expand Up @@ -668,7 +673,9 @@ func (host *FileSystemHost) Mount(mountpoint string, opts []string) bool {
}
}
defer func() {
host.Lock()
host.mntp = ""
host.Unlock()
}()

/*
Expand All @@ -688,7 +695,10 @@ func (host *FileSystemHost) Mount(mountpoint string, opts []string) bool {
host.sigc = make(chan os.Signal, 1)
defer close(host.sigc)
go func() {
_, ok := <-host.sigc
host.RLock()
sigc := host.sigc
host.RUnlock()
_, ok := <-sigc
if ok {
host.Unmount()
}
Expand All @@ -708,6 +718,8 @@ func (host *FileSystemHost) Mount(mountpoint string, opts []string) bool {
// Unmount may be called at any time after the Init() method has been called
// and before the Destroy() method has been called.
func (host *FileSystemHost) Unmount() bool {
host.RLock()

if nil == host.fuse {
return false
}
Expand All @@ -716,12 +728,16 @@ func (host *FileSystemHost) Unmount() bool {
mntp = c_CString(host.mntp)
defer c_free(unsafe.Pointer(mntp))
}
host.RUnlock()
return 0 != c_hostUnmount(host.fuse, mntp)
}

// Notify notifies the operating system about a file change.
// The action is a combination of the fuse.NOTIFY_* constants.
func (host *FileSystemHost) Notify(path string, action uint32) bool {
host.RLock()
defer host.RUnlock()

if nil == host.fuse {
return false
}
Expand Down

0 comments on commit 92831e3

Please sign in to comment.