Commit 0ff7c8ac authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fs: introduce ServerCallbacks

Options.ServerCallbacks can set the callbacks used when not mounting
the filesystem.

Change-Id: I51bf875a816c23e587ec8b575110221bdfcdaffe
parent 1e5729e0
...@@ -599,4 +599,8 @@ type Options struct { ...@@ -599,4 +599,8 @@ type Options struct {
// If nonzero, replace default (zero) GID with the given GID // If nonzero, replace default (zero) GID with the given GID
GID uint32 GID uint32
// ServerCallbacks can be provided to stub out notification
// functions for testing a filesystem without mounting it.
ServerCallbacks ServerCallbacks
} }
...@@ -37,10 +37,21 @@ type fileEntry struct { ...@@ -37,10 +37,21 @@ type fileEntry struct {
wg sync.WaitGroup wg sync.WaitGroup
} }
// ServerCallbacks are calls into the kernel to manipulate the inode,
// entry and page cache. They are stubbed so filesystems can be
// unittested without mounting them.
type ServerCallbacks interface {
DeleteNotify(parent uint64, child uint64, name string) fuse.Status
EntryNotify(parent uint64, name string) fuse.Status
InodeNotify(node uint64, off int64, length int64) fuse.Status
InodeRetrieveCache(node uint64, offset int64, dest []byte) (n int, st fuse.Status)
InodeNotifyStoreCache(node uint64, offset int64, data []byte) fuse.Status
}
type rawBridge struct { type rawBridge struct {
options Options options Options
root *Inode root *Inode
server *fuse.Server server ServerCallbacks
// mu protects the following data. Locks for inodes must be // mu protects the following data. Locks for inodes must be
// taken before rawBridge.mu // taken before rawBridge.mu
...@@ -213,6 +224,7 @@ func (b *rawBridge) setAttrTimeout(out *fuse.AttrOut) { ...@@ -213,6 +224,7 @@ func (b *rawBridge) setAttrTimeout(out *fuse.AttrOut) {
func NewNodeFS(root InodeEmbedder, opts *Options) fuse.RawFileSystem { func NewNodeFS(root InodeEmbedder, opts *Options) fuse.RawFileSystem {
bridge := &rawBridge{ bridge := &rawBridge{
automaticIno: opts.FirstAutomaticIno, automaticIno: opts.FirstAutomaticIno,
server: opts.ServerCallbacks,
} }
if bridge.automaticIno == 1 { if bridge.automaticIno == 1 {
bridge.automaticIno++ bridge.automaticIno++
......
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