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
29 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
33 * Client-side RPC wrappers (nlm_..._rpc)
34 * Called from nlm_client.c
36 * Source code derived from FreeBSD nlm_advlock.c
39 #include <sys/param.h>
40 #include <sys/fcntl.h>
42 #include <sys/flock.h>
43 #include <sys/mount.h>
44 #include <sys/mutex.h>
46 #include <sys/syslog.h>
47 #include <sys/systm.h>
48 #include <sys/unistd.h>
49 #include <sys/vnode.h>
50 #include <sys/queue.h>
52 #include <rpcsvc/nlm_prot.h>
55 #include <nfs/nfs_clnt.h>
56 #include <nfs/export.h>
57 #include <nfs/rnode.h>
62 nlm_convert_to_nlm_lock(struct nlm_lock
*dst
, struct nlm4_lock
*src
)
64 dst
->caller_name
= src
->caller_name
;
67 dst
->svid
= src
->svid
;
68 dst
->l_offset
= src
->l_offset
;
69 dst
->l_len
= src
->l_len
;
73 nlm_convert_to_nlm4_holder(struct nlm4_holder
*dst
, struct nlm_holder
*src
)
75 dst
->exclusive
= src
->exclusive
;
76 dst
->svid
= src
->svid
;
78 dst
->l_offset
= src
->l_offset
;
79 dst
->l_len
= src
->l_len
;
83 nlm_convert_to_nlm4_res(struct nlm4_res
*dst
, struct nlm_res
*src
)
85 dst
->cookie
= src
->cookie
;
86 dst
->stat
.stat
= (enum nlm4_stats
) src
->stat
.stat
;
90 nlm_test_rpc(nlm4_testargs
*args
, nlm4_testres
*res
,
91 CLIENT
*client
, rpcvers_t vers
)
93 if (vers
== NLM4_VERS
) {
94 return (nlm4_test_4(args
, res
, client
));
100 args1
.cookie
= args
->cookie
;
101 args1
.exclusive
= args
->exclusive
;
102 nlm_convert_to_nlm_lock(&args1
.alock
, &args
->alock
);
103 (void) memset(&res1
, 0, sizeof (res1
));
105 stat
= nlm_test_1(&args1
, &res1
, client
);
107 if (stat
== RPC_SUCCESS
) {
108 res
->cookie
= res1
.cookie
;
109 res
->stat
.stat
= (enum nlm4_stats
) res1
.stat
.stat
;
110 if (res1
.stat
.stat
== nlm_denied
)
111 nlm_convert_to_nlm4_holder(
112 &res
->stat
.nlm4_testrply_u
.holder
,
113 &res1
.stat
.nlm_testrply_u
.holder
);
121 nlm_lock_rpc(nlm4_lockargs
*args
, nlm4_res
*res
,
122 CLIENT
*client
, rpcvers_t vers
)
124 if (vers
== NLM4_VERS
) {
125 return (nlm4_lock_4(args
, res
, client
));
131 args1
.cookie
= args
->cookie
;
132 args1
.block
= args
->block
;
133 args1
.exclusive
= args
->exclusive
;
134 nlm_convert_to_nlm_lock(&args1
.alock
, &args
->alock
);
135 args1
.reclaim
= args
->reclaim
;
136 args1
.state
= args
->state
;
137 (void) memset(&res1
, 0, sizeof (res1
));
139 stat
= nlm_lock_1(&args1
, &res1
, client
);
141 if (stat
== RPC_SUCCESS
) {
142 nlm_convert_to_nlm4_res(res
, &res1
);
150 nlm_cancel_rpc(nlm4_cancargs
*args
, nlm4_res
*res
,
151 CLIENT
*client
, rpcvers_t vers
)
153 if (vers
== NLM4_VERS
) {
154 return (nlm4_cancel_4(args
, res
, client
));
160 args1
.cookie
= args
->cookie
;
161 args1
.block
= args
->block
;
162 args1
.exclusive
= args
->exclusive
;
163 nlm_convert_to_nlm_lock(&args1
.alock
, &args
->alock
);
164 (void) memset(&res1
, 0, sizeof (res1
));
166 stat
= nlm_cancel_1(&args1
, &res1
, client
);
168 if (stat
== RPC_SUCCESS
) {
169 nlm_convert_to_nlm4_res(res
, &res1
);
177 nlm_unlock_rpc(nlm4_unlockargs
*args
, nlm4_res
*res
,
178 CLIENT
*client
, rpcvers_t vers
)
180 if (vers
== NLM4_VERS
) {
181 return (nlm4_unlock_4(args
, res
, client
));
183 nlm_unlockargs args1
;
187 args1
.cookie
= args
->cookie
;
188 nlm_convert_to_nlm_lock(&args1
.alock
, &args
->alock
);
189 (void) memset(&res1
, 0, sizeof (res1
));
191 stat
= nlm_unlock_1(&args1
, &res1
, client
);
193 if (stat
== RPC_SUCCESS
) {
194 nlm_convert_to_nlm4_res(res
, &res1
);
202 nlm_null_rpc(CLIENT
*client
, rpcvers_t vers
)
204 if (vers
== NLM4_VERS
)
205 return (nlm4_null_4(NULL
, NULL
, client
));
207 return (nlm_null_1(NULL
, NULL
, client
));
215 nlm_convert_to_nlm_share(struct nlm_share
*dst
, struct nlm4_share
*src
)
218 dst
->caller_name
= src
->caller_name
;
221 dst
->mode
= src
->mode
;
222 dst
->access
= src
->access
;
226 nlm_convert_to_nlm4_shres(struct nlm4_shareres
*dst
,
227 struct nlm_shareres
*src
)
229 dst
->cookie
= src
->cookie
;
230 dst
->stat
= (enum nlm4_stats
) src
->stat
;
231 dst
->sequence
= src
->sequence
;
236 nlm_share_rpc(nlm4_shareargs
*args
, nlm4_shareres
*res
,
237 CLIENT
*client
, rpcvers_t vers
)
239 if (vers
== NLM4_VERS
) {
240 return (nlm4_share_4(args
, res
, client
));
246 args3
.cookie
= args
->cookie
;
247 nlm_convert_to_nlm_share(&args3
.share
, &args
->share
);
248 args3
.reclaim
= args
->reclaim
;
249 (void) memset(&res3
, 0, sizeof (res3
));
251 stat
= nlm_share_3(&args3
, &res3
, client
);
253 if (stat
== RPC_SUCCESS
) {
254 nlm_convert_to_nlm4_shres(res
, &res3
);
262 nlm_unshare_rpc(nlm4_shareargs
*args
, nlm4_shareres
*res
,
263 CLIENT
*client
, rpcvers_t vers
)
265 if (vers
== NLM4_VERS
) {
266 return (nlm4_unshare_4(args
, res
, client
));
272 args3
.cookie
= args
->cookie
;
273 nlm_convert_to_nlm_share(&args3
.share
, &args
->share
);
274 args3
.reclaim
= args
->reclaim
;
275 (void) memset(&res3
, 0, sizeof (res3
));
277 stat
= nlm_unshare_3(&args3
, &res3
, client
);
279 if (stat
== RPC_SUCCESS
) {
280 nlm_convert_to_nlm4_shres(res
, &res3
);