Commit 2f50d8b6 authored by NeilBrown's avatar NeilBrown Committed by J. Bruce Fields

sunrpc/cache: factor out cache_is_expired

This removes a tiny bit of code duplication, but more important
prepares for following patch which will perform the expiry check in
cache_lookup and the rest of the validity check in cache_check.
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
Signed-off-by: default avatarJ. Bruce Fields <bfields@citi.umich.edu>
parent 3af4974e
...@@ -49,6 +49,12 @@ static void cache_init(struct cache_head *h) ...@@ -49,6 +49,12 @@ static void cache_init(struct cache_head *h)
h->last_refresh = now; h->last_refresh = now;
} }
static inline int cache_is_expired(struct cache_detail *detail, struct cache_head *h)
{
return (h->expiry_time < get_seconds()) ||
(detail->flush_time > h->last_refresh);
}
struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
struct cache_head *key, int hash) struct cache_head *key, int hash)
{ {
...@@ -184,9 +190,7 @@ static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h) ...@@ -184,9 +190,7 @@ static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
static inline int cache_is_valid(struct cache_detail *detail, struct cache_head *h) static inline int cache_is_valid(struct cache_detail *detail, struct cache_head *h)
{ {
if (!test_bit(CACHE_VALID, &h->flags) || if (!test_bit(CACHE_VALID, &h->flags) ||
h->expiry_time < get_seconds()) cache_is_expired(detail, h))
return -EAGAIN;
else if (detail->flush_time > h->last_refresh)
return -EAGAIN; return -EAGAIN;
else { else {
/* entry is valid */ /* entry is valid */
...@@ -400,8 +404,7 @@ static int cache_clean(void) ...@@ -400,8 +404,7 @@ static int cache_clean(void)
for (ch = *cp ; ch ; cp = & ch->next, ch = *cp) { for (ch = *cp ; ch ; cp = & ch->next, ch = *cp) {
if (current_detail->nextcheck > ch->expiry_time) if (current_detail->nextcheck > ch->expiry_time)
current_detail->nextcheck = ch->expiry_time+1; current_detail->nextcheck = ch->expiry_time+1;
if (ch->expiry_time >= get_seconds() && if (!cache_is_expired(current_detail, ch))
ch->last_refresh >= current_detail->flush_time)
continue; continue;
*cp = ch->next; *cp = ch->next;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment