Commit 5f92e2f1 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Make autounionfs debug runtime switchable.

parent 13019c9b
...@@ -56,6 +56,7 @@ const ( ...@@ -56,6 +56,7 @@ const (
_STATUS = "status" _STATUS = "status"
_CONFIG = "config" _CONFIG = "config"
_DEBUG = "debug" _DEBUG = "debug"
_DEBUG_SETTING = "debug_setting"
_ROOT = "root" _ROOT = "root"
_VERSION = "gounionfs_version" _VERSION = "gounionfs_version"
_SCAN_CONFIG = ".scan_config" _SCAN_CONFIG = ".scan_config"
...@@ -215,10 +216,16 @@ func (fs *AutoUnionFs) Readlink(path string, context *fuse.Context) (out string, ...@@ -215,10 +216,16 @@ func (fs *AutoUnionFs) Readlink(path string, context *fuse.Context) (out string,
return fs.root, fuse.OK return fs.root, fuse.OK
} }
if comps[0] == _STATUS && comps[1] == _DEBUG_SETTING && fs.hasDebug() {
return "1", fuse.OK
}
if comps[0] != _CONFIG { if comps[0] != _CONFIG {
return "", fuse.ENOENT return "", fuse.ENOENT
} }
name := comps[1] name := comps[1]
fs.lock.RLock() fs.lock.RLock()
defer fs.lock.RUnlock() defer fs.lock.RUnlock()
...@@ -241,6 +248,11 @@ func (fs *AutoUnionFs) Symlink(pointedTo string, linkName string, context *fuse. ...@@ -241,6 +248,11 @@ func (fs *AutoUnionFs) Symlink(pointedTo string, linkName string, context *fuse.
return fuse.EPERM return fuse.EPERM
} }
if comps[0] == _STATUS && comps[1] == _DEBUG_SETTING {
fs.SetDebug(true)
return fuse.OK
}
if comps[0] == _CONFIG { if comps[0] == _CONFIG {
roots := fs.getRoots(pointedTo) roots := fs.getRoots(pointedTo)
if roots == nil { if roots == nil {
...@@ -253,12 +265,29 @@ func (fs *AutoUnionFs) Symlink(pointedTo string, linkName string, context *fuse. ...@@ -253,12 +265,29 @@ func (fs *AutoUnionFs) Symlink(pointedTo string, linkName string, context *fuse.
return fuse.EPERM return fuse.EPERM
} }
func (fs *AutoUnionFs) SetDebug(b bool) {
// Officially, this should use locking, but we don't care
// about race conditions here.
fs.nodeFs.Debug = b
fs.connector.Debug = b
fs.mountState.Debug = b
}
func (fs *AutoUnionFs) hasDebug() bool {
return fs.nodeFs.Debug
}
func (fs *AutoUnionFs) Unlink(path string, context *fuse.Context) (code fuse.Status) { func (fs *AutoUnionFs) Unlink(path string, context *fuse.Context) (code fuse.Status) {
comps := strings.Split(path, "/") comps := strings.Split(path, "/")
if len(comps) != 2 { if len(comps) != 2 {
return fuse.EPERM return fuse.EPERM
} }
if comps[0] == _STATUS && comps[1] == _DEBUG_SETTING {
fs.SetDebug(false)
return fuse.OK
}
if comps[0] == _CONFIG && comps[1] != _SCAN_CONFIG { if comps[0] == _CONFIG && comps[1] != _SCAN_CONFIG {
code = fs.rmFs(comps[1]) code = fs.rmFs(comps[1])
} else { } else {
...@@ -280,6 +309,12 @@ func (fs *AutoUnionFs) GetAttr(path string, context *fuse.Context) (*fuse.Attr, ...@@ -280,6 +309,12 @@ func (fs *AutoUnionFs) GetAttr(path string, context *fuse.Context) (*fuse.Attr,
return a, fuse.OK return a, fuse.OK
} }
if path == filepath.Join(_STATUS, _DEBUG_SETTING) && fs.hasDebug() {
return &fuse.Attr{
Mode: fuse.S_IFLNK | 0644,
}, fuse.OK
}
if path == filepath.Join(_STATUS, _VERSION) { if path == filepath.Join(_STATUS, _VERSION) {
a := &fuse.Attr{ a := &fuse.Attr{
Mode: fuse.S_IFREG | 0644, Mode: fuse.S_IFREG | 0644,
...@@ -334,7 +369,9 @@ func (fs *AutoUnionFs) StatusDir() (stream []fuse.DirEntry, status fuse.Status) ...@@ -334,7 +369,9 @@ func (fs *AutoUnionFs) StatusDir() (stream []fuse.DirEntry, status fuse.Status)
{Name: _DEBUG, Mode: fuse.S_IFREG | 0644}, {Name: _DEBUG, Mode: fuse.S_IFREG | 0644},
{Name: _ROOT, Mode: syscall.S_IFLNK | 0644}, {Name: _ROOT, Mode: syscall.S_IFLNK | 0644},
} }
if fs.hasDebug() {
stream = append(stream, fuse.DirEntry{Name: _DEBUG_SETTING, Mode: fuse.S_IFLNK | 0644})
}
return stream, fuse.OK return stream, fuse.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