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

nodefs: pass context to OnAdd

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