Kill the mutexes, don't seem to be required

This commit is contained in:
Alex Yatskov 2015-07-06 14:16:03 +09:00
parent 51c0dee7b3
commit 1ba41be529
3 changed files with 3 additions and 43 deletions

23
dir.go
View File

@ -26,7 +26,6 @@ import (
"errors" "errors"
"os" "os"
"path" "path"
"sync"
"bazil.org/fuse" "bazil.org/fuse"
"bazil.org/fuse/fs" "bazil.org/fuse/fs"
@ -43,20 +42,16 @@ type verDir struct {
node *verNode node *verNode
inode uint64 inode uint64
parent *verDir parent *verDir
mutex sync.Mutex
} }
func newVerDir(node *verNode, parent *verDir) *verDir { func newVerDir(node *verNode, parent *verDir) *verDir {
dirs := make(map[string]*verDir) dirs := make(map[string]*verDir)
files := make(map[string]*verFile) files := make(map[string]*verFile)
return &verDir{dirs, files, node, allocInode(), parent, sync.Mutex{}} return &verDir{dirs, files, node, allocInode(), parent}
} }
func (vd *verDir) version() error { func (vd *verDir) version() error {
vd.mutex.Lock()
defer vd.mutex.Unlock()
if vd.node.flags&NodeFlagNew == NodeFlagNew { if vd.node.flags&NodeFlagNew == NodeFlagNew {
return nil return nil
} }
@ -85,9 +80,7 @@ func (vd *verDir) createDir(name string) (*verDir, error) {
node := newVerNode(childPath, vd.node.ver, nil, NodeFlagDir|NodeFlagNew) node := newVerNode(childPath, vd.node.ver, nil, NodeFlagDir|NodeFlagNew)
dir := newVerDir(node, vd) dir := newVerDir(node, vd)
vd.mutex.Lock()
vd.dirs[name] = dir vd.dirs[name] = dir
vd.mutex.Unlock()
node.ver.meta.createNode(node.path) node.ver.meta.createNode(node.path)
return dir, nil return dir, nil
@ -107,18 +100,13 @@ func (vd *verDir) createFile(name string, flags fuse.OpenFlags, mode os.FileMode
return nil, nil, 0, err return nil, nil, 0, err
} }
vd.mutex.Lock()
vd.files[name] = file vd.files[name] = file
vd.mutex.Unlock()
node.ver.meta.createNode(node.path) node.ver.meta.createNode(node.path)
return file, handle, id, nil return file, handle, id, nil
} }
func (vd *verDir) removeDir(name string) error { func (vd *verDir) removeDir(name string) error {
vd.mutex.Lock()
defer vd.mutex.Unlock()
if err := vd.version(); err != nil { if err := vd.version(); err != nil {
return err return err
} }
@ -137,9 +125,6 @@ func (vd *verDir) removeDir(name string) error {
} }
func (vd *verDir) removeFile(name string) error { func (vd *verDir) removeFile(name string) error {
vd.mutex.Lock()
defer vd.mutex.Unlock()
if err := vd.version(); err != nil { if err := vd.version(); err != nil {
return err return err
} }
@ -208,9 +193,6 @@ func (vd *verDir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
// NodeRequestLookuper // NodeRequestLookuper
func (vd *verDir) Lookup(ctx context.Context, name string) (fs.Node, error) { func (vd *verDir) Lookup(ctx context.Context, name string) (fs.Node, error) {
vd.mutex.Lock()
defer vd.mutex.Unlock()
if dir, ok := vd.dirs[name]; ok { if dir, ok := vd.dirs[name]; ok {
return dir, nil return dir, nil
} }
@ -224,9 +206,6 @@ func (vd *verDir) Lookup(ctx context.Context, name string) (fs.Node, error) {
// HandleReadDirAller // HandleReadDirAller
func (vd *verDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { func (vd *verDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
vd.mutex.Lock()
defer vd.mutex.Unlock()
entries := []fuse.Dirent{{Inode: vd.inode, Name: ".", Type: fuse.DT_Dir}} entries := []fuse.Dirent{{Inode: vd.inode, Name: ".", Type: fuse.DT_Dir}}
if vd.parent != nil { if vd.parent != nil {
entry := fuse.Dirent{Inode: vd.parent.inode, Name: "..", Type: fuse.DT_Dir} entry := fuse.Dirent{Inode: vd.parent.inode, Name: "..", Type: fuse.DT_Dir}

13
file.go
View File

@ -24,7 +24,6 @@ package main
import ( import (
"os" "os"
"sync"
"bazil.org/fuse" "bazil.org/fuse"
"bazil.org/fuse/fs" "bazil.org/fuse/fs"
@ -42,17 +41,13 @@ type verFile struct {
inode uint64 inode uint64
parent *verDir parent *verDir
handles handleMap handles handleMap
mutex sync.Mutex
} }
func newVerFile(node *verNode, parent *verDir) *verFile { func newVerFile(node *verNode, parent *verDir) *verFile {
return &verFile{node, allocInode(), parent, make(handleMap), sync.Mutex{}} return &verFile{node, allocInode(), parent, make(handleMap)}
} }
func (vf *verFile) version() error { func (vf *verFile) version() error {
vf.mutex.Lock()
defer vf.mutex.Unlock()
if vf.node.flags&NodeFlagNew == NodeFlagNew { if vf.node.flags&NodeFlagNew == NodeFlagNew {
return nil return nil
} }
@ -85,17 +80,13 @@ func (vf *verFile) open(flags fuse.OpenFlags, mode os.FileMode) (*verFileHandle,
id := allocHandleId() id := allocHandleId()
verHandle := &verFileHandle{vf, path, handle} verHandle := &verFileHandle{vf, path, handle}
vf.mutex.Lock()
vf.handles[id] = verHandle vf.handles[id] = verHandle
vf.mutex.Unlock()
return verHandle, id, nil return verHandle, id, nil
} }
func (vf *verFile) release(handle fuse.HandleID) { func (vf *verFile) release(handle fuse.HandleID) {
vf.mutex.Lock()
delete(vf.handles, handle) delete(vf.handles, handle)
vf.mutex.Unlock()
} }
// Node // Node
@ -128,8 +119,6 @@ func (vf *verFile) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.O
// NodeFsyncer // NodeFsyncer
func (vf *verFile) Fsync(ctx context.Context, req *fuse.FsyncRequest) error { func (vf *verFile) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
vf.mutex.Lock()
defer vf.mutex.Unlock()
return vf.handles[req.Handle].handle.Sync() return vf.handles[req.Handle].handle.Sync()
} }

10
meta.go
View File

@ -28,7 +28,6 @@ import (
"os" "os"
"path" "path"
"strings" "strings"
"sync"
) )
// //
@ -43,11 +42,10 @@ type verMeta struct {
path string path string
deleted map[string]bool deleted map[string]bool
modified bool modified bool
mutex sync.Mutex
} }
func newVerMeta(path string) (*verMeta, error) { func newVerMeta(path string) (*verMeta, error) {
meta := &verMeta{path, make(map[string]bool), false, sync.Mutex{}} meta := &verMeta{path, make(map[string]bool), false}
if err := meta.load(); err != nil { if err := meta.load(); err != nil {
return nil, err return nil, err
} }
@ -70,18 +68,12 @@ func (m *verMeta) filter(nodes verNodeMap) {
} }
func (m *verMeta) removeNode(path string) { func (m *verMeta) removeNode(path string) {
m.mutex.Lock()
m.deleted[path] = true m.deleted[path] = true
m.mutex.Unlock()
m.modified = true m.modified = true
} }
func (m *verMeta) createNode(path string) { func (m *verMeta) createNode(path string) {
m.mutex.Lock()
m.deleted[path] = false m.deleted[path] = false
m.mutex.Unlock()
m.modified = true m.modified = true
} }