Commit 9b069ce5 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Use path interface for PathNodeFs.Mount/Unmount

parent 485ecd0f
...@@ -27,6 +27,8 @@ func TestMountOnExisting(t *testing.T) { ...@@ -27,6 +27,8 @@ func TestMountOnExisting(t *testing.T) {
if !code.Ok() { if !code.Ok() {
t.Fatal("expect OK:", code) t.Fatal("expect OK:", code)
} }
ts.nodeFs.Unmount("mnt")
} }
func TestMountRename(t *testing.T) { func TestMountRename(t *testing.T) {
...@@ -42,6 +44,7 @@ func TestMountRename(t *testing.T) { ...@@ -42,6 +44,7 @@ func TestMountRename(t *testing.T) {
if OsErrorToErrno(err) != EBUSY { if OsErrorToErrno(err) != EBUSY {
t.Fatal("rename mount point should fail with EBUSY:", err) t.Fatal("rename mount point should fail with EBUSY:", err)
} }
ts.nodeFs.Unmount("mnt")
} }
func TestMountReaddir(t *testing.T) { func TestMountReaddir(t *testing.T) {
...@@ -59,6 +62,7 @@ func TestMountReaddir(t *testing.T) { ...@@ -59,6 +62,7 @@ func TestMountReaddir(t *testing.T) {
if len(entries) != 1 || entries[0].Name != "mnt" { if len(entries) != 1 || entries[0].Name != "mnt" {
t.Error("wrong readdir result", entries) t.Error("wrong readdir result", entries)
} }
ts.nodeFs.Unmount("mnt")
} }
func TestRecursiveMount(t *testing.T) { func TestRecursiveMount(t *testing.T) {
...@@ -83,7 +87,7 @@ func TestRecursiveMount(t *testing.T) { ...@@ -83,7 +87,7 @@ func TestRecursiveMount(t *testing.T) {
f, err := os.Open(filepath.Join(submnt, "hello.txt")) f, err := os.Open(filepath.Join(submnt, "hello.txt"))
CheckSuccess(err) CheckSuccess(err)
log.Println("Attempting unmount, should fail") log.Println("Attempting unmount, should fail")
code = ts.connector.Unmount(ts.nodeFs.Node("mnt")) code = ts.nodeFs.Unmount("mnt")
if code != EBUSY { if code != EBUSY {
t.Error("expect EBUSY") t.Error("expect EBUSY")
} }
...@@ -94,7 +98,7 @@ func TestRecursiveMount(t *testing.T) { ...@@ -94,7 +98,7 @@ func TestRecursiveMount(t *testing.T) {
time.Sleep(1.5e9 * testTtl) time.Sleep(1.5e9 * testTtl)
log.Println("Attempting unmount, should succeed") log.Println("Attempting unmount, should succeed")
code = ts.connector.Unmount(ts.nodeFs.Node("mnt")) code = ts.nodeFs.Unmount("mnt")
if code != OK { if code != OK {
t.Error("umount failed.", code) t.Error("umount failed.", code)
} }
...@@ -121,14 +125,14 @@ func TestDeletedUnmount(t *testing.T) { ...@@ -121,14 +125,14 @@ func TestDeletedUnmount(t *testing.T) {
_, err = f.Write([]byte("bla")) _, err = f.Write([]byte("bla"))
CheckSuccess(err) CheckSuccess(err)
code = ts.connector.Unmount(ts.nodeFs.Node("mnt")) code = ts.nodeFs.Unmount("mnt")
if code != EBUSY { if code != EBUSY {
t.Error("expect EBUSY for unmount with open files", code) t.Error("expect EBUSY for unmount with open files", code)
} }
f.Close() f.Close()
time.Sleep(1.5e9 * testTtl) time.Sleep(1.5e9 * testTtl)
code = ts.connector.Unmount(ts.nodeFs.Node("mnt")) code = ts.nodeFs.Unmount("mnt")
if !code.Ok() { if !code.Ok() {
t.Error("should succeed", code) t.Error("should succeed", code)
} }
......
...@@ -27,11 +27,21 @@ type PathNodeFs struct { ...@@ -27,11 +27,21 @@ type PathNodeFs struct {
clientInodeMap map[uint64][]*clientInodePath clientInodeMap map[uint64][]*clientInodePath
} }
func (me *PathNodeFs) Mount(parent *Inode, name string, nodeFs NodeFileSystem, opts *FileSystemOptions) Status { func (me *PathNodeFs) Mount(path string, nodeFs NodeFileSystem, opts *FileSystemOptions) Status {
dir, name := filepath.Split(path)
dir = filepath.Clean(dir)
parent := me.Node(dir)
if parent == nil {
return ENOENT
}
return me.connector.Mount(parent, name, nodeFs, opts) return me.connector.Mount(parent, name, nodeFs, opts)
} }
func (me *PathNodeFs) Unmount(node *Inode) Status { func (me *PathNodeFs) Unmount(path string) Status {
node := me.Node(path)
if node == nil {
return ENOENT
}
return me.connector.Unmount(node) return me.connector.Unmount(node)
} }
......
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