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

nodefs: pass context to OnAdd

parent 5531575a
......@@ -54,8 +54,6 @@ Decisions
To decide
=========
* Should we provide automatic fileID numbering?
* function signatures, or types? The latter is easier to remember?
Easier to extend? The latter less efficient (indirections/copies)
......@@ -77,13 +75,4 @@ or
* What to do with semi-unused fields (CreateIn.Umask, OpenIn.Mode, etc.)
* Readlink return: []byte or string ?
* Should Operations.Lookup return *Inode or Operations ?
* Merge Fsync/FsyncDir?
* OnMount in Operations or in Options? Or argument to NewNodeFS? Or
OnAdd() ?
......@@ -104,7 +104,7 @@ type Operations interface {
// OnAdd is called once this Operations object is attached to
// an Inode.
OnAdd()
OnAdd(ctx context.Context)
}
// XAttrOperations is a collection of methods used to implement extended attributes.
......
......@@ -5,6 +5,7 @@
package nodefs
import (
"context"
"log"
"sync"
"syscall"
......@@ -44,7 +45,7 @@ type rawBridge struct {
}
// newInode creates creates new inode pointing to ops.
func (b *rawBridge) newInode(ops Operations, id NodeAttr, persistent bool) *Inode {
func (b *rawBridge) newInode(ctx context.Context, ops Operations, id NodeAttr, persistent bool) *Inode {
b.mu.Lock()
defer b.mu.Unlock()
......@@ -104,7 +105,7 @@ func (b *rawBridge) newInode(ops Operations, id NodeAttr, persistent bool) *Inod
newIno := ops.inode()
if newIno == inode {
newIno.ops.OnAdd()
newIno.ops.OnAdd(ctx)
}
return newIno
......@@ -188,7 +189,7 @@ func NewNodeFS(root DirOperations, opts *Options) fuse.RawFileSystem {
// Fh 0 means no file handle.
bridge.files = []*fileEntry{{}}
root.OnAdd()
root.OnAdd(context.Background())
return bridge
}
......
......@@ -66,20 +66,20 @@ type keepCacheRoot struct {
keep, nokeep *keepCacheFile
}
func (r *keepCacheRoot) OnAdd() {
func (r *keepCacheRoot) OnAdd(ctx context.Context) {
i := InodeOf(r)
r.keep = &keepCacheFile{
keepCache: true,
}
r.keep.setContent(0)
i.AddChild("keep", i.NewInode(r.keep, NodeAttr{}), true)
i.AddChild("keep", i.NewInode(ctx, r.keep, NodeAttr{}), true)
r.nokeep = &keepCacheFile{
keepCache: false,
}
r.nokeep.setContent(0)
i.AddChild("nokeep", i.NewInode(r.nokeep, NodeAttr{}), true)
i.AddChild("nokeep", i.NewInode(ctx, r.nokeep, NodeAttr{}), true)
}
func TestKeepCache(t *testing.T) {
......
......@@ -63,8 +63,8 @@ func (n *DefaultOperations) StatFs(ctx context.Context, out *fuse.StatfsOut) fus
return fuse.OK
}
func (n *DefaultOperations) OnAdd() {
// XXX context?
// The default OnAdd does nothing.
func (n *DefaultOperations) OnAdd(ctx context.Context) {
}
// GetAttr zeroes out argument and returns OK.
......
......@@ -5,6 +5,7 @@
package nodefs
import (
"context"
"fmt"
"log"
"sort"
......@@ -272,8 +273,8 @@ func (iparent *Inode) setEntry(name string, ichild *Inode) {
// NewPersistentInode returns an Inode whose lifetime is not in
// control of the kernel.
func (n *Inode) NewPersistentInode(node Operations, id NodeAttr) *Inode {
return n.newInode(node, id, true)
func (n *Inode) NewPersistentInode(ctx context.Context, node Operations, id NodeAttr) *Inode {
return n.newInode(ctx, node, id, true)
}
// ForgetPersistent manually marks the node as no longer important. If
......@@ -288,12 +289,12 @@ func (n *Inode) ForgetPersistent() {
// non-zero, is used to implement hard-links. If opaqueID is given,
// and another node with the same ID is known, that will node will be
// returned, and the passed-in `node` is ignored.
func (n *Inode) NewInode(node Operations, id NodeAttr) *Inode {
return n.newInode(node, id, false)
func (n *Inode) NewInode(ctx context.Context, node Operations, id NodeAttr) *Inode {
return n.newInode(ctx, node, id, false)
}
func (n *Inode) newInode(node Operations, id NodeAttr, persistent bool) *Inode {
return n.bridge.newInode(node, id, persistent)
func (n *Inode) newInode(ctx context.Context, node Operations, id NodeAttr, persistent bool) *Inode {
return n.bridge.newInode(ctx, node, id, persistent)
}
// removeRef decreases references. Returns if this operation caused
......
......@@ -29,7 +29,7 @@ func (r *interruptRoot) Lookup(ctx context.Context, name string, out *fuse.Entry
if name != "file" {
return nil, fuse.ENOENT
}
ch := InodeOf(r).NewInode(&r.child, NodeAttr{
ch := InodeOf(r).NewInode(ctx, &r.child, NodeAttr{
Ino: 2,
Gen: 1})
......
......@@ -70,7 +70,7 @@ func (n *loopbackNode) Lookup(ctx context.Context, name string, out *fuse.EntryO
out.Attr.FromStat(&st)
node := n.rootNode.newLoopbackNode()
ch := n.inode().NewInode(node, n.rootNode.idFromStat(&st))
ch := n.inode().NewInode(ctx, node, n.rootNode.idFromStat(&st))
return ch, fuse.OK
}
......@@ -89,7 +89,7 @@ func (n *loopbackNode) Mknod(ctx context.Context, name string, mode, rdev uint32
out.Attr.FromStat(&st)
node := n.rootNode.newLoopbackNode()
ch := n.inode().NewInode(node, n.rootNode.idFromStat(&st))
ch := n.inode().NewInode(ctx, node, n.rootNode.idFromStat(&st))
return ch, fuse.OK
}
......@@ -109,7 +109,7 @@ func (n *loopbackNode) Mkdir(ctx context.Context, name string, mode uint32, out
out.Attr.FromStat(&st)
node := n.rootNode.newLoopbackNode()
ch := n.inode().NewInode(node, n.rootNode.idFromStat(&st))
ch := n.inode().NewInode(ctx, node, n.rootNode.idFromStat(&st))
return ch, fuse.OK
}
......@@ -180,7 +180,7 @@ func (n *loopbackNode) Create(ctx context.Context, name string, flags uint32, mo
}
node := n.rootNode.newLoopbackNode()
ch := n.inode().NewInode(node, n.rootNode.idFromStat(&st))
ch := n.inode().NewInode(ctx, node, n.rootNode.idFromStat(&st))
lf := NewLoopbackFile(fd)
return ch, lf, 0, fuse.OK
}
......@@ -197,7 +197,7 @@ func (n *loopbackNode) Symlink(ctx context.Context, target, name string, out *fu
return nil, fuse.ToStatus(err)
}
node := n.rootNode.newLoopbackNode()
ch := n.inode().NewInode(node, n.rootNode.idFromStat(&st))
ch := n.inode().NewInode(ctx, node, n.rootNode.idFromStat(&st))
out.Attr.FromStat(&st)
return ch, fuse.OK
......@@ -217,7 +217,7 @@ func (n *loopbackNode) Link(ctx context.Context, target Operations, name string,
return nil, fuse.ToStatus(err)
}
node := n.rootNode.newLoopbackNode()
ch := n.inode().NewInode(node, n.rootNode.idFromStat(&st))
ch := n.inode().NewInode(ctx, node, n.rootNode.idFromStat(&st))
out.Attr.FromStat(&st)
return ch, fuse.OK
......
......@@ -167,7 +167,7 @@ type zipRoot struct {
r *zip.Reader
}
func (zr *zipRoot) OnAdd() {
func (zr *zipRoot) OnAdd(ctx context.Context) {
// OnAdd is called once we are attached to an Inode. We can
// then construct a tree. We construct the entire tree, and
// we don't want parts of the tree to disappear when the
......@@ -182,14 +182,14 @@ func (zr *zipRoot) OnAdd() {
}
ch := p.GetChild(component)
if ch == nil {
ch = InodeOf(zr).NewPersistentInode(&DefaultOperations{},
ch = InodeOf(zr).NewPersistentInode(ctx, &DefaultOperations{},
NodeAttr{Mode: fuse.S_IFDIR})
p.AddChild(component, ch, true)
}
p = ch
}
ch := InodeOf(zr).NewPersistentInode(&zipFile{file: f}, NodeAttr{})
ch := InodeOf(zr).NewPersistentInode(ctx, &zipFile{file: f}, NodeAttr{})
p.AddChild(base, ch, true)
}
}
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