-
Notifications
You must be signed in to change notification settings - Fork 67
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
Changes from 4 commits
25f7e4e
b076f18
e18ee07
39ae89f
2a9eb81
c979e09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
} | ||
|
||
|
@@ -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 | ||
} | ||
|
||
|
@@ -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. | ||
// children maps from previously-looked up base names (like "foo.txt") to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. I added mutex to protect children maps in e18ee07. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not enough. This read is also a race. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your review. I fixed it on 39ae89f. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
There was a problem hiding this comment.
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