alex
/
vfs
1
Fork 0

Revert "Kill the mutexes, don't seem to be required"

This reverts commit 1ba41be529.
This commit is contained in:
Alex Yatskov 2015-07-06 17:42:37 +09:00
parent cf4d7330f3
commit db22e54fa3
3 changed files with 43 additions and 3 deletions

23
dir.go
View File

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

13
file.go
View File

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

10
meta.go
View File

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