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)
238 args4.cookie = argp->cookie;
239 args4.exclusive = argp->exclusive;
240 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
242 if (nlm_do_test(&args4, &res4, rqstp, &rpc))
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);
253 nlm_test_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
256 xdr_free((xdrproc_t) xdr_nlm_testres, &res);
262 nlm_lock_msg_1_svc(struct nlm_lockargs *argp, void *result, struct svc_req *rqstp)
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 if (nlm_do_lock(&args4, &res4, rqstp, TRUE, &rpc))
280 nlm_convert_to_nlm_res(&res, &res4);
283 nlm_lock_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
286 xdr_free((xdrproc_t) xdr_nlm_res, &res);
292 nlm_cancel_msg_1_svc(struct nlm_cancargs *argp, void *result, struct svc_req *rqstp)
300 args4.cookie = argp->cookie;
301 args4.block = argp->block;
302 args4.exclusive = argp->exclusive;
303 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
305 if (nlm_do_cancel(&args4, &res4, rqstp, &rpc))
308 nlm_convert_to_nlm_res(&res, &res4);
311 nlm_cancel_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
314 xdr_free((xdrproc_t) xdr_nlm_res, &res);
320 nlm_unlock_msg_1_svc(struct nlm_unlockargs *argp, void *result, struct svc_req *rqstp)
322 nlm4_unlockargs args4;
328 args4.cookie = argp->cookie;
329 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
331 if (nlm_do_unlock(&args4, &res4, rqstp, &rpc))
334 nlm_convert_to_nlm_res(&res, &res4);
337 nlm_unlock_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
340 xdr_free((xdrproc_t) xdr_nlm_res, &res);
346 nlm_granted_msg_1_svc(struct nlm_testargs *argp, void *result, struct svc_req *rqstp)
354 args4.cookie = argp->cookie;
355 args4.exclusive = argp->exclusive;
356 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
358 if (nlm_do_granted(&args4, &res4, rqstp, &rpc))
361 nlm_convert_to_nlm_res(&res, &res4);
364 nlm_granted_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
367 xdr_free((xdrproc_t) xdr_nlm_res, &res);
373 nlm_test_res_1_svc(nlm_testres *argp, void *result, struct svc_req *rqstp)
377 args4.cookie = argp->cookie;
378 if (argp->stat.stat == nlm_denied)
379 nlm_convert_to_nlm4_holder(
380 &args4.stat.nlm4_testrply_u.holder,
381 &argp->stat.nlm_testrply_u.holder);
383 return (nlm4_test_res_4_svc(&args4, result, rqstp));
387 nlm_lock_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp)
391 nlm_convert_to_nlm4_res(&arg4, argp);
392 return (nlm4_lock_res_4_svc(&arg4, result, rqstp));
396 nlm_cancel_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp)
400 nlm_convert_to_nlm4_res(&arg4, argp);
401 return (nlm4_cancel_res_4_svc(&arg4, result, rqstp));
405 nlm_unlock_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp)
409 nlm_convert_to_nlm4_res(&arg4, argp);
410 return (nlm4_unlock_res_4_svc(&arg4, result, rqstp));
414 nlm_granted_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp)
418 nlm_convert_to_nlm4_res(&arg4, argp);
419 return (nlm4_granted_res_4_svc(&arg4, result, rqstp));
423 nlm_prog_1_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result)
426 (void) xdr_free(xdr_result, result);
431 nlm_share_3_svc(nlm_shareargs *argp, nlm_shareres *result, struct svc_req *rqstp)
434 nlm4_shareargs args4;
437 args4.cookie = argp->cookie;
438 nlm_convert_to_nlm4_share(&args4.share, &argp->share);
439 args4.reclaim = argp->reclaim;
441 retval = nlm4_share_4_svc(&args4, &res4, rqstp);
443 result->cookie = res4.cookie;
444 result->stat = nlm_convert_to_nlm_stats(res4.stat);
445 result->sequence = res4.sequence;
452 nlm_unshare_3_svc(nlm_shareargs *argp, nlm_shareres *result, struct svc_req *rqstp)
455 nlm4_shareargs args4;
458 args4.cookie = argp->cookie;
459 nlm_convert_to_nlm4_share(&args4.share, &argp->share);
460 args4.reclaim = argp->reclaim;
462 retval = nlm4_unshare_4_svc(&args4, &res4, rqstp);
464 result->cookie = res4.cookie;
465 result->stat = nlm_convert_to_nlm_stats(res4.stat);
466 result->sequence = res4.sequence;
473 nlm_nm_lock_3_svc(nlm_lockargs *argp, nlm_res *result, struct svc_req *rqstp)
479 args4.cookie = argp->cookie;
480 args4.block = argp->block;
481 args4.exclusive = argp->exclusive;
482 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
483 args4.reclaim = argp->reclaim;
484 args4.state = argp->state;
486 retval = nlm4_nm_lock_4_svc(&args4, &res4, rqstp);
488 nlm_convert_to_nlm_res(result, &res4);
494 nlm_free_all_3_svc(nlm_notify *argp, void *result, struct svc_req *rqstp)
496 struct nlm4_notify args4;
498 args4.name = argp->name;
499 args4.state = argp->state;
501 return (nlm4_free_all_4_svc(&args4, result, rqstp));
505 nlm_prog_3_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result)
508 (void) xdr_free(xdr_result, result);
513 nlm4_test_4_svc(nlm4_testargs *argp, nlm4_testres *result, struct svc_req *rqstp)
516 nlm_do_test(argp, result, rqstp, NULL);
521 nlm4_lock_4_svc(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp)
524 nlm_do_lock(argp, result, rqstp, TRUE, NULL);
529 nlm4_cancel_4_svc(nlm4_cancargs *argp, nlm4_res *result, struct svc_req *rqstp)
532 nlm_do_cancel(argp, result, rqstp, NULL);
537 nlm4_unlock_4_svc(nlm4_unlockargs *argp, nlm4_res *result, struct svc_req *rqstp)
540 nlm_do_unlock(argp, result, rqstp, NULL);
545 nlm4_granted_4_svc(nlm4_testargs *argp, nlm4_res *result, struct svc_req *rqstp)
548 nlm_do_granted(argp, result, rqstp, NULL);
553 nlm4_test_msg_4_svc(nlm4_testargs *argp, void *result, struct svc_req *rqstp)
559 if (nlm_do_test(argp, &res4, rqstp, &rpc))
562 nlm4_test_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
565 xdr_free((xdrproc_t) xdr_nlm4_testres, &res4);
571 nlm4_lock_msg_4_svc(nlm4_lockargs *argp, void *result, struct svc_req *rqstp)
577 if (nlm_do_lock(argp, &res4, rqstp, TRUE, &rpc))
580 nlm4_lock_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
583 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
589 nlm4_cancel_msg_4_svc(nlm4_cancargs *argp, void *result, struct svc_req *rqstp)
595 if (nlm_do_cancel(argp, &res4, rqstp, &rpc))
598 nlm4_cancel_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
601 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
607 nlm4_unlock_msg_4_svc(nlm4_unlockargs *argp, void *result, struct svc_req *rqstp)
613 if (nlm_do_unlock(argp, &res4, rqstp, &rpc))
616 nlm4_unlock_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
619 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
625 nlm4_granted_msg_4_svc(nlm4_testargs *argp, void *result, struct svc_req *rqstp)
631 if (nlm_do_granted(argp, &res4, rqstp, &rpc))
634 nlm4_granted_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
637 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
643 nlm4_test_res_4_svc(nlm4_testres *argp, void *result, struct svc_req *rqstp)
650 nlm4_lock_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
657 nlm4_cancel_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
664 nlm4_unlock_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
671 nlm4_granted_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
674 nlm_do_granted_res(argp, rqstp);
679 nlm4_share_4_svc(nlm4_shareargs *argp, nlm4_shareres *result, struct svc_req *rqstp)
682 memset(result, 0, sizeof(*result));
683 result->stat = nlm4_denied;
688 nlm4_unshare_4_svc(nlm4_shareargs *argp, nlm4_shareres *result, struct svc_req *rqstp)
691 memset(result, 0, sizeof(*result));
692 result->stat = nlm4_denied;
697 nlm4_nm_lock_4_svc(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp)
700 nlm_do_lock(argp, result, rqstp, FALSE, NULL);
705 nlm4_free_all_4_svc(nlm4_notify *argp, void *result, struct svc_req *rqstp)
708 nlm_do_free_all(argp);
713 nlm_prog_4_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result)
716 (void) xdr_free(xdr_result, result);