aboutsummaryrefslogtreecommitdiffstats
path: root/fs/lockd/mon.c
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2008-12-11 17:55:59 -0500
committerJ. Bruce Fields <bfields@citi.umich.edu>2009-01-06 11:53:55 -0500
commit77a3ef33e2de6fc8aabd7cb1700bfef81757c28a (patch)
treebb403f4517d49c7756921a70ba27ddce3963a05d /fs/lockd/mon.c
parentb39b897c259fc1fd1998505f2b1d4ec1f115bce1 (diff)
NSM: More clean up of nsm_get_handle()
Clean up: refactor nsm_get_handle() so it is organized the same way that nsm_reboot_lookup() is. There is an additional micro-optimization here. This change moves the "hostname & nsm_use_hostnames" test out of the list_for_each_entry() clause in nsm_get_handle(), since it is loop-invariant. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
Diffstat (limited to 'fs/lockd/mon.c')
-rw-r--r--fs/lockd/mon.c62
1 files changed, 35 insertions, 27 deletions
diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c
index 315ca07715c7..99aec744474c 100644
--- a/fs/lockd/mon.c
+++ b/fs/lockd/mon.c
@@ -213,6 +213,16 @@ static struct nsm_handle *nsm_lookup_hostname(const char *hostname,
213 return NULL; 213 return NULL;
214} 214}
215 215
216static struct nsm_handle *nsm_lookup_addr(const struct sockaddr *sap)
217{
218 struct nsm_handle *nsm;
219
220 list_for_each_entry(nsm, &nsm_handles, sm_link)
221 if (nlm_cmp_addr(nsm_addr(nsm), sap))
222 return nsm;
223 return NULL;
224}
225
216static struct nsm_handle *nsm_lookup_priv(const struct nsm_private *priv) 226static struct nsm_handle *nsm_lookup_priv(const struct nsm_private *priv)
217{ 227{
218 struct nsm_handle *nsm; 228 struct nsm_handle *nsm;
@@ -281,8 +291,7 @@ struct nsm_handle *nsm_get_handle(const struct sockaddr *sap,
281 const size_t salen, const char *hostname, 291 const size_t salen, const char *hostname,
282 const size_t hostname_len) 292 const size_t hostname_len)
283{ 293{
284 struct nsm_handle *nsm = NULL; 294 struct nsm_handle *cached, *new = NULL;
285 struct nsm_handle *pos;
286 295
287 if (hostname && memchr(hostname, '/', hostname_len) != NULL) { 296 if (hostname && memchr(hostname, '/', hostname_len) != NULL) {
288 if (printk_ratelimit()) { 297 if (printk_ratelimit()) {
@@ -295,38 +304,37 @@ struct nsm_handle *nsm_get_handle(const struct sockaddr *sap,
295 304
296retry: 305retry:
297 spin_lock(&nsm_lock); 306 spin_lock(&nsm_lock);
298 list_for_each_entry(pos, &nsm_handles, sm_link) { 307
299 308 if (nsm_use_hostnames && hostname != NULL)
300 if (hostname && nsm_use_hostnames) { 309 cached = nsm_lookup_hostname(hostname, hostname_len);
301 if (strlen(pos->sm_name) != hostname_len 310 else
302 || memcmp(pos->sm_name, hostname, hostname_len)) 311 cached = nsm_lookup_addr(sap);
303 continue; 312
304 } else if (!nlm_cmp_addr(nsm_addr(pos), sap)) 313 if (cached != NULL) {
305 continue; 314 atomic_inc(&cached->sm_count);
306 atomic_inc(&pos->sm_count); 315 spin_unlock(&nsm_lock);
307 kfree(nsm); 316 kfree(new);
308 nsm = pos; 317 dprintk("lockd: found nsm_handle for %s (%s), "
309 dprintk("lockd: found nsm_handle for %s (%s), cnt %d\n", 318 "cnt %d\n", cached->sm_name,
310 pos->sm_name, pos->sm_addrbuf, 319 cached->sm_addrbuf,
311 atomic_read(&pos->sm_count)); 320 atomic_read(&cached->sm_count));
312 goto found; 321 return cached;
313 } 322 }
314 if (nsm) { 323
315 list_add(&nsm->sm_link, &nsm_handles); 324 if (new != NULL) {
325 list_add(&new->sm_link, &nsm_handles);
326 spin_unlock(&nsm_lock);
316 dprintk("lockd: created nsm_handle for %s (%s)\n", 327 dprintk("lockd: created nsm_handle for %s (%s)\n",
317 nsm->sm_name, nsm->sm_addrbuf); 328 new->sm_name, new->sm_addrbuf);
318 goto found; 329 return new;
319 } 330 }
331
320 spin_unlock(&nsm_lock); 332 spin_unlock(&nsm_lock);
321 333
322 nsm = nsm_create_handle(sap, salen, hostname, hostname_len); 334 new = nsm_create_handle(sap, salen, hostname, hostname_len);
323 if (unlikely(nsm == NULL)) 335 if (unlikely(new == NULL))
324 return NULL; 336 return NULL;
325 goto retry; 337 goto retry;
326
327found:
328 spin_unlock(&nsm_lock);
329 return nsm;
330} 338}
331 339
332/** 340/**