Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 127466
b: refs/heads/master
c: 3420a8c
h: refs/heads/master
v: v3
  • Loading branch information
Chuck Lever authored and J. Bruce Fields committed Jan 6, 2009
1 parent 842ef3d commit 336263c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 576df4634e37e46b441fefb91915184edb13bb94
refs/heads/master: 3420a8c4359a189f7d854ed7075d151257415447
64 changes: 64 additions & 0 deletions trunk/fs/lockd/mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,29 @@ void nsm_unmonitor(const struct nlm_host *host)
}
}

static struct nsm_handle *nsm_lookup_hostname(const char *hostname,
const size_t len)
{
struct nsm_handle *nsm;

list_for_each_entry(nsm, &nsm_handles, sm_link)
if (strlen(nsm->sm_name) == len &&
memcmp(nsm->sm_name, hostname, len) == 0)
return nsm;
return NULL;
}

static struct nsm_handle *nsm_lookup_priv(const struct nsm_private *priv)
{
struct nsm_handle *nsm;

list_for_each_entry(nsm, &nsm_handles, sm_link)
if (memcmp(nsm->sm_priv.data, priv->data,
sizeof(priv->data)) == 0)
return nsm;
return NULL;
}

/*
* Construct a unique cookie to match this nsm_handle to this monitored
* host. It is passed to the local rpc.statd via NSMPROC_MON, and
Expand Down Expand Up @@ -297,6 +320,47 @@ struct nsm_handle *nsm_find(const struct sockaddr *sap, const size_t salen,
return nsm;
}

/**
* nsm_reboot_lookup - match NLMPROC_SM_NOTIFY arguments to an nsm_handle
* @info: pointer to NLMPROC_SM_NOTIFY arguments
*
* Returns a matching nsm_handle if found in the nsm cache; the returned
* nsm_handle's reference count is bumped and sm_monitored is cleared.
* Otherwise returns NULL if some error occurred.
*/
struct nsm_handle *nsm_reboot_lookup(const struct nlm_reboot *info)
{
struct nsm_handle *cached;

spin_lock(&nsm_lock);

if (nsm_use_hostnames && info->mon != NULL)
cached = nsm_lookup_hostname(info->mon, info->len);
else
cached = nsm_lookup_priv(&info->priv);

if (unlikely(cached == NULL)) {
spin_unlock(&nsm_lock);
dprintk("lockd: never saw rebooted peer '%.*s' before\n",
info->len, info->mon);
return cached;
}

atomic_inc(&cached->sm_count);
spin_unlock(&nsm_lock);

/*
* During subsequent lock activity, force a fresh
* notification to be set up for this host.
*/
cached->sm_monitored = 0;

dprintk("lockd: host %s (%s) rebooted, cnt %d\n",
cached->sm_name, cached->sm_addrbuf,
atomic_read(&cached->sm_count));
return cached;
}

/**
* nsm_release - Release an NSM handle
* @nsm: pointer to handle to be released
Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/lockd/lockd.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ struct nsm_handle *nsm_find(const struct sockaddr *sap, const size_t salen,
const char *hostname,
const size_t hostname_len,
const int create);
struct nsm_handle *nsm_reboot_lookup(const struct nlm_reboot *info);
void nsm_release(struct nsm_handle *nsm);

/*
Expand Down

0 comments on commit 336263c

Please sign in to comment.