Commit fab46421 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fuse: expose Connector in pathfs.FileSystem, expose Server in nodefs.FileSystemConnector.

parent 137fa1b9
...@@ -72,9 +72,6 @@ func main() { ...@@ -72,9 +72,6 @@ func main() {
conn.SetDebug(*debug) conn.SetDebug(*debug)
state.SetDebug(*debug) state.SetDebug(*debug)
gofs.SetMountState(state)
gofs.SetFileSystemConnector(conn)
state.Serve() state.Serve()
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
...@@ -76,6 +76,11 @@ func NewFileSystemConnector(nodeFs FileSystem, opts *Options) (c *FileSystemConn ...@@ -76,6 +76,11 @@ func NewFileSystemConnector(nodeFs FileSystem, opts *Options) (c *FileSystemConn
return c return c
} }
// Server returns the fuse.Server that talking to the kernel.
func (c *FileSystemConnector) Server() *fuse.Server {
return c.server
}
// SetDebug toggles printing of debug information. // SetDebug toggles printing of debug information.
func (c *FileSystemConnector) SetDebug(debug bool) { func (c *FileSystemConnector) SetDebug(debug bool) {
c.debug = debug c.debug = debug
......
...@@ -105,6 +105,10 @@ func (fs *PathNodeFs) String() string { ...@@ -105,6 +105,10 @@ func (fs *PathNodeFs) String() string {
return name return name
} }
func (fs *PathNodeFs) Connector() *nodefs.FileSystemConnector {
return fs.connector
}
func (fs *PathNodeFs) OnMount(conn *nodefs.FileSystemConnector) { func (fs *PathNodeFs) OnMount(conn *nodefs.FileSystemConnector) {
fs.connector = conn fs.connector = conn
fs.fs.OnMount(fs) fs.fs.OnMount(fs)
......
...@@ -37,9 +37,6 @@ type autoUnionFs struct { ...@@ -37,9 +37,6 @@ type autoUnionFs struct {
nodeFs *pathfs.PathNodeFs nodeFs *pathfs.PathNodeFs
options *AutoUnionFsOptions options *AutoUnionFsOptions
mountState *fuse.Server
connector *nodefs.FileSystemConnector
} }
type AutoUnionFsOptions struct { type AutoUnionFsOptions struct {
...@@ -66,15 +63,7 @@ const ( ...@@ -66,15 +63,7 @@ const (
_SCAN_CONFIG = ".scan_config" _SCAN_CONFIG = ".scan_config"
) )
// A pathfs.FileSystem that we can hookup with MountState and func NewAutoUnionFs(directory string, options AutoUnionFsOptions) pathfs.FileSystem {
// FileSystemConnector
type RootFileSystem interface {
SetMountState(state *fuse.Server)
SetFileSystemConnector(conn *nodefs.FileSystemConnector)
pathfs.FileSystem
}
func NewAutoUnionFs(directory string, options AutoUnionFsOptions) RootFileSystem {
if options.HideReadonly { if options.HideReadonly {
options.HiddenFiles = append(options.HiddenFiles, _READONLY) options.HiddenFiles = append(options.HiddenFiles, _READONLY)
} }
...@@ -285,8 +274,10 @@ func (fs *autoUnionFs) SetDebug(b bool) { ...@@ -285,8 +274,10 @@ func (fs *autoUnionFs) SetDebug(b bool) {
// about race conditions here. // about race conditions here.
fs.debug = b fs.debug = b
fs.nodeFs.SetDebug(b) fs.nodeFs.SetDebug(b)
fs.connector.SetDebug(b)
fs.mountState.SetDebug(b) conn := fs.nodeFs.Connector()
conn.SetDebug(b)
conn.Server().SetDebug(b)
} }
func (fs *autoUnionFs) hasDebug() bool { func (fs *autoUnionFs) hasDebug() bool {
...@@ -391,31 +382,22 @@ func (fs *autoUnionFs) StatusDir() (stream []fuse.DirEntry, status fuse.Status) ...@@ -391,31 +382,22 @@ func (fs *autoUnionFs) StatusDir() (stream []fuse.DirEntry, status fuse.Status)
return stream, fuse.OK return stream, fuse.OK
} }
// SetMountState stores the MountState, which is necessary for
// retrieving debug data.
func (fs *autoUnionFs) SetMountState(state *fuse.Server) {
fs.mountState = state
}
func (fs *autoUnionFs) SetFileSystemConnector(conn *nodefs.FileSystemConnector) {
fs.connector = conn
}
func (fs *autoUnionFs) DebugData() string { func (fs *autoUnionFs) DebugData() string {
if fs.mountState == nil { conn := fs.nodeFs.Connector()
if conn.Server() == nil {
return "autoUnionFs.mountState not set" return "autoUnionFs.mountState not set"
} }
setting := fs.mountState.KernelSettings() setting := conn.Server().KernelSettings()
msg := fmt.Sprintf( msg := fmt.Sprintf(
"Version: %v\n"+ "Version: %v\n"+
"Bufferpool: %v\n"+ "Bufferpool: %v\n"+
"Kernel: %v\n", "Kernel: %v\n",
fuse.Version(), fuse.Version(),
fs.mountState.DebugData(), conn.Server().DebugData(),
&setting) &setting)
if fs.connector != nil { if conn != nil {
msg += fmt.Sprintf("Live inodes: %d\n", fs.connector.InodeHandleCount()) msg += fmt.Sprintf("Live inodes: %d\n", conn.InodeHandleCount())
} }
return msg return msg
......
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