diff options
author | Jeff Layton <jlayton@redhat.com> | 2013-01-28 14:41:13 -0500 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2013-02-04 09:16:23 -0500 |
commit | d1a0774de6cb908f5ba7806d09aaf86bb03fa182 (patch) | |
tree | be9d6cc9f4bd3ce0c7f3da6665ced8f91e752258 /fs/nfsd | |
parent | 25e6b8b0e1a247747db5275b1b6b362f5acf2245 (diff) |
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: Jeff Layton <jlayton@redhat.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'fs/nfsd')
-rw-r--r-- | fs/nfsd/cache.h | 3 | ||||
-rw-r--r-- | fs/nfsd/nfscache.c | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/fs/nfsd/cache.h b/fs/nfsd/cache.h index f8c6df8649dc..9c7232b45103 100644 --- a/fs/nfsd/cache.h +++ b/fs/nfsd/cache.h | |||
@@ -70,6 +70,9 @@ enum { | |||
70 | */ | 70 | */ |
71 | #define RC_DELAY (HZ/5) | 71 | #define RC_DELAY (HZ/5) |
72 | 72 | ||
73 | /* Cache entries expire after this time period */ | ||
74 | #define RC_EXPIRE (120 * HZ) | ||
75 | |||
73 | int nfsd_reply_cache_init(void); | 76 | int nfsd_reply_cache_init(void); |
74 | void nfsd_reply_cache_shutdown(void); | 77 | void nfsd_reply_cache_shutdown(void); |
75 | int nfsd_cache_lookup(struct svc_rqst *); | 78 | int nfsd_cache_lookup(struct svc_rqst *); |
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index 2cdc4be84553..634b8566aaef 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c | |||
@@ -142,6 +142,13 @@ hash_refile(struct svc_cacherep *rp) | |||
142 | hlist_add_head(&rp->c_hash, cache_hash + request_hash(rp->c_xid)); | 142 | hlist_add_head(&rp->c_hash, cache_hash + request_hash(rp->c_xid)); |
143 | } | 143 | } |
144 | 144 | ||
145 | static inline bool | ||
146 | nfsd_cache_entry_expired(struct svc_cacherep *rp) | ||
147 | { | ||
148 | return rp->c_state != RC_INPROG && | ||
149 | time_after(jiffies, rp->c_timestamp + RC_EXPIRE); | ||
150 | } | ||
151 | |||
145 | /* | 152 | /* |
146 | * Try to find an entry matching the current call in the cache. When none | 153 | * Try to find an entry matching the current call in the cache. When none |
147 | * is found, we grab the oldest unlocked entry off the LRU list. | 154 | * is found, we grab the oldest unlocked entry off the LRU list. |
@@ -175,7 +182,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp) | |||
175 | if (rp->c_state != RC_UNUSED && | 182 | if (rp->c_state != RC_UNUSED && |
176 | xid == rp->c_xid && proc == rp->c_proc && | 183 | xid == rp->c_xid && proc == rp->c_proc && |
177 | proto == rp->c_prot && vers == rp->c_vers && | 184 | proto == rp->c_prot && vers == rp->c_vers && |
178 | time_before(jiffies, rp->c_timestamp + 120*HZ) && | 185 | !nfsd_cache_entry_expired(rp) && |
179 | rpc_cmp_addr(svc_addr(rqstp), (struct sockaddr *)&rp->c_addr) && | 186 | rpc_cmp_addr(svc_addr(rqstp), (struct sockaddr *)&rp->c_addr) && |
180 | rpc_get_port(svc_addr(rqstp)) == rpc_get_port((struct sockaddr *)&rp->c_addr)) { | 187 | rpc_get_port(svc_addr(rqstp)) == rpc_get_port((struct sockaddr *)&rp->c_addr)) { |
181 | nfsdstats.rchits++; | 188 | nfsdstats.rchits++; |