Commit b92a8fab authored by Trond Myklebust's avatar Trond Myklebust Committed by J. Bruce Fields

SUNRPC: Refactor sunrpc_cache_lookup

This is a trivial split into lookup and insert functions, no change in
behavior.
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
parent 608a0ab2
...@@ -54,13 +54,11 @@ static void cache_init(struct cache_head *h, struct cache_detail *detail) ...@@ -54,13 +54,11 @@ static void cache_init(struct cache_head *h, struct cache_detail *detail)
h->last_refresh = now; h->last_refresh = now;
} }
struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, static struct cache_head *sunrpc_cache_find(struct cache_detail *detail,
struct cache_head *key, int hash) struct cache_head *key, int hash)
{ {
struct cache_head *new = NULL, *freeme = NULL, *tmp = NULL; struct hlist_head *head = &detail->hash_table[hash];
struct hlist_head *head; struct cache_head *tmp;
head = &detail->hash_table[hash];
read_lock(&detail->hash_lock); read_lock(&detail->hash_lock);
...@@ -75,7 +73,15 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, ...@@ -75,7 +73,15 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
} }
} }
read_unlock(&detail->hash_lock); read_unlock(&detail->hash_lock);
/* Didn't find anything, insert an empty entry */ return NULL;
}
static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
struct cache_head *key,
int hash)
{
struct cache_head *new, *tmp, *freeme = NULL;
struct hlist_head *head = &detail->hash_table[hash];
new = detail->alloc(); new = detail->alloc();
if (!new) if (!new)
...@@ -114,8 +120,19 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, ...@@ -114,8 +120,19 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
cache_put(freeme, detail); cache_put(freeme, detail);
return new; return new;
} }
EXPORT_SYMBOL_GPL(sunrpc_cache_lookup);
struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
struct cache_head *key, int hash)
{
struct cache_head *ret;
ret = sunrpc_cache_find(detail, key, hash);
if (ret)
return ret;
/* Didn't find anything, insert an empty entry */
return sunrpc_cache_add_entry(detail, key, hash);
}
EXPORT_SYMBOL_GPL(sunrpc_cache_lookup);
static void cache_dequeue(struct cache_detail *detail, struct cache_head *ch); static void cache_dequeue(struct cache_detail *detail, struct cache_head *ch);
......
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