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

Provide same Node instance for same file not to make overlayfs confused. #19

Merged
merged 6 commits into from Oct 6, 2019
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion crfs.go
Expand Up @@ -474,6 +474,7 @@ func (n *layerDebugRoot) Lookup(ctx context.Context, name string) (fspkg.Node, e
te: root,
sr: r,
f: f,
child: make(map[string]*node),
}, nil
}

Expand Down Expand Up @@ -775,6 +776,7 @@ func (n *layerHostOwnerImageReference) Lookup(ctx context.Context, name string)
fs: n.fs,
te: root,
sr: r,
child: make(map[string]*node),
}, nil
}

Expand Down Expand Up @@ -901,6 +903,12 @@ type node struct {
te *stargz.TOCEntry
sr *stargz.Reader
f *os.File // non-nil if root & in debug mode

mu sync.Mutex // For children maps.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mu sync.Mutex // guards child, below

// children maps from previously-looked up base names (like "foo.txt") to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// child maps ...

(The field is named "child", not "children")

// the *node that was previously returned. This prevents FUSE inode numbers
// from getting out of sync
child map[string]*node
}

var (
Expand Down Expand Up @@ -966,11 +974,26 @@ func (h *nodeHandle) ReadDirAll(ctx context.Context) (ents []fuse.Dirent, err er
//
// See https://godoc.org/bazil.org/fuse/fs#NodeStringLookuper
func (n *node) Lookup(ctx context.Context, name string) (fspkg.Node, error) {
n.mu.Lock()
defer n.mu.Unlock()
if c, ok := n.child[name] ; ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a data race. The node.Lookup can be called from concurrent goroutines and no mutex is protecting this map read/write.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I added mutex to protect children maps in e18ee07.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not enough. This read is also a race.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review. I fixed it on 39ae89f.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run gofmt. No space before ;.

return c, nil
}

e, ok := n.te.LookupChild(name)
if !ok {
return nil, fuse.ENOENT
}
return &node{n.fs, e, n.sr, nil}, nil

c := &node{
fs: n.fs,
te: e,
sr: n.sr,
child: make(map[string]*node),
}
n.child[name] = c

return c, nil
}

// Readlink reads the target of a symlink.
Expand Down