Reworked inode numbering.
parent
064452dcc9
commit
8a4e3f242d
|
@ -15,14 +15,20 @@
|
||||||
package cachingfs
|
package cachingfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jacobsa/fuse"
|
"github.com/jacobsa/fuse"
|
||||||
"github.com/jacobsa/fuse/fuseutil"
|
"github.com/jacobsa/fuse/fuseutil"
|
||||||
|
"github.com/jacobsa/gcloud/syncutil"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Sizes of the files according to the file system.
|
||||||
|
FooSize = 123
|
||||||
|
BarSize = 456
|
||||||
|
)
|
||||||
|
|
||||||
// A file system with a fixed structure that looks like this:
|
// A file system with a fixed structure that looks like this:
|
||||||
//
|
//
|
||||||
// foo
|
// foo
|
||||||
|
@ -64,32 +70,60 @@ type CachingFS interface {
|
||||||
func NewCachingFS(
|
func NewCachingFS(
|
||||||
lookupEntryTimeout time.Duration,
|
lookupEntryTimeout time.Duration,
|
||||||
getattrTimeout time.Duration) (fs CachingFS, err error) {
|
getattrTimeout time.Duration) (fs CachingFS, err error) {
|
||||||
fs = &cachingFS{
|
cfs := &cachingFS{
|
||||||
inodeIDBase: fuse.RootInodeID + 1,
|
fooID: ((fuse.RootInodeID + 1 + numInodes - 1) / numInodes) + fooOffset,
|
||||||
mtime: time.Now(),
|
mtime: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfs.mu = syncutil.NewInvariantMutex(cfs.checkInvariants)
|
||||||
|
|
||||||
|
fs = cfs
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Inode IDs are issued such that "foo" always receives an ID that is
|
||||||
|
// congruent to fooOffset modulo numInodes, etc.
|
||||||
|
fooOffset = iota
|
||||||
|
dirOffset
|
||||||
|
barOffset
|
||||||
|
numInodes
|
||||||
|
)
|
||||||
|
|
||||||
type cachingFS struct {
|
type cachingFS struct {
|
||||||
fuseutil.NotImplementedFileSystem
|
fuseutil.NotImplementedFileSystem
|
||||||
mu sync.Mutex
|
mu syncutil.InvariantMutex
|
||||||
|
|
||||||
|
// The current ID of foo.
|
||||||
|
//
|
||||||
|
// INVARIANT: FooID() > fuse.RootInodeID
|
||||||
|
// INVARIANT: DirID() > fuse.RootInodeID
|
||||||
|
// INVARIANT: BarID() > fuse.RootInodeID
|
||||||
|
//
|
||||||
|
// INVARIANT: FooID() % numInodes == fooOffset
|
||||||
|
// INVARIANT: DirID() % numInodes == dirOffset
|
||||||
|
// INVARIANT: BarID() % numInodes == barOffset
|
||||||
|
//
|
||||||
// GUARDED_BY(mu)
|
// GUARDED_BY(mu)
|
||||||
inodeIDBase fuse.InodeID
|
fooID fuse.InodeID
|
||||||
|
|
||||||
// GUARDED_BY(mu)
|
// GUARDED_BY(mu)
|
||||||
mtime time.Time
|
mtime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOCKS_EXCLUDED(fs.mu)
|
func (fs *cachingFS) checkInvariants()
|
||||||
func (fs *cachingFS) RenumberInodes(base fuse.InodeID) {
|
|
||||||
fs.mu.Lock()
|
|
||||||
defer fs.mu.Unlock()
|
|
||||||
|
|
||||||
fs.inodeIDBase = base
|
// LOCKS_EXCLUDED(fs.mu)
|
||||||
}
|
func (fs *cachingFS) FooID() fuse.InodeID
|
||||||
|
|
||||||
|
// LOCKS_EXCLUDED(fs.mu)
|
||||||
|
func (fs *cachingFS) DirID() fuse.InodeID
|
||||||
|
|
||||||
|
// LOCKS_EXCLUDED(fs.mu)
|
||||||
|
func (fs *cachingFS) BarID() fuse.InodeID
|
||||||
|
|
||||||
|
// LOCKS_EXCLUDED(fs.mu)
|
||||||
|
func (fs *cachingFS) RenumberInodes()
|
||||||
|
|
||||||
// LOCKS_EXCLUDED(fs.mu)
|
// LOCKS_EXCLUDED(fs.mu)
|
||||||
func (fs *cachingFS) SetMtime(mtime time.Time) {
|
func (fs *cachingFS) SetMtime(mtime time.Time) {
|
||||||
|
|
Loading…
Reference in New Issue