Skip to content

Commit 57b6918

Browse files
committed
NFS: Cache access checks more aggressively
If an attribute revalidation fails, then we already know that we'll zap the access cache. If, OTOH, the inode isn't changing, there should be no need to eject access calls just because they are old. Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent 38512aa commit 57b6918

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

fs/nfs/dir.c

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,21 +2228,37 @@ static struct nfs_access_entry *nfs_access_search_rbtree(struct inode *inode, st
22282228
return NULL;
22292229
}
22302230

2231-
static int nfs_access_get_cached(struct inode *inode, struct rpc_cred *cred, struct nfs_access_entry *res)
2231+
static int nfs_access_get_cached(struct inode *inode, struct rpc_cred *cred, struct nfs_access_entry *res, bool may_block)
22322232
{
22332233
struct nfs_inode *nfsi = NFS_I(inode);
22342234
struct nfs_access_entry *cache;
2235-
int err = -ENOENT;
2235+
bool retry = true;
2236+
int err;
22362237

22372238
spin_lock(&inode->i_lock);
2238-
if (nfsi->cache_validity & NFS_INO_INVALID_ACCESS)
2239-
goto out_zap;
2240-
cache = nfs_access_search_rbtree(inode, cred);
2241-
if (cache == NULL)
2242-
goto out;
2243-
if (!nfs_have_delegated_attributes(inode) &&
2244-
!time_in_range_open(jiffies, cache->jiffies, cache->jiffies + nfsi->attrtimeo))
2245-
goto out_stale;
2239+
for(;;) {
2240+
if (nfsi->cache_validity & NFS_INO_INVALID_ACCESS)
2241+
goto out_zap;
2242+
cache = nfs_access_search_rbtree(inode, cred);
2243+
err = -ENOENT;
2244+
if (cache == NULL)
2245+
goto out;
2246+
/* Found an entry, is our attribute cache valid? */
2247+
if (!nfs_attribute_cache_expired(inode) &&
2248+
!(nfsi->cache_validity & NFS_INO_INVALID_ATTR))
2249+
break;
2250+
err = -ECHILD;
2251+
if (!may_block)
2252+
goto out;
2253+
if (!retry)
2254+
goto out_zap;
2255+
spin_unlock(&inode->i_lock);
2256+
err = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
2257+
if (err)
2258+
return err;
2259+
spin_lock(&inode->i_lock);
2260+
retry = false;
2261+
}
22462262
res->jiffies = cache->jiffies;
22472263
res->cred = cache->cred;
22482264
res->mask = cache->mask;
@@ -2251,12 +2267,6 @@ static int nfs_access_get_cached(struct inode *inode, struct rpc_cred *cred, str
22512267
out:
22522268
spin_unlock(&inode->i_lock);
22532269
return err;
2254-
out_stale:
2255-
rb_erase(&cache->rb_node, &nfsi->access_cache);
2256-
list_del(&cache->lru);
2257-
spin_unlock(&inode->i_lock);
2258-
nfs_access_free_entry(cache);
2259-
return -ENOENT;
22602270
out_zap:
22612271
spin_unlock(&inode->i_lock);
22622272
nfs_access_zap_cache(inode);
@@ -2283,13 +2293,12 @@ static int nfs_access_get_cached_rcu(struct inode *inode, struct rpc_cred *cred,
22832293
cache = NULL;
22842294
if (cache == NULL)
22852295
goto out;
2286-
if (!nfs_have_delegated_attributes(inode) &&
2287-
!time_in_range_open(jiffies, cache->jiffies, cache->jiffies + nfsi->attrtimeo))
2296+
err = nfs_revalidate_inode_rcu(NFS_SERVER(inode), inode);
2297+
if (err)
22882298
goto out;
22892299
res->jiffies = cache->jiffies;
22902300
res->cred = cache->cred;
22912301
res->mask = cache->mask;
2292-
err = 0;
22932302
out:
22942303
rcu_read_unlock();
22952304
return err;
@@ -2378,18 +2387,19 @@ EXPORT_SYMBOL_GPL(nfs_access_set_mask);
23782387
static int nfs_do_access(struct inode *inode, struct rpc_cred *cred, int mask)
23792388
{
23802389
struct nfs_access_entry cache;
2390+
bool may_block = (mask & MAY_NOT_BLOCK) == 0;
23812391
int status;
23822392

23832393
trace_nfs_access_enter(inode);
23842394

23852395
status = nfs_access_get_cached_rcu(inode, cred, &cache);
23862396
if (status != 0)
2387-
status = nfs_access_get_cached(inode, cred, &cache);
2397+
status = nfs_access_get_cached(inode, cred, &cache, may_block);
23882398
if (status == 0)
23892399
goto out_cached;
23902400

23912401
status = -ECHILD;
2392-
if (mask & MAY_NOT_BLOCK)
2402+
if (!may_block)
23932403
goto out;
23942404

23952405
/* Be clever: ask server to check for all possible rights */

0 commit comments

Comments
 (0)