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

Protect node.ents and node.entsCached with a mutex in fs/layer/node.go #1381

Merged
merged 1 commit into from
Sep 13, 2023
Merged
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
19 changes: 15 additions & 4 deletions fs/layer/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ func (fs *fs) inodeOfID(id uint32) (uint64, error) {
// node is a filesystem inode abstraction.
type node struct {
fusefs.Inode
fs *fs
id uint32
attr metadata.Attr
fs *fs
id uint32
attr metadata.Attr

ents []fuse.DirEntry
entsCached bool
entsMu sync.Mutex
}

func (n *node) isRootNode() bool {
Expand Down Expand Up @@ -162,9 +164,13 @@ func (n *node) readdir() ([]fuse.DirEntry, syscall.Errno) {
start := time.Now() // set start time
defer commonmetrics.MeasureLatencyInMicroseconds(commonmetrics.NodeReaddir, n.fs.layerDigest, start)

n.entsMu.Lock()
if n.entsCached {
return n.ents, 0
ents := n.ents
n.entsMu.Unlock()
return ents, 0
}
n.entsMu.Unlock()

isRoot := n.isRootNode()

Expand Down Expand Up @@ -228,6 +234,8 @@ func (n *node) readdir() ([]fuse.DirEntry, syscall.Errno) {
sort.Slice(ents, func(i, j int) bool {
return ents[i].Name < ents[j].Name
})
n.entsMu.Lock()
defer n.entsMu.Unlock()
n.ents, n.entsCached = ents, true // cache it

return ents, 0
Expand Down Expand Up @@ -279,6 +287,7 @@ func (n *node) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fu
}

// early return if this entry doesn't exist
n.entsMu.Lock()
if n.entsCached {
var found bool
for _, e := range n.ents {
Expand All @@ -287,9 +296,11 @@ func (n *node) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fu
}
}
if !found {
n.entsMu.Unlock()
return nil, syscall.ENOENT
}
}
n.entsMu.Unlock()

id, ce, err := n.fs.r.Metadata().GetChild(n.id, name)
if err != nil {
Expand Down