Commit 77a3ef33 authored by Chuck Lever's avatar Chuck Lever Committed by J. Bruce Fields

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: default avatarChuck Lever <chuck.lever@oracle.com>
Signed-off-by: default avatarJ. Bruce Fields <bfields@citi.umich.edu>
parent b39b897c
...@@ -213,6 +213,16 @@ static struct nsm_handle *nsm_lookup_hostname(const char *hostname, ...@@ -213,6 +213,16 @@ static struct nsm_handle *nsm_lookup_hostname(const char *hostname,
return NULL; return NULL;
} }
static struct nsm_handle *nsm_lookup_addr(const struct sockaddr *sap)
{
struct nsm_handle *nsm;
list_for_each_entry(nsm, &nsm_handles, sm_link)
if (nlm_cmp_addr(nsm_addr(nsm), sap))
return nsm;
return NULL;
}
static struct nsm_handle *nsm_lookup_priv(const struct nsm_private *priv) static struct nsm_handle *nsm_lookup_priv(const struct nsm_private *priv)
{ {
struct nsm_handle *nsm; struct nsm_handle *nsm;
...@@ -281,8 +291,7 @@ struct nsm_handle *nsm_get_handle(const struct sockaddr *sap, ...@@ -281,8 +291,7 @@ struct nsm_handle *nsm_get_handle(const struct sockaddr *sap,
const size_t salen, const char *hostname, const size_t salen, const char *hostname,
const size_t hostname_len) const size_t hostname_len)
{ {
struct nsm_handle *nsm = NULL; struct nsm_handle *cached, *new = NULL;
struct nsm_handle *pos;
if (hostname && memchr(hostname, '/', hostname_len) != NULL) { if (hostname && memchr(hostname, '/', hostname_len) != NULL) {
if (printk_ratelimit()) { if (printk_ratelimit()) {
...@@ -295,38 +304,37 @@ struct nsm_handle *nsm_get_handle(const struct sockaddr *sap, ...@@ -295,38 +304,37 @@ struct nsm_handle *nsm_get_handle(const struct sockaddr *sap,
retry: retry:
spin_lock(&nsm_lock); spin_lock(&nsm_lock);
list_for_each_entry(pos, &nsm_handles, sm_link) {
if (nsm_use_hostnames && hostname != NULL)
if (hostname && nsm_use_hostnames) { cached = nsm_lookup_hostname(hostname, hostname_len);
if (strlen(pos->sm_name) != hostname_len else
|| memcmp(pos->sm_name, hostname, hostname_len)) cached = nsm_lookup_addr(sap);
continue;
} else if (!nlm_cmp_addr(nsm_addr(pos), sap)) if (cached != NULL) {
continue; atomic_inc(&cached->sm_count);
atomic_inc(&pos->sm_count); spin_unlock(&nsm_lock);
kfree(nsm); kfree(new);
nsm = pos; dprintk("lockd: found nsm_handle for %s (%s), "
dprintk("lockd: found nsm_handle for %s (%s), cnt %d\n", "cnt %d\n", cached->sm_name,
pos->sm_name, pos->sm_addrbuf, cached->sm_addrbuf,
atomic_read(&pos->sm_count)); atomic_read(&cached->sm_count));
goto found; return cached;
} }
if (nsm) {
list_add(&nsm->sm_link, &nsm_handles); if (new != NULL) {
list_add(&new->sm_link, &nsm_handles);
spin_unlock(&nsm_lock);
dprintk("lockd: created nsm_handle for %s (%s)\n", dprintk("lockd: created nsm_handle for %s (%s)\n",
nsm->sm_name, nsm->sm_addrbuf); new->sm_name, new->sm_addrbuf);
goto found; return new;
} }
spin_unlock(&nsm_lock); spin_unlock(&nsm_lock);
nsm = nsm_create_handle(sap, salen, hostname, hostname_len); new = nsm_create_handle(sap, salen, hostname, hostname_len);
if (unlikely(nsm == NULL)) if (unlikely(new == NULL))
return NULL; return NULL;
goto retry; goto retry;
found:
spin_unlock(&nsm_lock);
return nsm;
} }
/** /**
......
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