Use FileSystem in cachingfs.

geesefs-0-30-9
Aaron Jacobs 2015-03-25 09:31:43 +11:00
parent a01f4b6ae5
commit e0aecb1d0b
2 changed files with 18 additions and 56 deletions

View File

@ -16,12 +16,12 @@ package cachingfs
import ( import (
"fmt" "fmt"
"io"
"os" "os"
"time" "time"
"github.com/jacobsa/fuse" "github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/fuseops" "github.com/jacobsa/fuse/fuseops"
"github.com/jacobsa/fuse/fuseutil"
"github.com/jacobsa/gcloud/syncutil" "github.com/jacobsa/gcloud/syncutil"
) )
@ -42,7 +42,7 @@ const (
// requests. It also exposes methods for renumbering inodes and updating mtimes // requests. It also exposes methods for renumbering inodes and updating mtimes
// that are useful in testing that these durations are honored. // that are useful in testing that these durations are honored.
type CachingFS interface { type CachingFS interface {
fuse.Server fuseutil.FileSystem
// Return the current inode ID of the file/directory with the given name. // Return the current inode ID of the file/directory with the given name.
FooID() fuseops.InodeID FooID() fuseops.InodeID
@ -99,6 +99,8 @@ const (
) )
type cachingFS struct { type cachingFS struct {
fuseutil.NotImplementedFileSystem
///////////////////////// /////////////////////////
// Constant data // Constant data
///////////////////////// /////////////////////////
@ -232,53 +234,18 @@ func (fs *cachingFS) SetMtime(mtime time.Time) {
fs.mtime = mtime 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) { func (fs *cachingFS) Init(
op.Respond(nil) op *fuseops.InitOp) (err error) {
return
} }
// LOCKS_EXCLUDED(fs.mu) // LOCKS_EXCLUDED(fs.mu)
func (fs *cachingFS) lookUpInode(op *fuseops.LookUpInodeOp) { func (fs *cachingFS) LookUpInode(
var err error op *fuseops.LookUpInodeOp) (err error) {
defer func() { op.Respond(err) }()
fs.mu.Lock() fs.mu.Lock()
defer fs.mu.Unlock() defer fs.mu.Unlock()
@ -331,10 +298,8 @@ func (fs *cachingFS) lookUpInode(op *fuseops.LookUpInodeOp) {
} }
// LOCKS_EXCLUDED(fs.mu) // LOCKS_EXCLUDED(fs.mu)
func (fs *cachingFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) { func (fs *cachingFS) GetInodeAttributes(
var err error op *fuseops.GetInodeAttributesOp) (err error) {
defer func() { op.Respond(err) }()
fs.mu.Lock() fs.mu.Lock()
defer fs.mu.Unlock() defer fs.mu.Unlock()
@ -362,16 +327,12 @@ func (fs *cachingFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) {
return return
} }
func (fs *cachingFS) openDir(op *fuseops.OpenDirOp) { func (fs *cachingFS) OpenDir(
var err error op *fuseops.OpenDirOp) (err error) {
defer func() { op.Respond(err) }()
return return
} }
func (fs *cachingFS) openFile(op *fuseops.OpenFileOp) { func (fs *cachingFS) OpenFile(
var err error op *fuseops.OpenFileOp) (err error) {
defer func() { op.Respond(err) }()
return return
} }

View File

@ -23,6 +23,7 @@ import (
"time" "time"
"github.com/googlecloudplatform/gcsfuse/timeutil" "github.com/googlecloudplatform/gcsfuse/timeutil"
"github.com/jacobsa/fuse/fuseutil"
"github.com/jacobsa/fuse/samples" "github.com/jacobsa/fuse/samples"
"github.com/jacobsa/fuse/samples/cachingfs" "github.com/jacobsa/fuse/samples/cachingfs"
. "github.com/jacobsa/oglematchers" . "github.com/jacobsa/oglematchers"
@ -54,7 +55,7 @@ func (t *cachingFSTest) setUp(
t.fs, err = cachingfs.NewCachingFS(lookupEntryTimeout, getattrTimeout) t.fs, err = cachingfs.NewCachingFS(lookupEntryTimeout, getattrTimeout)
AssertEq(nil, err) AssertEq(nil, err)
t.Server = t.fs t.Server = fuseutil.NewFileSystemServer(t.fs)
// Mount it. // Mount it.
t.SampleTest.SetUp(ti) t.SampleTest.SetUp(ti)