Skip to content

Commit

Permalink
Merged fix for issue #28 concurrent VFS access
Browse files Browse the repository at this point in the history
  • Loading branch information
oniony committed Mar 13, 2015
1 parent 944263b commit 02870f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/tmsu/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ import (
"tmsu/common"
)

var Version = common.ParseVersion("0.5.0")
var Version = common.ParseVersion("0.5.2")
26 changes: 25 additions & 1 deletion src/tmsu/vfs/fusevfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"path/filepath"
"strconv"
"strings"
"sync"
"syscall"
"time"
"tmsu/common/log"
Expand Down Expand Up @@ -90,10 +91,12 @@ type FuseVfs struct {
store *storage.Storage
mountPath string
server *fuse.Server
locker sync.Locker
}

func MountVfs(store *storage.Storage, mountPath string, options []string) (*FuseVfs, error) {
fuseVfs := FuseVfs{}
fuseVfs := FuseVfs{nil, "", nil, &(sync.Mutex{})}

pathFs := pathfs.NewPathNodeFs(&fuseVfs, nil)
conn := nodefs.NewFileSystemConnector(pathFs.Root(), nil)
mountOptions := &fuse.MountOptions{Options: options}
Expand Down Expand Up @@ -154,6 +157,9 @@ func (vfs FuseVfs) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse
log.Infof(2, "BEGIN GetAttr(%v)", name)
defer log.Infof(2, "END GetAttr(%v)", name)

vfs.locker.Lock()
defer vfs.locker.Unlock()

if err := vfs.store.Begin(); err != nil {
log.Fatalf("could not begin transaction: %v", err)
}
Expand Down Expand Up @@ -213,6 +219,9 @@ func (vfs FuseVfs) Mkdir(name string, mode uint32, context *fuse.Context) fuse.S
return fuse.EPERM
}

vfs.locker.Lock()
defer vfs.locker.Unlock()

if err := vfs.store.Begin(); err != nil {
log.Fatalf("could not begin transaction: %v", err)
}
Expand Down Expand Up @@ -273,6 +282,9 @@ func (vfs FuseVfs) OpenDir(name string, context *fuse.Context) ([]fuse.DirEntry,
log.Infof(2, "BEGIN OpenDir(%v)", name)
defer log.Infof(2, "END OpenDir(%v)", name)

vfs.locker.Lock()
defer vfs.locker.Unlock()

if err := vfs.store.Begin(); err != nil {
log.Fatalf("could not begin transaction: %v", err)
}
Expand Down Expand Up @@ -302,6 +314,9 @@ func (vfs FuseVfs) Readlink(name string, context *fuse.Context) (string, fuse.St
log.Infof(2, "BEGIN Readlink(%v)", name)
defer log.Infof(2, "END Readlink(%v)", name)

vfs.locker.Lock()
defer vfs.locker.Unlock()

if err := vfs.store.Begin(); err != nil {
log.Fatalf("could not begin transaction: %v", err)
}
Expand Down Expand Up @@ -331,6 +346,9 @@ func (vfs FuseVfs) Rename(oldName string, newName string, context *fuse.Context)
log.Infof(2, "BEGIN Rename(%v, %v)", oldName, newName)
defer log.Infof(2, "END Rename(%v, %v)", oldName, newName)

vfs.locker.Lock()
defer vfs.locker.Unlock()

if err := vfs.store.Begin(); err != nil {
log.Fatalf("could not begin transaction: %v", err)
}
Expand Down Expand Up @@ -373,6 +391,9 @@ func (vfs FuseVfs) Rmdir(name string, context *fuse.Context) fuse.Status {
log.Infof(2, "BEGIN Rmdir(%v)", name)
defer log.Infof(2, "END Rmdir(%v)", name)

vfs.locker.Lock()
defer vfs.locker.Unlock()

if err := vfs.store.Begin(); err != nil {
log.Fatalf("could not begin transaction: %v", err)
}
Expand Down Expand Up @@ -471,6 +492,9 @@ func (vfs FuseVfs) Unlink(name string, context *fuse.Context) fuse.Status {
log.Infof(2, "BEGIN Unlink(%v)", name)
defer log.Infof(2, "END Unlink(%v)", name)

vfs.locker.Lock()
defer vfs.locker.Unlock()

if err := vfs.store.Begin(); err != nil {
log.Fatalf("could not begin transaction: %v", err)
}
Expand Down

0 comments on commit 02870f9

Please sign in to comment.