From 41f74f692ff03b002c9305da61a21d8dc605b072 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys <hanwen@google.com> Date: Sat, 22 Jun 2013 13:25:31 +0200 Subject: [PATCH] Remove the LockingFileSystem and LockingRawFileSystem types from the public API. This reduces API clutter. --- fuse/lockingfs.go | 89 ++++++++++++++++++++++-------------------- fuse/pathfs/locking.go | 65 +++++++++++++++--------------- 2 files changed, 79 insertions(+), 75 deletions(-) diff --git a/fuse/lockingfs.go b/fuse/lockingfs.go index 0e414ed..662976b 100644 --- a/fuse/lockingfs.go +++ b/fuse/lockingfs.go @@ -10,186 +10,191 @@ import ( //////////////////////////////////////////////////////////////// // Locking raw FS. -type LockingRawFileSystem struct { +type lockingRawFileSystem struct { RawFS RawFileSystem lock sync.Mutex } -var _ = (RawFileSystem)((*LockingRawFileSystem)(nil)) +var _ = (RawFileSystem)((*lockingRawFileSystem)(nil)) -func (fs *LockingRawFileSystem) locked() func() { - fs.lock.Lock() - return func() { fs.lock.Unlock() } +// Returns a Wrap +func NewLockingRawFileSystem(fs RawFileSystem) RawFileSystem { + return &lockingRawFileSystem{ + RawFS: fs, + } +} + +func (fs *lockingRawFileSystem) FS() RawFileSystem { + return fs.RawFS } -func NewLockingRawFileSystem(rfs RawFileSystem) *LockingRawFileSystem { - l := &LockingRawFileSystem{} - l.RawFS = rfs - return l +func (fs *lockingRawFileSystem) locked() func() { + fs.lock.Lock() + return func() { fs.lock.Unlock() } } -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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() return fs.RawFS.FsyncDir(header, input) } -func (fs *LockingRawFileSystem) Init(params *RawFsInit) { +func (fs *lockingRawFileSystem) Init(params *RawFsInit) { defer fs.locked()() 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()() 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()() return fs.RawFS.Fallocate(c, in) } -func (fs *LockingRawFileSystem) String() string { +func (fs *lockingRawFileSystem) String() string { defer fs.locked()() return fmt.Sprintf("Locked(%s)", fs.RawFS.String()) } diff --git a/fuse/pathfs/locking.go b/fuse/pathfs/locking.go index 75d7ad6..f4c4e48 100644 --- a/fuse/pathfs/locking.go +++ b/fuse/pathfs/locking.go @@ -7,149 +7,148 @@ import ( "github.com/hanwen/go-fuse/fuse" ) -// This is a wrapper that makes a FileSystem threadsafe by -// trivially locking all operations. For improved performance, you -// should probably invent do your own locking inside the file system. -type LockingFileSystem struct { +type lockingFileSystem struct { // Should be public so people reusing can access the wrapped // FS. FS FileSystem lock sync.Mutex } -var _ = ((FileSystem)((*LockingFileSystem)(nil))) +var _ = ((FileSystem)((*lockingFileSystem)(nil))) -func NewLockingFileSystem(pfs FileSystem) *LockingFileSystem { - l := new(LockingFileSystem) +// NewLockingFileSystem is a wrapper that makes a FileSystem +// threadsafe by serializing each operation. +func NewLockingFileSystem(pfs FileSystem) FileSystem { + l := new(lockingFileSystem) l.FS = pfs return l } -func (fs *LockingFileSystem) String() string { +func (fs *lockingFileSystem) String() string { defer fs.locked()() return fs.FS.String() } -func (fs *LockingFileSystem) StatFs(name string) *fuse.StatfsOut { +func (fs *lockingFileSystem) StatFs(name string) *fuse.StatfsOut { defer fs.locked()() return fs.FS.StatFs(name) } -func (fs *LockingFileSystem) locked() func() { +func (fs *lockingFileSystem) locked() func() { fs.lock.Lock() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() 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) } -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()() return fs.FS.OpenDir(name, context) } -func (fs *LockingFileSystem) OnMount(nodeFs *PathNodeFs) { +func (fs *lockingFileSystem) OnMount(nodeFs *PathNodeFs) { defer fs.locked()() fs.FS.OnMount(nodeFs) } -func (fs *LockingFileSystem) OnUnmount() { +func (fs *lockingFileSystem) OnUnmount() { defer fs.locked()() 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()() 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()() 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()() 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()() 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()() 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()() 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()() return fs.FS.RemoveXAttr(name, attr, context) } -- 2.30.9