Commit 1229efb2 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Add FileSystemConnector.LookupNode().

parent 68e591c4
...@@ -212,6 +212,23 @@ func (me *FileSystemConnector) findInode(fullPath string) *Inode { ...@@ -212,6 +212,23 @@ func (me *FileSystemConnector) findInode(fullPath string) *Inode {
return n return n
} }
func (me *FileSystemConnector) LookupNode(parent *Inode, path string) *Inode {
if path == "" {
return parent
}
components := strings.Split(path, "/")
for _, r := range components {
_, child, _ := me.internalLookup(parent, r, nil)
if child == nil {
return nil
}
parent = child
}
return parent
}
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
func (me *FileSystemConnector) MountRoot(nodeFs NodeFileSystem, opts *FileSystemOptions) { func (me *FileSystemConnector) MountRoot(nodeFs NodeFileSystem, opts *FileSystemOptions) {
......
...@@ -142,9 +142,12 @@ func (me *fileSystemMount) registerFileHandle(node *Inode, dir rawDir, f File, f ...@@ -142,9 +142,12 @@ func (me *fileSystemMount) registerFileHandle(node *Inode, dir rawDir, f File, f
} }
// Creates a return entry for a non-existent path. // Creates a return entry for a non-existent path.
func (me *fileSystemMount) negativeEntry() *EntryOut { func (me *fileSystemMount) negativeEntry() (*EntryOut, Status) {
if me.options.NegativeTimeout > 0.0 {
out := new(EntryOut) out := new(EntryOut)
out.NodeId = 0 out.NodeId = 0
splitNs(me.options.NegativeTimeout, &out.EntryValid, &out.EntryValidNsec) splitNs(me.options.NegativeTimeout, &out.EntryValid, &out.EntryValidNsec)
return out return out, OK
}
return nil, ENOENT
} }
...@@ -15,37 +15,25 @@ func (me *FileSystemConnector) Init(fsInit *RawFsInit) { ...@@ -15,37 +15,25 @@ func (me *FileSystemConnector) Init(fsInit *RawFsInit) {
me.fsInit = *fsInit me.fsInit = *fsInit
} }
func (me *FileSystemConnector) lookupMountUpdate(mount *fileSystemMount) (out *EntryOut, status Status) { func (me *FileSystemConnector) lookupMountUpdate(mount *fileSystemMount) (fi *os.FileInfo, node *Inode, code Status) {
fi, err := mount.fs.Root().GetAttr(nil, nil) fi, code = mount.fs.Root().GetAttr(nil, nil)
if err == ENOENT && mount.options.NegativeTimeout > 0.0 { if !code.Ok() {
return mount.negativeEntry(), OK log.Println("Root getattr should not return error", code)
} return &os.FileInfo{Mode: S_IFDIR | 0755}, mount.mountInode, OK
if !err.Ok() {
return nil, err
} }
out = mount.fileInfoToEntry(fi) return fi, mount.mountInode, OK
out.NodeId = me.lookupUpdate(mount.mountInode)
out.Ino = out.NodeId
// We don't do NFS.
out.Generation = 1
return out, OK
} }
func (me *FileSystemConnector) Lookup(header *InHeader, name string) (out *EntryOut, code Status) { func (me *FileSystemConnector) internalLookup(parent *Inode, name string, context *Context) (fi *os.FileInfo, node *Inode, code Status) {
parent := me.toInode(header.NodeId)
context := &header.Context
if subMount := me.findMount(parent, name); subMount != nil { if subMount := me.findMount(parent, name); subMount != nil {
return me.lookupMountUpdate(subMount) return me.lookupMountUpdate(subMount)
} }
mount := parent.mount
child := parent.GetChild(name) child := parent.GetChild(name)
if child != nil { if child != nil {
parent = nil parent = nil
} }
var fi *os.FileInfo
var fsNode FsNode var fsNode FsNode
if child != nil { if child != nil {
fi, code = child.fsInode.GetAttr(nil, context) fi, code = child.fsInode.GetAttr(nil, context)
...@@ -54,20 +42,31 @@ func (me *FileSystemConnector) Lookup(header *InHeader, name string) (out *Entry ...@@ -54,20 +42,31 @@ func (me *FileSystemConnector) Lookup(header *InHeader, name string) (out *Entry
fi, fsNode, code = parent.fsInode.Lookup(name, context) fi, fsNode, code = parent.fsInode.Lookup(name, context)
} }
if child == nil && fsNode != nil {
child = fsNode.Inode()
}
return fi, child, code
}
func (me *FileSystemConnector) Lookup(header *InHeader, name string) (out *EntryOut, code Status) {
parent := me.toInode(header.NodeId)
context := &header.Context
fi, child, code := me.internalLookup(parent, name, context)
if !code.Ok() { if !code.Ok() {
if code == ENOENT && mount.options.NegativeTimeout > 0.0 { if code == ENOENT {
return mount.negativeEntry(), OK return parent.mount.negativeEntry()
} }
return nil, code return nil, code
} }
out = mount.fileInfoToEntry(fi)
out.Generation = 1
if child == nil { if child == nil {
child = fsNode.Inode() log.Println("HUH", name)
} }
out = child.mount.fileInfoToEntry(fi)
out.NodeId = me.lookupUpdate(child) out.NodeId = me.lookupUpdate(child)
out.Generation = 1
out.Ino = out.NodeId out.Ino = out.NodeId
return out, OK return out, OK
} }
......
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