Skip to content

Commit

Permalink
Protect all read/write operations to node children maps from race.
Browse files Browse the repository at this point in the history
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
  • Loading branch information
ktock committed Sep 21, 2019
1 parent e18ee07 commit 39ae89f
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions crfs.go
Expand Up @@ -974,6 +974,8 @@ 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 {
return c, nil
}
Expand All @@ -989,15 +991,7 @@ func (n *node) Lookup(ctx context.Context, name string) (fspkg.Node, error) {
sr: n.sr,
child: make(map[string]*node),
}
n.mu.Lock()
if c2, ok := n.child[name] ; ok {
// Someone generated node object during our looking up.
// In this case, we use this registered one not to make kernel confused.
c = c2
} else {
n.child[name] = c
}
n.mu.Unlock()
n.child[name] = c

return c, nil
}
Expand Down

0 comments on commit 39ae89f

Please sign in to comment.