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 {
//
StatFs(out *raw.StatfsOut, context *Context) (code Status)
// Provide callbacks for pushing notifications to the kernel.
Init(params *RawFsInit)
// This is called on processing the first request. This call
// 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.
//
// 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
// will give the correct result for Lstat (ENOENT), but the kernel
// 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 {
type defaultRawFileSystem struct{}
func (fs *defaultRawFileSystem) Init(init *RawFsInit) {
func (fs *defaultRawFileSystem) Init(*Server) {
}
func (fs *defaultRawFileSystem) String() string {
......
......@@ -15,8 +15,6 @@ type lockingRawFileSystem struct {
lock sync.Mutex
}
var _ = (RawFileSystem)((*lockingRawFileSystem)(nil))
// Returns a Wrap
func NewLockingRawFileSystem(fs RawFileSystem) RawFileSystem {
return &lockingRawFileSystem{
......@@ -189,9 +187,9 @@ func (fs *lockingRawFileSystem) FsyncDir(header *Context, input *raw.FsyncIn) (c
return fs.RawFS.FsyncDir(header, input)
}
func (fs *lockingRawFileSystem) Init(params *RawFsInit) {
func (fs *lockingRawFileSystem) Init(s *Server) {
defer fs.locked()()
fs.RawFS.Init(params)
fs.RawFS.Init(s)
}
func (fs *lockingRawFileSystem) StatFs(out *raw.StatfsOut, context *Context) (code Status) {
......
......@@ -36,7 +36,7 @@ type FileSystemConnector struct {
debug bool
// Callbacks for talking back to the kernel.
fsInit fuse.RawFsInit
server *fuse.Server
nodeFs FileSystem
......@@ -340,7 +340,7 @@ func (c *FileSystemConnector) Unmount(node *Inode) fuse.Status {
// We have to wait until the kernel has forgotten the
// mountpoint, so the write to node.mountPoint is no longer
// 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() {
mount.treeLock.Unlock()
parentNode.mount.treeLock.Unlock()
......@@ -375,12 +375,7 @@ func (c *FileSystemConnector) FileNotify(node *Inode, off int64, length int64) f
if nId == 0 {
return fuse.OK
}
out := raw.NotifyInvalInodeOut{
Length: length,
Off: off,
Ino: nId,
}
return c.fsInit.InodeNotify(&out)
return c.server.InodeNotify(nId, off, length)
}
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 {
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 {
......@@ -412,5 +407,5 @@ func (c *FileSystemConnector) DeleteNotify(dir *Inode, child *Inode, name string
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 {
return name
}
func (c *rawBridge) Init(fsInit *fuse.RawFsInit) {
c.fsInit = *fsInit
func (c *rawBridge) Init(s *fuse.Server) {
c.server = s
}
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
if err != nil {
return nil, err
}
initParams := RawFsInit{
InodeNotify: func(n *raw.NotifyInvalInodeOut) Status {
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.fileSystem.Init(ms)
ms.mountPoint = mountPoint
ms.mountFd = fd
return ms, nil
......@@ -388,7 +378,14 @@ func (ms *Server) write(req *request) Status {
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{
inHeader: &raw.InHeader{
Opcode: _OP_NOTIFY_INODE,
......@@ -409,9 +406,13 @@ func (ms *Server) writeInodeNotify(entry *raw.NotifyInvalInodeOut) Status {
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 {
return ms.writeEntryNotify(parent, name)
return ms.EntryNotify(parent, name)
}
req := request{
......@@ -446,7 +447,9 @@ func (ms *Server) writeDeleteNotify(parent uint64, child uint64, name string) St
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{
inHeader: &raw.InHeader{
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