summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/klm/nlm_rpc_clnt.c
blob: d7f44205330d17e47b0976206a49db2e0fbc672b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*
 * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
 * Authors: Doug Rabson <dfr@rabson.org>
 * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
 */

/*
 * Client-side RPC wrappers (nlm_..._rpc)
 * Called from nlm_client.c
 *
 * Source code derived from FreeBSD nlm_advlock.c
 */

#include <sys/param.h>
#include <sys/fcntl.h>
#include <sys/lock.h>
#include <sys/flock.h>
#include <sys/mount.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/syslog.h>
#include <sys/systm.h>
#include <sys/unistd.h>
#include <sys/vnode.h>
#include <sys/queue.h>

#include <rpcsvc/nlm_prot.h>

#include <nfs/nfs.h>
#include <nfs/nfs_clnt.h>
#include <nfs/export.h>
#include <nfs/rnode.h>

#include "nlm_impl.h"

static void
nlm_convert_to_nlm_lock(struct nlm_lock *dst, struct nlm4_lock *src)
{
	dst->caller_name = src->caller_name;
	dst->fh = src->fh;
	dst->oh = src->oh;
	dst->svid = src->svid;
	dst->l_offset = src->l_offset;
	dst->l_len = src->l_len;
}

static void
nlm_convert_to_nlm4_holder(struct nlm4_holder *dst, struct nlm_holder *src)
{
	dst->exclusive = src->exclusive;
	dst->svid = src->svid;
	dst->oh = src->oh;
	dst->l_offset = src->l_offset;
	dst->l_len = src->l_len;
}

static void
nlm_convert_to_nlm4_res(struct nlm4_res *dst, struct nlm_res *src)
{
	dst->cookie = src->cookie;
	dst->stat.stat = (enum nlm4_stats) src->stat.stat;
}

enum clnt_stat
nlm_test_rpc(nlm4_testargs *args, nlm4_testres *res,
    CLIENT *client, rpcvers_t vers)
{
	if (vers == NLM4_VERS) {
		return (nlm4_test_4(args, res, client));
	} else {
		nlm_testargs args1;
		nlm_testres res1;
		enum clnt_stat stat;

		args1.cookie = args->cookie;
		args1.exclusive = args->exclusive;
		nlm_convert_to_nlm_lock(&args1.alock, &args->alock);
		(void) memset(&res1, 0, sizeof (res1));

		stat = nlm_test_1(&args1, &res1, client);

		if (stat == RPC_SUCCESS) {
			res->cookie = res1.cookie;
			res->stat.stat = (enum nlm4_stats) res1.stat.stat;
			if (res1.stat.stat == nlm_denied)
				nlm_convert_to_nlm4_holder(
				    &res->stat.nlm4_testrply_u.holder,
				    &res1.stat.nlm_testrply_u.holder);
		}

		return (stat);
	}
}

enum clnt_stat
nlm_lock_rpc(nlm4_lockargs *args, nlm4_res *res,
    CLIENT *client, rpcvers_t vers)
{
	if (vers == NLM4_VERS) {
		return (nlm4_lock_4(args, res, client));
	} else {
		nlm_lockargs args1;
		nlm_res res1;
		enum clnt_stat stat;

		args1.cookie = args->cookie;
		args1.block = args->block;
		args1.exclusive = args->exclusive;
		nlm_convert_to_nlm_lock(&args1.alock, &args->alock);
		args1.reclaim = args->reclaim;
		args1.state = args->state;
		(void) memset(&res1, 0, sizeof (res1));

		stat = nlm_lock_1(&args1, &res1, client);

		if (stat == RPC_SUCCESS) {
			nlm_convert_to_nlm4_res(res, &res1);
		}

		return (stat);
	}
}

enum clnt_stat
nlm_cancel_rpc(nlm4_cancargs *args, nlm4_res *res,
    CLIENT *client, rpcvers_t vers)
{
	if (vers == NLM4_VERS) {
		return (nlm4_cancel_4(args, res, client));
	} else {
		nlm_cancargs args1;
		nlm_res res1;
		enum clnt_stat stat;

		args1.cookie = args->cookie;
		args1.block = args->block;
		args1.exclusive = args->exclusive;
		nlm_convert_to_nlm_lock(&args1.alock, &args->alock);
		(void) memset(&res1, 0, sizeof (res1));

		stat = nlm_cancel_1(&args1, &res1, client);

		if (stat == RPC_SUCCESS) {
			nlm_convert_to_nlm4_res(res, &res1);
		}

		return (stat);
	}
}

enum clnt_stat
nlm_unlock_rpc(nlm4_unlockargs *args, nlm4_res *res,
    CLIENT *client, rpcvers_t vers)
{
	if (vers == NLM4_VERS) {
		return (nlm4_unlock_4(args, res, client));
	} else {
		nlm_unlockargs args1;
		nlm_res res1;
		enum clnt_stat stat;

		args1.cookie = args->cookie;
		nlm_convert_to_nlm_lock(&args1.alock, &args->alock);
		(void) memset(&res1, 0, sizeof (res1));

		stat = nlm_unlock_1(&args1, &res1, client);

		if (stat == RPC_SUCCESS) {
			nlm_convert_to_nlm4_res(res, &res1);
		}

		return (stat);
	}
}

enum clnt_stat
nlm_null_rpc(CLIENT *client, rpcvers_t vers)
{
	if (vers == NLM4_VERS)
		return (nlm4_null_4(NULL, NULL, client));

	return (nlm_null_1(NULL, NULL, client));
}

/*
 * Share reservations
 */

static void
nlm_convert_to_nlm_share(struct nlm_share *dst, struct nlm4_share *src)
{

	dst->caller_name = src->caller_name;
	dst->fh = src->fh;
	dst->oh = src->oh;
	dst->mode = src->mode;
	dst->access = src->access;
}

static void
nlm_convert_to_nlm4_shres(struct nlm4_shareres *dst,
	struct nlm_shareres *src)
{
	dst->cookie = src->cookie;
	dst->stat = (enum nlm4_stats) src->stat;
	dst->sequence = src->sequence;
}


enum clnt_stat
nlm_share_rpc(nlm4_shareargs *args, nlm4_shareres *res,
    CLIENT *client, rpcvers_t vers)
{
	if (vers == NLM4_VERS) {
		return (nlm4_share_4(args, res, client));
	} else {
		nlm_shareargs args3;
		nlm_shareres res3;
		enum clnt_stat stat;

		args3.cookie = args->cookie;
		nlm_convert_to_nlm_share(&args3.share, &args->share);
		args3.reclaim = args->reclaim;
		(void) memset(&res3, 0, sizeof (res3));

		stat = nlm_share_3(&args3, &res3, client);

		if (stat == RPC_SUCCESS) {
			nlm_convert_to_nlm4_shres(res, &res3);
		}

		return (stat);
	}
}

enum clnt_stat
nlm_unshare_rpc(nlm4_shareargs *args, nlm4_shareres *res,
    CLIENT *client, rpcvers_t vers)
{
	if (vers == NLM4_VERS) {
		return (nlm4_unshare_4(args, res, client));
	} else {
		nlm_shareargs args3;
		nlm_shareres res3;
		enum clnt_stat stat;

		args3.cookie = args->cookie;
		nlm_convert_to_nlm_share(&args3.share, &args->share);
		args3.reclaim = args->reclaim;
		(void) memset(&res3, 0, sizeof (res3));

		stat = nlm_unshare_3(&args3, &res3, client);

		if (stat == RPC_SUCCESS) {
			nlm_convert_to_nlm4_shres(res, &res3);
		}

		return (stat);
	}
}