Commit 277f27e2 authored by Trond Myklebust's avatar Trond Myklebust Committed by Chuck Lever
Browse files

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: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
[ cel: resolved a merge conflict ]
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent 65286b88
Loading
Loading
Loading
Loading
+0 −3
Original line number Original line Diff line number Diff line
@@ -209,9 +209,6 @@ static inline void cache_put(struct cache_head *h, struct cache_detail *cd)


static inline bool cache_is_expired(struct cache_detail *detail, struct cache_head *h)
static inline bool cache_is_expired(struct cache_detail *detail, struct cache_head *h)
{
{
	if (!test_bit(CACHE_VALID, &h->flags))
		return false;

	return  (h->expiry_time < seconds_since_boot()) ||
	return  (h->expiry_time < seconds_since_boot()) ||
		(detail->flush_time >= h->last_refresh);
		(detail->flush_time >= h->last_refresh);
}
}
+19 −17
Original line number Original line Diff line number Diff line
@@ -64,14 +64,15 @@ static struct cache_head *sunrpc_cache_find_rcu(struct cache_detail *detail,


	rcu_read_lock();
	rcu_read_lock();
	hlist_for_each_entry_rcu(tmp, head, cache_list) {
	hlist_for_each_entry_rcu(tmp, head, cache_list) {
		if (detail->match(tmp, key)) {
		if (!detail->match(tmp, key))
			if (cache_is_expired(detail, tmp))
			continue;
		if (test_bit(CACHE_VALID, &tmp->flags) &&
		    cache_is_expired(detail, tmp))
			continue;
			continue;
		tmp = cache_get_rcu(tmp);
		tmp = cache_get_rcu(tmp);
		rcu_read_unlock();
		rcu_read_unlock();
		return tmp;
		return tmp;
	}
	}
	}
	rcu_read_unlock();
	rcu_read_unlock();
	return NULL;
	return NULL;
}
}
@@ -114,8 +115,10 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
	/* check if entry appeared while we slept */
	/* check if entry appeared while we slept */
	hlist_for_each_entry_rcu(tmp, head, cache_list,
	hlist_for_each_entry_rcu(tmp, head, cache_list,
				 lockdep_is_held(&detail->hash_lock)) {
				 lockdep_is_held(&detail->hash_lock)) {
		if (detail->match(tmp, key)) {
		if (!detail->match(tmp, key))
			if (cache_is_expired(detail, tmp)) {
			continue;
		if (test_bit(CACHE_VALID, &tmp->flags) &&
		    cache_is_expired(detail, tmp)) {
			sunrpc_begin_cache_remove_entry(tmp, detail);
			sunrpc_begin_cache_remove_entry(tmp, detail);
			freeme = tmp;
			freeme = tmp;
			break;
			break;
@@ -125,7 +128,6 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
		cache_put(new, detail);
		cache_put(new, detail);
		return tmp;
		return tmp;
	}
	}
	}


	hlist_add_head_rcu(&new->cache_list, head);
	hlist_add_head_rcu(&new->cache_list, head);
	detail->entries++;
	detail->entries++;