2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
5 * Authors: Doug Rabson <dfr@rabson.org>
6 * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
32 /*static char sccsid[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro";*/
33 /*static char sccsid[] = "from: * @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC";*/
34 __RCSID("$NetBSD: nlm_prot.x,v 1.6 2000/06/07 14:30:15 bouyer Exp $");
36 __FBSDID("$FreeBSD$");
38 #include <sys/param.h>
39 #include <sys/malloc.h>
40 #include <sys/systm.h>
42 #include <nlm/nlm_prot.h>
45 /**********************************************************************/
48 * Convert between various versions of the protocol structures.
52 nlm_convert_to_nlm4_lock(struct nlm4_lock *dst, struct nlm_lock *src)
55 dst->caller_name = src->caller_name;
58 dst->svid = src->svid;
59 dst->l_offset = src->l_offset;
60 dst->l_len = src->l_len;
64 nlm_convert_to_nlm4_share(struct nlm4_share *dst, struct nlm_share *src)
67 dst->caller_name = src->caller_name;
70 dst->mode = src->mode;
71 dst->access = src->access;
75 nlm_convert_to_nlm_holder(struct nlm_holder *dst, struct nlm4_holder *src)
78 dst->exclusive = src->exclusive;
79 dst->svid = src->svid;
81 dst->l_offset = src->l_offset;
82 dst->l_len = src->l_len;
86 nlm_convert_to_nlm4_holder(struct nlm4_holder *dst, struct nlm_holder *src)
89 dst->exclusive = src->exclusive;
90 dst->svid = src->svid;
92 dst->l_offset = src->l_offset;
93 dst->l_len = src->l_len;
97 nlm_convert_to_nlm_stats(enum nlm4_stats src)
99 if (src > nlm4_deadlck)
101 return (enum nlm_stats) src;
105 nlm_convert_to_nlm_res(struct nlm_res *dst, struct nlm4_res *src)
107 dst->cookie = src->cookie;
108 dst->stat.stat = nlm_convert_to_nlm_stats(src->stat.stat);
112 nlm_convert_to_nlm4_res(struct nlm4_res *dst, struct nlm_res *src)
114 dst->cookie = src->cookie;
115 dst->stat.stat = (enum nlm4_stats) src->stat.stat;
118 /**********************************************************************/
125 nlm_sm_notify_0_svc(struct nlm_sm_status *argp, void *result, struct svc_req *rqstp)
133 nlm_test_1_svc(struct nlm_testargs *argp, nlm_testres *result, struct svc_req *rqstp)
139 args4.cookie = argp->cookie;
140 args4.exclusive = argp->exclusive;
141 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
143 retval = nlm4_test_4_svc(&args4, &res4, rqstp);
145 result->cookie = res4.cookie;
146 result->stat.stat = nlm_convert_to_nlm_stats(res4.stat.stat);
147 if (result->stat.stat == nlm_denied)
148 nlm_convert_to_nlm_holder(
149 &result->stat.nlm_testrply_u.holder,
150 &res4.stat.nlm4_testrply_u.holder);
157 nlm_lock_1_svc(struct nlm_lockargs *argp, nlm_res *result, struct svc_req *rqstp)
163 args4.cookie = argp->cookie;
164 args4.block = argp->block;
165 args4.exclusive = argp->exclusive;
166 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
167 args4.reclaim = argp->reclaim;
168 args4.state = argp->state;
170 retval = nlm4_lock_4_svc(&args4, &res4, rqstp);
172 nlm_convert_to_nlm_res(result, &res4);
178 nlm_cancel_1_svc(struct nlm_cancargs *argp, nlm_res *result, struct svc_req *rqstp)
184 args4.cookie = argp->cookie;
185 args4.block = argp->block;
186 args4.exclusive = argp->exclusive;
187 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
189 retval = nlm4_cancel_4_svc(&args4, &res4, rqstp);
191 nlm_convert_to_nlm_res(result, &res4);
197 nlm_unlock_1_svc(struct nlm_unlockargs *argp, nlm_res *result, struct svc_req *rqstp)
200 nlm4_unlockargs args4;
203 args4.cookie = argp->cookie;
204 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
206 retval = nlm4_unlock_4_svc(&args4, &res4, rqstp);
208 nlm_convert_to_nlm_res(result, &res4);
214 nlm_granted_1_svc(struct nlm_testargs *argp, nlm_res *result, struct svc_req *rqstp)
220 args4.cookie = argp->cookie;
221 args4.exclusive = argp->exclusive;
222 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
224 retval = nlm4_granted_4_svc(&args4, &res4, rqstp);
226 nlm_convert_to_nlm_res(result, &res4);
232 nlm_test_msg_1_svc(struct nlm_testargs *argp, void *result, struct svc_req *rqstp)
240 args4.cookie = argp->cookie;
241 args4.exclusive = argp->exclusive;
242 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
244 if (nlm_do_test(&args4, &res4, rqstp, &rpc))
247 res.cookie = res4.cookie;
248 res.stat.stat = nlm_convert_to_nlm_stats(res4.stat.stat);
249 if (res.stat.stat == nlm_denied)
250 nlm_convert_to_nlm_holder(
251 &res.stat.nlm_testrply_u.holder,
252 &res4.stat.nlm4_testrply_u.holder);
255 nlm_test_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
258 xdr_free((xdrproc_t) xdr_nlm_testres, &res);
264 nlm_lock_msg_1_svc(struct nlm_lockargs *argp, void *result, struct svc_req *rqstp)
272 args4.cookie = argp->cookie;
273 args4.block = argp->block;
274 args4.exclusive = argp->exclusive;
275 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
276 args4.reclaim = argp->reclaim;
277 args4.state = argp->state;
279 if (nlm_do_lock(&args4, &res4, rqstp, TRUE, &rpc))
282 nlm_convert_to_nlm_res(&res, &res4);
285 nlm_lock_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
288 xdr_free((xdrproc_t) xdr_nlm_res, &res);
294 nlm_cancel_msg_1_svc(struct nlm_cancargs *argp, void *result, struct svc_req *rqstp)
302 args4.cookie = argp->cookie;
303 args4.block = argp->block;
304 args4.exclusive = argp->exclusive;
305 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
307 if (nlm_do_cancel(&args4, &res4, rqstp, &rpc))
310 nlm_convert_to_nlm_res(&res, &res4);
313 nlm_cancel_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
316 xdr_free((xdrproc_t) xdr_nlm_res, &res);
322 nlm_unlock_msg_1_svc(struct nlm_unlockargs *argp, void *result, struct svc_req *rqstp)
324 nlm4_unlockargs args4;
330 args4.cookie = argp->cookie;
331 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
333 if (nlm_do_unlock(&args4, &res4, rqstp, &rpc))
336 nlm_convert_to_nlm_res(&res, &res4);
339 nlm_unlock_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
342 xdr_free((xdrproc_t) xdr_nlm_res, &res);
348 nlm_granted_msg_1_svc(struct nlm_testargs *argp, void *result, struct svc_req *rqstp)
356 args4.cookie = argp->cookie;
357 args4.exclusive = argp->exclusive;
358 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
360 if (nlm_do_granted(&args4, &res4, rqstp, &rpc))
363 nlm_convert_to_nlm_res(&res, &res4);
366 nlm_granted_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
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, NULL);
523 nlm4_lock_4_svc(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp)
526 nlm_do_lock(argp, result, rqstp, TRUE, NULL);
531 nlm4_cancel_4_svc(nlm4_cancargs *argp, nlm4_res *result, struct svc_req *rqstp)
534 nlm_do_cancel(argp, result, rqstp, NULL);
539 nlm4_unlock_4_svc(nlm4_unlockargs *argp, nlm4_res *result, struct svc_req *rqstp)
542 nlm_do_unlock(argp, result, rqstp, NULL);
547 nlm4_granted_4_svc(nlm4_testargs *argp, nlm4_res *result, struct svc_req *rqstp)
550 nlm_do_granted(argp, result, rqstp, NULL);
555 nlm4_test_msg_4_svc(nlm4_testargs *argp, void *result, struct svc_req *rqstp)
561 if (nlm_do_test(argp, &res4, rqstp, &rpc))
564 nlm4_test_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
567 xdr_free((xdrproc_t) xdr_nlm4_testres, &res4);
573 nlm4_lock_msg_4_svc(nlm4_lockargs *argp, void *result, struct svc_req *rqstp)
579 if (nlm_do_lock(argp, &res4, rqstp, TRUE, &rpc))
582 nlm4_lock_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
585 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
591 nlm4_cancel_msg_4_svc(nlm4_cancargs *argp, void *result, struct svc_req *rqstp)
597 if (nlm_do_cancel(argp, &res4, rqstp, &rpc))
600 nlm4_cancel_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
603 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
609 nlm4_unlock_msg_4_svc(nlm4_unlockargs *argp, void *result, struct svc_req *rqstp)
615 if (nlm_do_unlock(argp, &res4, rqstp, &rpc))
618 nlm4_unlock_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
621 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
627 nlm4_granted_msg_4_svc(nlm4_testargs *argp, void *result, struct svc_req *rqstp)
633 if (nlm_do_granted(argp, &res4, rqstp, &rpc))
636 nlm4_granted_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
639 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
645 nlm4_test_res_4_svc(nlm4_testres *argp, void *result, struct svc_req *rqstp)
652 nlm4_lock_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
659 nlm4_cancel_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
666 nlm4_unlock_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
673 nlm4_granted_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
676 nlm_do_granted_res(argp, rqstp);
681 nlm4_share_4_svc(nlm4_shareargs *argp, nlm4_shareres *result, struct svc_req *rqstp)
684 memset(result, 0, sizeof(*result));
685 result->stat = nlm4_denied;
690 nlm4_unshare_4_svc(nlm4_shareargs *argp, nlm4_shareres *result, struct svc_req *rqstp)
693 memset(result, 0, sizeof(*result));
694 result->stat = nlm4_denied;
699 nlm4_nm_lock_4_svc(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp)
702 nlm_do_lock(argp, result, rqstp, FALSE, NULL);
707 nlm4_free_all_4_svc(nlm4_notify *argp, void *result, struct svc_req *rqstp)
710 nlm_do_free_all(argp);
715 nlm_prog_4_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result)
718 (void) xdr_free(xdr_result, result);