From 567c5eed11cfcea78b80169487664106a41fa1fe Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Fri, 10 Aug 2018 15:41:44 -0700 Subject: cache policy: Check policy before returning a negative dirent. The cache policy determines whether Lookup should return a negative dirent, or just ENOENT. This CL fixes one spot where we returned a negative dirent without first consulting the policy. PiperOrigin-RevId: 208280230 Change-Id: I8f963bbdb45a95a74ad0ecc1eef47eff2092d3a4 --- pkg/sentry/fs/gofer/path.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'pkg/sentry/fs') diff --git a/pkg/sentry/fs/gofer/path.go b/pkg/sentry/fs/gofer/path.go index 15e9863fb..bec9680f8 100644 --- a/pkg/sentry/fs/gofer/path.go +++ b/pkg/sentry/fs/gofer/path.go @@ -29,15 +29,19 @@ import ( // Lookup loads an Inode at name into a Dirent based on the session's cache // policy. func (i *inodeOperations) Lookup(ctx context.Context, dir *fs.Inode, name string) (*fs.Dirent, error) { - if i.session().cachePolicy.cacheReaddir() { + cp := i.session().cachePolicy + if cp.cacheReaddir() { // Check to see if we have readdirCache that indicates the // child does not exist. Avoid holding readdirMu longer than // we need to. i.readdirMu.Lock() if i.readdirCache != nil && !i.readdirCache.Contains(name) { - // No such child. Return a negative dirent. + // No such child. i.readdirMu.Unlock() - return fs.NewNegativeDirent(name), nil + if cp.cacheNegativeDirents() { + return fs.NewNegativeDirent(name), nil + } + return nil, syserror.ENOENT } i.readdirMu.Unlock() } @@ -46,7 +50,7 @@ func (i *inodeOperations) Lookup(ctx context.Context, dir *fs.Inode, name string qids, newFile, mask, p9attr, err := i.fileState.file.walkGetAttr(ctx, []string{name}) if err != nil { if err == syscall.ENOENT { - if i.session().cachePolicy.cacheNegativeDirents() { + if cp.cacheNegativeDirents() { // Return a negative Dirent. It will stay cached until something // is created over it. return fs.NewNegativeDirent(name), nil -- cgit v1.2.3