Updated cachingfs.
parent
ca8df835f6
commit
e0068fc2a7
|
@ -16,13 +16,13 @@ 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/gcloud/syncutil"
|
"github.com/jacobsa/gcloud/syncutil"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -232,6 +232,40 @@ 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
|
// Op methods
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -241,10 +275,9 @@ func (fs *cachingFS) init(op *fuseops.InitOp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOCKS_EXCLUDED(fs.mu)
|
// LOCKS_EXCLUDED(fs.mu)
|
||||||
func (fs *cachingFS) LookUpInode(
|
func (fs *cachingFS) lookUpInode(op *fuseops.LookUpInodeOp) {
|
||||||
ctx context.Context,
|
var err error
|
||||||
req *fuse.LookUpInodeRequest) (resp *fuse.LookUpInodeResponse, err error) {
|
defer func() { op.Respond(err) }()
|
||||||
resp = &fuse.LookUpInodeResponse{}
|
|
||||||
|
|
||||||
fs.mu.Lock()
|
fs.mu.Lock()
|
||||||
defer fs.mu.Unlock()
|
defer fs.mu.Unlock()
|
||||||
|
@ -253,10 +286,10 @@ func (fs *cachingFS) LookUpInode(
|
||||||
var id fuseops.InodeID
|
var id fuseops.InodeID
|
||||||
var attrs fuseops.InodeAttributes
|
var attrs fuseops.InodeAttributes
|
||||||
|
|
||||||
switch req.Name {
|
switch op.Name {
|
||||||
case "foo":
|
case "foo":
|
||||||
// Parent must be the root.
|
// Parent must be the root.
|
||||||
if req.Parent != fuseops.RootInodeID {
|
if op.Parent != fuseops.RootInodeID {
|
||||||
err = fuse.ENOENT
|
err = fuse.ENOENT
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -266,7 +299,7 @@ func (fs *cachingFS) LookUpInode(
|
||||||
|
|
||||||
case "dir":
|
case "dir":
|
||||||
// Parent must be the root.
|
// Parent must be the root.
|
||||||
if req.Parent != fuseops.RootInodeID {
|
if op.Parent != fuseops.RootInodeID {
|
||||||
err = fuse.ENOENT
|
err = fuse.ENOENT
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -276,7 +309,7 @@ func (fs *cachingFS) LookUpInode(
|
||||||
|
|
||||||
case "bar":
|
case "bar":
|
||||||
// Parent must be dir.
|
// Parent must be dir.
|
||||||
if req.Parent == fuseops.RootInodeID || req.Parent%numInodes != dirOffset {
|
if op.Parent == fuseops.RootInodeID || op.Parent%numInodes != dirOffset {
|
||||||
err = fuse.ENOENT
|
err = fuse.ENOENT
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -290,19 +323,17 @@ func (fs *cachingFS) LookUpInode(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in the response.
|
// Fill in the response.
|
||||||
resp.Entry.Child = id
|
op.Entry.Child = id
|
||||||
resp.Entry.Attributes = attrs
|
op.Entry.Attributes = attrs
|
||||||
resp.Entry.EntryExpiration = time.Now().Add(fs.lookupEntryTimeout)
|
op.Entry.EntryExpiration = time.Now().Add(fs.lookupEntryTimeout)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOCKS_EXCLUDED(fs.mu)
|
// LOCKS_EXCLUDED(fs.mu)
|
||||||
func (fs *cachingFS) GetInodeAttributes(
|
func (fs *cachingFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) {
|
||||||
ctx context.Context,
|
var err error
|
||||||
req *fuse.GetInodeAttributesRequest) (
|
defer func() { op.Respond(err) }()
|
||||||
resp *fuse.GetInodeAttributesResponse, err error) {
|
|
||||||
resp = &fuse.GetInodeAttributesResponse{}
|
|
||||||
|
|
||||||
fs.mu.Lock()
|
fs.mu.Lock()
|
||||||
defer fs.mu.Unlock()
|
defer fs.mu.Unlock()
|
||||||
|
@ -311,38 +342,36 @@ func (fs *cachingFS) GetInodeAttributes(
|
||||||
var attrs fuseops.InodeAttributes
|
var attrs fuseops.InodeAttributes
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case req.Inode == fuseops.RootInodeID:
|
case op.Inode == fuseops.RootInodeID:
|
||||||
attrs = fs.rootAttrs()
|
attrs = fs.rootAttrs()
|
||||||
|
|
||||||
case req.Inode%numInodes == fooOffset:
|
case op.Inode%numInodes == fooOffset:
|
||||||
attrs = fs.fooAttrs()
|
attrs = fs.fooAttrs()
|
||||||
|
|
||||||
case req.Inode%numInodes == dirOffset:
|
case op.Inode%numInodes == dirOffset:
|
||||||
attrs = fs.dirAttrs()
|
attrs = fs.dirAttrs()
|
||||||
|
|
||||||
case req.Inode%numInodes == barOffset:
|
case op.Inode%numInodes == barOffset:
|
||||||
attrs = fs.barAttrs()
|
attrs = fs.barAttrs()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in the response.
|
// Fill in the response.
|
||||||
resp.Attributes = attrs
|
op.Attributes = attrs
|
||||||
resp.AttributesExpiration = time.Now().Add(fs.getattrTimeout)
|
op.AttributesExpiration = time.Now().Add(fs.getattrTimeout)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *cachingFS) OpenDir(
|
func (fs *cachingFS) openDir(op *fuseops.OpenDirOp) {
|
||||||
ctx context.Context,
|
var err error
|
||||||
req *fuse.OpenDirRequest) (
|
defer func() { op.Respond(err) }()
|
||||||
resp *fuse.OpenDirResponse, err error) {
|
|
||||||
resp = &fuse.OpenDirResponse{}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *cachingFS) OpenFile(
|
func (fs *cachingFS) openFile(op *fuseops.OpenFileOp) {
|
||||||
ctx context.Context,
|
var err error
|
||||||
req *fuse.OpenFileRequest) (
|
defer func() { op.Respond(err) }()
|
||||||
resp *fuse.OpenFileResponse, err error) {
|
|
||||||
resp = &fuse.OpenFileResponse{}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue