save/restore debug regs, kick DR intercepts to userspace
[freebsd-src/fkvm-freebsd.git] / sys / nlm / nlm_prot_server.c
blob6ff86ce3815957e1304b8a606469c8a37a7782e3
1 /*-
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
8 * are met:
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
25 * SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 #ifndef lint
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 $");
33 #endif /* not lint */
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/malloc.h>
38 #include <sys/systm.h>
40 #include <nlm/nlm_prot.h>
41 #include <nlm/nlm.h>
43 /**********************************************************************/
46 * Convert between various versions of the protocol structures.
49 static void
50 nlm_convert_to_nlm4_lock(struct nlm4_lock *dst, struct nlm_lock *src)
53 dst->caller_name = src->caller_name;
54 dst->fh = src->fh;
55 dst->oh = src->oh;
56 dst->svid = src->svid;
57 dst->l_offset = src->l_offset;
58 dst->l_len = src->l_len;
61 static void
62 nlm_convert_to_nlm4_share(struct nlm4_share *dst, struct nlm_share *src)
65 dst->caller_name = src->caller_name;
66 dst->fh = src->fh;
67 dst->oh = src->oh;
68 dst->mode = src->mode;
69 dst->access = src->access;
72 static void
73 nlm_convert_to_nlm_holder(struct nlm_holder *dst, struct nlm4_holder *src)
76 dst->exclusive = src->exclusive;
77 dst->svid = src->svid;
78 dst->oh = src->oh;
79 dst->l_offset = src->l_offset;
80 dst->l_len = src->l_len;
83 static void
84 nlm_convert_to_nlm4_holder(struct nlm4_holder *dst, struct nlm_holder *src)
87 dst->exclusive = src->exclusive;
88 dst->svid = src->svid;
89 dst->oh = src->oh;
90 dst->l_offset = src->l_offset;
91 dst->l_len = src->l_len;
94 static enum nlm_stats
95 nlm_convert_to_nlm_stats(enum nlm4_stats src)
97 if (src > nlm4_deadlck)
98 return nlm_denied;
99 return (enum nlm_stats) src;
102 static void
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);
109 static void
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 /**********************************************************************/
119 * RPC server stubs.
122 bool_t
123 nlm_sm_notify_0_svc(struct nlm_sm_status *argp, void *result, struct svc_req *rqstp)
125 nlm_sm_notify(argp);
127 return (TRUE);
130 bool_t
131 nlm_test_1_svc(struct nlm_testargs *argp, nlm_testres *result, struct svc_req *rqstp)
133 bool_t retval;
134 nlm4_testargs args4;
135 nlm4_testres res4;
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);
142 if (retval) {
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);
151 return (retval);
154 bool_t
155 nlm_lock_1_svc(struct nlm_lockargs *argp, nlm_res *result, struct svc_req *rqstp)
157 bool_t retval;
158 nlm4_lockargs args4;
159 nlm4_res res4;
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);
169 if (retval)
170 nlm_convert_to_nlm_res(result, &res4);
172 return (retval);
175 bool_t
176 nlm_cancel_1_svc(struct nlm_cancargs *argp, nlm_res *result, struct svc_req *rqstp)
178 bool_t retval;
179 nlm4_cancargs args4;
180 nlm4_res res4;
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);
188 if (retval)
189 nlm_convert_to_nlm_res(result, &res4);
191 return (retval);
194 bool_t
195 nlm_unlock_1_svc(struct nlm_unlockargs *argp, nlm_res *result, struct svc_req *rqstp)
197 bool_t retval;
198 nlm4_unlockargs args4;
199 nlm4_res res4;
201 args4.cookie = argp->cookie;
202 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
204 retval = nlm4_unlock_4_svc(&args4, &res4, rqstp);
205 if (retval)
206 nlm_convert_to_nlm_res(result, &res4);
208 return (retval);
211 bool_t
212 nlm_granted_1_svc(struct nlm_testargs *argp, nlm_res *result, struct svc_req *rqstp)
214 bool_t retval;
215 nlm4_testargs args4;
216 nlm4_res res4;
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);
223 if (retval)
224 nlm_convert_to_nlm_res(result, &res4);
226 return (retval);
229 bool_t
230 nlm_test_msg_1_svc(struct nlm_testargs *argp, void *result, struct svc_req *rqstp)
232 nlm4_testargs args4;
233 nlm4_testres res4;
234 nlm_testres res;
235 CLIENT *rpc;
236 char dummy;
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))
243 return (FALSE);
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 if (rpc) {
253 nlm_test_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
254 CLNT_RELEASE(rpc);
256 xdr_free((xdrproc_t) xdr_nlm_testres, &res);
258 return (FALSE);
261 bool_t
262 nlm_lock_msg_1_svc(struct nlm_lockargs *argp, void *result, struct svc_req *rqstp)
264 nlm4_lockargs args4;
265 nlm4_res res4;
266 nlm_res res;
267 CLIENT *rpc;
268 char dummy;
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))
278 return (FALSE);
280 nlm_convert_to_nlm_res(&res, &res4);
282 if (rpc) {
283 nlm_lock_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
284 CLNT_RELEASE(rpc);
286 xdr_free((xdrproc_t) xdr_nlm_res, &res);
288 return (FALSE);
291 bool_t
292 nlm_cancel_msg_1_svc(struct nlm_cancargs *argp, void *result, struct svc_req *rqstp)
294 nlm4_cancargs args4;
295 nlm4_res res4;
296 nlm_res res;
297 CLIENT *rpc;
298 char dummy;
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))
306 return (FALSE);
308 nlm_convert_to_nlm_res(&res, &res4);
310 if (rpc) {
311 nlm_cancel_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
312 CLNT_RELEASE(rpc);
314 xdr_free((xdrproc_t) xdr_nlm_res, &res);
316 return (FALSE);
319 bool_t
320 nlm_unlock_msg_1_svc(struct nlm_unlockargs *argp, void *result, struct svc_req *rqstp)
322 nlm4_unlockargs args4;
323 nlm4_res res4;
324 nlm_res res;
325 CLIENT *rpc;
326 char dummy;
328 args4.cookie = argp->cookie;
329 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
331 if (nlm_do_unlock(&args4, &res4, rqstp, &rpc))
332 return (FALSE);
334 nlm_convert_to_nlm_res(&res, &res4);
336 if (rpc) {
337 nlm_unlock_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
338 CLNT_RELEASE(rpc);
340 xdr_free((xdrproc_t) xdr_nlm_res, &res);
342 return (FALSE);
345 bool_t
346 nlm_granted_msg_1_svc(struct nlm_testargs *argp, void *result, struct svc_req *rqstp)
348 nlm4_testargs args4;
349 nlm4_res res4;
350 nlm_res res;
351 CLIENT *rpc;
352 char dummy;
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))
359 return (FALSE);
361 nlm_convert_to_nlm_res(&res, &res4);
363 if (rpc) {
364 nlm_granted_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv);
365 CLNT_RELEASE(rpc);
367 xdr_free((xdrproc_t) xdr_nlm_res, &res);
369 return (FALSE);
372 bool_t
373 nlm_test_res_1_svc(nlm_testres *argp, void *result, struct svc_req *rqstp)
375 nlm4_testres args4;
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));
386 bool_t
387 nlm_lock_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp)
389 nlm4_res arg4;
391 nlm_convert_to_nlm4_res(&arg4, argp);
392 return (nlm4_lock_res_4_svc(&arg4, result, rqstp));
395 bool_t
396 nlm_cancel_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp)
398 nlm4_res arg4;
400 nlm_convert_to_nlm4_res(&arg4, argp);
401 return (nlm4_cancel_res_4_svc(&arg4, result, rqstp));
404 bool_t
405 nlm_unlock_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp)
407 nlm4_res arg4;
409 nlm_convert_to_nlm4_res(&arg4, argp);
410 return (nlm4_unlock_res_4_svc(&arg4, result, rqstp));
413 bool_t
414 nlm_granted_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp)
416 nlm4_res arg4;
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);
427 return (TRUE);
430 bool_t
431 nlm_share_3_svc(nlm_shareargs *argp, nlm_shareres *result, struct svc_req *rqstp)
433 bool_t retval;
434 nlm4_shareargs args4;
435 nlm4_shareres res4;
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);
442 if (retval) {
443 result->cookie = res4.cookie;
444 result->stat = nlm_convert_to_nlm_stats(res4.stat);
445 result->sequence = res4.sequence;
448 return (retval);
451 bool_t
452 nlm_unshare_3_svc(nlm_shareargs *argp, nlm_shareres *result, struct svc_req *rqstp)
454 bool_t retval;
455 nlm4_shareargs args4;
456 nlm4_shareres res4;
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);
463 if (retval) {
464 result->cookie = res4.cookie;
465 result->stat = nlm_convert_to_nlm_stats(res4.stat);
466 result->sequence = res4.sequence;
469 return (retval);
472 bool_t
473 nlm_nm_lock_3_svc(nlm_lockargs *argp, nlm_res *result, struct svc_req *rqstp)
475 bool_t retval;
476 nlm4_lockargs args4;
477 nlm4_res res4;
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);
487 if (retval)
488 nlm_convert_to_nlm_res(result, &res4);
490 return (retval);
493 bool_t
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);
509 return (TRUE);
512 bool_t
513 nlm4_test_4_svc(nlm4_testargs *argp, nlm4_testres *result, struct svc_req *rqstp)
516 nlm_do_test(argp, result, rqstp, NULL);
517 return (TRUE);
520 bool_t
521 nlm4_lock_4_svc(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp)
524 nlm_do_lock(argp, result, rqstp, TRUE, NULL);
525 return (TRUE);
528 bool_t
529 nlm4_cancel_4_svc(nlm4_cancargs *argp, nlm4_res *result, struct svc_req *rqstp)
532 nlm_do_cancel(argp, result, rqstp, NULL);
533 return (TRUE);
536 bool_t
537 nlm4_unlock_4_svc(nlm4_unlockargs *argp, nlm4_res *result, struct svc_req *rqstp)
540 nlm_do_unlock(argp, result, rqstp, NULL);
541 return (TRUE);
544 bool_t
545 nlm4_granted_4_svc(nlm4_testargs *argp, nlm4_res *result, struct svc_req *rqstp)
548 nlm_do_granted(argp, result, rqstp, NULL);
549 return (TRUE);
552 bool_t
553 nlm4_test_msg_4_svc(nlm4_testargs *argp, void *result, struct svc_req *rqstp)
555 nlm4_testres res4;
556 CLIENT *rpc;
557 char dummy;
559 if (nlm_do_test(argp, &res4, rqstp, &rpc))
560 return (FALSE);
561 if (rpc) {
562 nlm4_test_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
563 CLNT_RELEASE(rpc);
565 xdr_free((xdrproc_t) xdr_nlm4_testres, &res4);
567 return (FALSE);
570 bool_t
571 nlm4_lock_msg_4_svc(nlm4_lockargs *argp, void *result, struct svc_req *rqstp)
573 nlm4_res res4;
574 CLIENT *rpc;
575 char dummy;
577 if (nlm_do_lock(argp, &res4, rqstp, TRUE, &rpc))
578 return (FALSE);
579 if (rpc) {
580 nlm4_lock_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
581 CLNT_RELEASE(rpc);
583 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
585 return (FALSE);
588 bool_t
589 nlm4_cancel_msg_4_svc(nlm4_cancargs *argp, void *result, struct svc_req *rqstp)
591 nlm4_res res4;
592 CLIENT *rpc;
593 char dummy;
595 if (nlm_do_cancel(argp, &res4, rqstp, &rpc))
596 return (FALSE);
597 if (rpc) {
598 nlm4_cancel_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
599 CLNT_RELEASE(rpc);
601 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
603 return (FALSE);
606 bool_t
607 nlm4_unlock_msg_4_svc(nlm4_unlockargs *argp, void *result, struct svc_req *rqstp)
609 nlm4_res res4;
610 CLIENT *rpc;
611 char dummy;
613 if (nlm_do_unlock(argp, &res4, rqstp, &rpc))
614 return (FALSE);
615 if (rpc) {
616 nlm4_unlock_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
617 CLNT_RELEASE(rpc);
619 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
621 return (FALSE);
624 bool_t
625 nlm4_granted_msg_4_svc(nlm4_testargs *argp, void *result, struct svc_req *rqstp)
627 nlm4_res res4;
628 CLIENT *rpc;
629 char dummy;
631 if (nlm_do_granted(argp, &res4, rqstp, &rpc))
632 return (FALSE);
633 if (rpc) {
634 nlm4_granted_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv);
635 CLNT_RELEASE(rpc);
637 xdr_free((xdrproc_t) xdr_nlm4_res, &res4);
639 return (FALSE);
642 bool_t
643 nlm4_test_res_4_svc(nlm4_testres *argp, void *result, struct svc_req *rqstp)
646 return (FALSE);
649 bool_t
650 nlm4_lock_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
653 return (FALSE);
656 bool_t
657 nlm4_cancel_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
660 return (FALSE);
663 bool_t
664 nlm4_unlock_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
667 return (FALSE);
670 bool_t
671 nlm4_granted_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp)
674 return (FALSE);
677 bool_t
678 nlm4_share_4_svc(nlm4_shareargs *argp, nlm4_shareres *result, struct svc_req *rqstp)
681 memset(result, 0, sizeof(*result));
682 result->stat = nlm4_denied;
683 return (TRUE);
686 bool_t
687 nlm4_unshare_4_svc(nlm4_shareargs *argp, nlm4_shareres *result, struct svc_req *rqstp)
690 memset(result, 0, sizeof(*result));
691 result->stat = nlm4_denied;
692 return (TRUE);
695 bool_t
696 nlm4_nm_lock_4_svc(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp)
699 nlm_do_lock(argp, result, rqstp, FALSE, NULL);
700 return (TRUE);
703 bool_t
704 nlm4_free_all_4_svc(nlm4_notify *argp, void *result, struct svc_req *rqstp)
707 nlm_do_free_all(argp);
708 return (TRUE);
712 nlm_prog_4_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result)
715 (void) xdr_free(xdr_result, result);
716 return (TRUE);