Skip to content

Commit f9ecfd9

Browse files
tranji-cloudgvisor-bot
authored andcommitted
Close the controlFD used to fstat upon an inode cache hit
Fixes #12125 PiperOrigin-RevId: 805463538
1 parent 3eb1b76 commit f9ecfd9

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

pkg/sentry/fsimpl/gofer/directfs_inode.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ func (fs *filesystem) newDirectfsDentry(controlFD int) (*dentry, error) {
134134
d dentry
135135
i directfsInode
136136
}{}
137-
138-
temp.d.inode = fs.getOrCreateInode(inoKey, func() *inode {
137+
temp.d.inode = fs.getOrCreateInode(inoKey, func() { _ = unix.Close(controlFD) }, func() *inode {
139138
temp.i = directfsInode{
140139
inode: inode{
141140
fs: fs,

pkg/sentry/fsimpl/gofer/gofer.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,16 @@ type filesystem struct {
260260
released atomicbitops.Int32
261261
}
262262

263-
// getOrCreateInode returns the inode for the given inoKey and increments its reference count.
264-
// If the inode is not found, then createInode is called and the new inode is returned.
263+
// getOrCreateInode returns the inode for the given inoKey and upon inode cache
264+
// hit, calls onCacheHit and increments the inode's reference count. On cache
265+
// miss, createInode is called and the new inode is returned.
265266
// getOrCreateInode locks fs.inodeMu.
266267
// The caller is responsible for decrementing the inode's reference count when done.
267-
func (fs *filesystem) getOrCreateInode(inoKey inoKey, createInode func() *inode) *inode {
268+
func (fs *filesystem) getOrCreateInode(inoKey inoKey, onCacheHit func(), createInode func() *inode) *inode {
268269
fs.inodeMu.Lock()
269270
defer fs.inodeMu.Unlock()
270271
if cachedInode, ok := fs.inodeByKey[inoKey]; ok {
272+
onCacheHit()
271273
cachedInode.incRef()
272274
return cachedInode
273275
}

pkg/sentry/fsimpl/gofer/lisafs_inode.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ func (fs *filesystem) newLisafsDentry(ctx context.Context, ino *lisafs.Inode) (*
125125
d dentry
126126
i lisafsInode
127127
}{}
128-
temp.d.inode = fs.getOrCreateInode(inoKey, func() *inode {
128+
temp.d.inode = fs.getOrCreateInode(inoKey, func() {
129+
fs.client.CloseFD(ctx, ino.ControlFD, false /* flush */)
130+
}, func() *inode {
129131
temp.i = lisafsInode{
130132
inode: inode{
131133
fs: fs,

0 commit comments

Comments
 (0)