Commit 76583006 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Hide members of inode.

parent 94429a4b
package fuse
// This file contains the internal logic of the
// FileSystemConnector. The functions for satisfying the raw interface are in
// fsops.go
......@@ -43,7 +42,7 @@ func NewFileSystemConnector(fs FileSystem, opts *FileSystemOptions) (me *FileSys
}
me.inodeMap = NewHandleMap(!opts.SkipCheckHandles)
me.rootNode = me.newInode(true)
me.rootNode.NodeId = FUSE_ROOT_ID
me.rootNode.nodeId = FUSE_ROOT_ID
me.verify()
me.mountRoot(fs, opts)
return me
......@@ -59,11 +58,11 @@ func (me *FileSystemConnector) verify() {
func (me *FileSystemConnector) newInode(isDir bool) *inode {
data := new(inode)
data.NodeId = me.inodeMap.Register(&data.Handled)
data.nodeId = me.inodeMap.Register(&data.handled)
data.fsInode = new(fsInode)
data.fsInode.inode = data
if isDir {
data.Children = make(map[string]*inode, initDirSize)
data.children = make(map[string]*inode, initDirSize)
}
return data
......@@ -75,29 +74,29 @@ func (me *FileSystemConnector) lookupUpdate(parent *inode, name string, isDir bo
parent.treeLock.Lock()
defer parent.treeLock.Unlock()
data, ok := parent.Children[name]
data, ok := parent.children[name]
if !ok {
data = me.newInode(isDir)
parent.addChild(name, data)
data.mount = parent.mount
data.treeLock = &data.mount.treeLock
}
data.LookupCount += lookupCount
data.lookupCount += lookupCount
return data
}
func (me *FileSystemConnector) lookupMount(parent *inode, name string, lookupCount int) (mount *fileSystemMount) {
parent.treeLock.RLock()
defer parent.treeLock.RUnlock()
if parent.Mounts == nil {
if parent.mounts == nil {
return nil
}
mount, ok := parent.Mounts[name]
mount, ok := parent.mounts[name]
if ok {
mount.treeLock.Lock()
defer mount.treeLock.Unlock()
mount.mountInode.LookupCount += lookupCount
mount.mountInode.lookupCount += lookupCount
return mount
}
return nil
......@@ -118,13 +117,13 @@ func (me *FileSystemConnector) forgetUpdate(nodeId uint64, forgetCount int) {
node.treeLock.Lock()
defer node.treeLock.Unlock()
node.LookupCount -= forgetCount
node.lookupCount -= forgetCount
me.considerDropInode(node)
}
func (me *FileSystemConnector) considerDropInode(n *inode) (drop bool) {
delChildren := []string{}
for k, v := range n.Children {
for k, v := range n.children {
if v.mountPoint == nil && me.considerDropInode(v) {
delChildren = append(delChildren, k)
}
......@@ -134,19 +133,19 @@ func (me *FileSystemConnector) considerDropInode(n *inode) (drop bool) {
if ch == nil {
panic(fmt.Sprintf("trying to del child %q, but not present", k))
}
me.inodeMap.Forget(ch.NodeId)
me.inodeMap.Forget(ch.nodeId)
}
if len(n.Children) > 0 || n.LookupCount > 0 {
if len(n.children) > 0 || n.lookupCount > 0 {
return false
}
if n == me.rootNode || n.mountPoint != nil {
return false
}
n.OpenFilesMutex.Lock()
defer n.OpenFilesMutex.Unlock()
return len(n.OpenFiles) == 0
n.openFilesMutex.Lock()
defer n.openFilesMutex.Unlock()
return len(n.openFiles) == 0
}
func (me *FileSystemConnector) renameUpdate(oldParent *inode, oldName string, newParent *inode, newName string) {
......@@ -196,7 +195,7 @@ func (me *FileSystemConnector) findLastKnownInode(fullPath string) (*inode, []st
defer node.mountPoint.treeLock.RUnlock()
}
next := node.Children[component]
next := node.children[component]
if next == nil {
return node, comps[i:]
}
......@@ -250,7 +249,7 @@ func (me *FileSystemConnector) Mount(mountPoint string, fs FileSystem, opts *Fil
if parent.mount == nil {
return ENOENT
}
node := parent.Children[base]
node := parent.children[base]
if node != nil {
return EBUSY
}
......@@ -263,10 +262,10 @@ func (me *FileSystemConnector) Mount(mountPoint string, fs FileSystem, opts *Fil
node.mountFs(fs, opts)
parent.addChild(base, node)
if parent.Mounts == nil {
parent.Mounts = make(map[string]*fileSystemMount)
if parent.mounts == nil {
parent.mounts = make(map[string]*fileSystemMount)
}
parent.Mounts[base] = node.mountPoint
parent.mounts[base] = node.mountPoint
if me.Debug {
log.Println("Mount: ", fs, "on dir", mountPoint,
"parent", parent)
......@@ -301,7 +300,7 @@ func (me *FileSystemConnector) Unmount(path string) Status {
parentNode.treeLock.Lock()
defer parentNode.treeLock.Unlock()
mount := parentNode.Mounts[name]
mount := parentNode.mounts[name]
if mount == nil {
return EINVAL
}
......@@ -318,11 +317,11 @@ func (me *FileSystemConnector) Unmount(path string) Status {
mount.mountInode = nil
mountInode.mountPoint = nil
parentNode.Mounts[name] = nil, false
parentNode.Children[name] = nil, false
parentNode.mounts[name] = nil, false
parentNode.children[name] = nil, false
mount.fs.Unmount()
me.fsInit.EntryNotify(parentNode.NodeId, name)
me.fsInit.EntryNotify(parentNode.nodeId, name)
return OK
}
......@@ -336,7 +335,7 @@ func (me *FileSystemConnector) FileNotify(path string, off int64, length int64)
out := NotifyInvalInodeOut{
Length: length,
Off: off,
Ino: node.NodeId,
Ino: node.nodeId,
}
return me.fsInit.InodeNotify(&out)
}
......@@ -347,16 +346,16 @@ func (me *FileSystemConnector) EntryNotify(dir string, name string) Status {
return ENOENT
}
return me.fsInit.EntryNotify(node.NodeId, name)
return me.fsInit.EntryNotify(node.nodeId, name)
}
func (me *FileSystemConnector) Notify(path string) Status {
node, rest := me.findLastKnownInode(path)
if len(rest) > 0 {
return me.fsInit.EntryNotify(node.NodeId, rest[0])
return me.fsInit.EntryNotify(node.nodeId, rest[0])
}
out := NotifyInvalInodeOut{
Ino: node.NodeId,
Ino: node.nodeId,
}
return me.fsInit.InodeNotify(&out)
}
......@@ -70,27 +70,27 @@ func (me *FileSystemConnector) getOpenedFile(h uint64) *openedFile {
func (me *fileSystemMount) unregisterFileHandle(handle uint64, node *inode) *openedFile {
obj := me.openFiles.Forget(handle)
opened := (*openedFile)(unsafe.Pointer(obj))
node.OpenFilesMutex.Lock()
defer node.OpenFilesMutex.Unlock()
node.openFilesMutex.Lock()
defer node.openFilesMutex.Unlock()
idx := -1
for i, v := range node.OpenFiles {
for i, v := range node.openFiles {
if v == opened {
idx = i
break
}
}
l := len(node.OpenFiles)
node.OpenFiles[idx] = node.OpenFiles[l-1]
node.OpenFiles = node.OpenFiles[:l-1]
l := len(node.openFiles)
node.openFiles[idx] = node.openFiles[l-1]
node.openFiles = node.openFiles[:l-1]
return opened
}
func (me *fileSystemMount) registerFileHandle(node *inode, dir rawDir, f File, flags uint32) (uint64, *openedFile) {
node.OpenFilesMutex.Lock()
defer node.OpenFilesMutex.Unlock()
node.openFilesMutex.Lock()
defer node.openFilesMutex.Unlock()
b := &openedFile{
dir: dir,
file: f,
......@@ -103,7 +103,7 @@ func (me *fileSystemMount) registerFileHandle(node *inode, dir rawDir, f File, f
f = withFlags.File
}
node.OpenFiles = append(node.OpenFiles, b)
node.openFiles = append(node.openFiles, b)
handle := me.openFiles.Register(&b.Handled)
return handle, b
}
......@@ -32,9 +32,9 @@ func (me *FileSystemConnector) internalMountLookup(mount *fileSystemMount, looku
}
mount.treeLock.Lock()
defer mount.treeLock.Unlock()
mount.mountInode.LookupCount += lookupCount
mount.mountInode.lookupCount += lookupCount
out = &EntryOut{
NodeId: mount.mountInode.NodeId,
NodeId: mount.mountInode.nodeId,
Generation: 1, // where to get the generation?
}
mount.fileInfoToEntry(fi, out)
......@@ -56,11 +56,11 @@ func (me *FileSystemConnector) internalLookup(parent *inode, name string, lookup
}
node = me.lookupUpdate(parent, name, fi.IsDirectory(), lookupCount)
out = &EntryOut{
NodeId: node.NodeId,
NodeId: node.nodeId,
Generation: 1, // where to get the generation?
}
parent.mount.fileInfoToEntry(fi, out)
out.Attr.Ino = node.NodeId
out.Attr.Ino = node.nodeId
return out, OK, node
}
......
......@@ -7,14 +7,14 @@ import (
// The inode reflects the kernel's idea of the inode.
type inode struct {
Handled
handled Handled
// Constant during lifetime.
NodeId uint64
nodeId uint64
// Number of open files and its protection.
OpenFilesMutex sync.Mutex
OpenFiles []*openedFile
openFilesMutex sync.Mutex
openFiles []*openedFile
// treeLock is a pointer to me.mount.treeLock; we need store
// this mutex separately, since unmount may set me.mount = nil
......@@ -27,12 +27,12 @@ type inode struct {
// All data below is protected by treeLock.
fsInode *fsInode
Children map[string]*inode
children map[string]*inode
// Contains directories that function as mounts. The entries
// are duplicated in Children.
Mounts map[string]*fileSystemMount
LookupCount int
// are duplicated in children.
mounts map[string]*fileSystemMount
lookupCount int
// Non-nil if this is a mountpoint.
mountPoint *fileSystemMount
......@@ -46,21 +46,21 @@ type inode struct {
// Must be called with treeLock for the mount held.
func (me *inode) addChild(name string, child *inode) {
if paranoia {
ch := me.Children[name]
ch := me.children[name]
if ch != nil {
panic(fmt.Sprintf("Already have an inode with same name: %v: %v", name, ch))
}
}
me.Children[name] = child
me.children[name] = child
me.fsInode.addChild(name, child.fsInode)
}
// Must be called with treeLock for the mount held.
func (me *inode) rmChild(name string) (ch *inode) {
ch = me.Children[name]
ch = me.children[name]
if ch != nil {
me.Children[name] = nil, false
me.children[name] = nil, false
me.fsInode.rmChild(name, ch.fsInode)
}
return ch
......@@ -80,7 +80,7 @@ func (me *inode) mountFs(fs FileSystem, opts *FileSystemOptions) {
// Must be called with treeLock held.
func (me *inode) canUnmount() bool {
for _, v := range me.Children {
for _, v := range me.children {
if v.mountPoint != nil {
// This access may be out of date, but it is no
// problem to err on the safe side.
......@@ -91,20 +91,20 @@ func (me *inode) canUnmount() bool {
}
}
me.OpenFilesMutex.Lock()
defer me.OpenFilesMutex.Unlock()
return len(me.OpenFiles) == 0
me.openFilesMutex.Lock()
defer me.openFilesMutex.Unlock()
return len(me.openFiles) == 0
}
func (me *inode) IsDir() bool {
return me.Children != nil
return me.children != nil
}
func (me *inode) getMountDirEntries() (out []DirEntry) {
me.treeLock.RLock()
defer me.treeLock.RUnlock()
for k, _ := range me.Mounts {
for k, _ := range me.mounts {
out = append(out, DirEntry{
Name: k,
Mode: S_IFDIR,
......@@ -115,10 +115,10 @@ func (me *inode) getMountDirEntries() (out []DirEntry) {
// Returns any open file, preferably a r/w one.
func (me *inode) getAnyFile() (file File) {
me.OpenFilesMutex.Lock()
defer me.OpenFilesMutex.Unlock()
me.openFilesMutex.Lock()
defer me.openFilesMutex.Unlock()
for _, f := range me.OpenFiles {
for _, f := range me.openFiles {
if file == nil || f.OpenFlags & O_ANYWRITE != 0 {
file = f.file
}
......@@ -128,10 +128,10 @@ func (me *inode) getAnyFile() (file File) {
// Returns an open writable file for the given inode.
func (me *inode) getWritableFiles() (files []File) {
me.OpenFilesMutex.Lock()
defer me.OpenFilesMutex.Unlock()
me.openFilesMutex.Lock()
defer me.openFilesMutex.Unlock()
for _, f := range me.OpenFiles {
for _, f := range me.openFiles {
if f.OpenFlags & O_ANYWRITE != 0 {
files = append(files, f.file)
}
......@@ -152,14 +152,14 @@ func (me *inode) verify(cur *fileSystemMount) {
panic(fmt.Sprintf("me.mount not set correctly %v %v", me.mount, cur))
}
for name, m := range me.Mounts {
if m.mountInode != me.Children[name] {
for name, m := range me.mounts {
if m.mountInode != me.children[name] {
panic(fmt.Sprintf("mountpoint parent mismatch: node:%v name:%v ch:%v",
me.mountPoint, name, me.Children))
me.mountPoint, name, me.children))
}
}
for _, ch := range me.Children {
for _, ch := range me.children {
if ch == nil {
panic("Found nil child.")
}
......
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