Deleted Added
full compact
31c31
< __FBSDID("$FreeBSD: head/sys/nlm/nlm_prot_impl.c 197730 2009-10-03 12:22:12Z nyan $");
---
> __FBSDID("$FreeBSD: head/sys/nlm/nlm_prot_impl.c 197840 2009-10-07 19:50:14Z zml $");
33a34
> #include <sys/fail.h>
79a81,85
> * We only look for GRANTED_RES messages for a little while.
> */
> #define NLM_EXPIRE_TIMEOUT 10
>
> /*
206a213
> time_t af_expiretime; /* (c) notification time */
239a247
> uint32_t nh_grantcookie; /* (l) grant cookie counter */
240a249
> struct nlm_async_lock_list nh_granted; /* (l) granted locks */
249a259,277
> struct nlm_grantcookie {
> uint32_t ng_sysid;
> uint32_t ng_cookie;
> };
>
> static inline uint32_t
> ng_sysid(struct netobj *src)
> {
>
> return ((struct nlm_grantcookie *)src->n_bytes)->ng_sysid;
> }
>
> static inline uint32_t
> ng_cookie(struct netobj *src)
> {
>
> return ((struct nlm_grantcookie *)src->n_bytes)->ng_cookie;
> }
>
283a312,324
> * Create a netobj from an arbitrary source.
> */
> void
> nlm_make_netobj(struct netobj *dst, caddr_t src, size_t srcsize,
> struct malloc_type *type)
> {
>
> dst->n_len = srcsize;
> dst->n_bytes = malloc(srcsize, type, M_WAITOK);
> memcpy(dst->n_bytes, src, srcsize);
> }
>
> /*
291,293c332
< dst->n_len = src->n_len;
< dst->n_bytes = malloc(src->n_len, type, M_WAITOK);
< memcpy(dst->n_bytes, src->n_bytes, src->n_len);
---
> nlm_make_netobj(dst, src->n_bytes, src->n_len, type);
295a335
>
521,522c561,564
< NLM_DEBUG(2, "NLM: async lock %p for %s (sysid %d) granted\n",
< af, af->af_host->nh_caller_name, af->af_host->nh_sysid);
---
> NLM_DEBUG(2, "NLM: async lock %p for %s (sysid %d) granted,"
> " cookie %d:%d\n", af, af->af_host->nh_caller_name,
> af->af_host->nh_sysid, ng_sysid(&af->af_granted.cookie),
> ng_cookie(&af->af_granted.cookie));
559,564c601
< * Move this entry to the nh_finished list. Someone else will
< * free it later - its too hard to do it here safely without
< * racing with cancel.
< *
< * XXX possibly we should have a third "granted sent but not
< * ack'ed" list so that we can re-send the granted message.
---
> * Move this entry to the nh_granted list.
565a603
> af->af_expiretime = time_uptime + NLM_EXPIRE_TIMEOUT;
568c606
< TAILQ_INSERT_TAIL(&af->af_host->nh_finished, af, af_link);
---
> TAILQ_INSERT_TAIL(&af->af_host->nh_granted, af, af_link);
638c676
< nlm_free_finished_locks(struct nlm_host *host)
---
> nlm_check_expired_locks(struct nlm_host *host)
640a679
> time_t uptime = time_uptime;
642a682,692
> while ((af = TAILQ_FIRST(&host->nh_granted)) != NULL
> && uptime >= af->af_expiretime) {
> NLM_DEBUG(2, "NLM: async lock %p for %s (sysid %d) expired,"
> " cookie %d:%d\n", af, af->af_host->nh_caller_name,
> af->af_host->nh_sysid, ng_sysid(&af->af_granted.cookie),
> ng_cookie(&af->af_granted.cookie));
> TAILQ_REMOVE(&host->nh_granted, af, af_link);
> mtx_unlock(&host->nh_lock);
> nlm_free_async_lock(af);
> mtx_lock(&host->nh_lock);
> }
725c775
< nlm_free_finished_locks(host);
---
> nlm_check_expired_locks(host);
801a852
> host->nh_grantcookie = 1;
802a854
> TAILQ_INIT(&host->nh_granted);
1837c1889
< nlm_free_finished_locks(host);
---
> nlm_check_expired_locks(host);
1942c1994
< nlm_free_finished_locks(host);
---
> nlm_check_expired_locks(host);
1970a2023
> struct nlm_grantcookie cookie;
1995a2049,2052
> if (!af) {
> cookie.ng_sysid = host->nh_sysid;
> cookie.ng_cookie = host->nh_grantcookie++;
> }
2013a2071,2072
> nlm_make_netobj(&af->af_granted.cookie,
> (caddr_t)&cookie, sizeof(cookie), M_RPC);
2114c2173
< nlm_free_finished_locks(host);
---
> nlm_check_expired_locks(host);
2203c2262
< nlm_free_finished_locks(host);
---
> nlm_check_expired_locks(host);
2259a2319
> KFAIL_POINT_CODE(DEBUG_FP, nlm_deny_grant, goto out);
2277a2338,2339
>
> out:
2284a2347,2405
> nlm_do_granted_res(nlm4_res *argp, struct svc_req *rqstp)
> {
> struct nlm_host *host = NULL;
> struct nlm_async_lock *af = NULL;
> int error;
>
> if (argp->cookie.n_len != sizeof(struct nlm_grantcookie)) {
> NLM_DEBUG(1, "NLM: bogus grant cookie");
> goto out;
> }
>
> host = nlm_find_host_by_sysid(ng_sysid(&argp->cookie));
> if (!host) {
> NLM_DEBUG(1, "NLM: Unknown host rejected our grant");
> goto out;
> }
>
> mtx_lock(&host->nh_lock);
> TAILQ_FOREACH(af, &host->nh_granted, af_link)
> if (ng_cookie(&argp->cookie) ==
> ng_cookie(&af->af_granted.cookie))
> break;
> if (af)
> TAILQ_REMOVE(&host->nh_granted, af, af_link);
> mtx_unlock(&host->nh_lock);
>
> if (!af) {
> NLM_DEBUG(1, "NLM: host %s (sysid %d) replied to our grant "
> "with unrecognized cookie %d:%d", host->nh_caller_name,
> host->nh_sysid, ng_sysid(&argp->cookie),
> ng_cookie(&argp->cookie));
> goto out;
> }
>
> if (argp->stat.stat != nlm4_granted) {
> af->af_fl.l_type = F_UNLCK;
> error = VOP_ADVLOCK(af->af_vp, NULL, F_UNLCK, &af->af_fl, F_REMOTE);
> if (error) {
> NLM_DEBUG(1, "NLM: host %s (sysid %d) rejected our grant "
> "and we failed to unlock (%d)", host->nh_caller_name,
> host->nh_sysid, error);
> goto out;
> }
>
> NLM_DEBUG(5, "NLM: async lock %p rejected by host %s (sysid %d)",
> af, host->nh_caller_name, host->nh_sysid);
> } else {
> NLM_DEBUG(5, "NLM: async lock %p accepted by host %s (sysid %d)",
> af, host->nh_caller_name, host->nh_sysid);
> }
>
> out:
> if (af)
> nlm_free_async_lock(af);
> if (host)
> nlm_host_release(host);
> }
>
> void