Added fsImpl members.
parent
a37b22d786
commit
b2b1b6a4ef
|
@ -18,6 +18,7 @@ import (
|
||||||
"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/fuse/fuseutil"
|
||||||
|
"github.com/jacobsa/gcloud/syncutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create a file system whose sole contents are a file named "foo" and a
|
// Create a file system whose sole contents are a file named "foo" and a
|
||||||
|
@ -34,8 +35,19 @@ import (
|
||||||
// there are no inodes with non-zero reference counts remaining, after
|
// there are no inodes with non-zero reference counts remaining, after
|
||||||
// unmounting.
|
// unmounting.
|
||||||
func NewFileSystem() (fs *ForgetFS) {
|
func NewFileSystem() (fs *ForgetFS) {
|
||||||
impl := &fsImpl{}
|
// Set up the actual file system.
|
||||||
|
impl := &fsImpl{
|
||||||
|
inodes: map[fuseops.InodeID]*inode{
|
||||||
|
cannedID_Root: &inode{},
|
||||||
|
cannedID_Foo: &inode{},
|
||||||
|
cannedID_Bar: &inode{},
|
||||||
|
},
|
||||||
|
nextInodeID: cannedID_Next,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl.mu = syncutil.NewInvariantMutex(impl.checkInvariants)
|
||||||
|
|
||||||
|
// Set up a wrapper that exposes only certain methods.
|
||||||
fs = &ForgetFS{
|
fs = &ForgetFS{
|
||||||
impl: impl,
|
impl: impl,
|
||||||
server: fuseutil.NewFileSystemServer(impl),
|
server: fuseutil.NewFileSystemServer(impl),
|
||||||
|
@ -67,10 +79,45 @@ func (fs *ForgetFS) Check() {
|
||||||
// Actual implementation
|
// Actual implementation
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
const (
|
||||||
|
cannedID_Root = fuseops.RootInodeID + iota
|
||||||
|
cannedID_Foo
|
||||||
|
cannedID_Bar
|
||||||
|
cannedID_Next
|
||||||
|
)
|
||||||
|
|
||||||
type fsImpl struct {
|
type fsImpl struct {
|
||||||
fuseutil.NotImplementedFileSystem
|
fuseutil.NotImplementedFileSystem
|
||||||
|
|
||||||
|
/////////////////////////
|
||||||
|
// Mutable state
|
||||||
|
/////////////////////////
|
||||||
|
|
||||||
|
mu syncutil.InvariantMutex
|
||||||
|
|
||||||
|
// An index of inode by ID, for all IDs we have issued.
|
||||||
|
//
|
||||||
|
// INVARIANT: For each v, v.lookupCount >= 0
|
||||||
|
//
|
||||||
|
// GUARDED_BY(mu)
|
||||||
|
inodes map[fuseops.InodeID]*inode
|
||||||
|
|
||||||
|
// The next ID to issue.
|
||||||
|
//
|
||||||
|
// INVARIANT: For each k in inodes, k < nextInodeID
|
||||||
|
//
|
||||||
|
// GUARDED_BY(mu)
|
||||||
|
nextInodeID fuseops.InodeID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type inode struct {
|
||||||
|
// The current lookup count.
|
||||||
|
lookupCount int
|
||||||
|
}
|
||||||
|
|
||||||
|
// LOCKS_REQUIRED(fs.mu)
|
||||||
|
func (fs *fsImpl) checkInvariants()
|
||||||
|
|
||||||
func (fs *fsImpl) Init(
|
func (fs *fsImpl) Init(
|
||||||
op *fuseops.InitOp) {
|
op *fuseops.InitOp) {
|
||||||
var err error
|
var err error
|
||||||
|
|
|
@ -42,7 +42,11 @@ func (t *ForgetFSTest) SetUp(ti *TestInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ForgetFSTest) TearDown() {
|
func (t *ForgetFSTest) TearDown() {
|
||||||
panic("TODO: Unmount then call Check")
|
// Unmount.
|
||||||
|
t.SampleTest.TearDown()
|
||||||
|
|
||||||
|
// Crash if anything is left.
|
||||||
|
t.fs.Check()
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue