Commit 8b4fc94a authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fuse: drop RawFsInit method; expose Notify functions directly in Server.

parent 7e41a9d5
...@@ -126,23 +126,16 @@ type RawFileSystem interface { ...@@ -126,23 +126,16 @@ type RawFileSystem interface {
// //
StatFs(out *raw.StatfsOut, context *Context) (code Status) StatFs(out *raw.StatfsOut, context *Context) (code Status)
// Provide callbacks for pushing notifications to the kernel. // This is called on processing the first request. This call
Init(params *RawFsInit) // is intended so the filesystem can talk back to the kernel
// (through notify methods) and has access to debug data.
Init(*Server)
} }
// Talk back to FUSE. // Talk back to FUSE.
// //
// InodeNotify invalidates the information associated with the inode
// (ie. data cache, attributes, etc.)
// //
// EntryNotify should be used if the existence status of an entry changes,
// (ie. to notify of creation or deletion of the file).
// //
// Somewhat confusingly, InodeNotify for a file that stopped to exist // Somewhat confusingly, InodeNotify for a file that stopped to exist
// will give the correct result for Lstat (ENOENT), but the kernel // will give the correct result for Lstat (ENOENT), but the kernel
// will still issue file Open() on the inode. // will still issue file Open() on the inode.
type RawFsInit struct {
InodeNotify func(*raw.NotifyInvalInodeOut) Status
EntryNotify func(parent uint64, name string) Status
DeleteNotify func(parent uint64, child uint64, name string) Status
}
...@@ -14,7 +14,7 @@ func NewDefaultRawFileSystem() RawFileSystem { ...@@ -14,7 +14,7 @@ func NewDefaultRawFileSystem() RawFileSystem {
type defaultRawFileSystem struct{} type defaultRawFileSystem struct{}
func (fs *defaultRawFileSystem) Init(init *RawFsInit) { func (fs *defaultRawFileSystem) Init(*Server) {
} }
func (fs *defaultRawFileSystem) String() string { func (fs *defaultRawFileSystem) String() string {
......
...@@ -15,8 +15,6 @@ type lockingRawFileSystem struct { ...@@ -15,8 +15,6 @@ type lockingRawFileSystem struct {
lock sync.Mutex lock sync.Mutex
} }
var _ = (RawFileSystem)((*lockingRawFileSystem)(nil))
// Returns a Wrap // Returns a Wrap
func NewLockingRawFileSystem(fs RawFileSystem) RawFileSystem { func NewLockingRawFileSystem(fs RawFileSystem) RawFileSystem {
return &lockingRawFileSystem{ return &lockingRawFileSystem{
...@@ -189,9 +187,9 @@ func (fs *lockingRawFileSystem) FsyncDir(header *Context, input *raw.FsyncIn) (c ...@@ -189,9 +187,9 @@ func (fs *lockingRawFileSystem) FsyncDir(header *Context, input *raw.FsyncIn) (c
return fs.RawFS.FsyncDir(header, input) return fs.RawFS.FsyncDir(header, input)
} }
func (fs *lockingRawFileSystem) Init(params *RawFsInit) { func (fs *lockingRawFileSystem) Init(s *Server) {
defer fs.locked()() defer fs.locked()()
fs.RawFS.Init(params) fs.RawFS.Init(s)
} }
func (fs *lockingRawFileSystem) StatFs(out *raw.StatfsOut, context *Context) (code Status) { func (fs *lockingRawFileSystem) StatFs(out *raw.StatfsOut, context *Context) (code Status) {
......
...@@ -36,7 +36,7 @@ type FileSystemConnector struct { ...@@ -36,7 +36,7 @@ type FileSystemConnector struct {
debug bool debug bool
// Callbacks for talking back to the kernel. // Callbacks for talking back to the kernel.
fsInit fuse.RawFsInit server *fuse.Server
nodeFs FileSystem nodeFs FileSystem
...@@ -340,7 +340,7 @@ func (c *FileSystemConnector) Unmount(node *Inode) fuse.Status { ...@@ -340,7 +340,7 @@ func (c *FileSystemConnector) Unmount(node *Inode) fuse.Status {
// We have to wait until the kernel has forgotten the // We have to wait until the kernel has forgotten the
// mountpoint, so the write to node.mountPoint is no longer // mountpoint, so the write to node.mountPoint is no longer
// racy. // racy.
code := c.fsInit.DeleteNotify(parentId, c.inodeMap.Handle(&node.handled), name) code := c.server.DeleteNotify(parentId, c.inodeMap.Handle(&node.handled), name)
if code.Ok() { if code.Ok() {
mount.treeLock.Unlock() mount.treeLock.Unlock()
parentNode.mount.treeLock.Unlock() parentNode.mount.treeLock.Unlock()
...@@ -375,12 +375,7 @@ func (c *FileSystemConnector) FileNotify(node *Inode, off int64, length int64) f ...@@ -375,12 +375,7 @@ func (c *FileSystemConnector) FileNotify(node *Inode, off int64, length int64) f
if nId == 0 { if nId == 0 {
return fuse.OK return fuse.OK
} }
out := raw.NotifyInvalInodeOut{ return c.server.InodeNotify(nId, off, length)
Length: length,
Off: off,
Ino: nId,
}
return c.fsInit.InodeNotify(&out)
} }
func (c *FileSystemConnector) EntryNotify(node *Inode, name string) fuse.Status { func (c *FileSystemConnector) EntryNotify(node *Inode, name string) fuse.Status {
...@@ -394,7 +389,7 @@ func (c *FileSystemConnector) EntryNotify(node *Inode, name string) fuse.Status ...@@ -394,7 +389,7 @@ func (c *FileSystemConnector) EntryNotify(node *Inode, name string) fuse.Status
if nId == 0 { if nId == 0 {
return fuse.OK return fuse.OK
} }
return c.fsInit.EntryNotify(nId, name) return c.server.EntryNotify(nId, name)
} }
func (c *FileSystemConnector) DeleteNotify(dir *Inode, child *Inode, name string) fuse.Status { func (c *FileSystemConnector) DeleteNotify(dir *Inode, child *Inode, name string) fuse.Status {
...@@ -412,5 +407,5 @@ func (c *FileSystemConnector) DeleteNotify(dir *Inode, child *Inode, name string ...@@ -412,5 +407,5 @@ func (c *FileSystemConnector) DeleteNotify(dir *Inode, child *Inode, name string
chId := c.inodeMap.Handle(&child.handled) chId := c.inodeMap.Handle(&child.handled)
return c.fsInit.DeleteNotify(nId, chId, name) return c.server.DeleteNotify(nId, chId, name)
} }
...@@ -53,8 +53,8 @@ func (c *rawBridge) String() string { ...@@ -53,8 +53,8 @@ func (c *rawBridge) String() string {
return name return name
} }
func (c *rawBridge) Init(fsInit *fuse.RawFsInit) { func (c *rawBridge) Init(s *fuse.Server) {
c.fsInit = *fsInit c.server = s
} }
func (c *FileSystemConnector) lookupMountUpdate(out *fuse.Attr, mount *fileSystemMount) (node *Inode, code fuse.Status) { func (c *FileSystemConnector) lookupMountUpdate(out *fuse.Attr, mount *fileSystemMount) (node *Inode, code fuse.Status) {
......
...@@ -166,18 +166,8 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server ...@@ -166,18 +166,8 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server
if err != nil { if err != nil {
return nil, err return nil, err
} }
initParams := RawFsInit{
InodeNotify: func(n *raw.NotifyInvalInodeOut) Status { ms.fileSystem.Init(ms)
return ms.writeInodeNotify(n)
},
EntryNotify: func(parent uint64, n string) Status {
return ms.writeEntryNotify(parent, n)
},
DeleteNotify: func(parent uint64, child uint64, n string) Status {
return ms.writeDeleteNotify(parent, child, n)
},
}
ms.fileSystem.Init(&initParams)
ms.mountPoint = mountPoint ms.mountPoint = mountPoint
ms.mountFd = fd ms.mountFd = fd
return ms, nil return ms, nil
...@@ -388,7 +378,14 @@ func (ms *Server) write(req *request) Status { ...@@ -388,7 +378,14 @@ func (ms *Server) write(req *request) Status {
return s return s
} }
func (ms *Server) writeInodeNotify(entry *raw.NotifyInvalInodeOut) Status { // InodeNotify invalidates the information associated with the inode
// (ie. data cache, attributes, etc.)
func (ms *Server) InodeNotify(node uint64, off int64, length int64) Status {
entry := &raw.NotifyInvalInodeOut{
Ino: node,
Off: off,
Length: length,
}
req := request{ req := request{
inHeader: &raw.InHeader{ inHeader: &raw.InHeader{
Opcode: _OP_NOTIFY_INODE, Opcode: _OP_NOTIFY_INODE,
...@@ -409,9 +406,13 @@ func (ms *Server) writeInodeNotify(entry *raw.NotifyInvalInodeOut) Status { ...@@ -409,9 +406,13 @@ func (ms *Server) writeInodeNotify(entry *raw.NotifyInvalInodeOut) Status {
return result return result
} }
func (ms *Server) writeDeleteNotify(parent uint64, child uint64, name string) Status { // DeleteNotify notifies the kernel that an entry is removed from a
// directory. In many cases, this is equivalent to EntryNotify,
// except when the directory is in use, eg. as working directory of
// some process.
func (ms *Server) DeleteNotify(parent uint64, child uint64, name string) Status {
if ms.kernelSettings.Minor < 18 { if ms.kernelSettings.Minor < 18 {
return ms.writeEntryNotify(parent, name) return ms.EntryNotify(parent, name)
} }
req := request{ req := request{
...@@ -446,7 +447,9 @@ func (ms *Server) writeDeleteNotify(parent uint64, child uint64, name string) St ...@@ -446,7 +447,9 @@ func (ms *Server) writeDeleteNotify(parent uint64, child uint64, name string) St
return result return result
} }
func (ms *Server) writeEntryNotify(parent uint64, name string) Status { // EntryNotify should be used if the existence status of an entry
// within a directory changes.
func (ms *Server) EntryNotify(parent uint64, name string) Status {
req := request{ req := request{
inHeader: &raw.InHeader{ inHeader: &raw.InHeader{
Opcode: _OP_NOTIFY_ENTRY, Opcode: _OP_NOTIFY_ENTRY,
......
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