Commit 2fd32745 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

unionfs: test debug_setting symlink.

parent 27ecdf3b
...@@ -18,6 +18,9 @@ type FileSystem interface { ...@@ -18,6 +18,9 @@ type FileSystem interface {
// Used for pretty printing. // Used for pretty printing.
String() string String() string
// If called, provide debug output through the log package.
SetDebug(debug bool)
// Attributes. This function is the main entry point, through // Attributes. This function is the main entry point, through
// which FUSE discovers which files and directories exist. // which FUSE discovers which files and directories exist.
// //
......
...@@ -16,6 +16,8 @@ func NewDefaultFileSystem() FileSystem { ...@@ -16,6 +16,8 @@ func NewDefaultFileSystem() FileSystem {
// defaultFileSystem implements a FileSystem that returns ENOSYS for every operation. // defaultFileSystem implements a FileSystem that returns ENOSYS for every operation.
type defaultFileSystem struct{} type defaultFileSystem struct{}
func (fs *defaultFileSystem) SetDebug(debug bool) {}
// defaultFileSystem // defaultFileSystem
func (fs *defaultFileSystem) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) { func (fs *defaultFileSystem) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
return nil, fuse.ENOSYS return nil, fuse.ENOSYS
......
...@@ -28,6 +28,11 @@ func (fs *lockingFileSystem) String() string { ...@@ -28,6 +28,11 @@ func (fs *lockingFileSystem) String() string {
return fs.FS.String() return fs.FS.String()
} }
func (fs *lockingFileSystem) SetDebug(debug bool) {
defer fs.locked()()
fs.FS.SetDebug(debug)
}
func (fs *lockingFileSystem) StatFs(name string) *fuse.StatfsOut { func (fs *lockingFileSystem) StatFs(name string) *fuse.StatfsOut {
defer fs.locked()() defer fs.locked()()
return fs.FS.StatFs(name) return fs.FS.StatFs(name)
......
...@@ -19,6 +19,10 @@ func NewPrefixFileSystem(fs FileSystem, prefix string) FileSystem { ...@@ -19,6 +19,10 @@ func NewPrefixFileSystem(fs FileSystem, prefix string) FileSystem {
return &prefixFileSystem{fs, prefix} return &prefixFileSystem{fs, prefix}
} }
func (fs *prefixFileSystem) SetDebug(debug bool) {
fs.FileSystem.SetDebug(debug)
}
func (fs *prefixFileSystem) prefixed(n string) string { func (fs *prefixFileSystem) prefixed(n string) string {
return filepath.Join(fs.Prefix, n) return filepath.Join(fs.Prefix, n)
} }
......
...@@ -270,8 +270,7 @@ func (fs *autoUnionFs) Symlink(pointedTo string, linkName string, context *fuse. ...@@ -270,8 +270,7 @@ func (fs *autoUnionFs) Symlink(pointedTo string, linkName string, context *fuse.
} }
func (fs *autoUnionFs) SetDebug(b bool) { func (fs *autoUnionFs) SetDebug(b bool) {
// Officially, this should use locking, but we don't care // TODO(hanwen): this should use locking.
// about race conditions here.
fs.debug = b fs.debug = b
fs.nodeFs.SetDebug(b) fs.nodeFs.SetDebug(b)
......
// +build !race
package unionfs
import (
"os"
"testing"
"time"
)
// Ideally, this should check inject a logger rather than a boolean,
// so we can check if the messages are as we expect. Right now, this
// test requires visual inspection. When run with -v, the UNLINK reply
// and SYMLINK request are not printed.
func TestToggleDebug(t *testing.T) {
wd, clean := setup(t)
defer clean()
os.Remove(wd + "/mnt/status/debug_setting")
time.Sleep(10 * time.Millisecond)
if err := os.Symlink("xyz", wd+"/mnt/status/debug_setting"); err != nil {
t.Fatalf("Symlink: %v", err)
}
// now we should be in debug mode.
link, err := os.Readlink(wd + "/mnt/status/debug_setting")
if err != nil {
t.Fatalf("Readlink: %v", err)
}
if link != "1" {
t.Errorf("got %q want %q for debug_setting readlink",
link, "1")
}
}
...@@ -53,12 +53,11 @@ func setup(t *testing.T) (workdir string, cleanup func()) { ...@@ -53,12 +53,11 @@ func setup(t *testing.T) (workdir string, cleanup func()) {
fs := NewAutoUnionFs(wd+"/store", testAOpts) fs := NewAutoUnionFs(wd+"/store", testAOpts)
nfs := pathfs.NewPathNodeFs(fs, nil) nfs := pathfs.NewPathNodeFs(fs, nil)
state, conn, err := nodefs.MountFileSystem(wd+"/mnt", nfs, &testAOpts.Options) state, _, err := nodefs.MountFileSystem(wd+"/mnt", nfs, &testAOpts.Options)
if err != nil { if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err) t.Fatalf("MountNodeFileSystem failed: %v", err)
} }
state.SetDebug(VerboseTest()) fs.SetDebug(VerboseTest())
conn.SetDebug(VerboseTest())
go state.Serve() go state.Serve()
return wd, func() { return wd, func() {
......
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