Commit 608f78e2 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Rename mountData to fileSystemMount.

parent a9652704
...@@ -30,7 +30,7 @@ import ( ...@@ -30,7 +30,7 @@ import (
// openedFile stores either an open dir or an open file. // openedFile stores either an open dir or an open file.
type openedFile struct { type openedFile struct {
Handled Handled
*mountData *fileSystemMount
*inode *inode
Flags uint32 Flags uint32
...@@ -38,12 +38,12 @@ type openedFile struct { ...@@ -38,12 +38,12 @@ type openedFile struct {
file File file File
} }
type mountData struct { type fileSystemMount struct {
// If non-nil the file system mounted here. // If non-nil the file system mounted here.
fs FileSystem fs FileSystem
// Node that we were mounted on. // Node that we were mounted on.
mountPoint *inode mountInode *inode
// We could have separate treeLocks per mount; something to // We could have separate treeLocks per mount; something to
// consider if we can measure significant contention for // consider if we can measure significant contention for
...@@ -58,20 +58,20 @@ type mountData struct { ...@@ -58,20 +58,20 @@ type mountData struct {
openFiles *HandleMap openFiles *HandleMap
} }
func newMount(fs FileSystem) *mountData { func newMount(fs FileSystem) *fileSystemMount {
return &mountData{ return &fileSystemMount{
fs: fs, fs: fs,
openFiles: NewHandleMap(), openFiles: NewHandleMap(),
} }
} }
func (me *mountData) setOwner(attr *Attr) { func (me *fileSystemMount) setOwner(attr *Attr) {
if me.options.Owner != nil { if me.options.Owner != nil {
attr.Owner = *me.options.Owner attr.Owner = *me.options.Owner
} }
} }
func (me *mountData) unregisterFileHandle(node *inode, handle uint64) *openedFile { func (me *fileSystemMount) unregisterFileHandle(node *inode, handle uint64) *openedFile {
obj := me.openFiles.Forget(handle) obj := me.openFiles.Forget(handle)
opened := (*openedFile)(unsafe.Pointer(obj)) opened := (*openedFile)(unsafe.Pointer(obj))
...@@ -82,14 +82,14 @@ func (me *mountData) unregisterFileHandle(node *inode, handle uint64) *openedFil ...@@ -82,14 +82,14 @@ func (me *mountData) unregisterFileHandle(node *inode, handle uint64) *openedFil
return opened return opened
} }
func (me *mountData) registerFileHandle(node *inode, dir rawDir, f File, flags uint32) uint64 { func (me *fileSystemMount) registerFileHandle(node *inode, dir rawDir, f File, flags uint32) uint64 {
node.OpenCountMutex.Lock() node.OpenCountMutex.Lock()
defer node.OpenCountMutex.Unlock() defer node.OpenCountMutex.Unlock()
b := &openedFile{ b := &openedFile{
dir: dir, dir: dir,
file: f, file: f,
inode: node, inode: node,
mountData: me, fileSystemMount: me,
Flags: flags, Flags: flags,
} }
node.OpenCount++ node.OpenCount++
...@@ -126,16 +126,16 @@ type inode struct { ...@@ -126,16 +126,16 @@ type inode struct {
Name string Name string
Parent *inode Parent *inode
Children map[string]*inode Children map[string]*inode
Mounts map[string]*mountData Mounts map[string]*fileSystemMount
LookupCount int LookupCount int
// Non-nil if this is a mountpoint. // Non-nil if this is a mountpoint.
mountPoint *mountData mountPoint *fileSystemMount
// The file system to which this node belongs. Is constant // The file system to which this node belongs. Is constant
// during the lifetime, except upon Unmount() when it is set // during the lifetime, except upon Unmount() when it is set
// to nil. // to nil.
mount *mountData mount *fileSystemMount
} }
// Must be called with treeLock held. // Must be called with treeLock held.
...@@ -183,13 +183,13 @@ func (me *inode) GetMountDirEntries() (out []DirEntry) { ...@@ -183,13 +183,13 @@ func (me *inode) GetMountDirEntries() (out []DirEntry) {
const initDirSize = 20 const initDirSize = 20
func (me *inode) verify(cur *mountData) { func (me *inode) verify(cur *fileSystemMount) {
if !(me.NodeId == FUSE_ROOT_ID || me.LookupCount > 0 || len(me.Children) > 0 || me.mountPoint != nil) { if !(me.NodeId == FUSE_ROOT_ID || me.LookupCount > 0 || len(me.Children) > 0 || me.mountPoint != nil) {
p, _ := me.GetPath() p, _ := me.GetPath()
panic(fmt.Sprintf("node %v %d should be dead: %v %v", p, me.NodeId, len(me.Children), me.LookupCount)) panic(fmt.Sprintf("node %v %d should be dead: %v %v", p, me.NodeId, len(me.Children), me.LookupCount))
} }
if me.mountPoint != nil { if me.mountPoint != nil {
if me != me.mountPoint.mountPoint { if me != me.mountPoint.mountInode {
panic("mountpoint mismatch") panic("mountpoint mismatch")
} }
cur = me.mountPoint cur = me.mountPoint
...@@ -199,12 +199,11 @@ func (me *inode) verify(cur *mountData) { ...@@ -199,12 +199,11 @@ func (me *inode) verify(cur *mountData) {
} }
for name, m := range me.Mounts { for name, m := range me.Mounts {
if m.mountPoint != me.Children[name] { if m.mountInode != me.Children[name] {
panic(fmt.Sprintf("mountpoint parent mismatch: node:%v name:%v ch:%v", panic(fmt.Sprintf("mountpoint parent mismatch: node:%v name:%v ch:%v",
me.mountPoint, name, me.Children)) me.mountPoint, name, me.Children))
} }
} }
for n, ch := range me.Children { for n, ch := range me.Children {
if ch == nil { if ch == nil {
panic("Found nil child.") panic("Found nil child.")
...@@ -233,7 +232,7 @@ func (me *inode) GetFullPath() (path string) { ...@@ -233,7 +232,7 @@ func (me *inode) GetFullPath() (path string) {
// GetPath returns the path relative to the mount governing this // GetPath returns the path relative to the mount governing this
// inode. It returns nil for mount if the file was deleted or the // inode. It returns nil for mount if the file was deleted or the
// filesystem unmounted. // filesystem unmounted.
func (me *inode) GetPath() (path string, mount *mountData) { func (me *inode) GetPath() (path string, mount *fileSystemMount) {
me.treeLock.RLock() me.treeLock.RLock()
defer me.treeLock.RUnlock() defer me.treeLock.RUnlock()
if me.mount == nil { if me.mount == nil {
...@@ -359,7 +358,7 @@ func (me *FileSystemConnector) lookupUpdate(parent *inode, name string, isDir bo ...@@ -359,7 +358,7 @@ func (me *FileSystemConnector) lookupUpdate(parent *inode, name string, isDir bo
return data return data
} }
func (me *FileSystemConnector) lookupMount(parent *inode, name string, lookupCount int) (path string, mount *mountData, isMount bool) { func (me *FileSystemConnector) lookupMount(parent *inode, name string, lookupCount int) (path string, mount *fileSystemMount, isMount bool) {
parent.treeLock.RLock() parent.treeLock.RLock()
defer parent.treeLock.RUnlock() defer parent.treeLock.RUnlock()
if parent.Mounts == nil { if parent.Mounts == nil {
...@@ -370,7 +369,7 @@ func (me *FileSystemConnector) lookupMount(parent *inode, name string, lookupCou ...@@ -370,7 +369,7 @@ func (me *FileSystemConnector) lookupMount(parent *inode, name string, lookupCou
if ok { if ok {
mount.treeLock.Lock() mount.treeLock.Lock()
defer mount.treeLock.Unlock() defer mount.treeLock.Unlock()
mount.mountPoint.LookupCount += lookupCount mount.mountInode.LookupCount += lookupCount
return "", mount, true return "", mount, true
} }
return "", nil, false return "", nil, false
...@@ -536,10 +535,10 @@ func (me *FileSystemConnector) Mount(mountPoint string, fs FileSystem, opts *Fil ...@@ -536,10 +535,10 @@ func (me *FileSystemConnector) Mount(mountPoint string, fs FileSystem, opts *Fil
node.mountPoint = newMount(fs) node.mountPoint = newMount(fs)
node.treeLock = &node.mountPoint.treeLock node.treeLock = &node.mountPoint.treeLock
node.mount = node.mountPoint node.mount = node.mountPoint
node.mountPoint.mountPoint = node node.mountPoint.mountInode = node
if parent != nil { if parent != nil {
if parent.Mounts == nil { if parent.Mounts == nil {
parent.Mounts = make(map[string]*mountData) parent.Mounts = make(map[string]*fileSystemMount)
} }
parent.Mounts[node.Name] = node.mountPoint parent.Mounts[node.Name] = node.mountPoint
} }
...@@ -607,7 +606,7 @@ func (me *FileSystemConnector) unsafeUnmountNode(node *inode) { ...@@ -607,7 +606,7 @@ func (me *FileSystemConnector) unsafeUnmountNode(node *inode) {
} }
node.recursiveUnmount() node.recursiveUnmount()
unmounted := node.mountPoint unmounted := node.mountPoint
unmounted.mountPoint = nil unmounted.mountInode = nil
node.mountPoint = nil node.mountPoint = nil
parentNode := node.Parent parentNode := node.Parent
...@@ -619,7 +618,7 @@ func (me *FileSystemConnector) unsafeUnmountNode(node *inode) { ...@@ -619,7 +618,7 @@ func (me *FileSystemConnector) unsafeUnmountNode(node *inode) {
unmounted.fs.Unmount() unmounted.fs.Unmount()
} }
func (me *FileSystemConnector) GetPath(nodeid uint64) (path string, mount *mountData, node *inode) { func (me *FileSystemConnector) GetPath(nodeid uint64) (path string, mount *fileSystemMount, node *inode) {
n := me.getInodeData(nodeid) n := me.getInodeData(nodeid)
p, m := n.GetPath() p, m := n.GetPath()
...@@ -630,14 +629,14 @@ func (me *FileSystemConnector) GetPath(nodeid uint64) (path string, mount *mount ...@@ -630,14 +629,14 @@ func (me *FileSystemConnector) GetPath(nodeid uint64) (path string, mount *mount
return p, m, n return p, m, n
} }
func (me *FileSystemConnector) getOpenFileData(nodeid uint64, fh uint64) (f File, m *mountData, p string) { func (me *FileSystemConnector) getOpenFileData(nodeid uint64, fh uint64) (f File, m *fileSystemMount, p string) {
node := me.getInodeData(nodeid) node := me.getInodeData(nodeid)
node.treeLock.RLock() node.treeLock.RLock()
defer node.treeLock.RUnlock() defer node.treeLock.RUnlock()
if fh != 0 { if fh != 0 {
opened := me.getOpenedFile(fh) opened := me.getOpenedFile(fh)
m = opened.mountData m = opened.fileSystemMount
f = opened.file f = opened.file
} }
......
...@@ -39,7 +39,7 @@ func (me *FileSystemConnector) internalLookup(parent *inode, name string, lookup ...@@ -39,7 +39,7 @@ func (me *FileSystemConnector) internalLookup(parent *inode, name string, lookup
func (me *FileSystemConnector) internalLookupWithNode(parent *inode, name string, lookupCount int) (out *EntryOut, status Status, node *inode) { func (me *FileSystemConnector) internalLookupWithNode(parent *inode, name string, lookupCount int) (out *EntryOut, status Status, node *inode) {
fullPath, mount, isMountPoint := me.lookupMount(parent, name, lookupCount) fullPath, mount, isMountPoint := me.lookupMount(parent, name, lookupCount)
if isMountPoint { if isMountPoint {
node = mount.mountPoint node = mount.mountInode
} else { } else {
fullPath, mount = parent.GetPath() fullPath, mount = parent.GetPath()
fullPath = filepath.Join(fullPath, name) fullPath = filepath.Join(fullPath, name)
...@@ -101,7 +101,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out ...@@ -101,7 +101,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out
out = &AttrOut{} out = &AttrOut{}
CopyFileInfo(fi, &out.Attr) CopyFileInfo(fi, &out.Attr)
out.Attr.Ino = header.NodeId out.Attr.Ino = header.NodeId
SplitNs(opened.mountData.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec) SplitNs(opened.fileSystemMount.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec)
return out, OK return out, OK
} }
...@@ -412,7 +412,7 @@ func (me *FileSystemConnector) Flush(input *FlushIn) Status { ...@@ -412,7 +412,7 @@ func (me *FileSystemConnector) Flush(input *FlushIn) Status {
// We only signal releases to the FS if the // We only signal releases to the FS if the
// open could have changed things. // open could have changed things.
var path string var path string
var mount *mountData var mount *fileSystemMount
path, mount = opened.inode.GetPath() path, mount = opened.inode.GetPath()
if mount != nil { if mount != nil {
......
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