diff options
author | Jeff Layton <jlayton@redhat.com> | 2013-01-28 14:41:14 -0500 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2013-02-04 09:16:24 -0500 |
commit | a4a3ec3291249c7db0e03d8b8188ef259b2873da (patch) | |
tree | 4e2a3e38bd63c1d59ceb56b27d56465291cad942 /fs/nfsd | |
parent | d1a0774de6cb908f5ba7806d09aaf86bb03fa182 (diff) |
nfsd: break out hashtable search into separate function
Later, we'll need more than one call site for this, so break it out
into a new function.
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/nfscache.c | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index 634b8566aaef..b89e7c8b10ce 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c | |||
@@ -150,6 +150,35 @@ nfsd_cache_entry_expired(struct svc_cacherep *rp) | |||
150 | } | 150 | } |
151 | 151 | ||
152 | /* | 152 | /* |
153 | * Search the request hash for an entry that matches the given rqstp. | ||
154 | * Must be called with cache_lock held. Returns the found entry or | ||
155 | * NULL on failure. | ||
156 | */ | ||
157 | static struct svc_cacherep * | ||
158 | nfsd_cache_search(struct svc_rqst *rqstp) | ||
159 | { | ||
160 | struct svc_cacherep *rp; | ||
161 | struct hlist_node *hn; | ||
162 | struct hlist_head *rh; | ||
163 | __be32 xid = rqstp->rq_xid; | ||
164 | u32 proto = rqstp->rq_prot, | ||
165 | vers = rqstp->rq_vers, | ||
166 | proc = rqstp->rq_proc; | ||
167 | |||
168 | rh = &cache_hash[request_hash(xid)]; | ||
169 | hlist_for_each_entry(rp, hn, rh, c_hash) { | ||
170 | if (rp->c_state != RC_UNUSED && | ||
171 | xid == rp->c_xid && proc == rp->c_proc && | ||
172 | proto == rp->c_prot && vers == rp->c_vers && | ||
173 | !nfsd_cache_entry_expired(rp) && | ||
174 | rpc_cmp_addr(svc_addr(rqstp), (struct sockaddr *)&rp->c_addr) && | ||
175 | rpc_get_port(svc_addr(rqstp)) == rpc_get_port((struct sockaddr *)&rp->c_addr)) | ||
176 | return rp; | ||
177 | } | ||
178 | return NULL; | ||
179 | } | ||
180 | |||
181 | /* | ||
153 | * Try to find an entry matching the current call in the cache. When none | 182 | * Try to find an entry matching the current call in the cache. When none |
154 | * is found, we grab the oldest unlocked entry off the LRU list. | 183 | * is found, we grab the oldest unlocked entry off the LRU list. |
155 | * Note that no operation within the loop may sleep. | 184 | * Note that no operation within the loop may sleep. |
@@ -157,8 +186,6 @@ nfsd_cache_entry_expired(struct svc_cacherep *rp) | |||
157 | int | 186 | int |
158 | nfsd_cache_lookup(struct svc_rqst *rqstp) | 187 | nfsd_cache_lookup(struct svc_rqst *rqstp) |
159 | { | 188 | { |
160 | struct hlist_node *hn; | ||
161 | struct hlist_head *rh; | ||
162 | struct svc_cacherep *rp; | 189 | struct svc_cacherep *rp; |
163 | __be32 xid = rqstp->rq_xid; | 190 | __be32 xid = rqstp->rq_xid; |
164 | u32 proto = rqstp->rq_prot, | 191 | u32 proto = rqstp->rq_prot, |
@@ -177,17 +204,10 @@ nfsd_cache_lookup(struct svc_rqst *rqstp) | |||
177 | spin_lock(&cache_lock); | 204 | spin_lock(&cache_lock); |
178 | rtn = RC_DOIT; | 205 | rtn = RC_DOIT; |
179 | 206 | ||
180 | rh = &cache_hash[request_hash(xid)]; | 207 | rp = nfsd_cache_search(rqstp); |
181 | hlist_for_each_entry(rp, hn, rh, c_hash) { | 208 | if (rp) { |
182 | if (rp->c_state != RC_UNUSED && | 209 | nfsdstats.rchits++; |
183 | xid == rp->c_xid && proc == rp->c_proc && | 210 | goto found_entry; |
184 | proto == rp->c_prot && vers == rp->c_vers && | ||
185 | !nfsd_cache_entry_expired(rp) && | ||
186 | rpc_cmp_addr(svc_addr(rqstp), (struct sockaddr *)&rp->c_addr) && | ||
187 | rpc_get_port(svc_addr(rqstp)) == rpc_get_port((struct sockaddr *)&rp->c_addr)) { | ||
188 | nfsdstats.rchits++; | ||
189 | goto found_entry; | ||
190 | } | ||
191 | } | 211 | } |
192 | nfsdstats.rcmisses++; | 212 | nfsdstats.rcmisses++; |
193 | 213 | ||