Commit 62dac3a2 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Move path interface to notify to PathNodeFs.

parent 98d0cf6b
......@@ -26,7 +26,7 @@ func (me *cacheFs) Open(name string, flags uint32, context *Context) (fuseFile F
}
func setupCacheTest() (string, *FileSystemConnector, func()) {
func setupCacheTest() (string, *PathNodeFs, func()) {
dir := MakeTempDir()
os.Mkdir(dir+"/mnt", 0755)
os.Mkdir(dir+"/orig", 0755)
......@@ -34,13 +34,15 @@ func setupCacheTest() (string, *FileSystemConnector, func()) {
fs := &cacheFs{
LoopbackFileSystem: NewLoopbackFileSystem(dir + "/orig"),
}
state, conn, err := MountPathFileSystem(dir+"/mnt", fs, nil)
pfs := NewPathNodeFs(fs)
state, conn, err := MountNodeFileSystem(dir+"/mnt", pfs, nil)
CheckSuccess(err)
state.Debug = true
conn.Debug = true
pfs.Debug = true
go state.Loop(false)
return dir, conn, func() {
return dir, pfs, func() {
err := state.Unmount()
if err == nil {
os.RemoveAll(dir)
......@@ -49,7 +51,7 @@ func setupCacheTest() (string, *FileSystemConnector, func()) {
}
func TestCacheFs(t *testing.T) {
wd, conn, clean := setupCacheTest()
wd, pathfs, clean := setupCacheTest()
defer clean()
content1 := "hello"
......@@ -74,7 +76,7 @@ func TestCacheFs(t *testing.T) {
t.Fatalf("expect 'hello' %q", string(c))
}
code := conn.EntryNotify("", "file.txt")
code := pathfs.EntryNotify("", "file.txt")
if !code.Ok() {
t.Errorf("Entry notify failed: %v", code)
}
......@@ -82,7 +84,7 @@ func TestCacheFs(t *testing.T) {
c, err = ioutil.ReadFile(wd + "/mnt/file.txt")
CheckSuccess(err)
if string(c) != string(content2) {
t.Fatalf("expect '%s' %q", content2, string(c))
t.Fatalf("Mismatch after notify expect '%s' %q", content2, string(c))
}
}
......
......@@ -325,12 +325,7 @@ func (me *FileSystemConnector) Unmount(node *Inode) Status {
return OK
}
func (me *FileSystemConnector) FileNotify(path string, off int64, length int64) Status {
node := me.findInode(path)
if node == nil {
return ENOENT
}
func (me *FileSystemConnector) FileNotify(node *Inode, off int64, length int64) Status {
out := NotifyInvalInodeOut{
Length: length,
Off: off,
......@@ -339,22 +334,7 @@ func (me *FileSystemConnector) FileNotify(path string, off int64, length int64)
return me.fsInit.InodeNotify(&out)
}
func (me *FileSystemConnector) EntryNotify(dir string, name string) Status {
node := me.findInode(dir)
if node == nil {
return ENOENT
}
return me.fsInit.EntryNotify(node.nodeId, name)
func (me *FileSystemConnector) EntryNotify(dir *Inode, name string) Status {
return me.fsInit.EntryNotify(dir.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])
}
out := NotifyInvalInodeOut{
Ino: node.nodeId,
}
return me.fsInit.InodeNotify(&out)
}
......@@ -33,6 +33,7 @@ func (me *NotifyFs) Open(name string, f uint32, context *Context) (File, Status)
type NotifyTest struct {
fs *NotifyFs
pathfs *PathNodeFs
connector *FileSystemConnector
dir string
state *MountState
......@@ -50,7 +51,8 @@ func NewNotifyTest() *NotifyTest {
}
var err os.Error
me.state, me.connector, err = MountPathFileSystem(me.dir, me.fs, opts)
me.pathfs = NewPathNodeFs(me.fs)
me.state, me.connector, err = MountNodeFileSystem(me.dir, me.pathfs, opts)
CheckSuccess(err)
me.state.Debug = true
go me.state.Loop(false)
......@@ -86,7 +88,7 @@ func TestInodeNotify(t *testing.T) {
t.Error(fi)
}
code := test.connector.FileNotify("file", -1, 0)
code := test.pathfs.FileNotify("file", -1, 0)
if !code.Ok() {
t.Error(code)
}
......@@ -117,7 +119,7 @@ func TestEntryNotify(t *testing.T) {
t.Errorf("negative entry should have been cached: %#v", fi)
}
code := test.connector.EntryNotify("dir", "file")
code := test.pathfs.EntryNotify("dir", "file")
if !code.Ok() {
t.Errorf("EntryNotify returns error: %v", code)
}
......
......@@ -17,6 +17,7 @@ type clientInodePath struct {
}
type PathNodeFs struct {
Debug bool
fs FileSystem
root *pathInode
connector *FileSystemConnector
......@@ -46,17 +47,55 @@ func (me *PathNodeFs) StatFs() *StatfsOut {
return me.fs.StatFs()
}
func (me *PathNodeFs) Node(name string) *Inode {
func (me *PathNodeFs) Node(name string) (*Inode) {
n, rest := me.LastNode(name)
if len(rest) > 0 {
return nil
}
return n
}
func (me *PathNodeFs) LastNode(name string) (*Inode, []string) {
if name == "" {
return me.Root().Inode(), nil
}
name = filepath.Clean(name)
comps := strings.Split(name, string(filepath.Separator))
node := me.root.Inode()
for _, c := range comps {
node = node.GetChild(c)
if node == nil {
break
for i, c := range comps {
next := node.GetChild(c)
if next == nil {
return node, comps[i:]
}
node = next
}
return node, nil
}
func (me *PathNodeFs) FileNotify(path string, off int64, length int64) Status {
node := me.Node(path)
if node == nil {
return ENOENT
}
return me.connector.FileNotify(node, off, length)
}
func (me *PathNodeFs) EntryNotify(dir string, name string) Status {
node := me.Node(dir)
if node == nil {
return ENOENT
}
return node
return me.connector.EntryNotify(node, name)
}
func (me *PathNodeFs) Notify(path string) Status {
node, rest := me.LastNode(path)
if len(rest) > 0 {
return me.connector.EntryNotify(node, rest[0])
}
return me.connector.FileNotify(node, 0, 0)
}
func (me *PathNodeFs) AllFiles(name string, mask uint32) []WithFlags {
......@@ -102,7 +141,6 @@ type pathInode struct {
DefaultFsNode
}
func (me *pathInode) fillNewChildAttr(path string, child *pathInode, c *Context) (fi *os.FileInfo) {
fi, _ = me.fs.GetAttr(path, c)
if fi != nil && fi.Ino > 0 {
......
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