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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
* All rights reserved.
*/
/*
* Copyright 2017 Joyent, Inc.
* Copyright 2018 Nexenta Systems, Inc.
*/
#include <sys/types.h>
#include <rpc/types.h>
#include <sys/systm.h>
#include <sys/vfs.h>
#include <sys/errno.h>
#include <sys/cred.h>
#include <sys/policy.h>
#include <sys/siginfo.h>
#include <sys/proc.h> /* for exit() declaration */
#include <sys/kmem.h>
#include <nfs/nfs4.h>
#include <nfs/nfssys.h>
#include <sys/thread.h>
#include <rpc/auth.h>
#include <rpc/rpcsys.h>
#include <rpc/svc.h>
/*
* This is filled in with an appropriate address for the
* function that will traverse the rfs4_client_t table
* and mark any matching IP Address as "forced_expire".
*
* It is the server init() function that plops the
* function pointer.
*/
void (*rfs4_client_clrst)(struct nfs4clrst_args *) = NULL;
/* This filled in by nfssrv:_init() */
void (*nfs_srv_quiesce_func)(void) = NULL;
extern void nfscmd_args(uint_t);
/*
* These will be reset by klmmod:lm_svc(), when lockd starts NLM service,
* based on values read by lockd from /etc/default/nfs. Since nfssrv depends on
* klmmod, the declarations need to be here (in nfs, on which both depend) so
* that nfssrv can see the klmmod changes.
* When the dependency of NFSv4 on NLM/lockd is removed, this will need to
* be adjusted.
*/
#define RFS4_LEASETIME 90 /* seconds */
time_t rfs4_lease_time = RFS4_LEASETIME;
time_t rfs4_grace_period = RFS4_LEASETIME;
/* DSS: distributed stable storage */
size_t nfs4_dss_buflen = 0;
/* This filled in by nfssrv:_init() */
int (*nfs_srv_dss_func)(char *, size_t) = NULL;
int
nfs_export(void *arg)
{
STRUCT_DECL(exportfs_args, ea);
STRUCT_INIT(ea, get_udatamodel());
if (copyin(arg, STRUCT_BUF(ea), STRUCT_SIZE(ea)))
return (set_errno(EFAULT));
return (exportfs(STRUCT_BUF(ea), get_udatamodel(), CRED()));
}
int
nfssys(enum nfssys_op opcode, void *arg)
{
int error = 0;
if (!(opcode == NFS_REVAUTH || opcode == NFS4_SVC) &&
secpolicy_nfs(CRED()) != 0)
return (set_errno(EPERM));
switch (opcode) {
case NFS4_CLR_STATE: { /* Clear NFS4 client state */
struct nfs4clrst_args clr;
STRUCT_DECL(nfs4clrst_args, u_clr);
/*
* If the server is not loaded then no point in
* clearing nothing :-)
*/
if (rfs4_client_clrst == NULL) {
break;
}
STRUCT_INIT(u_clr, get_udatamodel());
if (copyin(arg, STRUCT_BUF(u_clr), STRUCT_SIZE(u_clr)))
return (set_errno(EFAULT));
clr.vers = STRUCT_FGET(u_clr, vers);
if (clr.vers != NFS4_CLRST_VERSION)
return (set_errno(EINVAL));
clr.addr_type = STRUCT_FGET(u_clr, addr_type);
clr.ap = STRUCT_FGETP(u_clr, ap);
rfs4_client_clrst(&clr);
break;
}
case SVCPOOL_CREATE: { /* setup an RPC server thread pool */
struct svcpool_args p;
if (copyin(arg, &p, sizeof (p)))
return (set_errno(EFAULT));
error = svc_pool_create(&p);
break;
}
case SVCPOOL_WAIT: { /* wait in kernel for threads to be needed */
int id;
if (copyin(arg, &id, sizeof (id)))
return (set_errno(EFAULT));
error = svc_wait(id);
break;
}
case SVCPOOL_RUN: { /* give work to a runnable thread */
int id;
if (copyin(arg, &id, sizeof (id)))
return (set_errno(EFAULT));
error = svc_do_run(id);
break;
}
case RDMA_SVC_INIT: {
struct rdma_svc_args rsa;
char netstore[20] = "tcp";
if (get_udatamodel() != DATAMODEL_NATIVE) {
STRUCT_DECL(rdma_svc_args, ursa);
STRUCT_INIT(ursa, get_udatamodel());
if (copyin(arg, STRUCT_BUF(ursa), STRUCT_SIZE(ursa)))
return (set_errno(EFAULT));
rsa.poolid = STRUCT_FGET(ursa, poolid);
rsa.nfs_versmin = STRUCT_FGET(ursa, nfs_versmin);
rsa.nfs_versmax = STRUCT_FGET(ursa, nfs_versmax);
rsa.delegation = STRUCT_FGET(ursa, delegation);
} else {
if (copyin(arg, &rsa, sizeof (rsa)))
return (set_errno(EFAULT));
}
rsa.netid = netstore;
error = rdma_start(&rsa);
break;
}
case NFS_SVC: { /* NFS server daemon */
STRUCT_DECL(nfs_svc_args, nsa);
STRUCT_INIT(nsa, get_udatamodel());
if (copyin(arg, STRUCT_BUF(nsa), STRUCT_SIZE(nsa)))
return (set_errno(EFAULT));
error = nfs_svc(STRUCT_BUF(nsa), get_udatamodel());
break;
}
case EXPORTFS: { /* export a file system */
error = nfs_export(arg);
break;
}
case NFS_GETFH: { /* get a file handle */
STRUCT_DECL(nfs_getfh_args, nga);
STRUCT_INIT(nga, get_udatamodel());
if (copyin(arg, STRUCT_BUF(nga), STRUCT_SIZE(nga)))
return (set_errno(EFAULT));
error = nfs_getfh(STRUCT_BUF(nga), get_udatamodel(), CRED());
break;
}
case NFS_REVAUTH: { /* revoke the cached credentials for the uid */
STRUCT_DECL(nfs_revauth_args, nra);
STRUCT_INIT(nra, get_udatamodel());
if (copyin(arg, STRUCT_BUF(nra), STRUCT_SIZE(nra)))
return (set_errno(EFAULT));
/* This call performs its own privilege checking */
error = sec_clnt_revoke(STRUCT_FGET(nra, authtype),
STRUCT_FGET(nra, uid), CRED(), NULL, get_udatamodel());
break;
}
case LM_SVC: { /* LM server daemon */
struct lm_svc_args lsa;
if (get_udatamodel() != DATAMODEL_NATIVE) {
STRUCT_DECL(lm_svc_args, ulsa);
STRUCT_INIT(ulsa, get_udatamodel());
if (copyin(arg, STRUCT_BUF(ulsa), STRUCT_SIZE(ulsa)))
return (set_errno(EFAULT));
lsa.version = STRUCT_FGET(ulsa, version);
lsa.fd = STRUCT_FGET(ulsa, fd);
lsa.n_fmly = STRUCT_FGET(ulsa, n_fmly);
lsa.n_proto = STRUCT_FGET(ulsa, n_proto);
lsa.n_rdev = expldev(STRUCT_FGET(ulsa, n_rdev));
lsa.n_v4_only = STRUCT_FGET(ulsa, n_v4_only);
lsa.timout = STRUCT_FGET(ulsa, timout);
lsa.grace = STRUCT_FGET(ulsa, grace);
lsa.retransmittimeout = STRUCT_FGET(ulsa,
retransmittimeout);
} else {
if (copyin(arg, &lsa, sizeof (lsa)))
return (set_errno(EFAULT));
}
error = lm_svc(&lsa);
break;
}
case KILL_LOCKMGR: {
error = lm_shutdown();
break;
}
case LOG_FLUSH: { /* Flush log buffer and possibly rename */
STRUCT_DECL(nfsl_flush_args, nfa);
STRUCT_INIT(nfa, get_udatamodel());
if (copyin(arg, STRUCT_BUF(nfa), STRUCT_SIZE(nfa)))
return (set_errno(EFAULT));
error = nfsl_flush(STRUCT_BUF(nfa), get_udatamodel());
break;
}
case NFS4_SVC: { /* NFS client callback daemon */
STRUCT_DECL(nfs4_svc_args, nsa);
STRUCT_INIT(nsa, get_udatamodel());
if (copyin(arg, STRUCT_BUF(nsa), STRUCT_SIZE(nsa)))
return (set_errno(EFAULT));
error = nfs4_svc(STRUCT_BUF(nsa), get_udatamodel());
break;
}
/* Request that NFSv4 server quiesce on next shutdown */
case NFS4_SVC_REQUEST_QUIESCE: {
int id;
/* check that nfssrv module is loaded */
if (nfs_srv_quiesce_func == NULL)
return (set_errno(ENOTSUP));
if (copyin(arg, &id, sizeof (id)))
return (set_errno(EFAULT));
error = svc_pool_control(id, SVCPSET_SHUTDOWN_PROC,
(void *)nfs_srv_quiesce_func);
break;
}
case NFS_IDMAP: {
struct nfsidmap_args idm;
if (copyin(arg, &idm, sizeof (idm)))
return (set_errno(EFAULT));
nfs_idmap_args(&idm);
error = 0;
break;
}
case NFS4_DSS_SETPATHS_SIZE: {
/* crosses ILP32/LP64 boundary */
uint32_t nfs4_dss_bufsize = 0;
if (copyin(arg, &nfs4_dss_bufsize, sizeof (nfs4_dss_bufsize)))
return (set_errno(EFAULT));
nfs4_dss_buflen = (long)nfs4_dss_bufsize;
error = 0;
break;
}
case NFS4_DSS_SETPATHS: {
char *nfs4_dss_bufp;
/* check that nfssrv module is loaded */
if (nfs_srv_dss_func == NULL)
return (set_errno(ENOTSUP));
/*
* NFS4_DSS_SETPATHS_SIZE must be called before
* NFS4_DSS_SETPATHS, to tell us how big a buffer we need
* to allocate.
*/
if (nfs4_dss_buflen == 0)
return (set_errno(EINVAL));
nfs4_dss_bufp = kmem_alloc(nfs4_dss_buflen, KM_SLEEP);
if (nfs4_dss_bufp == NULL)
return (set_errno(ENOMEM));
if (copyin(arg, nfs4_dss_bufp, nfs4_dss_buflen)) {
kmem_free(nfs4_dss_bufp, nfs4_dss_buflen);
return (set_errno(EFAULT));
}
/* unpack the buffer and extract the pathnames */
error = nfs_srv_dss_func(nfs4_dss_bufp, nfs4_dss_buflen);
kmem_free(nfs4_dss_bufp, nfs4_dss_buflen);
break;
}
case NFS4_EPHEMERAL_MOUNT_TO: {
uint_t mount_to;
/*
* Not a very complicated call.
*/
if (copyin(arg, &mount_to, sizeof (mount_to)))
return (set_errno(EFAULT));
nfs4_ephemeral_set_mount_to(mount_to);
error = 0;
break;
}
case MOUNTD_ARGS: {
uint_t did;
/*
* For now, only passing down the door fd; if we
* ever need to pass down more info, we can use
* a (properly aligned) struct.
*/
if (copyin(arg, &did, sizeof (did)))
return (set_errno(EFAULT));
mountd_args(did);
error = 0;
break;
}
case NFSCMD_ARGS: {
uint_t did;
/*
* For now, only passing down the door fd; if we
* ever need to pass down more info, we can use
* a (properly aligned) struct.
*/
if (copyin(arg, &did, sizeof (did)))
return (set_errno(EFAULT));
nfscmd_args(did);
error = 0;
break;
}
default:
error = EINVAL;
break;
}
return ((error != 0) ? set_errno(error) : 0);
}
|