提交 d1a0774d 编写于 作者: J Jeff Layton 提交者: J. Bruce Fields

nfsd: clean up and clarify the cache expiration code

Add a preprocessor constant for the expiry time of cache entries, and
move the test for an expired entry into a function. Note that the current
code does not test for RC_INPROG. It just assumes that it won't take more
than 2 minutes to fill out an in-progress entry.

I'm not sure how valid that assumption is though, so let's just ensure
that we never consider an RC_INPROG entry to be expired.
Signed-off-by: NJeff Layton <jlayton@redhat.com>
Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
上级 25e6b8b0
...@@ -70,6 +70,9 @@ enum { ...@@ -70,6 +70,9 @@ enum {
*/ */
#define RC_DELAY (HZ/5) #define RC_DELAY (HZ/5)
/* Cache entries expire after this time period */
#define RC_EXPIRE (120 * HZ)
int nfsd_reply_cache_init(void); int nfsd_reply_cache_init(void);
void nfsd_reply_cache_shutdown(void); void nfsd_reply_cache_shutdown(void);
int nfsd_cache_lookup(struct svc_rqst *); int nfsd_cache_lookup(struct svc_rqst *);
......
...@@ -142,6 +142,13 @@ hash_refile(struct svc_cacherep *rp) ...@@ -142,6 +142,13 @@ hash_refile(struct svc_cacherep *rp)
hlist_add_head(&rp->c_hash, cache_hash + request_hash(rp->c_xid)); hlist_add_head(&rp->c_hash, cache_hash + request_hash(rp->c_xid));
} }
static inline bool
nfsd_cache_entry_expired(struct svc_cacherep *rp)
{
return rp->c_state != RC_INPROG &&
time_after(jiffies, rp->c_timestamp + RC_EXPIRE);
}
/* /*
* Try to find an entry matching the current call in the cache. When none * Try to find an entry matching the current call in the cache. When none
* is found, we grab the oldest unlocked entry off the LRU list. * is found, we grab the oldest unlocked entry off the LRU list.
...@@ -175,7 +182,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp) ...@@ -175,7 +182,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp)
if (rp->c_state != RC_UNUSED && if (rp->c_state != RC_UNUSED &&
xid == rp->c_xid && proc == rp->c_proc && xid == rp->c_xid && proc == rp->c_proc &&
proto == rp->c_prot && vers == rp->c_vers && proto == rp->c_prot && vers == rp->c_vers &&
time_before(jiffies, rp->c_timestamp + 120*HZ) && !nfsd_cache_entry_expired(rp) &&
rpc_cmp_addr(svc_addr(rqstp), (struct sockaddr *)&rp->c_addr) && rpc_cmp_addr(svc_addr(rqstp), (struct sockaddr *)&rp->c_addr) &&
rpc_get_port(svc_addr(rqstp)) == rpc_get_port((struct sockaddr *)&rp->c_addr)) { rpc_get_port(svc_addr(rqstp)) == rpc_get_port((struct sockaddr *)&rp->c_addr)) {
nfsdstats.rchits++; nfsdstats.rchits++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册