Commit 41f74f69 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Remove the LockingFileSystem and LockingRawFileSystem types from the

public API.

This reduces API clutter.
parent baa8ca67
...@@ -10,186 +10,191 @@ import ( ...@@ -10,186 +10,191 @@ import (
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// Locking raw FS. // Locking raw FS.
type LockingRawFileSystem struct { type lockingRawFileSystem struct {
RawFS RawFileSystem RawFS RawFileSystem
lock sync.Mutex lock sync.Mutex
} }
var _ = (RawFileSystem)((*LockingRawFileSystem)(nil)) var _ = (RawFileSystem)((*lockingRawFileSystem)(nil))
func (fs *LockingRawFileSystem) locked() func() { // Returns a Wrap
fs.lock.Lock() func NewLockingRawFileSystem(fs RawFileSystem) RawFileSystem {
return func() { fs.lock.Unlock() } return &lockingRawFileSystem{
RawFS: fs,
}
}
func (fs *lockingRawFileSystem) FS() RawFileSystem {
return fs.RawFS
} }
func NewLockingRawFileSystem(rfs RawFileSystem) *LockingRawFileSystem { func (fs *lockingRawFileSystem) locked() func() {
l := &LockingRawFileSystem{} fs.lock.Lock()
l.RawFS = rfs return func() { fs.lock.Unlock() }
return l
} }
func (fs *LockingRawFileSystem) Lookup(out *raw.EntryOut, h *Context, name string) (code Status) { func (fs *lockingRawFileSystem) Lookup(out *raw.EntryOut, h *Context, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Lookup(out, h, name) return fs.RawFS.Lookup(out, h, name)
} }
func (fs *LockingRawFileSystem) Forget(nodeID uint64, nlookup uint64) { func (fs *lockingRawFileSystem) Forget(nodeID uint64, nlookup uint64) {
defer fs.locked()() defer fs.locked()()
fs.RawFS.Forget(nodeID, nlookup) fs.RawFS.Forget(nodeID, nlookup)
} }
func (fs *LockingRawFileSystem) GetAttr(out *raw.AttrOut, header *Context, input *raw.GetAttrIn) (code Status) { func (fs *lockingRawFileSystem) GetAttr(out *raw.AttrOut, header *Context, input *raw.GetAttrIn) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.GetAttr(out, header, input) return fs.RawFS.GetAttr(out, header, input)
} }
func (fs *LockingRawFileSystem) Open(out *raw.OpenOut, header *Context, input *raw.OpenIn) (status Status) { func (fs *lockingRawFileSystem) Open(out *raw.OpenOut, header *Context, input *raw.OpenIn) (status Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Open(out, header, input) return fs.RawFS.Open(out, header, input)
} }
func (fs *LockingRawFileSystem) SetAttr(out *raw.AttrOut, header *Context, input *raw.SetAttrIn) (code Status) { func (fs *lockingRawFileSystem) SetAttr(out *raw.AttrOut, header *Context, input *raw.SetAttrIn) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.SetAttr(out, header, input) return fs.RawFS.SetAttr(out, header, input)
} }
func (fs *LockingRawFileSystem) Readlink(header *Context) (out []byte, code Status) { func (fs *lockingRawFileSystem) Readlink(header *Context) (out []byte, code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Readlink(header) return fs.RawFS.Readlink(header)
} }
func (fs *LockingRawFileSystem) Mknod(out *raw.EntryOut, header *Context, input *raw.MknodIn, name string) (code Status) { func (fs *lockingRawFileSystem) Mknod(out *raw.EntryOut, header *Context, input *raw.MknodIn, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Mknod(out, header, input, name) return fs.RawFS.Mknod(out, header, input, name)
} }
func (fs *LockingRawFileSystem) Mkdir(out *raw.EntryOut, header *Context, input *raw.MkdirIn, name string) (code Status) { func (fs *lockingRawFileSystem) Mkdir(out *raw.EntryOut, header *Context, input *raw.MkdirIn, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Mkdir(out, header, input, name) return fs.RawFS.Mkdir(out, header, input, name)
} }
func (fs *LockingRawFileSystem) Unlink(header *Context, name string) (code Status) { func (fs *lockingRawFileSystem) Unlink(header *Context, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Unlink(header, name) return fs.RawFS.Unlink(header, name)
} }
func (fs *LockingRawFileSystem) Rmdir(header *Context, name string) (code Status) { func (fs *lockingRawFileSystem) Rmdir(header *Context, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Rmdir(header, name) return fs.RawFS.Rmdir(header, name)
} }
func (fs *LockingRawFileSystem) Symlink(out *raw.EntryOut, header *Context, pointedTo string, linkName string) (code Status) { func (fs *lockingRawFileSystem) Symlink(out *raw.EntryOut, header *Context, pointedTo string, linkName string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Symlink(out, header, pointedTo, linkName) return fs.RawFS.Symlink(out, header, pointedTo, linkName)
} }
func (fs *LockingRawFileSystem) Rename(header *Context, input *raw.RenameIn, oldName string, newName string) (code Status) { func (fs *lockingRawFileSystem) Rename(header *Context, input *raw.RenameIn, oldName string, newName string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Rename(header, input, oldName, newName) return fs.RawFS.Rename(header, input, oldName, newName)
} }
func (fs *LockingRawFileSystem) Link(out *raw.EntryOut, header *Context, input *raw.LinkIn, name string) (code Status) { func (fs *lockingRawFileSystem) Link(out *raw.EntryOut, header *Context, input *raw.LinkIn, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Link(out, header, input, name) return fs.RawFS.Link(out, header, input, name)
} }
func (fs *LockingRawFileSystem) SetXAttr(header *Context, input *raw.SetXAttrIn, attr string, data []byte) Status { func (fs *lockingRawFileSystem) SetXAttr(header *Context, input *raw.SetXAttrIn, attr string, data []byte) Status {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.SetXAttr(header, input, attr, data) return fs.RawFS.SetXAttr(header, input, attr, data)
} }
func (fs *LockingRawFileSystem) GetXAttrData(header *Context, attr string) (data []byte, code Status) { func (fs *lockingRawFileSystem) GetXAttrData(header *Context, attr string) (data []byte, code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.GetXAttrData(header, attr) return fs.RawFS.GetXAttrData(header, attr)
} }
func (fs *LockingRawFileSystem) GetXAttrSize(header *Context, attr string) (sz int, code Status) { func (fs *lockingRawFileSystem) GetXAttrSize(header *Context, attr string) (sz int, code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.GetXAttrSize(header, attr) return fs.RawFS.GetXAttrSize(header, attr)
} }
func (fs *LockingRawFileSystem) ListXAttr(header *Context) (data []byte, code Status) { func (fs *lockingRawFileSystem) ListXAttr(header *Context) (data []byte, code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.ListXAttr(header) return fs.RawFS.ListXAttr(header)
} }
func (fs *LockingRawFileSystem) RemoveXAttr(header *Context, attr string) Status { func (fs *lockingRawFileSystem) RemoveXAttr(header *Context, attr string) Status {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.RemoveXAttr(header, attr) return fs.RawFS.RemoveXAttr(header, attr)
} }
func (fs *LockingRawFileSystem) Access(header *Context, input *raw.AccessIn) (code Status) { func (fs *lockingRawFileSystem) Access(header *Context, input *raw.AccessIn) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Access(header, input) return fs.RawFS.Access(header, input)
} }
func (fs *LockingRawFileSystem) Create(out *raw.CreateOut, header *Context, input *raw.CreateIn, name string) (code Status) { func (fs *lockingRawFileSystem) Create(out *raw.CreateOut, header *Context, input *raw.CreateIn, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Create(out, header, input, name) return fs.RawFS.Create(out, header, input, name)
} }
func (fs *LockingRawFileSystem) OpenDir(out *raw.OpenOut, header *Context, input *raw.OpenIn) (status Status) { func (fs *lockingRawFileSystem) OpenDir(out *raw.OpenOut, header *Context, input *raw.OpenIn) (status Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.OpenDir(out, header, input) return fs.RawFS.OpenDir(out, header, input)
} }
func (fs *LockingRawFileSystem) Release(header *Context, input *raw.ReleaseIn) { func (fs *lockingRawFileSystem) Release(header *Context, input *raw.ReleaseIn) {
defer fs.locked()() defer fs.locked()()
fs.RawFS.Release(header, input) fs.RawFS.Release(header, input)
} }
func (fs *LockingRawFileSystem) ReleaseDir(header *Context, h *raw.ReleaseIn) { func (fs *lockingRawFileSystem) ReleaseDir(header *Context, h *raw.ReleaseIn) {
defer fs.locked()() defer fs.locked()()
fs.RawFS.ReleaseDir(header, h) fs.RawFS.ReleaseDir(header, h)
} }
func (fs *LockingRawFileSystem) Read(header *Context, input *raw.ReadIn, buf []byte) (ReadResult, Status) { func (fs *lockingRawFileSystem) Read(header *Context, input *raw.ReadIn, buf []byte) (ReadResult, Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Read(header, input, buf) return fs.RawFS.Read(header, input, buf)
} }
func (fs *LockingRawFileSystem) Write(header *Context, input *raw.WriteIn, data []byte) (written uint32, code Status) { func (fs *lockingRawFileSystem) Write(header *Context, input *raw.WriteIn, data []byte) (written uint32, code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Write(header, input, data) return fs.RawFS.Write(header, input, data)
} }
func (fs *LockingRawFileSystem) Flush(header *Context, input *raw.FlushIn) Status { func (fs *lockingRawFileSystem) Flush(header *Context, input *raw.FlushIn) Status {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Flush(header, input) return fs.RawFS.Flush(header, input)
} }
func (fs *LockingRawFileSystem) Fsync(header *Context, input *raw.FsyncIn) (code Status) { func (fs *lockingRawFileSystem) Fsync(header *Context, input *raw.FsyncIn) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Fsync(header, input) return fs.RawFS.Fsync(header, input)
} }
func (fs *LockingRawFileSystem) ReadDir(out *DirEntryList, header *Context, input *raw.ReadIn) Status { func (fs *lockingRawFileSystem) ReadDir(out *DirEntryList, header *Context, input *raw.ReadIn) Status {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.ReadDir(out, header, input) return fs.RawFS.ReadDir(out, header, input)
} }
func (fs *LockingRawFileSystem) FsyncDir(header *Context, input *raw.FsyncIn) (code Status) { func (fs *lockingRawFileSystem) FsyncDir(header *Context, input *raw.FsyncIn) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.FsyncDir(header, input) return fs.RawFS.FsyncDir(header, input)
} }
func (fs *LockingRawFileSystem) Init(params *RawFsInit) { func (fs *lockingRawFileSystem) Init(params *RawFsInit) {
defer fs.locked()() defer fs.locked()()
fs.RawFS.Init(params) fs.RawFS.Init(params)
} }
func (fs *LockingRawFileSystem) StatFs(out *StatfsOut, context *Context) (code Status) { func (fs *lockingRawFileSystem) StatFs(out *StatfsOut, context *Context) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.StatFs(out, context) return fs.RawFS.StatFs(out, context)
} }
func (fs *LockingRawFileSystem) Fallocate(c *Context, in *raw.FallocateIn) (code Status) { func (fs *lockingRawFileSystem) Fallocate(c *Context, in *raw.FallocateIn) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.RawFS.Fallocate(c, in) return fs.RawFS.Fallocate(c, in)
} }
func (fs *LockingRawFileSystem) String() string { func (fs *lockingRawFileSystem) String() string {
defer fs.locked()() defer fs.locked()()
return fmt.Sprintf("Locked(%s)", fs.RawFS.String()) return fmt.Sprintf("Locked(%s)", fs.RawFS.String())
} }
...@@ -7,149 +7,148 @@ import ( ...@@ -7,149 +7,148 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
) )
// This is a wrapper that makes a FileSystem threadsafe by type lockingFileSystem struct {
// trivially locking all operations. For improved performance, you
// should probably invent do your own locking inside the file system.
type LockingFileSystem struct {
// Should be public so people reusing can access the wrapped // Should be public so people reusing can access the wrapped
// FS. // FS.
FS FileSystem FS FileSystem
lock sync.Mutex lock sync.Mutex
} }
var _ = ((FileSystem)((*LockingFileSystem)(nil))) var _ = ((FileSystem)((*lockingFileSystem)(nil)))
func NewLockingFileSystem(pfs FileSystem) *LockingFileSystem { // NewLockingFileSystem is a wrapper that makes a FileSystem
l := new(LockingFileSystem) // threadsafe by serializing each operation.
func NewLockingFileSystem(pfs FileSystem) FileSystem {
l := new(lockingFileSystem)
l.FS = pfs l.FS = pfs
return l return l
} }
func (fs *LockingFileSystem) String() string { func (fs *lockingFileSystem) String() string {
defer fs.locked()() defer fs.locked()()
return fs.FS.String() return fs.FS.String()
} }
func (fs *LockingFileSystem) StatFs(name string) *fuse.StatfsOut { func (fs *lockingFileSystem) StatFs(name string) *fuse.StatfsOut {
defer fs.locked()() defer fs.locked()()
return fs.FS.StatFs(name) return fs.FS.StatFs(name)
} }
func (fs *LockingFileSystem) locked() func() { func (fs *lockingFileSystem) locked() func() {
fs.lock.Lock() fs.lock.Lock()
return func() { fs.lock.Unlock() } return func() { fs.lock.Unlock() }
} }
func (fs *LockingFileSystem) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) { func (fs *lockingFileSystem) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.GetAttr(name, context) return fs.FS.GetAttr(name, context)
} }
func (fs *LockingFileSystem) Readlink(name string, context *fuse.Context) (string, fuse.Status) { func (fs *lockingFileSystem) Readlink(name string, context *fuse.Context) (string, fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.Readlink(name, context) return fs.FS.Readlink(name, context)
} }
func (fs *LockingFileSystem) Mknod(name string, mode uint32, dev uint32, context *fuse.Context) fuse.Status { func (fs *lockingFileSystem) Mknod(name string, mode uint32, dev uint32, context *fuse.Context) fuse.Status {
defer fs.locked()() defer fs.locked()()
return fs.FS.Mknod(name, mode, dev, context) return fs.FS.Mknod(name, mode, dev, context)
} }
func (fs *LockingFileSystem) Mkdir(name string, mode uint32, context *fuse.Context) fuse.Status { func (fs *lockingFileSystem) Mkdir(name string, mode uint32, context *fuse.Context) fuse.Status {
defer fs.locked()() defer fs.locked()()
return fs.FS.Mkdir(name, mode, context) return fs.FS.Mkdir(name, mode, context)
} }
func (fs *LockingFileSystem) Unlink(name string, context *fuse.Context) (code fuse.Status) { func (fs *lockingFileSystem) Unlink(name string, context *fuse.Context) (code fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.Unlink(name, context) return fs.FS.Unlink(name, context)
} }
func (fs *LockingFileSystem) Rmdir(name string, context *fuse.Context) (code fuse.Status) { func (fs *lockingFileSystem) Rmdir(name string, context *fuse.Context) (code fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.Rmdir(name, context) return fs.FS.Rmdir(name, context)
} }
func (fs *LockingFileSystem) Symlink(value string, linkName string, context *fuse.Context) (code fuse.Status) { func (fs *lockingFileSystem) Symlink(value string, linkName string, context *fuse.Context) (code fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.Symlink(value, linkName, context) return fs.FS.Symlink(value, linkName, context)
} }
func (fs *LockingFileSystem) Rename(oldName string, newName string, context *fuse.Context) (code fuse.Status) { func (fs *lockingFileSystem) Rename(oldName string, newName string, context *fuse.Context) (code fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.Rename(oldName, newName, context) return fs.FS.Rename(oldName, newName, context)
} }
func (fs *LockingFileSystem) Link(oldName string, newName string, context *fuse.Context) (code fuse.Status) { func (fs *lockingFileSystem) Link(oldName string, newName string, context *fuse.Context) (code fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.Link(oldName, newName, context) return fs.FS.Link(oldName, newName, context)
} }
func (fs *LockingFileSystem) Chmod(name string, mode uint32, context *fuse.Context) (code fuse.Status) { func (fs *lockingFileSystem) Chmod(name string, mode uint32, context *fuse.Context) (code fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.Chmod(name, mode, context) return fs.FS.Chmod(name, mode, context)
} }
func (fs *LockingFileSystem) Chown(name string, uid uint32, gid uint32, context *fuse.Context) (code fuse.Status) { func (fs *lockingFileSystem) Chown(name string, uid uint32, gid uint32, context *fuse.Context) (code fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.Chown(name, uid, gid, context) return fs.FS.Chown(name, uid, gid, context)
} }
func (fs *LockingFileSystem) Truncate(name string, offset uint64, context *fuse.Context) (code fuse.Status) { func (fs *lockingFileSystem) Truncate(name string, offset uint64, context *fuse.Context) (code fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.Truncate(name, offset, context) return fs.FS.Truncate(name, offset, context)
} }
func (fs *LockingFileSystem) Open(name string, flags uint32, context *fuse.Context) (file fuse.File, code fuse.Status) { func (fs *lockingFileSystem) Open(name string, flags uint32, context *fuse.Context) (file fuse.File, code fuse.Status) {
return fs.FS.Open(name, flags, context) return fs.FS.Open(name, flags, context)
} }
func (fs *LockingFileSystem) OpenDir(name string, context *fuse.Context) (stream []fuse.DirEntry, status fuse.Status) { func (fs *lockingFileSystem) OpenDir(name string, context *fuse.Context) (stream []fuse.DirEntry, status fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.OpenDir(name, context) return fs.FS.OpenDir(name, context)
} }
func (fs *LockingFileSystem) OnMount(nodeFs *PathNodeFs) { func (fs *lockingFileSystem) OnMount(nodeFs *PathNodeFs) {
defer fs.locked()() defer fs.locked()()
fs.FS.OnMount(nodeFs) fs.FS.OnMount(nodeFs)
} }
func (fs *LockingFileSystem) OnUnmount() { func (fs *lockingFileSystem) OnUnmount() {
defer fs.locked()() defer fs.locked()()
fs.FS.OnUnmount() fs.FS.OnUnmount()
} }
func (fs *LockingFileSystem) Access(name string, mode uint32, context *fuse.Context) (code fuse.Status) { func (fs *lockingFileSystem) Access(name string, mode uint32, context *fuse.Context) (code fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.Access(name, mode, context) return fs.FS.Access(name, mode, context)
} }
func (fs *LockingFileSystem) Create(name string, flags uint32, mode uint32, context *fuse.Context) (file fuse.File, code fuse.Status) { func (fs *lockingFileSystem) Create(name string, flags uint32, mode uint32, context *fuse.Context) (file fuse.File, code fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.Create(name, flags, mode, context) return fs.FS.Create(name, flags, mode, context)
} }
func (fs *LockingFileSystem) Utimens(name string, Atime *time.Time, Mtime *time.Time, context *fuse.Context) (code fuse.Status) { func (fs *lockingFileSystem) Utimens(name string, Atime *time.Time, Mtime *time.Time, context *fuse.Context) (code fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.Utimens(name, Atime, Mtime, context) return fs.FS.Utimens(name, Atime, Mtime, context)
} }
func (fs *LockingFileSystem) GetXAttr(name string, attr string, context *fuse.Context) ([]byte, fuse.Status) { func (fs *lockingFileSystem) GetXAttr(name string, attr string, context *fuse.Context) ([]byte, fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.GetXAttr(name, attr, context) return fs.FS.GetXAttr(name, attr, context)
} }
func (fs *LockingFileSystem) SetXAttr(name string, attr string, data []byte, flags int, context *fuse.Context) fuse.Status { func (fs *lockingFileSystem) SetXAttr(name string, attr string, data []byte, flags int, context *fuse.Context) fuse.Status {
defer fs.locked()() defer fs.locked()()
return fs.FS.SetXAttr(name, attr, data, flags, context) return fs.FS.SetXAttr(name, attr, data, flags, context)
} }
func (fs *LockingFileSystem) ListXAttr(name string, context *fuse.Context) ([]string, fuse.Status) { func (fs *lockingFileSystem) ListXAttr(name string, context *fuse.Context) ([]string, fuse.Status) {
defer fs.locked()() defer fs.locked()()
return fs.FS.ListXAttr(name, context) return fs.FS.ListXAttr(name, context)
} }
func (fs *LockingFileSystem) RemoveXAttr(name string, attr string, context *fuse.Context) fuse.Status { func (fs *lockingFileSystem) RemoveXAttr(name string, attr string, context *fuse.Context) fuse.Status {
defer fs.locked()() defer fs.locked()()
return fs.FS.RemoveXAttr(name, attr, context) return fs.FS.RemoveXAttr(name, attr, context)
} }
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