From e0aecb1d0b49ab3b950c4267108bc3b1516a1b14 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 25 Mar 2015 09:31:43 +1100 Subject: [PATCH] Use FileSystem in cachingfs. --- samples/cachingfs/caching_fs.go | 71 +++++++--------------------- samples/cachingfs/caching_fs_test.go | 3 +- 2 files changed, 18 insertions(+), 56 deletions(-) diff --git a/samples/cachingfs/caching_fs.go b/samples/cachingfs/caching_fs.go index 9fcd2c3..c3f6c0f 100644 --- a/samples/cachingfs/caching_fs.go +++ b/samples/cachingfs/caching_fs.go @@ -16,12 +16,12 @@ package cachingfs import ( "fmt" - "io" "os" "time" "github.com/jacobsa/fuse" "github.com/jacobsa/fuse/fuseops" + "github.com/jacobsa/fuse/fuseutil" "github.com/jacobsa/gcloud/syncutil" ) @@ -42,7 +42,7 @@ const ( // requests. It also exposes methods for renumbering inodes and updating mtimes // that are useful in testing that these durations are honored. type CachingFS interface { - fuse.Server + fuseutil.FileSystem // Return the current inode ID of the file/directory with the given name. FooID() fuseops.InodeID @@ -99,6 +99,8 @@ const ( ) type cachingFS struct { + fuseutil.NotImplementedFileSystem + ///////////////////////// // Constant data ///////////////////////// @@ -232,53 +234,18 @@ func (fs *cachingFS) SetMtime(mtime time.Time) { fs.mtime = mtime } -// LOCKS_EXCLUDED(fs.mu) -func (fs *cachingFS) ServeOps(c *fuse.Connection) { - for { - op, err := c.ReadOp() - if err == io.EOF { - break - } - - if err != nil { - panic(err) - } - - switch typed := op.(type) { - case *fuseops.InitOp: - fs.init(typed) - - case *fuseops.LookUpInodeOp: - fs.lookUpInode(typed) - - case *fuseops.GetInodeAttributesOp: - fs.getInodeAttributes(typed) - - case *fuseops.OpenDirOp: - fs.openDir(typed) - - case *fuseops.OpenFileOp: - fs.openFile(typed) - - default: - typed.Respond(fuse.ENOSYS) - } - } -} - //////////////////////////////////////////////////////////////////////// -// Op methods +// FileSystem methods //////////////////////////////////////////////////////////////////////// -func (fs *cachingFS) init(op *fuseops.InitOp) { - op.Respond(nil) +func (fs *cachingFS) Init( + op *fuseops.InitOp) (err error) { + return } // LOCKS_EXCLUDED(fs.mu) -func (fs *cachingFS) lookUpInode(op *fuseops.LookUpInodeOp) { - var err error - defer func() { op.Respond(err) }() - +func (fs *cachingFS) LookUpInode( + op *fuseops.LookUpInodeOp) (err error) { fs.mu.Lock() defer fs.mu.Unlock() @@ -331,10 +298,8 @@ func (fs *cachingFS) lookUpInode(op *fuseops.LookUpInodeOp) { } // LOCKS_EXCLUDED(fs.mu) -func (fs *cachingFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) { - var err error - defer func() { op.Respond(err) }() - +func (fs *cachingFS) GetInodeAttributes( + op *fuseops.GetInodeAttributesOp) (err error) { fs.mu.Lock() defer fs.mu.Unlock() @@ -362,16 +327,12 @@ func (fs *cachingFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) { return } -func (fs *cachingFS) openDir(op *fuseops.OpenDirOp) { - var err error - defer func() { op.Respond(err) }() - +func (fs *cachingFS) OpenDir( + op *fuseops.OpenDirOp) (err error) { return } -func (fs *cachingFS) openFile(op *fuseops.OpenFileOp) { - var err error - defer func() { op.Respond(err) }() - +func (fs *cachingFS) OpenFile( + op *fuseops.OpenFileOp) (err error) { return } diff --git a/samples/cachingfs/caching_fs_test.go b/samples/cachingfs/caching_fs_test.go index 1819981..8c971bb 100644 --- a/samples/cachingfs/caching_fs_test.go +++ b/samples/cachingfs/caching_fs_test.go @@ -23,6 +23,7 @@ import ( "time" "github.com/googlecloudplatform/gcsfuse/timeutil" + "github.com/jacobsa/fuse/fuseutil" "github.com/jacobsa/fuse/samples" "github.com/jacobsa/fuse/samples/cachingfs" . "github.com/jacobsa/oglematchers" @@ -54,7 +55,7 @@ func (t *cachingFSTest) setUp( t.fs, err = cachingfs.NewCachingFS(lookupEntryTimeout, getattrTimeout) AssertEq(nil, err) - t.Server = t.fs + t.Server = fuseutil.NewFileSystemServer(t.fs) // Mount it. t.SampleTest.SetUp(ti)