Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inode.Initialized() for checking if an inode has been initialized. #520

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions fs/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,36 @@ func (fn *testIno1) Lookup(ctx context.Context, name string, out *fuse.EntryOut)
child := fn.NewInode(ctx, &testIno1{}, stable)
return child, 0
}

func TestForgottenIno(t *testing.T) {
rootNode := testForgottenIno{}
testMount(t, &rootNode, nil)
if rootNode.Initialized() && rootNode.Forgotten() {
t.Error("newly-created inode should not be forgotten")
}
ino, errno := rootNode.Lookup(context.TODO(), "test", nil)
if errno != syscall.F_OK {
t.Error("error creating new inode")
}
if ino.Initialized() && ino.Forgotten() {
t.Error("newly-created inode should not be forgotten")
}
ok := rootNode.AddChild("test", ino, false)
if !ok {
t.Error("error adding child inode to fs")
}
if ino.Initialized() && ino.Forgotten() {
t.Error("newly-mounted inode should not be forgotten")
}
}

type testForgottenIno struct {
Inode
}

func (n *testForgottenIno) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*Inode, syscall.Errno) {
childNode := &testForgottenIno{}
stable := StableAttr{Mode: syscall.S_IFREG, Ino: 999}
child := n.NewInode(ctx, childNode, stable)
return child, syscall.F_OK
}
8 changes: 8 additions & 0 deletions fs/inode.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ func unlockNodes(ns ...*Inode) {
}
}

// Initialized returns true if this inode has been initialized and added to the
// filesystem tree.
func (n *Inode) Initialized() bool {
n.mu.Lock()
defer n.mu.Unlock()
return n.changeCounter > 0
}

// Forgotten returns true if the kernel holds no references to this
// inode. This can be used for background cleanup tasks, since the
// kernel has no way of reviving forgotten nodes by its own
Expand Down