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>
5 *
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.
14 *
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.
26 */
27
28/*
29 * Copyright 2019 Nexenta by DDN, Inc. All rights reserved.
30 * Copyright (c) 2012 by Delphix. All rights reserved.
31 */
32
33/*
34 * NFS Lock Manager, RPC service functions (nlm_..._svc)
35 * Called via nlm_dispatch.c tables.
36 *
37 * Source code derived from FreeBSD nlm_prot_server.c
38 *
39 * The real service functions all use nlm4_... args and return
40 * data types.  These wrappers convert older forms to and from
41 * the new forms and call the nlm_do_... service functions.
42 */
43
44#include <sys/param.h>
45#include <sys/systm.h>
46
47#include <rpcsvc/nlm_prot.h>
48#include "nlm_impl.h"
49
50/*
51 * Convert between various versions of the protocol structures.
52 */
53
54/*
55 * Down-convert, for granted_1 call
56 *
57 * This converts a 64-bit lock to 32-bit form for our granted
58 * call-back when we're dealing with a 32-bit NLM client.
59 * Our NLM_LOCK handler ensures that any lock we grant to a
60 * 32-bit client can be represented in 32-bits.  If the
61 * ASSERTs here fire, then the call to nlm_init_flock in
62 * nlm_do_lock has failed to restrict a 32-bit client to
63 * 32-bit lock ranges.
64 */
65static void
66nlm_convert_to_nlm_lock(struct nlm_lock *dst, const struct nlm4_lock *src)
67{
68	dst->caller_name = src->caller_name;
69	dst->fh = src->fh;
70	dst->oh = src->oh;
71	dst->svid = src->svid;
72	ASSERT(src->l_offset <= MAX_UOFF32);
73	dst->l_offset = (uint32_t)src->l_offset;
74	ASSERT(src->l_len <= MAX_UOFF32);
75	dst->l_len = (uint32_t)src->l_len;
76}
77
78/*
79 * Up-convert for v1 granted response
80 */
81static void
82nlm_convert_to_nlm4_res(struct nlm4_res *dst, const struct nlm_res *src)
83{
84	dst->cookie = src->cookie;
85	dst->stat.stat = (nlm4_stats) src->stat.stat;
86}
87
88/*
89 * Up-convert for v1 svc functions with a 32-bit lock range arg.
90 * Note that lock range checks (like overflow) are done later,
91 * in nlm_init_flock().
92 */
93static void
94nlm_convert_to_nlm4_lock(struct nlm4_lock *dst, const struct nlm_lock *src)
95{
96
97	dst->caller_name = src->caller_name;
98	dst->fh = src->fh;
99	dst->oh = src->oh;
100	dst->svid = src->svid;
101	dst->l_offset = src->l_offset;
102	dst->l_len = src->l_len;
103}
104
105static void
106nlm_convert_to_nlm4_share(struct nlm4_share *dst, const struct nlm_share *src)
107{
108
109	dst->caller_name = src->caller_name;
110	dst->fh = src->fh;
111	dst->oh = src->oh;
112	dst->mode = src->mode;
113	dst->access = src->access;
114}
115
116/*
117 * Down-convert for v1 NLM_TEST or NLM_TEST_MSG response.
118 * Note that nlm_do_test is careful to give us lock ranges
119 * that can be represented with 32-bit values.  If the
120 * ASSERTs here fire, then the code in nlm_do_test that
121 * builds an nlm4_holder for a 32-bit client has failed to
122 * restrict the reported conflicting lock range so it's a
123 * valid 32-bit lock range.
124 */
125static void
126nlm_convert_to_nlm_holder(struct nlm_holder *dst, const struct nlm4_holder *src)
127{
128	dst->exclusive = src->exclusive;
129	dst->svid = src->svid;
130	dst->oh = src->oh;
131	ASSERT(src->l_offset <= MAX_UOFF32);
132	dst->l_offset = (uint32_t)src->l_offset;
133	ASSERT(src->l_len <= MAX_UOFF32);
134	dst->l_len = (uint32_t)src->l_len;
135}
136
137static enum nlm_stats
138nlm_convert_to_nlm_stats(enum nlm4_stats src)
139{
140	if (src > nlm4_deadlck)
141		return (nlm_denied);
142	return ((enum nlm_stats)src);
143}
144
145static void
146nlm_convert_to_nlm_res(struct nlm_res *dst, const struct nlm4_res *src)
147{
148	dst->cookie = src->cookie;
149	dst->stat.stat = nlm_convert_to_nlm_stats(src->stat.stat);
150}
151
152/* ******************************************************************** */
153
154/*
155 * Version 1 svc functions
156 */
157
158bool_t
159nlm_test_1_svc(struct nlm_testargs *argp, nlm_testres *resp,
160    struct svc_req *sr)
161{
162	nlm4_testargs args4;
163	nlm4_testres res4;
164
165	bzero(&args4, sizeof (args4));
166	bzero(&res4, sizeof (res4));
167
168	args4.cookie = argp->cookie;
169	args4.exclusive = argp->exclusive;
170	nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
171
172	nlm_do_test(&args4, &res4, sr, NULL);
173
174	resp->cookie = res4.cookie;
175	resp->stat.stat = nlm_convert_to_nlm_stats(res4.stat.stat);
176	if (resp->stat.stat == nlm_denied)
177		nlm_convert_to_nlm_holder(
178		    &resp->stat.nlm_testrply_u.holder,
179		    &res4.stat.nlm4_testrply_u.holder);
180
181	return (TRUE);
182}
183
184/*
185 * Callback functions for nlm_lock_1_svc
186 */
187static bool_t nlm_lock_1_reply(SVCXPRT *, nlm4_res *);
188static enum clnt_stat nlm_granted_1_cb(nlm4_testargs *, nlm4_res *, CLIENT *);
189
190bool_t
191nlm_lock_1_svc(nlm_lockargs *argp, nlm_res *resp,
192    struct svc_req *sr)
193{
194	nlm4_lockargs args4;
195	nlm4_res res4;
196
197	bzero(&res4, sizeof (res4));
198
199	args4.cookie = argp->cookie;
200	args4.block = argp->block;
201	args4.exclusive = argp->exclusive;
202	nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
203	args4.reclaim = argp->reclaim;
204	args4.state = argp->state;
205
206	/* NLM_LOCK */
207	nlm_do_lock(&args4, &res4, sr,
208	    nlm_lock_1_reply, NULL,
209	    nlm_granted_1_cb);
210
211	/* for freeresult */
212	nlm_convert_to_nlm_res(resp, &res4);
213
214	/* above does its own reply */
215	return (FALSE);
216}
217
218static bool_t
219nlm_lock_1_reply(SVCXPRT *transp, nlm4_res *resp)
220{
221	nlm_res res1;
222
223	nlm_convert_to_nlm_res(&res1, resp);
224	return (svc_sendreply(transp, xdr_nlm_res, (char *)&res1));
225}
226
227static enum clnt_stat
228nlm_granted_1_cb(nlm4_testargs *argp, nlm4_res *resp, CLIENT *clnt)
229{
230	nlm_testargs args1;
231	nlm_res res1;
232	int rv;
233
234	bzero(&res1, sizeof (res1));
235
236	args1.cookie = argp->cookie;
237	args1.exclusive = argp->exclusive;
238	nlm_convert_to_nlm_lock(&args1.alock, &argp->alock);
239
240	rv = nlm_granted_1(&args1, &res1, clnt);
241
242	nlm_convert_to_nlm4_res(resp, &res1);
243
244	return (rv);
245}
246
247bool_t
248nlm_cancel_1_svc(struct nlm_cancargs *argp, nlm_res *resp,
249    struct svc_req *sr)
250{
251	nlm4_cancargs args4;
252	nlm4_res res4;
253
254	bzero(&res4, sizeof (res4));
255
256	args4.cookie = argp->cookie;
257	args4.block = argp->block;
258	args4.exclusive = argp->exclusive;
259	nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
260
261	nlm_do_cancel(&args4, &res4, sr, NULL);
262
263	nlm_convert_to_nlm_res(resp, &res4);
264
265	return (TRUE);
266}
267
268bool_t
269nlm_unlock_1_svc(struct nlm_unlockargs *argp, nlm_res *resp,
270    struct svc_req *sr)
271{
272	nlm4_unlockargs args4;
273	nlm4_res res4;
274
275	bzero(&res4, sizeof (res4));
276
277	args4.cookie = argp->cookie;
278	nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
279
280	nlm_do_unlock(&args4, &res4, sr, NULL);
281
282	nlm_convert_to_nlm_res(resp, &res4);
283
284	return (TRUE);
285}
286
287bool_t
288nlm_granted_1_svc(struct nlm_testargs *argp, nlm_res *resp,
289    struct svc_req *sr)
290{
291	nlm4_testargs args4;
292	nlm4_res res4;
293
294	bzero(&res4, sizeof (res4));
295
296	args4.cookie = argp->cookie;
297	args4.exclusive = argp->exclusive;
298	nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
299
300	nlm_do_granted(&args4, &res4, sr, NULL);
301
302	nlm_convert_to_nlm_res(resp, &res4);
303
304	return (TRUE);
305}
306
307/*
308 * The _msg_ calls get no reply.  Instead, these callers
309 * expect an RPC call to the corresponding _res function.
310 * We pass this callback function to nlm_do_test so it will
311 * use it to do the RPC callback, with the correct res type.
312 *
313 * The callback functions have nearly the same arg signature
314 * as the client call functions so that many of those can be
315 * optimized to nothing by the compiler.  Also, passing the
316 * null result arg for these just to reduce warnings.
317 *
318 * See similar callbacks for other _msg functions below.
319 */
320
321static enum clnt_stat nlm_test_res_1_cb(nlm4_testres *, void *, CLIENT *);
322
323bool_t
324nlm_test_msg_1_svc(struct nlm_testargs *argp, void *resp,
325    struct svc_req *sr)
326{
327	nlm4_testargs args4;
328	nlm4_testres res4;
329
330	bzero(&res4, sizeof (res4));
331
332	args4.cookie = argp->cookie;
333	args4.exclusive = argp->exclusive;
334	nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
335
336	nlm_do_test(&args4, &res4, sr,
337	    nlm_test_res_1_cb);
338
339	/* NB: We have a result our caller will not free. */
340	xdr_free((xdrproc_t)xdr_nlm4_testres, (void *)&res4);
341	(void) resp;
342
343	/* The _msg_ calls get no reply. */
344	return (FALSE);
345}
346
347static enum clnt_stat
348nlm_test_res_1_cb(nlm4_testres *res4, void *null, CLIENT *clnt)
349{
350	nlm_testres res1;
351
352	res1.cookie = res4->cookie;
353	res1.stat.stat = nlm_convert_to_nlm_stats(res4->stat.stat);
354	if (res1.stat.stat == nlm_denied)
355		nlm_convert_to_nlm_holder(
356		    &res1.stat.nlm_testrply_u.holder,
357		    &res4->stat.nlm4_testrply_u.holder);
358
359	return (nlm_test_res_1(&res1, null, clnt));
360}
361
362/*
363 * Callback functions for nlm_lock_msg_1_svc
364 */
365static enum clnt_stat nlm_lock_res_1_cb(nlm4_res *, void *, CLIENT *);
366static enum clnt_stat nlm_granted_msg_1_cb(nlm4_testargs *, nlm4_res *,
367    CLIENT *);
368
369bool_t
370nlm_lock_msg_1_svc(nlm_lockargs *argp, void *resp,
371    struct svc_req *sr)
372{
373	nlm4_lockargs args4;
374	nlm4_res res4;
375
376	bzero(&res4, sizeof (res4));
377
378	args4.cookie = argp->cookie;
379	args4.block = argp->block;
380	args4.exclusive = argp->exclusive;
381	nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
382	args4.reclaim = argp->reclaim;
383	args4.state = argp->state;
384
385	/* NLM_LOCK_MSG */
386	nlm_do_lock(&args4, &res4, sr,
387	    NULL, nlm_lock_res_1_cb,
388	    nlm_granted_msg_1_cb);
389
390	/* NB: We have a result our caller will not free. */
391	xdr_free((xdrproc_t)xdr_nlm4_res, (void *)&res4);
392	(void) resp;
393
394	/* The _msg_ calls get no reply. */
395	return (FALSE);
396}
397
398static enum clnt_stat
399nlm_lock_res_1_cb(nlm4_res *resp, void *null, CLIENT *clnt)
400{
401	nlm_res res1;
402
403	nlm_convert_to_nlm_res(&res1, resp);
404	return (nlm_lock_res_1(&res1, null, clnt));
405}
406
407static enum clnt_stat
408nlm_granted_msg_1_cb(nlm4_testargs *argp, nlm4_res *resp, CLIENT *clnt)
409{
410	nlm_testargs args1;
411	int rv;
412
413	args1.cookie = argp->cookie;
414	args1.exclusive = argp->exclusive;
415	nlm_convert_to_nlm_lock(&args1.alock, &argp->alock);
416
417	rv = nlm_granted_msg_1(&args1, NULL, clnt);
418
419	/* MSG call doesn't fill in *resp, so do it here. */
420	if (rv != RPC_SUCCESS)
421		resp->stat.stat = nlm4_failed;
422
423	return (rv);
424}
425
426
427static enum clnt_stat nlm_cancel_res_1_cb(nlm4_res *, void *, CLIENT *);
428
429bool_t
430nlm_cancel_msg_1_svc(struct nlm_cancargs *argp, void *resp,
431    struct svc_req *sr)
432{
433	nlm4_cancargs args4;
434	nlm4_res res4;
435
436	bzero(&res4, sizeof (res4));
437
438	args4.cookie = argp->cookie;
439	args4.block = argp->block;
440	args4.exclusive = argp->exclusive;
441	nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
442
443	nlm_do_cancel(&args4, &res4, sr,
444	    nlm_cancel_res_1_cb);
445
446	/* NB: We have a result our caller will not free. */
447	xdr_free((xdrproc_t)xdr_nlm4_res, (void *)&res4);
448	(void) resp;
449
450	/* The _msg_ calls get no reply. */
451	return (FALSE);
452}
453
454static enum clnt_stat
455nlm_cancel_res_1_cb(nlm4_res *res4, void *null, CLIENT *clnt)
456{
457	nlm_res res1;
458
459	nlm_convert_to_nlm_res(&res1, res4);
460	return (nlm_cancel_res_1(&res1, null, clnt));
461}
462
463
464static enum clnt_stat nlm_unlock_res_1_cb(nlm4_res *, void *, CLIENT *);
465
466bool_t
467nlm_unlock_msg_1_svc(struct nlm_unlockargs *argp, void *resp,
468    struct svc_req *sr)
469{
470	nlm4_unlockargs args4;
471	nlm4_res res4;
472
473	bzero(&res4, sizeof (res4));
474
475	args4.cookie = argp->cookie;
476	nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
477
478	nlm_do_unlock(&args4, &res4, sr,
479	    nlm_unlock_res_1_cb);
480
481	/* NB: We have a result our caller will not free. */
482	xdr_free((xdrproc_t)xdr_nlm4_res, (void *)&res4);
483	(void) resp;
484
485	/* The _msg_ calls get no reply. */
486	return (FALSE);
487}
488
489static enum clnt_stat
490nlm_unlock_res_1_cb(nlm4_res *res4, void *null, CLIENT *clnt)
491{
492	nlm_res res1;
493
494	nlm_convert_to_nlm_res(&res1, res4);
495	return (nlm_unlock_res_1(&res1, null, clnt));
496}
497
498
499static enum clnt_stat nlm_granted_res_1_cb(nlm4_res *, void *, CLIENT *);
500
501bool_t
502nlm_granted_msg_1_svc(struct nlm_testargs *argp, void *resp,
503    struct svc_req *sr)
504{
505	nlm4_testargs args4;
506	nlm4_res res4;
507
508	bzero(&res4, sizeof (res4));
509
510	args4.cookie = argp->cookie;
511	args4.exclusive = argp->exclusive;
512	nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
513
514	nlm_do_granted(&args4, &res4, sr,
515	    nlm_granted_res_1_cb);
516
517	/* NB: We have a result our caller will not free. */
518	xdr_free((xdrproc_t)xdr_nlm4_res, (void *)&res4);
519	(void) resp;
520
521	/* The _msg_ calls get no reply. */
522	return (FALSE);
523}
524
525static enum clnt_stat
526nlm_granted_res_1_cb(nlm4_res *res4, void *null, CLIENT *clnt)
527{
528	nlm_res res1;
529
530	nlm_convert_to_nlm_res(&res1, res4);
531	return (nlm_granted_res_1(&res1, null, clnt));
532}
533
534/*
535 * The _res_ calls get no reply.  These RPC calls are
536 * "call backs" in response to RPC _msg_ calls.
537 * We don't care about these responses.
538 */
539
540/* ARGSUSED */
541bool_t
542nlm_test_res_1_svc(nlm_testres *argp, void *resp, struct svc_req *sr)
543{
544	/* The _res_ calls get no reply. */
545	return (FALSE);
546}
547
548/* ARGSUSED */
549bool_t
550nlm_lock_res_1_svc(nlm_res *argp, void *resp, struct svc_req *sr)
551{
552	/* The _res_ calls get no reply. */
553	return (FALSE);
554}
555
556/* ARGSUSED */
557bool_t
558nlm_cancel_res_1_svc(nlm_res *argp, void *resp, struct svc_req *sr)
559{
560	/* The _res_ calls get no reply. */
561	return (FALSE);
562}
563
564/* ARGSUSED */
565bool_t
566nlm_unlock_res_1_svc(nlm_res *argp, void *resp, struct svc_req *sr)
567{
568	/* The _res_ calls get no reply. */
569	return (FALSE);
570}
571
572/* ARGSUSED */
573bool_t
574nlm_granted_res_1_svc(nlm_res *argp, void *resp, struct svc_req *sr)
575{
576	/* The _res_ calls get no reply. */
577	return (FALSE);
578}
579
580/*
581 * Version 2 svc functions (used by local statd)
582 */
583
584bool_t
585nlm_sm_notify1_2_svc(struct nlm_sm_status *argp, void *resp,
586    struct svc_req *sr)
587{
588	nlm_do_notify1(argp, resp, sr);
589	return (TRUE);
590}
591
592bool_t
593nlm_sm_notify2_2_svc(struct nlm_sm_status *argp, void *resp,
594    struct svc_req *sr)
595{
596	nlm_do_notify2(argp, resp, sr);
597	return (TRUE);
598}
599
600/*
601 * Version 3 svc functions
602 */
603
604bool_t
605nlm_share_3_svc(nlm_shareargs *argp, nlm_shareres *resp,
606    struct svc_req *sr)
607{
608	nlm4_shareargs args4;
609	nlm4_shareres res4;
610
611	bzero(&res4, sizeof (res4));
612
613	args4.cookie = argp->cookie;
614	nlm_convert_to_nlm4_share(&args4.share, &argp->share);
615	args4.reclaim = argp->reclaim;
616
617	nlm_do_share(&args4, &res4, sr);
618
619	resp->cookie = res4.cookie;
620	resp->stat = nlm_convert_to_nlm_stats(res4.stat);
621	resp->sequence = res4.sequence;
622
623	return (TRUE);
624}
625
626bool_t
627nlm_unshare_3_svc(nlm_shareargs *argp, nlm_shareres *resp,
628    struct svc_req *sr)
629{
630	nlm4_shareargs args4;
631	nlm4_shareres res4;
632
633	bzero(&res4, sizeof (res4));
634
635	args4.cookie = argp->cookie;
636	nlm_convert_to_nlm4_share(&args4.share, &argp->share);
637	args4.reclaim = argp->reclaim;
638
639	nlm_do_unshare(&args4, &res4, sr);
640
641	resp->cookie = res4.cookie;
642	resp->stat = nlm_convert_to_nlm_stats(res4.stat);
643	resp->sequence = res4.sequence;
644
645	return (TRUE);
646}
647
648bool_t
649nlm_nm_lock_3_svc(nlm_lockargs *argp, nlm_res *resp, struct svc_req *sr)
650{
651	nlm4_lockargs args4;
652	nlm4_res res4;
653
654	bzero(&res4, sizeof (res4));
655
656	args4.cookie = argp->cookie;
657	args4.block = argp->block;
658	args4.exclusive = argp->exclusive;
659	nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock);
660	args4.reclaim = argp->reclaim;
661	args4.state = argp->state;
662
663	/*
664	 * Don't allow blocking for non-monitored (nm_lock) calls.
665	 * These clients don't handle any callbacks, including
666	 * the granted call we make after a blocking lock.
667	 * Same reply callback as nlm_lock_1_svc
668	 */
669	args4.block = FALSE;
670
671	/* NLM_NM_LOCK */
672	nlm_do_lock(&args4, &res4, sr,
673	    nlm_lock_1_reply, NULL,
674	    NULL); /* indicates non-monitored */
675
676	/* for freeresult */
677	nlm_convert_to_nlm_res(resp, &res4);
678
679	/* above does its own reply */
680	return (FALSE);
681}
682
683bool_t
684nlm_free_all_3_svc(nlm_notify *argp, void *resp, struct svc_req *sr)
685{
686	struct nlm4_notify args4;
687
688	args4.name = argp->name;
689	args4.state = argp->state;
690
691	nlm_do_free_all(&args4, resp, sr);
692
693	return (TRUE);
694}
695
696/*
697 * Version 4 svc functions
698 */
699
700bool_t
701nlm4_test_4_svc(nlm4_testargs *argp, nlm4_testres *resp, struct svc_req *sr)
702{
703	nlm_do_test(argp, resp, sr, NULL);
704	return (TRUE);
705}
706
707/*
708 * Callback functions for nlm4_lock_4_svc
709 */
710static bool_t nlm4_lock_4_reply(SVCXPRT *, nlm4_res *);
711
712bool_t
713nlm4_lock_4_svc(nlm4_lockargs *argp, nlm4_res *resp,
714    struct svc_req *sr)
715{
716
717	/* NLM4_LOCK */
718	nlm_do_lock(argp, resp, sr,
719	    nlm4_lock_4_reply, NULL,
720	    nlm4_granted_4);
721
722	/* above does its own reply */
723	return (FALSE);
724}
725
726static bool_t
727nlm4_lock_4_reply(SVCXPRT *transp, nlm4_res *resp)
728{
729	return (svc_sendreply(transp, xdr_nlm4_res, (char *)resp));
730}
731
732bool_t
733nlm4_cancel_4_svc(nlm4_cancargs *argp, nlm4_res *resp, struct svc_req *sr)
734{
735	nlm_do_cancel(argp, resp, sr, NULL);
736	return (TRUE);
737}
738
739bool_t
740nlm4_unlock_4_svc(nlm4_unlockargs *argp, nlm4_res *resp, struct svc_req *sr)
741{
742	nlm_do_unlock(argp, resp, sr, NULL);
743	return (TRUE);
744}
745
746bool_t
747nlm4_granted_4_svc(nlm4_testargs *argp, nlm4_res *resp, struct svc_req *sr)
748{
749	nlm_do_granted(argp, resp, sr, NULL);
750	return (TRUE);
751}
752
753bool_t
754nlm4_test_msg_4_svc(nlm4_testargs *argp, void *resp, struct svc_req *sr)
755{
756	nlm4_testres res4;
757
758	bzero(&res4, sizeof (res4));
759	nlm_do_test(argp, &res4, sr,
760	    nlm4_test_res_4);
761
762	/* NB: We have a result our caller will not free. */
763	xdr_free((xdrproc_t)xdr_nlm4_testres, (void *)&res4);
764	(void) resp;
765
766	/* The _msg_ calls get no reply. */
767	return (FALSE);
768}
769
770/*
771 * Callback functions for nlm4_lock_msg_4_svc
772 * (using the RPC client stubs directly)
773 */
774static enum clnt_stat nlm4_granted_msg_4_cb(nlm4_testargs *, nlm4_res *,
775    CLIENT *);
776
777bool_t
778nlm4_lock_msg_4_svc(nlm4_lockargs *argp, void *resp,
779    struct svc_req *sr)
780{
781	nlm4_res res4;
782
783	/* NLM4_LOCK_MSG */
784	bzero(&res4, sizeof (res4));
785	nlm_do_lock(argp, &res4, sr,
786	    NULL, nlm4_lock_res_4,
787	    nlm4_granted_msg_4_cb);
788
789	/* NB: We have a result our caller will not free. */
790	xdr_free((xdrproc_t)xdr_nlm4_res, (void *)&res4);
791	(void) resp;
792
793	/* The _msg_ calls get no reply. */
794	return (FALSE);
795}
796
797static enum clnt_stat
798nlm4_granted_msg_4_cb(nlm4_testargs *argp, nlm4_res *resp, CLIENT *clnt)
799{
800	int rv;
801
802	rv = nlm4_granted_msg_4(argp, NULL, clnt);
803
804	/* MSG call doesn't fill in *resp, so do it here. */
805	if (rv != RPC_SUCCESS)
806		resp->stat.stat = nlm4_failed;
807
808	return (rv);
809}
810
811bool_t
812nlm4_cancel_msg_4_svc(nlm4_cancargs *argp, void *resp, struct svc_req *sr)
813{
814	nlm4_res res4;
815
816	bzero(&res4, sizeof (res4));
817	nlm_do_cancel(argp, &res4, sr,
818	    nlm4_cancel_res_4);
819
820	/* NB: We have a result our caller will not free. */
821	xdr_free((xdrproc_t)xdr_nlm4_res, (void *)&res4);
822	(void) resp;
823
824	/* The _msg_ calls get no reply. */
825	return (FALSE);
826}
827
828bool_t
829nlm4_unlock_msg_4_svc(nlm4_unlockargs *argp, void *resp, struct svc_req *sr)
830{
831	nlm4_res res4;
832
833	bzero(&res4, sizeof (res4));
834	nlm_do_unlock(argp, &res4, sr,
835	    nlm4_unlock_res_4);
836
837	/* NB: We have a result our caller will not free. */
838	xdr_free((xdrproc_t)xdr_nlm4_res, (void *)&res4);
839	(void) resp;
840
841	/* The _msg_ calls get no reply. */
842	return (FALSE);
843}
844
845bool_t
846nlm4_granted_msg_4_svc(nlm4_testargs *argp, void *resp, struct svc_req *sr)
847{
848	nlm4_res res4;
849
850	bzero(&res4, sizeof (res4));
851	nlm_do_granted(argp, &res4, sr,
852	    nlm4_granted_res_4);
853
854	/* NB: We have a result our caller will not free. */
855	xdr_free((xdrproc_t)xdr_nlm4_res, (void *)&res4);
856	(void) resp;
857
858	/* The _msg_ calls get no reply. */
859	return (FALSE);
860}
861
862/* ARGSUSED */
863bool_t
864nlm4_test_res_4_svc(nlm4_testres *argp, void *resp, struct svc_req *sr)
865{
866	/* The _res_ calls get no reply. */
867	return (FALSE);
868}
869
870/* ARGSUSED */
871bool_t
872nlm4_lock_res_4_svc(nlm4_res *argp, void *resp, struct svc_req *sr)
873{
874	/* The _res_ calls get no reply. */
875	return (FALSE);
876}
877
878/* ARGSUSED */
879bool_t
880nlm4_cancel_res_4_svc(nlm4_res *argp, void *resp, struct svc_req *sr)
881{
882	/* The _res_ calls get no reply. */
883	return (FALSE);
884}
885
886/* ARGSUSED */
887bool_t
888nlm4_unlock_res_4_svc(nlm4_res *argp, void *resp, struct svc_req *sr)
889{
890	/* The _res_ calls get no reply. */
891	return (FALSE);
892}
893
894/* ARGSUSED */
895bool_t
896nlm4_granted_res_4_svc(nlm4_res *argp, void *resp, struct svc_req *sr)
897{
898	/* The _res_ calls get no reply. */
899	return (FALSE);
900}
901
902/* ARGSUSED */
903bool_t
904nlm4_share_4_svc(nlm4_shareargs *argp, nlm4_shareres *resp,
905    struct svc_req *sr)
906{
907	nlm_do_share(argp, resp, sr);
908	return (TRUE);
909}
910
911/* ARGSUSED */
912bool_t
913nlm4_unshare_4_svc(nlm4_shareargs *argp, nlm4_shareres *resp,
914    struct svc_req *sr)
915{
916	nlm_do_unshare(argp, resp, sr);
917	return (TRUE);
918}
919
920bool_t
921nlm4_nm_lock_4_svc(nlm4_lockargs *argp, nlm4_res *resp, struct svc_req *sr)
922{
923
924	/*
925	 * Don't allow blocking for non-monitored (nm_lock) calls.
926	 * These clients don't handle any callbacks, including
927	 * the granted call we make after a blocking lock.
928	 * Same reply callback as nlm4_lock_4_svc
929	 */
930	argp->block = FALSE;
931
932	/* NLM4_NM_LOCK */
933	nlm_do_lock(argp, resp, sr,
934	    nlm4_lock_4_reply, NULL,
935	    NULL); /* indicates non-monitored */
936
937	/* above does its own reply */
938	return (FALSE);
939}
940
941bool_t
942nlm4_free_all_4_svc(nlm4_notify *argp, void *resp, struct svc_req *sr)
943{
944	nlm_do_free_all(argp, resp, sr);
945	return (TRUE);
946}
947