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