Skip to content

Commit 277f27e

Browse files
trondmychucklever
authored andcommitted
SUNRPC/cache: Allow garbage collection of invalid cache entries
If the cache entry never gets initialised, we want the garbage collector to be able to evict it. Otherwise if the upcall daemon fails to initialise the entry, we end up never expiring it. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> [ cel: resolved a merge conflict ] Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 65286b8 commit 277f27e

2 files changed

Lines changed: 19 additions & 20 deletions

File tree

‎include/linux/sunrpc/cache.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@ static inline void cache_put(struct cache_head *h, struct cache_detail *cd)
209209

210210
static inline bool cache_is_expired(struct cache_detail *detail, struct cache_head *h)
211211
{
212-
if (!test_bit(CACHE_VALID, &h->flags))
213-
return false;
214-
215212
return (h->expiry_time < seconds_since_boot()) ||
216213
(detail->flush_time >= h->last_refresh);
217214
}

‎net/sunrpc/cache.c‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ static struct cache_head *sunrpc_cache_find_rcu(struct cache_detail *detail,
6464

6565
rcu_read_lock();
6666
hlist_for_each_entry_rcu(tmp, head, cache_list) {
67-
if (detail->match(tmp, key)) {
68-
if (cache_is_expired(detail, tmp))
69-
continue;
70-
tmp = cache_get_rcu(tmp);
71-
rcu_read_unlock();
72-
return tmp;
73-
}
67+
if (!detail->match(tmp, key))
68+
continue;
69+
if (test_bit(CACHE_VALID, &tmp->flags) &&
70+
cache_is_expired(detail, tmp))
71+
continue;
72+
tmp = cache_get_rcu(tmp);
73+
rcu_read_unlock();
74+
return tmp;
7475
}
7576
rcu_read_unlock();
7677
return NULL;
@@ -114,17 +115,18 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
114115
/* check if entry appeared while we slept */
115116
hlist_for_each_entry_rcu(tmp, head, cache_list,
116117
lockdep_is_held(&detail->hash_lock)) {
117-
if (detail->match(tmp, key)) {
118-
if (cache_is_expired(detail, tmp)) {
119-
sunrpc_begin_cache_remove_entry(tmp, detail);
120-
freeme = tmp;
121-
break;
122-
}
123-
cache_get(tmp);
124-
spin_unlock(&detail->hash_lock);
125-
cache_put(new, detail);
126-
return tmp;
118+
if (!detail->match(tmp, key))
119+
continue;
120+
if (test_bit(CACHE_VALID, &tmp->flags) &&
121+
cache_is_expired(detail, tmp)) {
122+
sunrpc_begin_cache_remove_entry(tmp, detail);
123+
freeme = tmp;
124+
break;
127125
}
126+
cache_get(tmp);
127+
spin_unlock(&detail->hash_lock);
128+
cache_put(new, detail);
129+
return tmp;
128130
}
129131

130132
hlist_add_head_rcu(&new->cache_list, head);

0 commit comments

Comments
 (0)