Skip to content

Commit

Permalink
fs: avert data races on the nodeRef map
Browse files Browse the repository at this point in the history
Under load, a filesystem that attempts to explicitly invalidate nodes via the
InvalidateEntry and InvalidateNodeAttr methods of the server can race on access
to the server's nodeRef map. This leads to panics when the runtime detects it.

According to the comments on the server, the "meta" lock is supposed to be held
when accessing this map; however the Invalidate* methods do not do this. The
obvious fix of adding locks there does not quite work, since in some cases the
server already holds that lock (vending a request to the FS) making the upcall
a deadlock.

This patch addresses the problem by introducing a new lock specifically for the
nodeRef map, and ensuring it is explicitly acquired by the methods that access
that map.
  • Loading branch information
creachadair committed Aug 21, 2023
1 parent fcffb10 commit 238c0ba
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fs/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ type Server struct {
meta sync.Mutex
req map[fuse.RequestID]func() // map request to cancel functions
node []*serveNode
nodeRefLock sync.Mutex
nodeRef map[Node]fuse.NodeID
inode2idLock sync.Mutex
inode2id map[uint64]fuse.NodeID
Expand Down Expand Up @@ -1716,6 +1717,8 @@ func (s *Server) getNodeId(node Node) (id fuse.NodeID, ok bool) {
s.inode2idLock.Unlock()
return
}
s.nodeRefLock.Lock()
defer s.nodeRefLock.Unlock()
id, ok = s.nodeRef[node]
return
}
Expand All @@ -1726,6 +1729,8 @@ func (s *Server) setNodeId(node Node, id fuse.NodeID) {
s.inode2idLock.Unlock()
return
}
s.nodeRefLock.Lock()
defer s.nodeRefLock.Unlock()
s.nodeRef[node] = id
}
func (s *Server) delNodeId(node Node) {
Expand All @@ -1735,6 +1740,8 @@ func (s *Server) delNodeId(node Node) {
s.inode2idLock.Unlock()
return
}
s.nodeRefLock.Lock()
defer s.nodeRefLock.Unlock()
delete(s.nodeRef, node)
}

Expand Down

0 comments on commit 238c0ba

Please sign in to comment.