Commit 8edb1e8f authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Use HandleMap for remembering inodes.

parent a3b1fcbf
...@@ -118,6 +118,7 @@ var paranoia = false ...@@ -118,6 +118,7 @@ var paranoia = false
// TODO should rename to dentry? // TODO should rename to dentry?
type inode struct { type inode struct {
Handled
Parent *inode Parent *inode
Children map[string]*inode Children map[string]*inode
NodeId uint64 NodeId uint64
...@@ -305,22 +306,15 @@ type FileSystemConnector struct { ...@@ -305,22 +306,15 @@ type FileSystemConnector struct {
Debug bool Debug bool
//////////////// ////////////////
inodeMap *HandleMap
// inodeMapMutex protects inodeMap
inodeMapMutex sync.Mutex
// Invariants: see the verify() method.
inodeMap map[uint64]*inode
rootNode *inode rootNode *inode
} }
func (me *FileSystemConnector) Statistics() string { func (me *FileSystemConnector) Statistics() string {
root := me.rootNode root := me.rootNode
me.inodeMapMutex.Lock()
defer me.inodeMapMutex.Unlock()
return fmt.Sprintf("Mounts %20d\nFiles %20d\nInodes %20d\n", return fmt.Sprintf("Mounts %20d\nFiles %20d\nInodes %20d\n",
root.TotalMountCount(), root.TotalMountCount(),
root.TotalOpenCount(), len(me.inodeMap)) root.TotalOpenCount(), me.inodeMap.Count())
} }
func (me *FileSystemConnector) decodeFileHandle(h uint64) *fileBridge { func (me *FileSystemConnector) decodeFileHandle(h uint64) *fileBridge {
...@@ -347,28 +341,18 @@ func (me *FileSystemConnector) verify() { ...@@ -347,28 +341,18 @@ func (me *FileSystemConnector) verify() {
if !paranoia { if !paranoia {
return return
} }
me.inodeMapMutex.Lock() me.inodeMap.verify()
defer me.inodeMapMutex.Unlock()
for k, v := range me.inodeMap {
if v.NodeId != k {
panic(fmt.Sprintf("nodeid mismatch %v %v", v, k))
}
}
root := me.rootNode root := me.rootNode
root.verify(me.rootNode.mountPoint) root.verify(me.rootNode.mountPoint)
} }
func (me *FileSystemConnector) newInode(root bool, isDir bool) *inode { func (me *FileSystemConnector) newInode(root bool, isDir bool) *inode {
data := new(inode) data := new(inode)
data.NodeId = me.inodeMap.Register(&data.Handled)
if root { if root {
data.NodeId = FUSE_ROOT_ID
me.rootNode = data me.rootNode = data
} else { data.NodeId = FUSE_ROOT_ID
data.NodeId = uint64(uintptr(unsafe.Pointer(data)))
} }
me.inodeMap[data.NodeId] = data
if isDir { if isDir {
data.Children = make(map[string]*inode, initDirSize) data.Children = make(map[string]*inode, initDirSize)
} }
...@@ -397,8 +381,7 @@ func (me *FileSystemConnector) getInodeData(nodeid uint64) *inode { ...@@ -397,8 +381,7 @@ func (me *FileSystemConnector) getInodeData(nodeid uint64) *inode {
if nodeid == FUSE_ROOT_ID { if nodeid == FUSE_ROOT_ID {
return me.rootNode return me.rootNode
} }
return (*inode)(unsafe.Pointer(DecodeHandle(nodeid)))
return (*inode)(unsafe.Pointer(uintptr(nodeid)))
} }
func (me *FileSystemConnector) forgetUpdate(nodeId uint64, forgetCount int) { func (me *FileSystemConnector) forgetUpdate(nodeId uint64, forgetCount int) {
...@@ -419,10 +402,9 @@ func (me *FileSystemConnector) considerDropInode(n *inode) { ...@@ -419,10 +402,9 @@ func (me *FileSystemConnector) considerDropInode(n *inode) {
n.OpenCount <= 0 n.OpenCount <= 0
if dropInode { if dropInode {
n.setParent(nil) n.setParent(nil)
if n != me.rootNode {
me.inodeMapMutex.Lock() me.inodeMap.Forget(n.NodeId)
defer me.inodeMapMutex.Unlock() }
me.inodeMap[n.NodeId] = nil, false
} }
} }
...@@ -488,7 +470,7 @@ func (me *FileSystemConnector) findInode(fullPath string) *inode { ...@@ -488,7 +470,7 @@ func (me *FileSystemConnector) findInode(fullPath string) *inode {
func EmptyFileSystemConnector() (out *FileSystemConnector) { func EmptyFileSystemConnector() (out *FileSystemConnector) {
out = new(FileSystemConnector) out = new(FileSystemConnector)
out.inodeMap = make(map[uint64]*inode) out.inodeMap = NewHandleMap()
rootData := out.newInode(true, true) rootData := out.newInode(true, true)
rootData.Children = make(map[string]*inode, initDirSize) rootData.Children = make(map[string]*inode, initDirSize)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment