2 * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
3 * Authors: Doug Rabson <dfr@rabson.org>
4 * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
30 /*static char sccsid[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro";*/
31 /*static char sccsid[] = "from: * @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC";*/
32 __RCSID("$NetBSD: nlm_prot.x,v 1.6 2000/06/07 14:30:15 bouyer Exp $");
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/malloc.h>
38 #include <sys/systm.h>
40 #include <nlm/nlm_prot.h>
43 /**********************************************************************/
46 * Convert between various versions of the protocol structures.
50 nlm_convert_to_nlm4_lock(struct nlm4_lock *dst, struct nlm_lock *src)
53 dst->caller_name = src->caller_name;
56 dst->svid = src->svid;
57 dst->l_offset = src->l_offset;
58 dst->l_len = src->l_len;
62 nlm_convert_to_nlm4_share(struct nlm4_share *dst, struct nlm_share *src)
65 dst->caller_name = src->caller_name;
68 dst->mode = src->mode;
69 dst->access = src->access;
73 nlm_convert_to_nlm_holder(struct nlm_holder *dst, struct nlm4_holder *src)
76 dst->exclusive = src->exclusive;
77 dst->svid = src->svid;
79 dst->l_offset = src->l_offset;
80 dst->l_len = src->l_len;
84 nlm_convert_to_nlm4_holder(struct nlm4_holder *dst, struct nlm_holder *src)
87 dst->exclusive = src->exclusive;
88 dst->svid = src->svid;
90 dst->l_offset = src->l_offset;
91 dst->l_len = src->l_len;
95 nlm_convert_to_nlm_stats(enum nlm4_stats src)
97 if (src > nlm4_deadlck)
99 return (enum nlm_stats) src;
103 nlm_convert_to_nlm_res(struct nlm_res *dst, struct nlm4_res *src)
105 dst->cookie = src->cookie;
106 dst->stat.stat = nlm_convert_to_nlm_stats(src->stat.stat);
110 nlm_convert_to_nlm4_res(struct nlm4_res *dst, struct nlm_res *src)
112 dst->cookie = src->cookie;
113 dst->stat.stat = (enum nlm4_stats) src->stat.stat;
116 /**********************************************************************/
123 nlm_sm_notify_0_svc(struct nlm_sm_status *argp, void *result, struct svc_req *rqstp)
131 nlm_test_1_svc(struct nlm_testargs *argp, nlm_testres *result, struct svc_req *rqstp)
137 args4.cookie = argp->cookie;
138 args4.exclusive = argp->exclusive;
139 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
141 retval = nlm4_test_4_svc(&args4, &res4, rqstp);
143 result->cookie = res4.cookie;
144 result->stat.stat = nlm_convert_to_nlm_stats(res4.stat.stat);
145 if (result->stat.stat == nlm_denied)
146 nlm_convert_to_nlm_holder(
147 &result->stat.nlm_testrply_u.holder,
148 &res4.stat.nlm4_testrply_u.holder);
155 nlm_lock_1_svc(struct nlm_lockargs *argp, nlm_res *result, struct svc_req *rqstp)
161 args4.cookie = argp->cookie;
162 args4.block = argp->block;
163 args4.exclusive = argp->exclusive;
164 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
165 args4.reclaim = argp->reclaim;
166 args4.state = argp->state;
168 retval = nlm4_lock_4_svc(&args4, &res4, rqstp);
170 nlm_convert_to_nlm_res(result, &res4);
176 nlm_cancel_1_svc(struct nlm_cancargs *argp, nlm_res *result, struct svc_req *rqstp)
182 args4.cookie = argp->cookie;
183 args4.block = argp->block;
184 args4.exclusive = argp->exclusive;
185 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
187 retval = nlm4_cancel_4_svc(&args4, &res4, rqstp);
189 nlm_convert_to_nlm_res(result, &res4);
195 nlm_unlock_1_svc(struct nlm_unlockargs *argp, nlm_res *result, struct svc_req *rqstp)
198 nlm4_unlockargs args4;
201 args4.cookie = argp->cookie;
202 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
204 retval = nlm4_unlock_4_svc(&args4, &res4, rqstp);
206 nlm_convert_to_nlm_res(result, &res4);
212 nlm_granted_1_svc(struct nlm_testargs *argp, nlm_res *result, struct svc_req *rqstp)
218 args4.cookie = argp->cookie;
219 args4.exclusive = argp->exclusive;
220 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
222 retval = nlm4_granted_4_svc(&args4, &res4, rqstp);
224 nlm_convert_to_nlm_res(result, &res4);
230 nlm_test_msg_1_svc(struct nlm_testargs *argp, void *result, struct svc_req *rqstp)
235 struct nlm_host *host;
239 args4.cookie = argp->cookie;
240 args4.exclusive = argp->exclusive;
241 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
243 host = nlm_do_test(&args4, &res4, rqstp);
245 res.cookie = res4.cookie;
246 res.stat.stat = nlm_convert_to_nlm_stats(res4.stat.stat);
247 if (res.stat.stat == nlm_denied)
248 nlm_convert_to_nlm_holder(
249 &res.stat.nlm_testrply_u.holder,
250 &res4.stat.nlm4_testrply_u.holder);
252 rpc = nlm_host_get_rpc(host);
254 nlm_test_res_1(&res, &dummy, rpc);
255 xdr_free((xdrproc_t) xdr_nlm_testres, &res);
261 nlm_lock_msg_1_svc(struct nlm_lockargs *argp, void *result, struct svc_req *rqstp)
266 struct nlm_host *host;
270 args4.cookie = argp->cookie;
271 args4.block = argp->block;
272 args4.exclusive = argp->exclusive;
273 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
274 args4.reclaim = argp->reclaim;
275 args4.state = argp->state;
277 host = nlm_do_lock(&args4, &res4, rqstp, TRUE);
279 nlm_convert_to_nlm_res(&res, &res4);
281 rpc = nlm_host_get_rpc(host);
283 nlm_lock_res_1(&res, &dummy, rpc);
284 xdr_free((xdrproc_t) xdr_nlm_res, &res);
290 nlm_cancel_msg_1_svc(struct nlm_cancargs *argp, void *result, struct svc_req *rqstp)
295 struct nlm_host *host;
299 args4.cookie = argp->cookie;
300 args4.block = argp->block;
301 args4.exclusive = argp->exclusive;
302 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
304 host = nlm_do_cancel(&args4, &res4, rqstp);
306 nlm_convert_to_nlm_res(&res, &res4);
308 rpc = nlm_host_get_rpc(host);
310 nlm_cancel_res_1(&res, &dummy, rpc);
311 xdr_free((xdrproc_t) xdr_nlm_res, &res);
317 nlm_unlock_msg_1_svc(struct nlm_unlockargs *argp, void *result, struct svc_req *rqstp)
319 nlm4_unlockargs args4;
322 struct nlm_host *host;
326 args4.cookie = argp->cookie;
327 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
329 host = nlm_do_unlock(&args4, &res4, rqstp);
331 nlm_convert_to_nlm_res(&res, &res4);
333 rpc = nlm_host_get_rpc(host);
335 nlm_unlock_res_1(&res, &dummy, rpc);
336 xdr_free((xdrproc_t) xdr_nlm_res, &res);
342 nlm_granted_msg_1_svc(struct nlm_testargs *argp, void *result, struct svc_req *rqstp)
347 struct nlm_host *host;
351 args4.cookie = argp->cookie;
352 args4.exclusive = argp->exclusive;
353 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
356 * We make a synchronous call to userland and send the reply
359 nlm4_granted_4_svc(&args4, &res4, rqstp);
361 nlm_convert_to_nlm_res(&res, &res4);
363 host = nlm_find_host_by_addr(
364 (struct sockaddr *) rqstp->rq_xprt->xp_rtaddr.buf,
366 rpc = nlm_host_get_rpc(host);
368 nlm_granted_res_1(&res, &dummy, rpc);
369 xdr_free((xdrproc_t) xdr_nlm_res, &res);
375 nlm_test_res_1_svc(nlm_testres *argp, void *result, struct svc_req *rqstp)
379 args4.cookie = argp->cookie;
380 if (argp->stat.stat == nlm_denied)
381 nlm_convert_to_nlm4_holder(
382 &args4.stat.nlm4_testrply_u.holder,
383 &argp->stat.nlm_testrply_u.holder);
385 return (nlm4_test_res_4_svc(&args4, result, rqstp));
389 nlm_lock_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp)
393 nlm_convert_to_nlm4_res(&arg4, argp);
394 return (nlm4_lock_res_4_svc(&arg4, result, rqstp));
398 nlm_cancel_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp)
402 nlm_convert_to_nlm4_res(&arg4, argp);
403 return (nlm4_cancel_res_4_svc(&arg4, result, rqstp));
407 nlm_unlock_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp)
411 nlm_convert_to_nlm4_res(&arg4, argp);
412 return (nlm4_unlock_res_4_svc(&arg4, result, rqstp));
416 nlm_granted_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp)
420 nlm_convert_to_nlm4_res(&arg4, argp);
421 return (nlm4_granted_res_4_svc(&arg4, result, rqstp));
425 nlm_prog_1_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result)
428 (void) xdr_free(xdr_result, result);
433 nlm_share_3_svc(nlm_shareargs *argp, nlm_shareres *result, struct svc_req *rqstp)
436 nlm4_shareargs args4;
439 args4.cookie = argp->cookie;
440 nlm_convert_to_nlm4_share(&args4.share, &argp->share);
441 args4.reclaim = argp->reclaim;
443 retval = nlm4_share_4_svc(&args4, &res4, rqstp);
445 result->cookie = res4.cookie;
446 result->stat = nlm_convert_to_nlm_stats(res4.stat);
447 result->sequence = res4.sequence;
454 nlm_unshare_3_svc(nlm_shareargs *argp, nlm_shareres *result, struct svc_req *rqstp)
457 nlm4_shareargs args4;
460 args4.cookie = argp->cookie;
461 nlm_convert_to_nlm4_share(&args4.share, &argp->share);
462 args4.reclaim = argp->reclaim;
464 retval = nlm4_unshare_4_svc(&args4, &res4, rqstp);
466 result->cookie = res4.cookie;
467 result->stat = nlm_convert_to_nlm_stats(res4.stat);
468 result->sequence = res4.sequence;
475 nlm_nm_lock_3_svc(nlm_lockargs *argp, nlm_res *result, struct svc_req *rqstp)
481 args4.cookie = argp->cookie;
482 args4.block = argp->block;
483 args4.exclusive = argp->exclusive;
484 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
485 args4.reclaim = argp->reclaim;
486 args4.state = argp->state;
488 retval = nlm4_nm_lock_4_svc(&args4, &res4, rqstp);
490 nlm_convert_to_nlm_res(result, &res4);
496 nlm_free_all_3_svc(nlm_notify *argp, void *result, struct svc_req *rqstp)
498 struct nlm4_notify args4;
500 args4.name = argp->name;
501 args4.state = argp->state;
503 return (nlm4_free_all_4_svc(&args4, result, rqstp));
507 nlm_prog_3_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result)
510 (void) xdr_free(xdr_result, result);
515 nlm4_test_4_svc(nlm4_testargs *argp, nlm4_testres *result, struct svc_req *rqstp)
518 nlm_do_test(argp, result, rqstp);
523 nlm4_lock_4_svc(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp)
526 nlm_do_lock(argp, result, rqstp, TRUE);
531 nlm4_cancel_4_svc(nlm4_cancargs *argp, nlm4_res *result, struct svc_req *rqstp)
534 nlm_do_cancel(argp, result, rqstp);
539 nlm4_unlock_4_svc(nlm4_unlockargs *argp, nlm4_res *result, struct svc_req *rqstp)
542 nlm_do_unlock(argp, result, rqstp);
547 nlm4_granted_4_svc(nlm4_testargs *argp, nlm4_res *result, struct svc_req *rqstp)
552 memset(result, 0, sizeof(*result));
553 nlm_copy_netobj(&result->cookie, &argp->cookie, M_RPC);
556 * Set a non-zero timeout to give the userland a chance to reply.
558 lockd = nlm_user_lockd();
560 result->stat.stat = nlm4_failed;
565 CLNT_CONTROL(lockd, CLSET_TIMEOUT, &tv);
566 nlm4_granted_4(argp, result, lockd);
569 CLNT_CONTROL(lockd, CLSET_TIMEOUT, &tv);
575 nlm4_test_msg_4_svc(nlm4_testargs *argp, void *result, struct svc_req *rqstp)
578 struct nlm_host *host;
582 host = nlm_do_test(argp, &res4, rqstp);
583 rpc = nlm_host_get_rpc(host);
585 nlm4_test_res_4(&res4, &dummy, rpc);
586 xdr_free((xdrproc_t) xdr_nlm4_testres, &res4);
592 nlm4_lock_msg_4_svc(nlm4_lockargs *argp, void *result, struct svc_req *rqstp)
595 struct nlm_host *host;
599 host = nlm_do_lock(argp, &res4, rqstp, TRUE);
600 rpc = nlm_host_get_rpc(host);
602 nlm4_lock_res_4(&res4, &dummy, rpc);
603 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
609 nlm4_cancel_msg_4_svc(nlm4_cancargs *argp, void *result, struct svc_req *rqstp)
612 struct nlm_host *host;
616 host = nlm_do_cancel(argp, &res4, rqstp);
617 rpc = nlm_host_get_rpc(host);
619 nlm4_cancel_res_4(&res4, &dummy, rpc);
620 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
626 nlm4_unlock_msg_4_svc(nlm4_unlockargs *argp, void *result, struct svc_req *rqstp)
629 struct nlm_host *host;
633 host = nlm_do_unlock(argp, &res4, rqstp);
634 rpc = nlm_host_get_rpc(host);
636 nlm4_unlock_res_4(&res4, &dummy, rpc);
637 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
643 nlm4_granted_msg_4_svc(nlm4_testargs *argp, void *result, struct svc_req *rqstp)
645 struct nlm_host *host;
651 * We make a synchronous call to userland and send the reply
654 nlm4_granted_4_svc(argp, &res4, rqstp);
656 host = nlm_find_host_by_addr(
657 (struct sockaddr *) rqstp->rq_xprt->xp_rtaddr.buf,
659 rpc = nlm_host_get_rpc(host);
661 nlm4_granted_res_4(&res4, &dummy, rpc);
662 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
668 nlm4_test_res_4_svc(nlm4_testres *argp, void *result, struct svc_req *rqstp)
672 lockd = nlm_user_lockd();
674 nlm4_test_res_4(argp, result, lockd);
680 nlm4_lock_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
684 lockd = nlm_user_lockd();
686 nlm4_lock_res_4(argp, result, lockd);
692 nlm4_cancel_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
696 lockd = nlm_user_lockd();
698 nlm4_cancel_res_4(argp, result, lockd);
704 nlm4_unlock_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
708 lockd = nlm_user_lockd();
710 nlm4_unlock_res_4(argp, result, lockd);
716 nlm4_granted_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
723 nlm4_share_4_svc(nlm4_shareargs *argp, nlm4_shareres *result, struct svc_req *rqstp)
726 memset(result, 0, sizeof(*result));
727 result->stat = nlm4_denied;
732 nlm4_unshare_4_svc(nlm4_shareargs *argp, nlm4_shareres *result, struct svc_req *rqstp)
735 memset(result, 0, sizeof(*result));
736 result->stat = nlm4_denied;
741 nlm4_nm_lock_4_svc(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp)
744 nlm_do_lock(argp, result, rqstp, FALSE);
749 nlm4_free_all_4_svc(nlm4_notify *argp, void *result, struct svc_req *rqstp)
752 nlm_do_free_all(argp);
757 nlm_prog_4_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result)
760 (void) xdr_free(xdr_result, result);