Print this page
Fix NFS design problems re. multiple zone keys
Make NFS server zone-specific data all have the same lifetime
Fix rfs4_clean_state_exi
Fix exi_cache_reclaim
Fix mistakes in zone keys work
More fixes re. exi_zoneid and exi_tree
(danmcd -> Keep some ASSERT()s around for readability.)
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/nfs/nfs_server.c
+++ new/usr/src/uts/common/fs/nfs/nfs_server.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
24 24 * Copyright (c) 2013 by Delphix. All rights reserved.
25 25 * Copyright (c) 2017 Joyent Inc
26 26 * Copyright 2019 Nexenta by DDN, Inc.
27 27 */
28 28
29 29 /*
30 30 * Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
31 31 * All rights reserved.
32 32 * Use is subject to license terms.
33 33 */
34 34
35 35 /*
36 36 * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
37 37 * Copyright (c) 2013 by Delphix. All rights reserved.
38 38 * Copyright 2018 Nexenta Systems, Inc.
39 39 * Copyright (c) 2017 Joyent Inc
40 40 */
41 41
42 42 #include <sys/param.h>
43 43 #include <sys/types.h>
44 44 #include <sys/systm.h>
45 45 #include <sys/cred.h>
46 46 #include <sys/proc.h>
47 47 #include <sys/user.h>
48 48 #include <sys/buf.h>
49 49 #include <sys/vfs.h>
50 50 #include <sys/vnode.h>
51 51 #include <sys/pathname.h>
52 52 #include <sys/uio.h>
53 53 #include <sys/file.h>
54 54 #include <sys/stat.h>
55 55 #include <sys/errno.h>
56 56 #include <sys/socket.h>
57 57 #include <sys/sysmacros.h>
58 58 #include <sys/siginfo.h>
59 59 #include <sys/tiuser.h>
60 60 #include <sys/statvfs.h>
61 61 #include <sys/stream.h>
62 62 #include <sys/strsun.h>
63 63 #include <sys/strsubr.h>
64 64 #include <sys/stropts.h>
65 65 #include <sys/timod.h>
66 66 #include <sys/t_kuser.h>
67 67 #include <sys/kmem.h>
68 68 #include <sys/kstat.h>
69 69 #include <sys/dirent.h>
70 70 #include <sys/cmn_err.h>
71 71 #include <sys/debug.h>
72 72 #include <sys/unistd.h>
73 73 #include <sys/vtrace.h>
74 74 #include <sys/mode.h>
75 75 #include <sys/acl.h>
76 76 #include <sys/sdt.h>
77 77 #include <sys/debug.h>
78 78
79 79 #include <rpc/types.h>
80 80 #include <rpc/auth.h>
81 81 #include <rpc/auth_unix.h>
82 82 #include <rpc/auth_des.h>
83 83 #include <rpc/svc.h>
84 84 #include <rpc/xdr.h>
85 85 #include <rpc/rpc_rdma.h>
86 86
87 87 #include <nfs/nfs.h>
88 88 #include <nfs/export.h>
89 89 #include <nfs/nfssys.h>
90 90 #include <nfs/nfs_clnt.h>
91 91 #include <nfs/nfs_acl.h>
92 92 #include <nfs/nfs_log.h>
93 93 #include <nfs/lm.h>
94 94 #include <nfs/nfs_dispatch.h>
95 95 #include <nfs/nfs4_drc.h>
96 96
97 97 #include <sys/modctl.h>
98 98 #include <sys/cladm.h>
99 99 #include <sys/clconf.h>
100 100
101 101 #include <sys/tsol/label.h>
102 102
103 103 #define MAXHOST 32
104 104 const char *kinet_ntop6(uchar_t *, char *, size_t);
105 105
106 106 /*
107 107 * Module linkage information.
|
↓ open down ↓ |
107 lines elided |
↑ open up ↑ |
108 108 */
109 109
110 110 static struct modlmisc modlmisc = {
111 111 &mod_miscops, "NFS server module"
112 112 };
113 113
114 114 static struct modlinkage modlinkage = {
115 115 MODREV_1, (void *)&modlmisc, NULL
116 116 };
117 117
118 -zone_key_t nfssrv_zone_key;
118 +zone_key_t nfssrv_zone_key;
119 +list_t nfssrv_globals_list;
120 +krwlock_t nfssrv_globals_rwl;
121 +
119 122 kmem_cache_t *nfs_xuio_cache;
120 123 int nfs_loaned_buffers = 0;
121 124
122 125 int
123 126 _init(void)
124 127 {
125 128 int status;
126 129
127 130 nfs_srvinit();
128 131
129 132 status = mod_install((struct modlinkage *)&modlinkage);
130 133 if (status != 0) {
131 134 /*
132 135 * Could not load module, cleanup previous
133 136 * initialization work.
134 137 */
135 138 nfs_srvfini();
136 139
137 140 return (status);
138 141 }
139 142
140 143 /*
141 144 * Initialise some placeholders for nfssys() calls. These have
142 145 * to be declared by the nfs module, since that handles nfssys()
143 146 * calls - also used by NFS clients - but are provided by this
144 147 * nfssrv module. These also then serve as confirmation to the
145 148 * relevant code in nfs that nfssrv has been loaded, as they're
146 149 * initially NULL.
147 150 */
148 151 nfs_srv_quiesce_func = nfs_srv_quiesce_all;
149 152 nfs_srv_dss_func = rfs4_dss_setpaths;
150 153
151 154 /* setup DSS paths here; must be done before initial server startup */
152 155 rfs4_dss_paths = rfs4_dss_oldpaths = NULL;
153 156
154 157 /* initialize the copy reduction caches */
155 158
156 159 nfs_xuio_cache = kmem_cache_create("nfs_xuio_cache",
157 160 sizeof (nfs_xuio_t), 0, NULL, NULL, NULL, NULL, NULL, 0);
158 161
159 162 return (status);
160 163 }
161 164
162 165 int
163 166 _fini()
164 167 {
165 168 return (EBUSY);
166 169 }
167 170
168 171 int
169 172 _info(struct modinfo *modinfop)
170 173 {
171 174 return (mod_info(&modlinkage, modinfop));
172 175 }
173 176
174 177 /*
175 178 * PUBLICFH_CHECK() checks if the dispatch routine supports
176 179 * RPC_PUBLICFH_OK, if the filesystem is exported public, and if the
177 180 * incoming request is using the public filehandle. The check duplicates
178 181 * the exportmatch() call done in checkexport(), and we should consider
179 182 * modifying those routines to avoid the duplication. For now, we optimize
180 183 * by calling exportmatch() only after checking that the dispatch routine
181 184 * supports RPC_PUBLICFH_OK, and if the filesystem is explicitly exported
182 185 * public (i.e., not the placeholder).
183 186 */
184 187 #define PUBLICFH_CHECK(ne, disp, exi, fsid, xfid) \
185 188 ((disp->dis_flags & RPC_PUBLICFH_OK) && \
186 189 ((exi->exi_export.ex_flags & EX_PUBLIC) || \
187 190 (exi == ne->exi_public && exportmatch(ne->exi_root, \
188 191 fsid, xfid))))
189 192
190 193 static void nfs_srv_shutdown_all(int);
191 194 static void rfs4_server_start(nfs_globals_t *, int);
192 195 static void nullfree(void);
193 196 static void rfs_dispatch(struct svc_req *, SVCXPRT *);
|
↓ open down ↓ |
65 lines elided |
↑ open up ↑ |
194 197 static void acl_dispatch(struct svc_req *, SVCXPRT *);
195 198 static void common_dispatch(struct svc_req *, SVCXPRT *,
196 199 rpcvers_t, rpcvers_t, char *,
197 200 struct rpc_disptable *);
198 201 static int checkauth(struct exportinfo *, struct svc_req *, cred_t *, int,
199 202 bool_t, bool_t *);
200 203 static char *client_name(struct svc_req *req);
201 204 static char *client_addr(struct svc_req *req, char *buf);
202 205 extern int sec_svc_getcred(struct svc_req *, cred_t *cr, char **, int *);
203 206 extern bool_t sec_svc_inrootlist(int, caddr_t, int, caddr_t *);
204 -static void *nfs_srv_zone_init(zoneid_t);
205 -static void nfs_srv_zone_fini(zoneid_t, void *);
207 +static void *nfs_server_zone_init(zoneid_t);
208 +static void nfs_server_zone_fini(zoneid_t, void *);
209 +static void nfs_server_zone_shutdown(zoneid_t, void *);
206 210
207 211 #define NFSLOG_COPY_NETBUF(exi, xprt, nb) { \
208 212 (nb)->maxlen = (xprt)->xp_rtaddr.maxlen; \
209 213 (nb)->len = (xprt)->xp_rtaddr.len; \
210 214 (nb)->buf = kmem_alloc((nb)->len, KM_SLEEP); \
211 215 bcopy((xprt)->xp_rtaddr.buf, (nb)->buf, (nb)->len); \
212 216 }
213 217
214 218 /*
215 219 * Public Filehandle common nfs routines
216 220 */
217 221 static int MCLpath(char **);
218 222 static void URLparse(char *);
219 223
220 224 /*
221 225 * NFS callout table.
222 226 * This table is used by svc_getreq() to dispatch a request with
223 227 * a given prog/vers pair to an appropriate service provider
224 228 * dispatch routine.
225 229 *
226 230 * NOTE: ordering is relied upon below when resetting the version min/max
227 231 * for NFS_PROGRAM. Careful, if this is ever changed.
228 232 */
229 233 static SVC_CALLOUT __nfs_sc_clts[] = {
230 234 { NFS_PROGRAM, NFS_VERSMIN, NFS_VERSMAX, rfs_dispatch },
231 235 { NFS_ACL_PROGRAM, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX, acl_dispatch }
232 236 };
233 237
234 238 static SVC_CALLOUT_TABLE nfs_sct_clts = {
235 239 sizeof (__nfs_sc_clts) / sizeof (__nfs_sc_clts[0]), FALSE,
236 240 __nfs_sc_clts
237 241 };
238 242
239 243 static SVC_CALLOUT __nfs_sc_cots[] = {
240 244 { NFS_PROGRAM, NFS_VERSMIN, NFS_VERSMAX, rfs_dispatch },
241 245 { NFS_ACL_PROGRAM, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX, acl_dispatch }
242 246 };
243 247
244 248 static SVC_CALLOUT_TABLE nfs_sct_cots = {
245 249 sizeof (__nfs_sc_cots) / sizeof (__nfs_sc_cots[0]), FALSE, __nfs_sc_cots
246 250 };
247 251
248 252 static SVC_CALLOUT __nfs_sc_rdma[] = {
249 253 { NFS_PROGRAM, NFS_VERSMIN, NFS_VERSMAX, rfs_dispatch },
250 254 { NFS_ACL_PROGRAM, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX, acl_dispatch }
251 255 };
252 256
253 257 static SVC_CALLOUT_TABLE nfs_sct_rdma = {
254 258 sizeof (__nfs_sc_rdma) / sizeof (__nfs_sc_rdma[0]), FALSE, __nfs_sc_rdma
255 259 };
|
↓ open down ↓ |
40 lines elided |
↑ open up ↑ |
256 260
257 261 /*
258 262 * DSS: distributed stable storage
259 263 * lists of all DSS paths: current, and before last warmstart
260 264 */
261 265 nvlist_t *rfs4_dss_paths, *rfs4_dss_oldpaths;
262 266
263 267 int rfs4_dispatch(struct rpcdisp *, struct svc_req *, SVCXPRT *, char *);
264 268 bool_t rfs4_minorvers_mismatch(struct svc_req *, SVCXPRT *, void *);
265 269
270 +nfs_globals_t *
271 +nfs_srv_getzg(void)
272 +{
273 + nfs_globals_t *ng;
274 +
275 + ng = zone_getspecific(nfssrv_zone_key, curzone);
276 + return (ng);
277 +}
278 +
266 279 /*
267 280 * Will be called at the point the server pool is being unregistered
268 281 * from the pool list. From that point onwards, the pool is waiting
269 282 * to be drained and as such the server state is stale and pertains
270 283 * to the old instantiation of the NFS server pool.
271 284 */
272 285 void
273 286 nfs_srv_offline(void)
274 287 {
275 288 nfs_globals_t *ng;
276 289
277 - ng = zone_getspecific(nfssrv_zone_key, curzone);
290 + ng = nfs_srv_getzg();
278 291
279 292 mutex_enter(&ng->nfs_server_upordown_lock);
280 293 if (ng->nfs_server_upordown == NFS_SERVER_RUNNING) {
281 294 ng->nfs_server_upordown = NFS_SERVER_OFFLINE;
282 295 }
283 296 mutex_exit(&ng->nfs_server_upordown_lock);
284 297 }
285 298
286 299 /*
287 300 * Will be called at the point the server pool is being destroyed so
288 301 * all transports have been closed and no service threads are in
289 302 * existence.
290 303 *
291 304 * If we quiesce the server, we're shutting it down without destroying the
292 305 * server state. This allows it to warm start subsequently.
293 306 */
294 307 void
295 308 nfs_srv_stop_all(void)
296 309 {
297 310 int quiesce = 0;
298 311 nfs_srv_shutdown_all(quiesce);
299 312 }
300 313
301 314 /*
302 315 * This alternative shutdown routine can be requested via nfssys()
303 316 */
|
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
304 317 void
305 318 nfs_srv_quiesce_all(void)
306 319 {
307 320 int quiesce = 1;
308 321 nfs_srv_shutdown_all(quiesce);
309 322 }
310 323
311 324 static void
312 325 nfs_srv_shutdown_all(int quiesce)
313 326 {
314 - nfs_globals_t *ng = zone_getspecific(nfssrv_zone_key, curzone);
327 + nfs_globals_t *ng = nfs_srv_getzg();
315 328
316 329 mutex_enter(&ng->nfs_server_upordown_lock);
317 330 if (quiesce) {
318 331 if (ng->nfs_server_upordown == NFS_SERVER_RUNNING ||
319 332 ng->nfs_server_upordown == NFS_SERVER_OFFLINE) {
320 333 ng->nfs_server_upordown = NFS_SERVER_QUIESCED;
321 334 cv_signal(&ng->nfs_server_upordown_cv);
322 335
323 336 /* reset DSS state */
324 337 rfs4_dss_numnewpaths = 0;
325 338 rfs4_dss_newpaths = NULL;
326 339
327 340 cmn_err(CE_NOTE, "nfs_server: server is now quiesced; "
328 341 "NFSv4 state has been preserved");
329 342 }
330 343 } else {
331 344 if (ng->nfs_server_upordown == NFS_SERVER_OFFLINE) {
332 345 ng->nfs_server_upordown = NFS_SERVER_STOPPING;
333 346 mutex_exit(&ng->nfs_server_upordown_lock);
334 347 rfs4_state_zone_fini();
335 348 rfs4_fini_drc();
336 349 mutex_enter(&ng->nfs_server_upordown_lock);
337 350 ng->nfs_server_upordown = NFS_SERVER_STOPPED;
338 351
339 352 /* reset DSS state */
340 353 rfs4_dss_numnewpaths = 0;
341 354 rfs4_dss_newpaths = NULL;
342 355
343 356 cv_signal(&ng->nfs_server_upordown_cv);
344 357 }
345 358 }
346 359 mutex_exit(&ng->nfs_server_upordown_lock);
347 360 }
348 361
349 362 static int
350 363 nfs_srv_set_sc_versions(struct file *fp, SVC_CALLOUT_TABLE **sctpp,
351 364 rpcvers_t versmin, rpcvers_t versmax)
352 365 {
353 366 struct strioctl strioc;
354 367 struct T_info_ack tinfo;
355 368 int error, retval;
356 369
357 370 /*
358 371 * Find out what type of transport this is.
359 372 */
360 373 strioc.ic_cmd = TI_GETINFO;
361 374 strioc.ic_timout = -1;
362 375 strioc.ic_len = sizeof (tinfo);
363 376 strioc.ic_dp = (char *)&tinfo;
364 377 tinfo.PRIM_type = T_INFO_REQ;
365 378
366 379 error = strioctl(fp->f_vnode, I_STR, (intptr_t)&strioc, 0, K_TO_K,
367 380 CRED(), &retval);
368 381 if (error || retval)
369 382 return (error);
370 383
371 384 /*
372 385 * Based on our query of the transport type...
373 386 *
374 387 * Reset the min/max versions based on the caller's request
375 388 * NOTE: This assumes that NFS_PROGRAM is first in the array!!
376 389 * And the second entry is the NFS_ACL_PROGRAM.
377 390 */
378 391 switch (tinfo.SERV_type) {
379 392 case T_CLTS:
380 393 if (versmax == NFS_V4)
381 394 return (EINVAL);
382 395 __nfs_sc_clts[0].sc_versmin = versmin;
383 396 __nfs_sc_clts[0].sc_versmax = versmax;
384 397 __nfs_sc_clts[1].sc_versmin = versmin;
385 398 __nfs_sc_clts[1].sc_versmax = versmax;
386 399 *sctpp = &nfs_sct_clts;
387 400 break;
388 401 case T_COTS:
389 402 case T_COTS_ORD:
390 403 __nfs_sc_cots[0].sc_versmin = versmin;
391 404 __nfs_sc_cots[0].sc_versmax = versmax;
392 405 /* For the NFS_ACL program, check the max version */
393 406 if (versmax > NFS_ACL_VERSMAX)
394 407 versmax = NFS_ACL_VERSMAX;
395 408 __nfs_sc_cots[1].sc_versmin = versmin;
396 409 __nfs_sc_cots[1].sc_versmax = versmax;
397 410 *sctpp = &nfs_sct_cots;
398 411 break;
399 412 default:
400 413 error = EINVAL;
401 414 }
402 415
403 416 return (error);
404 417 }
405 418
406 419 /*
407 420 * NFS Server system call.
408 421 * Does all of the work of running a NFS server.
409 422 * uap->fd is the fd of an open transport provider
410 423 */
411 424 int
412 425 nfs_svc(struct nfs_svc_args *arg, model_t model)
413 426 {
414 427 nfs_globals_t *ng;
415 428 file_t *fp;
416 429 SVCMASTERXPRT *xprt;
417 430 int error;
418 431 int readsize;
|
↓ open down ↓ |
94 lines elided |
↑ open up ↑ |
419 432 char buf[KNC_STRSIZE];
420 433 size_t len;
421 434 STRUCT_HANDLE(nfs_svc_args, uap);
422 435 struct netbuf addrmask;
423 436 SVC_CALLOUT_TABLE *sctp = NULL;
424 437
425 438 #ifdef lint
426 439 model = model; /* STRUCT macros don't always refer to it */
427 440 #endif
428 441
429 - ng = zone_getspecific(nfssrv_zone_key, curzone);
442 + ng = nfs_srv_getzg();
430 443 STRUCT_SET_HANDLE(uap, model, arg);
431 444
432 445 /* Check privileges in nfssys() */
433 446
434 447 if ((fp = getf(STRUCT_FGET(uap, fd))) == NULL)
435 448 return (EBADF);
436 449
450 + /* Setup global file handle in nfs_export */
451 + if ((error = nfs_export_get_rootfh(ng)) != 0)
452 + return (error);
453 +
437 454 /*
438 455 * Set read buffer size to rsize
439 456 * and add room for RPC headers.
440 457 */
441 458 readsize = nfs3tsize() + (RPC_MAXDATASIZE - NFS_MAXDATA);
442 459 if (readsize < RPC_MAXDATASIZE)
443 460 readsize = RPC_MAXDATASIZE;
444 461
445 462 error = copyinstr((const char *)STRUCT_FGETP(uap, netid), buf,
446 463 KNC_STRSIZE, &len);
447 464 if (error) {
448 465 releasef(STRUCT_FGET(uap, fd));
449 466 return (error);
450 467 }
451 468
452 469 addrmask.len = STRUCT_FGET(uap, addrmask.len);
453 470 addrmask.maxlen = STRUCT_FGET(uap, addrmask.maxlen);
454 471 addrmask.buf = kmem_alloc(addrmask.maxlen, KM_SLEEP);
455 472 error = copyin(STRUCT_FGETP(uap, addrmask.buf), addrmask.buf,
456 473 addrmask.len);
457 474 if (error) {
458 475 releasef(STRUCT_FGET(uap, fd));
459 476 kmem_free(addrmask.buf, addrmask.maxlen);
460 477 return (error);
461 478 }
462 479
463 480 ng->nfs_versmin = STRUCT_FGET(uap, versmin);
464 481 ng->nfs_versmax = STRUCT_FGET(uap, versmax);
465 482
466 483 /* Double check the vers min/max ranges */
467 484 if ((ng->nfs_versmin > ng->nfs_versmax) ||
468 485 (ng->nfs_versmin < NFS_VERSMIN) ||
469 486 (ng->nfs_versmax > NFS_VERSMAX)) {
470 487 ng->nfs_versmin = NFS_VERSMIN_DEFAULT;
471 488 ng->nfs_versmax = NFS_VERSMAX_DEFAULT;
472 489 }
473 490
474 491 if (error = nfs_srv_set_sc_versions(fp, &sctp, ng->nfs_versmin,
475 492 ng->nfs_versmax)) {
476 493 releasef(STRUCT_FGET(uap, fd));
477 494 kmem_free(addrmask.buf, addrmask.maxlen);
478 495 return (error);
479 496 }
480 497
481 498 /* Initialize nfsv4 server */
482 499 if (ng->nfs_versmax == (rpcvers_t)NFS_V4)
483 500 rfs4_server_start(ng, STRUCT_FGET(uap, delegation));
484 501
485 502 /* Create a transport handle. */
486 503 error = svc_tli_kcreate(fp, readsize, buf, &addrmask, &xprt,
487 504 sctp, NULL, NFS_SVCPOOL_ID, TRUE);
488 505
489 506 if (error)
490 507 kmem_free(addrmask.buf, addrmask.maxlen);
491 508
492 509 releasef(STRUCT_FGET(uap, fd));
493 510
494 511 /* HA-NFSv4: save the cluster nodeid */
495 512 if (cluster_bootflags & CLUSTER_BOOTED)
496 513 lm_global_nlmid = clconf_get_nodeid();
497 514
498 515 return (error);
499 516 }
500 517
501 518 static void
502 519 rfs4_server_start(nfs_globals_t *ng, int nfs4_srv_delegation)
503 520 {
504 521 /*
505 522 * Determine if the server has previously been "started" and
506 523 * if not, do the per instance initialization
507 524 */
508 525 mutex_enter(&ng->nfs_server_upordown_lock);
509 526
510 527 if (ng->nfs_server_upordown != NFS_SERVER_RUNNING) {
511 528 /* Do we need to stop and wait on the previous server? */
512 529 while (ng->nfs_server_upordown == NFS_SERVER_STOPPING ||
513 530 ng->nfs_server_upordown == NFS_SERVER_OFFLINE)
514 531 cv_wait(&ng->nfs_server_upordown_cv,
515 532 &ng->nfs_server_upordown_lock);
516 533
517 534 if (ng->nfs_server_upordown != NFS_SERVER_RUNNING) {
518 535 (void) svc_pool_control(NFS_SVCPOOL_ID,
519 536 SVCPSET_UNREGISTER_PROC, (void *)&nfs_srv_offline);
520 537 (void) svc_pool_control(NFS_SVCPOOL_ID,
521 538 SVCPSET_SHUTDOWN_PROC, (void *)&nfs_srv_stop_all);
522 539
523 540 rfs4_do_server_start(ng->nfs_server_upordown,
524 541 nfs4_srv_delegation,
525 542 cluster_bootflags & CLUSTER_BOOTED);
526 543
527 544 ng->nfs_server_upordown = NFS_SERVER_RUNNING;
528 545 }
529 546 cv_signal(&ng->nfs_server_upordown_cv);
530 547 }
531 548 mutex_exit(&ng->nfs_server_upordown_lock);
532 549 }
533 550
534 551 /*
535 552 * If RDMA device available,
536 553 * start RDMA listener.
537 554 */
538 555 int
539 556 rdma_start(struct rdma_svc_args *rsa)
540 557 {
541 558 nfs_globals_t *ng;
542 559 int error;
543 560 rdma_xprt_group_t started_rdma_xprts;
544 561 rdma_stat stat;
|
↓ open down ↓ |
98 lines elided |
↑ open up ↑ |
545 562 int svc_state = 0;
546 563
547 564 /* Double check the vers min/max ranges */
548 565 if ((rsa->nfs_versmin > rsa->nfs_versmax) ||
549 566 (rsa->nfs_versmin < NFS_VERSMIN) ||
550 567 (rsa->nfs_versmax > NFS_VERSMAX)) {
551 568 rsa->nfs_versmin = NFS_VERSMIN_DEFAULT;
552 569 rsa->nfs_versmax = NFS_VERSMAX_DEFAULT;
553 570 }
554 571
555 - ng = zone_getspecific(nfssrv_zone_key, curzone);
572 + ng = nfs_srv_getzg();
556 573 ng->nfs_versmin = rsa->nfs_versmin;
557 574 ng->nfs_versmax = rsa->nfs_versmax;
558 575
559 576 /* Set the versions in the callout table */
560 577 __nfs_sc_rdma[0].sc_versmin = rsa->nfs_versmin;
561 578 __nfs_sc_rdma[0].sc_versmax = rsa->nfs_versmax;
562 579 /* For the NFS_ACL program, check the max version */
563 580 __nfs_sc_rdma[1].sc_versmin = rsa->nfs_versmin;
564 581 if (rsa->nfs_versmax > NFS_ACL_VERSMAX)
565 582 __nfs_sc_rdma[1].sc_versmax = NFS_ACL_VERSMAX;
566 583 else
567 584 __nfs_sc_rdma[1].sc_versmax = rsa->nfs_versmax;
568 585
569 586 /* Initialize nfsv4 server */
570 587 if (rsa->nfs_versmax == (rpcvers_t)NFS_V4)
571 588 rfs4_server_start(ng, rsa->delegation);
572 589
573 590 started_rdma_xprts.rtg_count = 0;
574 591 started_rdma_xprts.rtg_listhead = NULL;
575 592 started_rdma_xprts.rtg_poolid = rsa->poolid;
576 593
577 594 restart:
578 595 error = svc_rdma_kcreate(rsa->netid, &nfs_sct_rdma, rsa->poolid,
579 596 &started_rdma_xprts);
580 597
581 598 svc_state = !error;
582 599
583 600 while (!error) {
584 601
585 602 /*
586 603 * wait till either interrupted by a signal on
587 604 * nfs service stop/restart or signalled by a
588 605 * rdma attach/detatch.
589 606 */
590 607
591 608 stat = rdma_kwait();
592 609
593 610 /*
594 611 * stop services if running -- either on a HCA detach event
595 612 * or if the nfs service is stopped/restarted.
596 613 */
597 614
598 615 if ((stat == RDMA_HCA_DETACH || stat == RDMA_INTR) &&
599 616 svc_state) {
600 617 rdma_stop(&started_rdma_xprts);
601 618 svc_state = 0;
602 619 }
603 620
604 621 /*
605 622 * nfs service stop/restart, break out of the
606 623 * wait loop and return;
607 624 */
608 625 if (stat == RDMA_INTR)
609 626 return (0);
610 627
611 628 /*
612 629 * restart stopped services on a HCA attach event
613 630 * (if not already running)
614 631 */
615 632
616 633 if ((stat == RDMA_HCA_ATTACH) && (svc_state == 0))
617 634 goto restart;
618 635
619 636 /*
620 637 * loop until a nfs service stop/restart
621 638 */
622 639 }
623 640
624 641 return (error);
625 642 }
626 643
627 644 /* ARGSUSED */
628 645 void
629 646 rpc_null(caddr_t *argp, caddr_t *resp, struct exportinfo *exi,
630 647 struct svc_req *req, cred_t *cr, bool_t ro)
631 648 {
632 649 }
633 650
634 651 /* ARGSUSED */
635 652 void
636 653 rpc_null_v3(caddr_t *argp, caddr_t *resp, struct exportinfo *exi,
637 654 struct svc_req *req, cred_t *cr, bool_t ro)
638 655 {
639 656 DTRACE_NFSV3_4(op__null__start, struct svc_req *, req,
640 657 cred_t *, cr, vnode_t *, NULL, struct exportinfo *, exi);
641 658 DTRACE_NFSV3_4(op__null__done, struct svc_req *, req,
642 659 cred_t *, cr, vnode_t *, NULL, struct exportinfo *, exi);
643 660 }
644 661
645 662 /* ARGSUSED */
646 663 static void
647 664 rfs_error(caddr_t *argp, caddr_t *resp, struct exportinfo *exi,
648 665 struct svc_req *req, cred_t *cr, bool_t ro)
649 666 {
650 667 /* return (EOPNOTSUPP); */
651 668 }
652 669
653 670 static void
654 671 nullfree(void)
655 672 {
656 673 }
657 674
658 675 static char *rfscallnames_v2[] = {
659 676 "RFS2_NULL",
660 677 "RFS2_GETATTR",
661 678 "RFS2_SETATTR",
662 679 "RFS2_ROOT",
663 680 "RFS2_LOOKUP",
664 681 "RFS2_READLINK",
665 682 "RFS2_READ",
666 683 "RFS2_WRITECACHE",
667 684 "RFS2_WRITE",
668 685 "RFS2_CREATE",
669 686 "RFS2_REMOVE",
670 687 "RFS2_RENAME",
671 688 "RFS2_LINK",
672 689 "RFS2_SYMLINK",
673 690 "RFS2_MKDIR",
674 691 "RFS2_RMDIR",
675 692 "RFS2_READDIR",
676 693 "RFS2_STATFS"
677 694 };
678 695
679 696 static struct rpcdisp rfsdisptab_v2[] = {
680 697 /*
681 698 * NFS VERSION 2
682 699 */
683 700
684 701 /* RFS_NULL = 0 */
685 702 {rpc_null,
686 703 xdr_void, NULL_xdrproc_t, 0,
687 704 xdr_void, NULL_xdrproc_t, 0,
688 705 nullfree, RPC_IDEMPOTENT,
689 706 0},
690 707
691 708 /* RFS_GETATTR = 1 */
692 709 {rfs_getattr,
693 710 xdr_fhandle, xdr_fastfhandle, sizeof (fhandle_t),
694 711 xdr_attrstat, xdr_fastattrstat, sizeof (struct nfsattrstat),
695 712 nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_MAPRESP,
696 713 rfs_getattr_getfh},
697 714
698 715 /* RFS_SETATTR = 2 */
699 716 {rfs_setattr,
700 717 xdr_saargs, NULL_xdrproc_t, sizeof (struct nfssaargs),
701 718 xdr_attrstat, xdr_fastattrstat, sizeof (struct nfsattrstat),
702 719 nullfree, RPC_MAPRESP,
703 720 rfs_setattr_getfh},
704 721
705 722 /* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
706 723 {rfs_error,
707 724 xdr_void, NULL_xdrproc_t, 0,
708 725 xdr_void, NULL_xdrproc_t, 0,
709 726 nullfree, RPC_IDEMPOTENT,
710 727 0},
711 728
712 729 /* RFS_LOOKUP = 4 */
713 730 {rfs_lookup,
714 731 xdr_diropargs, NULL_xdrproc_t, sizeof (struct nfsdiropargs),
715 732 xdr_diropres, xdr_fastdiropres, sizeof (struct nfsdiropres),
716 733 nullfree, RPC_IDEMPOTENT|RPC_MAPRESP|RPC_PUBLICFH_OK,
717 734 rfs_lookup_getfh},
718 735
719 736 /* RFS_READLINK = 5 */
720 737 {rfs_readlink,
721 738 xdr_fhandle, xdr_fastfhandle, sizeof (fhandle_t),
722 739 xdr_rdlnres, NULL_xdrproc_t, sizeof (struct nfsrdlnres),
723 740 rfs_rlfree, RPC_IDEMPOTENT,
724 741 rfs_readlink_getfh},
725 742
726 743 /* RFS_READ = 6 */
727 744 {rfs_read,
728 745 xdr_readargs, NULL_xdrproc_t, sizeof (struct nfsreadargs),
729 746 xdr_rdresult, NULL_xdrproc_t, sizeof (struct nfsrdresult),
730 747 rfs_rdfree, RPC_IDEMPOTENT,
731 748 rfs_read_getfh},
732 749
733 750 /* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
734 751 {rfs_error,
735 752 xdr_void, NULL_xdrproc_t, 0,
736 753 xdr_void, NULL_xdrproc_t, 0,
737 754 nullfree, RPC_IDEMPOTENT,
738 755 0},
739 756
740 757 /* RFS_WRITE = 8 */
741 758 {rfs_write,
742 759 xdr_writeargs, NULL_xdrproc_t, sizeof (struct nfswriteargs),
743 760 xdr_attrstat, xdr_fastattrstat, sizeof (struct nfsattrstat),
744 761 nullfree, RPC_MAPRESP,
745 762 rfs_write_getfh},
746 763
747 764 /* RFS_CREATE = 9 */
748 765 {rfs_create,
749 766 xdr_creatargs, NULL_xdrproc_t, sizeof (struct nfscreatargs),
750 767 xdr_diropres, xdr_fastdiropres, sizeof (struct nfsdiropres),
751 768 nullfree, RPC_MAPRESP,
752 769 rfs_create_getfh},
753 770
754 771 /* RFS_REMOVE = 10 */
755 772 {rfs_remove,
756 773 xdr_diropargs, NULL_xdrproc_t, sizeof (struct nfsdiropargs),
757 774 #ifdef _LITTLE_ENDIAN
758 775 xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
759 776 #else
760 777 xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
761 778 #endif
762 779 nullfree, RPC_MAPRESP,
763 780 rfs_remove_getfh},
764 781
765 782 /* RFS_RENAME = 11 */
766 783 {rfs_rename,
767 784 xdr_rnmargs, NULL_xdrproc_t, sizeof (struct nfsrnmargs),
768 785 #ifdef _LITTLE_ENDIAN
769 786 xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
770 787 #else
771 788 xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
772 789 #endif
773 790 nullfree, RPC_MAPRESP,
774 791 rfs_rename_getfh},
775 792
776 793 /* RFS_LINK = 12 */
777 794 {rfs_link,
778 795 xdr_linkargs, NULL_xdrproc_t, sizeof (struct nfslinkargs),
779 796 #ifdef _LITTLE_ENDIAN
780 797 xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
781 798 #else
782 799 xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
783 800 #endif
784 801 nullfree, RPC_MAPRESP,
785 802 rfs_link_getfh},
786 803
787 804 /* RFS_SYMLINK = 13 */
788 805 {rfs_symlink,
789 806 xdr_slargs, NULL_xdrproc_t, sizeof (struct nfsslargs),
790 807 #ifdef _LITTLE_ENDIAN
791 808 xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
792 809 #else
793 810 xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
794 811 #endif
795 812 nullfree, RPC_MAPRESP,
796 813 rfs_symlink_getfh},
797 814
798 815 /* RFS_MKDIR = 14 */
799 816 {rfs_mkdir,
800 817 xdr_creatargs, NULL_xdrproc_t, sizeof (struct nfscreatargs),
801 818 xdr_diropres, xdr_fastdiropres, sizeof (struct nfsdiropres),
802 819 nullfree, RPC_MAPRESP,
803 820 rfs_mkdir_getfh},
804 821
805 822 /* RFS_RMDIR = 15 */
806 823 {rfs_rmdir,
807 824 xdr_diropargs, NULL_xdrproc_t, sizeof (struct nfsdiropargs),
808 825 #ifdef _LITTLE_ENDIAN
809 826 xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
810 827 #else
811 828 xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
812 829 #endif
813 830 nullfree, RPC_MAPRESP,
814 831 rfs_rmdir_getfh},
815 832
816 833 /* RFS_READDIR = 16 */
817 834 {rfs_readdir,
818 835 xdr_rddirargs, NULL_xdrproc_t, sizeof (struct nfsrddirargs),
819 836 xdr_putrddirres, NULL_xdrproc_t, sizeof (struct nfsrddirres),
820 837 rfs_rddirfree, RPC_IDEMPOTENT,
821 838 rfs_readdir_getfh},
822 839
823 840 /* RFS_STATFS = 17 */
824 841 {rfs_statfs,
825 842 xdr_fhandle, xdr_fastfhandle, sizeof (fhandle_t),
826 843 xdr_statfs, xdr_faststatfs, sizeof (struct nfsstatfs),
827 844 nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_MAPRESP,
828 845 rfs_statfs_getfh},
829 846 };
830 847
831 848 static char *rfscallnames_v3[] = {
832 849 "RFS3_NULL",
833 850 "RFS3_GETATTR",
834 851 "RFS3_SETATTR",
835 852 "RFS3_LOOKUP",
836 853 "RFS3_ACCESS",
837 854 "RFS3_READLINK",
838 855 "RFS3_READ",
839 856 "RFS3_WRITE",
840 857 "RFS3_CREATE",
841 858 "RFS3_MKDIR",
842 859 "RFS3_SYMLINK",
843 860 "RFS3_MKNOD",
844 861 "RFS3_REMOVE",
845 862 "RFS3_RMDIR",
846 863 "RFS3_RENAME",
847 864 "RFS3_LINK",
848 865 "RFS3_READDIR",
849 866 "RFS3_READDIRPLUS",
850 867 "RFS3_FSSTAT",
851 868 "RFS3_FSINFO",
852 869 "RFS3_PATHCONF",
853 870 "RFS3_COMMIT"
854 871 };
855 872
856 873 static struct rpcdisp rfsdisptab_v3[] = {
857 874 /*
858 875 * NFS VERSION 3
859 876 */
860 877
861 878 /* RFS_NULL = 0 */
862 879 {rpc_null_v3,
863 880 xdr_void, NULL_xdrproc_t, 0,
864 881 xdr_void, NULL_xdrproc_t, 0,
865 882 nullfree, RPC_IDEMPOTENT,
866 883 0},
867 884
868 885 /* RFS3_GETATTR = 1 */
869 886 {rfs3_getattr,
870 887 xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (GETATTR3args),
871 888 xdr_GETATTR3res, NULL_xdrproc_t, sizeof (GETATTR3res),
872 889 nullfree, (RPC_IDEMPOTENT | RPC_ALLOWANON),
873 890 rfs3_getattr_getfh},
874 891
875 892 /* RFS3_SETATTR = 2 */
876 893 {rfs3_setattr,
877 894 xdr_SETATTR3args, NULL_xdrproc_t, sizeof (SETATTR3args),
878 895 xdr_SETATTR3res, NULL_xdrproc_t, sizeof (SETATTR3res),
879 896 nullfree, 0,
880 897 rfs3_setattr_getfh},
881 898
882 899 /* RFS3_LOOKUP = 3 */
883 900 {rfs3_lookup,
884 901 xdr_diropargs3, NULL_xdrproc_t, sizeof (LOOKUP3args),
885 902 xdr_LOOKUP3res, NULL_xdrproc_t, sizeof (LOOKUP3res),
886 903 nullfree, (RPC_IDEMPOTENT | RPC_PUBLICFH_OK),
887 904 rfs3_lookup_getfh},
888 905
889 906 /* RFS3_ACCESS = 4 */
890 907 {rfs3_access,
891 908 xdr_ACCESS3args, NULL_xdrproc_t, sizeof (ACCESS3args),
892 909 xdr_ACCESS3res, NULL_xdrproc_t, sizeof (ACCESS3res),
893 910 nullfree, RPC_IDEMPOTENT,
894 911 rfs3_access_getfh},
895 912
896 913 /* RFS3_READLINK = 5 */
897 914 {rfs3_readlink,
898 915 xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (READLINK3args),
899 916 xdr_READLINK3res, NULL_xdrproc_t, sizeof (READLINK3res),
900 917 rfs3_readlink_free, RPC_IDEMPOTENT,
901 918 rfs3_readlink_getfh},
902 919
903 920 /* RFS3_READ = 6 */
904 921 {rfs3_read,
905 922 xdr_READ3args, NULL_xdrproc_t, sizeof (READ3args),
906 923 xdr_READ3res, NULL_xdrproc_t, sizeof (READ3res),
907 924 rfs3_read_free, RPC_IDEMPOTENT,
908 925 rfs3_read_getfh},
909 926
910 927 /* RFS3_WRITE = 7 */
911 928 {rfs3_write,
912 929 xdr_WRITE3args, NULL_xdrproc_t, sizeof (WRITE3args),
913 930 xdr_WRITE3res, NULL_xdrproc_t, sizeof (WRITE3res),
914 931 nullfree, 0,
915 932 rfs3_write_getfh},
916 933
917 934 /* RFS3_CREATE = 8 */
918 935 {rfs3_create,
919 936 xdr_CREATE3args, NULL_xdrproc_t, sizeof (CREATE3args),
920 937 xdr_CREATE3res, NULL_xdrproc_t, sizeof (CREATE3res),
921 938 nullfree, 0,
922 939 rfs3_create_getfh},
923 940
924 941 /* RFS3_MKDIR = 9 */
925 942 {rfs3_mkdir,
926 943 xdr_MKDIR3args, NULL_xdrproc_t, sizeof (MKDIR3args),
927 944 xdr_MKDIR3res, NULL_xdrproc_t, sizeof (MKDIR3res),
928 945 nullfree, 0,
929 946 rfs3_mkdir_getfh},
930 947
931 948 /* RFS3_SYMLINK = 10 */
932 949 {rfs3_symlink,
933 950 xdr_SYMLINK3args, NULL_xdrproc_t, sizeof (SYMLINK3args),
934 951 xdr_SYMLINK3res, NULL_xdrproc_t, sizeof (SYMLINK3res),
935 952 nullfree, 0,
936 953 rfs3_symlink_getfh},
937 954
938 955 /* RFS3_MKNOD = 11 */
939 956 {rfs3_mknod,
940 957 xdr_MKNOD3args, NULL_xdrproc_t, sizeof (MKNOD3args),
941 958 xdr_MKNOD3res, NULL_xdrproc_t, sizeof (MKNOD3res),
942 959 nullfree, 0,
943 960 rfs3_mknod_getfh},
944 961
945 962 /* RFS3_REMOVE = 12 */
946 963 {rfs3_remove,
947 964 xdr_diropargs3, NULL_xdrproc_t, sizeof (REMOVE3args),
948 965 xdr_REMOVE3res, NULL_xdrproc_t, sizeof (REMOVE3res),
949 966 nullfree, 0,
950 967 rfs3_remove_getfh},
951 968
952 969 /* RFS3_RMDIR = 13 */
953 970 {rfs3_rmdir,
954 971 xdr_diropargs3, NULL_xdrproc_t, sizeof (RMDIR3args),
955 972 xdr_RMDIR3res, NULL_xdrproc_t, sizeof (RMDIR3res),
956 973 nullfree, 0,
957 974 rfs3_rmdir_getfh},
958 975
959 976 /* RFS3_RENAME = 14 */
960 977 {rfs3_rename,
961 978 xdr_RENAME3args, NULL_xdrproc_t, sizeof (RENAME3args),
962 979 xdr_RENAME3res, NULL_xdrproc_t, sizeof (RENAME3res),
963 980 nullfree, 0,
964 981 rfs3_rename_getfh},
965 982
966 983 /* RFS3_LINK = 15 */
967 984 {rfs3_link,
968 985 xdr_LINK3args, NULL_xdrproc_t, sizeof (LINK3args),
969 986 xdr_LINK3res, NULL_xdrproc_t, sizeof (LINK3res),
970 987 nullfree, 0,
971 988 rfs3_link_getfh},
972 989
973 990 /* RFS3_READDIR = 16 */
974 991 {rfs3_readdir,
975 992 xdr_READDIR3args, NULL_xdrproc_t, sizeof (READDIR3args),
976 993 xdr_READDIR3res, NULL_xdrproc_t, sizeof (READDIR3res),
977 994 rfs3_readdir_free, RPC_IDEMPOTENT,
978 995 rfs3_readdir_getfh},
979 996
980 997 /* RFS3_READDIRPLUS = 17 */
981 998 {rfs3_readdirplus,
982 999 xdr_READDIRPLUS3args, NULL_xdrproc_t, sizeof (READDIRPLUS3args),
983 1000 xdr_READDIRPLUS3res, NULL_xdrproc_t, sizeof (READDIRPLUS3res),
984 1001 rfs3_readdirplus_free, RPC_AVOIDWORK,
985 1002 rfs3_readdirplus_getfh},
986 1003
987 1004 /* RFS3_FSSTAT = 18 */
988 1005 {rfs3_fsstat,
989 1006 xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (FSSTAT3args),
990 1007 xdr_FSSTAT3res, NULL_xdrproc_t, sizeof (FSSTAT3res),
991 1008 nullfree, RPC_IDEMPOTENT,
992 1009 rfs3_fsstat_getfh},
993 1010
994 1011 /* RFS3_FSINFO = 19 */
995 1012 {rfs3_fsinfo,
996 1013 xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (FSINFO3args),
997 1014 xdr_FSINFO3res, NULL_xdrproc_t, sizeof (FSINFO3res),
998 1015 nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON,
999 1016 rfs3_fsinfo_getfh},
1000 1017
1001 1018 /* RFS3_PATHCONF = 20 */
1002 1019 {rfs3_pathconf,
1003 1020 xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (PATHCONF3args),
1004 1021 xdr_PATHCONF3res, NULL_xdrproc_t, sizeof (PATHCONF3res),
1005 1022 nullfree, RPC_IDEMPOTENT,
1006 1023 rfs3_pathconf_getfh},
1007 1024
1008 1025 /* RFS3_COMMIT = 21 */
1009 1026 {rfs3_commit,
1010 1027 xdr_COMMIT3args, NULL_xdrproc_t, sizeof (COMMIT3args),
1011 1028 xdr_COMMIT3res, NULL_xdrproc_t, sizeof (COMMIT3res),
1012 1029 nullfree, RPC_IDEMPOTENT,
1013 1030 rfs3_commit_getfh},
1014 1031 };
1015 1032
1016 1033 static char *rfscallnames_v4[] = {
1017 1034 "RFS4_NULL",
1018 1035 "RFS4_COMPOUND",
1019 1036 "RFS4_NULL",
1020 1037 "RFS4_NULL",
1021 1038 "RFS4_NULL",
1022 1039 "RFS4_NULL",
1023 1040 "RFS4_NULL",
1024 1041 "RFS4_NULL",
1025 1042 "RFS4_CREATE"
1026 1043 };
1027 1044
1028 1045 static struct rpcdisp rfsdisptab_v4[] = {
1029 1046 /*
1030 1047 * NFS VERSION 4
1031 1048 */
1032 1049
1033 1050 /* RFS_NULL = 0 */
1034 1051 {rpc_null,
1035 1052 xdr_void, NULL_xdrproc_t, 0,
1036 1053 xdr_void, NULL_xdrproc_t, 0,
1037 1054 nullfree, RPC_IDEMPOTENT, 0},
1038 1055
1039 1056 /* RFS4_compound = 1 */
1040 1057 {rfs4_compound,
1041 1058 xdr_COMPOUND4args_srv, NULL_xdrproc_t, sizeof (COMPOUND4args),
1042 1059 xdr_COMPOUND4res_srv, NULL_xdrproc_t, sizeof (COMPOUND4res),
1043 1060 rfs4_compound_free, 0, 0},
1044 1061 };
1045 1062
1046 1063 union rfs_args {
1047 1064 /*
1048 1065 * NFS VERSION 2
1049 1066 */
1050 1067
1051 1068 /* RFS_NULL = 0 */
1052 1069
1053 1070 /* RFS_GETATTR = 1 */
1054 1071 fhandle_t nfs2_getattr_args;
1055 1072
1056 1073 /* RFS_SETATTR = 2 */
1057 1074 struct nfssaargs nfs2_setattr_args;
1058 1075
1059 1076 /* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
1060 1077
1061 1078 /* RFS_LOOKUP = 4 */
1062 1079 struct nfsdiropargs nfs2_lookup_args;
1063 1080
1064 1081 /* RFS_READLINK = 5 */
1065 1082 fhandle_t nfs2_readlink_args;
1066 1083
1067 1084 /* RFS_READ = 6 */
1068 1085 struct nfsreadargs nfs2_read_args;
1069 1086
1070 1087 /* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
1071 1088
1072 1089 /* RFS_WRITE = 8 */
1073 1090 struct nfswriteargs nfs2_write_args;
1074 1091
1075 1092 /* RFS_CREATE = 9 */
1076 1093 struct nfscreatargs nfs2_create_args;
1077 1094
1078 1095 /* RFS_REMOVE = 10 */
1079 1096 struct nfsdiropargs nfs2_remove_args;
1080 1097
1081 1098 /* RFS_RENAME = 11 */
1082 1099 struct nfsrnmargs nfs2_rename_args;
1083 1100
1084 1101 /* RFS_LINK = 12 */
1085 1102 struct nfslinkargs nfs2_link_args;
1086 1103
1087 1104 /* RFS_SYMLINK = 13 */
1088 1105 struct nfsslargs nfs2_symlink_args;
1089 1106
1090 1107 /* RFS_MKDIR = 14 */
1091 1108 struct nfscreatargs nfs2_mkdir_args;
1092 1109
1093 1110 /* RFS_RMDIR = 15 */
1094 1111 struct nfsdiropargs nfs2_rmdir_args;
1095 1112
1096 1113 /* RFS_READDIR = 16 */
1097 1114 struct nfsrddirargs nfs2_readdir_args;
1098 1115
1099 1116 /* RFS_STATFS = 17 */
1100 1117 fhandle_t nfs2_statfs_args;
1101 1118
1102 1119 /*
1103 1120 * NFS VERSION 3
1104 1121 */
1105 1122
1106 1123 /* RFS_NULL = 0 */
1107 1124
1108 1125 /* RFS3_GETATTR = 1 */
1109 1126 GETATTR3args nfs3_getattr_args;
1110 1127
1111 1128 /* RFS3_SETATTR = 2 */
1112 1129 SETATTR3args nfs3_setattr_args;
1113 1130
1114 1131 /* RFS3_LOOKUP = 3 */
1115 1132 LOOKUP3args nfs3_lookup_args;
1116 1133
1117 1134 /* RFS3_ACCESS = 4 */
1118 1135 ACCESS3args nfs3_access_args;
1119 1136
1120 1137 /* RFS3_READLINK = 5 */
1121 1138 READLINK3args nfs3_readlink_args;
1122 1139
1123 1140 /* RFS3_READ = 6 */
1124 1141 READ3args nfs3_read_args;
1125 1142
1126 1143 /* RFS3_WRITE = 7 */
1127 1144 WRITE3args nfs3_write_args;
1128 1145
1129 1146 /* RFS3_CREATE = 8 */
1130 1147 CREATE3args nfs3_create_args;
1131 1148
1132 1149 /* RFS3_MKDIR = 9 */
1133 1150 MKDIR3args nfs3_mkdir_args;
1134 1151
1135 1152 /* RFS3_SYMLINK = 10 */
1136 1153 SYMLINK3args nfs3_symlink_args;
1137 1154
1138 1155 /* RFS3_MKNOD = 11 */
1139 1156 MKNOD3args nfs3_mknod_args;
1140 1157
1141 1158 /* RFS3_REMOVE = 12 */
1142 1159 REMOVE3args nfs3_remove_args;
1143 1160
1144 1161 /* RFS3_RMDIR = 13 */
1145 1162 RMDIR3args nfs3_rmdir_args;
1146 1163
1147 1164 /* RFS3_RENAME = 14 */
1148 1165 RENAME3args nfs3_rename_args;
1149 1166
1150 1167 /* RFS3_LINK = 15 */
1151 1168 LINK3args nfs3_link_args;
1152 1169
1153 1170 /* RFS3_READDIR = 16 */
1154 1171 READDIR3args nfs3_readdir_args;
1155 1172
1156 1173 /* RFS3_READDIRPLUS = 17 */
1157 1174 READDIRPLUS3args nfs3_readdirplus_args;
1158 1175
1159 1176 /* RFS3_FSSTAT = 18 */
1160 1177 FSSTAT3args nfs3_fsstat_args;
1161 1178
1162 1179 /* RFS3_FSINFO = 19 */
1163 1180 FSINFO3args nfs3_fsinfo_args;
1164 1181
1165 1182 /* RFS3_PATHCONF = 20 */
1166 1183 PATHCONF3args nfs3_pathconf_args;
1167 1184
1168 1185 /* RFS3_COMMIT = 21 */
1169 1186 COMMIT3args nfs3_commit_args;
1170 1187
1171 1188 /*
1172 1189 * NFS VERSION 4
1173 1190 */
1174 1191
1175 1192 /* RFS_NULL = 0 */
1176 1193
1177 1194 /* COMPUND = 1 */
1178 1195 COMPOUND4args nfs4_compound_args;
1179 1196 };
1180 1197
1181 1198 union rfs_res {
1182 1199 /*
1183 1200 * NFS VERSION 2
1184 1201 */
1185 1202
1186 1203 /* RFS_NULL = 0 */
1187 1204
1188 1205 /* RFS_GETATTR = 1 */
1189 1206 struct nfsattrstat nfs2_getattr_res;
1190 1207
1191 1208 /* RFS_SETATTR = 2 */
1192 1209 struct nfsattrstat nfs2_setattr_res;
1193 1210
1194 1211 /* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
1195 1212
1196 1213 /* RFS_LOOKUP = 4 */
1197 1214 struct nfsdiropres nfs2_lookup_res;
1198 1215
1199 1216 /* RFS_READLINK = 5 */
1200 1217 struct nfsrdlnres nfs2_readlink_res;
1201 1218
1202 1219 /* RFS_READ = 6 */
1203 1220 struct nfsrdresult nfs2_read_res;
1204 1221
1205 1222 /* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
1206 1223
1207 1224 /* RFS_WRITE = 8 */
1208 1225 struct nfsattrstat nfs2_write_res;
1209 1226
1210 1227 /* RFS_CREATE = 9 */
1211 1228 struct nfsdiropres nfs2_create_res;
1212 1229
1213 1230 /* RFS_REMOVE = 10 */
1214 1231 enum nfsstat nfs2_remove_res;
1215 1232
1216 1233 /* RFS_RENAME = 11 */
1217 1234 enum nfsstat nfs2_rename_res;
1218 1235
1219 1236 /* RFS_LINK = 12 */
1220 1237 enum nfsstat nfs2_link_res;
1221 1238
1222 1239 /* RFS_SYMLINK = 13 */
1223 1240 enum nfsstat nfs2_symlink_res;
1224 1241
1225 1242 /* RFS_MKDIR = 14 */
1226 1243 struct nfsdiropres nfs2_mkdir_res;
1227 1244
1228 1245 /* RFS_RMDIR = 15 */
1229 1246 enum nfsstat nfs2_rmdir_res;
1230 1247
1231 1248 /* RFS_READDIR = 16 */
1232 1249 struct nfsrddirres nfs2_readdir_res;
1233 1250
1234 1251 /* RFS_STATFS = 17 */
1235 1252 struct nfsstatfs nfs2_statfs_res;
1236 1253
1237 1254 /*
1238 1255 * NFS VERSION 3
1239 1256 */
1240 1257
1241 1258 /* RFS_NULL = 0 */
1242 1259
1243 1260 /* RFS3_GETATTR = 1 */
1244 1261 GETATTR3res nfs3_getattr_res;
1245 1262
1246 1263 /* RFS3_SETATTR = 2 */
1247 1264 SETATTR3res nfs3_setattr_res;
1248 1265
1249 1266 /* RFS3_LOOKUP = 3 */
1250 1267 LOOKUP3res nfs3_lookup_res;
1251 1268
1252 1269 /* RFS3_ACCESS = 4 */
1253 1270 ACCESS3res nfs3_access_res;
1254 1271
1255 1272 /* RFS3_READLINK = 5 */
1256 1273 READLINK3res nfs3_readlink_res;
1257 1274
1258 1275 /* RFS3_READ = 6 */
1259 1276 READ3res nfs3_read_res;
1260 1277
1261 1278 /* RFS3_WRITE = 7 */
1262 1279 WRITE3res nfs3_write_res;
1263 1280
1264 1281 /* RFS3_CREATE = 8 */
1265 1282 CREATE3res nfs3_create_res;
1266 1283
1267 1284 /* RFS3_MKDIR = 9 */
1268 1285 MKDIR3res nfs3_mkdir_res;
1269 1286
1270 1287 /* RFS3_SYMLINK = 10 */
1271 1288 SYMLINK3res nfs3_symlink_res;
1272 1289
1273 1290 /* RFS3_MKNOD = 11 */
1274 1291 MKNOD3res nfs3_mknod_res;
1275 1292
1276 1293 /* RFS3_REMOVE = 12 */
1277 1294 REMOVE3res nfs3_remove_res;
1278 1295
1279 1296 /* RFS3_RMDIR = 13 */
1280 1297 RMDIR3res nfs3_rmdir_res;
1281 1298
1282 1299 /* RFS3_RENAME = 14 */
1283 1300 RENAME3res nfs3_rename_res;
1284 1301
1285 1302 /* RFS3_LINK = 15 */
1286 1303 LINK3res nfs3_link_res;
1287 1304
1288 1305 /* RFS3_READDIR = 16 */
1289 1306 READDIR3res nfs3_readdir_res;
1290 1307
1291 1308 /* RFS3_READDIRPLUS = 17 */
1292 1309 READDIRPLUS3res nfs3_readdirplus_res;
1293 1310
1294 1311 /* RFS3_FSSTAT = 18 */
1295 1312 FSSTAT3res nfs3_fsstat_res;
1296 1313
1297 1314 /* RFS3_FSINFO = 19 */
1298 1315 FSINFO3res nfs3_fsinfo_res;
1299 1316
1300 1317 /* RFS3_PATHCONF = 20 */
1301 1318 PATHCONF3res nfs3_pathconf_res;
1302 1319
1303 1320 /* RFS3_COMMIT = 21 */
1304 1321 COMMIT3res nfs3_commit_res;
1305 1322
1306 1323 /*
1307 1324 * NFS VERSION 4
1308 1325 */
1309 1326
1310 1327 /* RFS_NULL = 0 */
1311 1328
1312 1329 /* RFS4_COMPOUND = 1 */
1313 1330 COMPOUND4res nfs4_compound_res;
1314 1331
1315 1332 };
1316 1333
1317 1334 static struct rpc_disptable rfs_disptable[] = {
1318 1335 {sizeof (rfsdisptab_v2) / sizeof (rfsdisptab_v2[0]),
1319 1336 rfscallnames_v2,
1320 1337 &rfsproccnt_v2_ptr, rfsdisptab_v2},
1321 1338 {sizeof (rfsdisptab_v3) / sizeof (rfsdisptab_v3[0]),
1322 1339 rfscallnames_v3,
1323 1340 &rfsproccnt_v3_ptr, rfsdisptab_v3},
1324 1341 {sizeof (rfsdisptab_v4) / sizeof (rfsdisptab_v4[0]),
1325 1342 rfscallnames_v4,
1326 1343 &rfsproccnt_v4_ptr, rfsdisptab_v4},
1327 1344 };
1328 1345
1329 1346 /*
1330 1347 * If nfs_portmon is set, then clients are required to use privileged
1331 1348 * ports (ports < IPPORT_RESERVED) in order to get NFS services.
1332 1349 *
1333 1350 * N.B.: this attempt to carry forward the already ill-conceived notion
1334 1351 * of privileged ports for TCP/UDP is really quite ineffectual. Not only
1335 1352 * is it transport-dependent, it's laughably easy to spoof. If you're
1336 1353 * really interested in security, you must start with secure RPC instead.
1337 1354 */
1338 1355 static int nfs_portmon = 0;
1339 1356
1340 1357 #ifdef DEBUG
1341 1358 static int cred_hits = 0;
1342 1359 static int cred_misses = 0;
1343 1360 #endif
1344 1361
1345 1362 #ifdef DEBUG
1346 1363 /*
1347 1364 * Debug code to allow disabling of rfs_dispatch() use of
1348 1365 * fastxdrargs() and fastxdrres() calls for testing purposes.
1349 1366 */
1350 1367 static int rfs_no_fast_xdrargs = 0;
1351 1368 static int rfs_no_fast_xdrres = 0;
1352 1369 #endif
1353 1370
1354 1371 union acl_args {
1355 1372 /*
1356 1373 * ACL VERSION 2
1357 1374 */
1358 1375
1359 1376 /* ACL2_NULL = 0 */
1360 1377
1361 1378 /* ACL2_GETACL = 1 */
1362 1379 GETACL2args acl2_getacl_args;
1363 1380
1364 1381 /* ACL2_SETACL = 2 */
1365 1382 SETACL2args acl2_setacl_args;
1366 1383
1367 1384 /* ACL2_GETATTR = 3 */
1368 1385 GETATTR2args acl2_getattr_args;
1369 1386
1370 1387 /* ACL2_ACCESS = 4 */
1371 1388 ACCESS2args acl2_access_args;
1372 1389
1373 1390 /* ACL2_GETXATTRDIR = 5 */
1374 1391 GETXATTRDIR2args acl2_getxattrdir_args;
1375 1392
1376 1393 /*
1377 1394 * ACL VERSION 3
1378 1395 */
1379 1396
1380 1397 /* ACL3_NULL = 0 */
1381 1398
1382 1399 /* ACL3_GETACL = 1 */
1383 1400 GETACL3args acl3_getacl_args;
1384 1401
1385 1402 /* ACL3_SETACL = 2 */
1386 1403 SETACL3args acl3_setacl;
1387 1404
1388 1405 /* ACL3_GETXATTRDIR = 3 */
1389 1406 GETXATTRDIR3args acl3_getxattrdir_args;
1390 1407
1391 1408 };
1392 1409
1393 1410 union acl_res {
1394 1411 /*
1395 1412 * ACL VERSION 2
1396 1413 */
1397 1414
1398 1415 /* ACL2_NULL = 0 */
1399 1416
1400 1417 /* ACL2_GETACL = 1 */
1401 1418 GETACL2res acl2_getacl_res;
1402 1419
1403 1420 /* ACL2_SETACL = 2 */
1404 1421 SETACL2res acl2_setacl_res;
1405 1422
1406 1423 /* ACL2_GETATTR = 3 */
1407 1424 GETATTR2res acl2_getattr_res;
1408 1425
1409 1426 /* ACL2_ACCESS = 4 */
1410 1427 ACCESS2res acl2_access_res;
1411 1428
1412 1429 /* ACL2_GETXATTRDIR = 5 */
1413 1430 GETXATTRDIR2args acl2_getxattrdir_res;
1414 1431
1415 1432 /*
1416 1433 * ACL VERSION 3
1417 1434 */
1418 1435
1419 1436 /* ACL3_NULL = 0 */
1420 1437
1421 1438 /* ACL3_GETACL = 1 */
1422 1439 GETACL3res acl3_getacl_res;
1423 1440
1424 1441 /* ACL3_SETACL = 2 */
1425 1442 SETACL3res acl3_setacl_res;
1426 1443
1427 1444 /* ACL3_GETXATTRDIR = 3 */
1428 1445 GETXATTRDIR3res acl3_getxattrdir_res;
1429 1446
1430 1447 };
1431 1448
1432 1449 static bool_t
1433 1450 auth_tooweak(struct svc_req *req, char *res)
1434 1451 {
1435 1452
1436 1453 if (req->rq_vers == NFS_VERSION && req->rq_proc == RFS_LOOKUP) {
1437 1454 struct nfsdiropres *dr = (struct nfsdiropres *)res;
1438 1455 if ((enum wnfsstat)dr->dr_status == WNFSERR_CLNT_FLAVOR)
1439 1456 return (TRUE);
1440 1457 } else if (req->rq_vers == NFS_V3 && req->rq_proc == NFSPROC3_LOOKUP) {
1441 1458 LOOKUP3res *resp = (LOOKUP3res *)res;
1442 1459 if ((enum wnfsstat)resp->status == WNFSERR_CLNT_FLAVOR)
1443 1460 return (TRUE);
1444 1461 }
1445 1462 return (FALSE);
1446 1463 }
1447 1464
1448 1465
1449 1466 static void
1450 1467 common_dispatch(struct svc_req *req, SVCXPRT *xprt, rpcvers_t min_vers,
1451 1468 rpcvers_t max_vers, char *pgmname, struct rpc_disptable *disptable)
1452 1469 {
1453 1470 int which;
1454 1471 rpcvers_t vers;
1455 1472 char *args;
1456 1473 union {
1457 1474 union rfs_args ra;
1458 1475 union acl_args aa;
1459 1476 } args_buf;
1460 1477 char *res;
1461 1478 union {
1462 1479 union rfs_res rr;
1463 1480 union acl_res ar;
1464 1481 } res_buf;
1465 1482 struct rpcdisp *disp = NULL;
1466 1483 int dis_flags = 0;
1467 1484 cred_t *cr;
1468 1485 int error = 0;
1469 1486 int anon_ok;
1470 1487 struct exportinfo *exi = NULL;
1471 1488 unsigned int nfslog_rec_id;
1472 1489 int dupstat;
1473 1490 struct dupreq *dr;
1474 1491 int authres;
1475 1492 bool_t publicfh_ok = FALSE;
1476 1493 enum_t auth_flavor;
1477 1494 bool_t dupcached = FALSE;
1478 1495 struct netbuf nb;
1479 1496 bool_t logging_enabled = FALSE;
1480 1497 struct exportinfo *nfslog_exi = NULL;
1481 1498 char **procnames;
1482 1499 char cbuf[INET6_ADDRSTRLEN]; /* to hold both IPv4 and IPv6 addr */
1483 1500 bool_t ro = FALSE;
1484 1501 nfs_export_t *ne = nfs_get_export();
1485 1502
1486 1503 vers = req->rq_vers;
1487 1504
1488 1505 if (vers < min_vers || vers > max_vers) {
1489 1506 svcerr_progvers(req->rq_xprt, min_vers, max_vers);
1490 1507 error++;
1491 1508 cmn_err(CE_NOTE, "%s: bad version number %u", pgmname, vers);
1492 1509 goto done;
1493 1510 }
1494 1511 vers -= min_vers;
1495 1512
1496 1513 which = req->rq_proc;
1497 1514 if (which < 0 || which >= disptable[(int)vers].dis_nprocs) {
1498 1515 svcerr_noproc(req->rq_xprt);
1499 1516 error++;
1500 1517 goto done;
1501 1518 }
1502 1519
1503 1520 (*(disptable[(int)vers].dis_proccntp))[which].value.ui64++;
1504 1521
1505 1522 disp = &disptable[(int)vers].dis_table[which];
1506 1523 procnames = disptable[(int)vers].dis_procnames;
1507 1524
1508 1525 auth_flavor = req->rq_cred.oa_flavor;
1509 1526
1510 1527 /*
1511 1528 * Deserialize into the args struct.
1512 1529 */
1513 1530 args = (char *)&args_buf;
1514 1531
1515 1532 #ifdef DEBUG
1516 1533 if (rfs_no_fast_xdrargs || (auth_flavor == RPCSEC_GSS) ||
1517 1534 disp->dis_fastxdrargs == NULL_xdrproc_t ||
1518 1535 !SVC_GETARGS(xprt, disp->dis_fastxdrargs, (char *)&args))
1519 1536 #else
1520 1537 if ((auth_flavor == RPCSEC_GSS) ||
1521 1538 disp->dis_fastxdrargs == NULL_xdrproc_t ||
1522 1539 !SVC_GETARGS(xprt, disp->dis_fastxdrargs, (char *)&args))
1523 1540 #endif
1524 1541 {
1525 1542 bzero(args, disp->dis_argsz);
1526 1543 if (!SVC_GETARGS(xprt, disp->dis_xdrargs, args)) {
1527 1544 error++;
1528 1545 /*
1529 1546 * Check if we are outside our capabilities.
1530 1547 */
1531 1548 if (rfs4_minorvers_mismatch(req, xprt, (void *)args))
1532 1549 goto done;
1533 1550
1534 1551 svcerr_decode(xprt);
1535 1552 cmn_err(CE_NOTE,
1536 1553 "Failed to decode arguments for %s version %u "
1537 1554 "procedure %s client %s%s",
1538 1555 pgmname, vers + min_vers, procnames[which],
1539 1556 client_name(req), client_addr(req, cbuf));
1540 1557 goto done;
1541 1558 }
1542 1559 }
1543 1560
1544 1561 /*
1545 1562 * If Version 4 use that specific dispatch function.
1546 1563 */
1547 1564 if (req->rq_vers == 4) {
1548 1565 error += rfs4_dispatch(disp, req, xprt, args);
1549 1566 goto done;
1550 1567 }
1551 1568
1552 1569 dis_flags = disp->dis_flags;
1553 1570
1554 1571 /*
1555 1572 * Find export information and check authentication,
1556 1573 * setting the credential if everything is ok.
1557 1574 */
1558 1575 if (disp->dis_getfh != NULL) {
1559 1576 void *fh;
1560 1577 fsid_t *fsid;
1561 1578 fid_t *fid, *xfid;
1562 1579 fhandle_t *fh2;
1563 1580 nfs_fh3 *fh3;
1564 1581
1565 1582 fh = (*disp->dis_getfh)(args);
1566 1583 switch (req->rq_vers) {
1567 1584 case NFS_VERSION:
1568 1585 fh2 = (fhandle_t *)fh;
1569 1586 fsid = &fh2->fh_fsid;
1570 1587 fid = (fid_t *)&fh2->fh_len;
1571 1588 xfid = (fid_t *)&fh2->fh_xlen;
1572 1589 break;
1573 1590 case NFS_V3:
1574 1591 fh3 = (nfs_fh3 *)fh;
1575 1592 fsid = &fh3->fh3_fsid;
1576 1593 fid = FH3TOFIDP(fh3);
1577 1594 xfid = FH3TOXFIDP(fh3);
1578 1595 break;
1579 1596 }
1580 1597
1581 1598 /*
1582 1599 * Fix for bug 1038302 - corbin
1583 1600 * There is a problem here if anonymous access is
1584 1601 * disallowed. If the current request is part of the
1585 1602 * client's mount process for the requested filesystem,
1586 1603 * then it will carry root (uid 0) credentials on it, and
1587 1604 * will be denied by checkauth if that client does not
1588 1605 * have explicit root=0 permission. This will cause the
1589 1606 * client's mount operation to fail. As a work-around,
1590 1607 * we check here to see if the request is a getattr or
1591 1608 * statfs operation on the exported vnode itself, and
1592 1609 * pass a flag to checkauth with the result of this test.
1593 1610 *
1594 1611 * The filehandle refers to the mountpoint itself if
1595 1612 * the fh_data and fh_xdata portions of the filehandle
1596 1613 * are equal.
1597 1614 *
1598 1615 * Added anon_ok argument to checkauth().
1599 1616 */
1600 1617
1601 1618 if ((dis_flags & RPC_ALLOWANON) && EQFID(fid, xfid))
1602 1619 anon_ok = 1;
1603 1620 else
1604 1621 anon_ok = 0;
1605 1622
1606 1623 cr = xprt->xp_cred;
1607 1624 ASSERT(cr != NULL);
1608 1625 #ifdef DEBUG
1609 1626 {
1610 1627 if (crgetref(cr) != 1) {
1611 1628 crfree(cr);
1612 1629 cr = crget();
1613 1630 xprt->xp_cred = cr;
1614 1631 cred_misses++;
1615 1632 } else
1616 1633 cred_hits++;
1617 1634 }
1618 1635 #else
1619 1636 if (crgetref(cr) != 1) {
1620 1637 crfree(cr);
1621 1638 cr = crget();
1622 1639 xprt->xp_cred = cr;
1623 1640 }
1624 1641 #endif
1625 1642
1626 1643 exi = checkexport(fsid, xfid);
1627 1644
1628 1645 if (exi != NULL) {
1629 1646 publicfh_ok = PUBLICFH_CHECK(ne, disp, exi, fsid, xfid);
1630 1647
1631 1648 /*
1632 1649 * Don't allow non-V4 clients access
1633 1650 * to pseudo exports
1634 1651 */
1635 1652 if (PSEUDO(exi)) {
1636 1653 svcerr_weakauth(xprt);
1637 1654 error++;
1638 1655 goto done;
1639 1656 }
1640 1657
1641 1658 authres = checkauth(exi, req, cr, anon_ok, publicfh_ok,
1642 1659 &ro);
1643 1660 /*
1644 1661 * authres > 0: authentication OK - proceed
1645 1662 * authres == 0: authentication weak - return error
1646 1663 * authres < 0: authentication timeout - drop
1647 1664 */
1648 1665 if (authres <= 0) {
1649 1666 if (authres == 0) {
1650 1667 svcerr_weakauth(xprt);
1651 1668 error++;
1652 1669 }
1653 1670 goto done;
1654 1671 }
1655 1672 }
1656 1673 } else
1657 1674 cr = NULL;
1658 1675
1659 1676 if ((dis_flags & RPC_MAPRESP) && (auth_flavor != RPCSEC_GSS)) {
1660 1677 res = (char *)SVC_GETRES(xprt, disp->dis_ressz);
1661 1678 if (res == NULL)
1662 1679 res = (char *)&res_buf;
1663 1680 } else
1664 1681 res = (char *)&res_buf;
1665 1682
1666 1683 if (!(dis_flags & RPC_IDEMPOTENT)) {
1667 1684 dupstat = SVC_DUP_EXT(xprt, req, res, disp->dis_ressz, &dr,
1668 1685 &dupcached);
1669 1686
1670 1687 switch (dupstat) {
1671 1688 case DUP_ERROR:
1672 1689 svcerr_systemerr(xprt);
1673 1690 error++;
1674 1691 goto done;
1675 1692 /* NOTREACHED */
1676 1693 case DUP_INPROGRESS:
1677 1694 if (res != (char *)&res_buf)
1678 1695 SVC_FREERES(xprt);
1679 1696 error++;
1680 1697 goto done;
1681 1698 /* NOTREACHED */
1682 1699 case DUP_NEW:
1683 1700 case DUP_DROP:
1684 1701 curthread->t_flag |= T_DONTPEND;
1685 1702
1686 1703 (*disp->dis_proc)(args, res, exi, req, cr, ro);
1687 1704
1688 1705 curthread->t_flag &= ~T_DONTPEND;
1689 1706 if (curthread->t_flag & T_WOULDBLOCK) {
1690 1707 curthread->t_flag &= ~T_WOULDBLOCK;
1691 1708 SVC_DUPDONE_EXT(xprt, dr, res, NULL,
1692 1709 disp->dis_ressz, DUP_DROP);
1693 1710 if (res != (char *)&res_buf)
1694 1711 SVC_FREERES(xprt);
1695 1712 error++;
1696 1713 goto done;
1697 1714 }
1698 1715 if (dis_flags & RPC_AVOIDWORK) {
1699 1716 SVC_DUPDONE_EXT(xprt, dr, res, NULL,
1700 1717 disp->dis_ressz, DUP_DROP);
1701 1718 } else {
1702 1719 SVC_DUPDONE_EXT(xprt, dr, res,
1703 1720 disp->dis_resfree == nullfree ? NULL :
1704 1721 disp->dis_resfree,
1705 1722 disp->dis_ressz, DUP_DONE);
1706 1723 dupcached = TRUE;
1707 1724 }
1708 1725 break;
1709 1726 case DUP_DONE:
1710 1727 break;
1711 1728 }
1712 1729
1713 1730 } else {
1714 1731 curthread->t_flag |= T_DONTPEND;
1715 1732
1716 1733 (*disp->dis_proc)(args, res, exi, req, cr, ro);
1717 1734
1718 1735 curthread->t_flag &= ~T_DONTPEND;
1719 1736 if (curthread->t_flag & T_WOULDBLOCK) {
1720 1737 curthread->t_flag &= ~T_WOULDBLOCK;
1721 1738 if (res != (char *)&res_buf)
1722 1739 SVC_FREERES(xprt);
1723 1740 error++;
1724 1741 goto done;
1725 1742 }
1726 1743 }
1727 1744
1728 1745 if (auth_tooweak(req, res)) {
1729 1746 svcerr_weakauth(xprt);
1730 1747 error++;
1731 1748 goto done;
1732 1749 }
1733 1750
1734 1751 /*
1735 1752 * Check to see if logging has been enabled on the server.
1736 1753 * If so, then obtain the export info struct to be used for
1737 1754 * the later writing of the log record. This is done for
1738 1755 * the case that a lookup is done across a non-logged public
1739 1756 * file system.
1740 1757 */
1741 1758 if (nfslog_buffer_list != NULL) {
1742 1759 nfslog_exi = nfslog_get_exi(ne, exi, req, res, &nfslog_rec_id);
1743 1760 /*
1744 1761 * Is logging enabled?
1745 1762 */
1746 1763 logging_enabled = (nfslog_exi != NULL);
1747 1764
1748 1765 /*
1749 1766 * Copy the netbuf for logging purposes, before it is
1750 1767 * freed by svc_sendreply().
1751 1768 */
1752 1769 if (logging_enabled) {
1753 1770 NFSLOG_COPY_NETBUF(nfslog_exi, xprt, &nb);
1754 1771 /*
1755 1772 * If RPC_MAPRESP flag set (i.e. in V2 ops) the
1756 1773 * res gets copied directly into the mbuf and
1757 1774 * may be freed soon after the sendreply. So we
1758 1775 * must copy it here to a safe place...
1759 1776 */
1760 1777 if (res != (char *)&res_buf) {
1761 1778 bcopy(res, (char *)&res_buf, disp->dis_ressz);
1762 1779 }
1763 1780 }
1764 1781 }
1765 1782
1766 1783 /*
1767 1784 * Serialize and send results struct
1768 1785 */
1769 1786 #ifdef DEBUG
1770 1787 if (rfs_no_fast_xdrres == 0 && res != (char *)&res_buf)
1771 1788 #else
1772 1789 if (res != (char *)&res_buf)
1773 1790 #endif
1774 1791 {
1775 1792 if (!svc_sendreply(xprt, disp->dis_fastxdrres, res)) {
1776 1793 cmn_err(CE_NOTE, "%s: bad sendreply", pgmname);
1777 1794 svcerr_systemerr(xprt);
1778 1795 error++;
1779 1796 }
1780 1797 } else {
1781 1798 if (!svc_sendreply(xprt, disp->dis_xdrres, res)) {
1782 1799 cmn_err(CE_NOTE, "%s: bad sendreply", pgmname);
1783 1800 svcerr_systemerr(xprt);
1784 1801 error++;
1785 1802 }
1786 1803 }
1787 1804
1788 1805 /*
1789 1806 * Log if needed
1790 1807 */
1791 1808 if (logging_enabled) {
1792 1809 nfslog_write_record(nfslog_exi, req, args, (char *)&res_buf,
1793 1810 cr, &nb, nfslog_rec_id, NFSLOG_ONE_BUFFER);
1794 1811 exi_rele(nfslog_exi);
1795 1812 kmem_free((&nb)->buf, (&nb)->len);
1796 1813 }
1797 1814
1798 1815 /*
1799 1816 * Free results struct. With the addition of NFS V4 we can
1800 1817 * have non-idempotent procedures with functions.
1801 1818 */
1802 1819 if (disp->dis_resfree != nullfree && dupcached == FALSE) {
1803 1820 (*disp->dis_resfree)(res);
1804 1821 }
1805 1822
1806 1823 done:
1807 1824 /*
1808 1825 * Free arguments struct
1809 1826 */
1810 1827 if (disp) {
1811 1828 if (!SVC_FREEARGS(xprt, disp->dis_xdrargs, args)) {
1812 1829 cmn_err(CE_NOTE, "%s: bad freeargs", pgmname);
1813 1830 error++;
1814 1831 }
1815 1832 } else {
1816 1833 if (!SVC_FREEARGS(xprt, (xdrproc_t)0, (caddr_t)0)) {
1817 1834 cmn_err(CE_NOTE, "%s: bad freeargs", pgmname);
1818 1835 error++;
1819 1836 }
1820 1837 }
1821 1838
1822 1839 if (exi != NULL)
1823 1840 exi_rele(exi);
1824 1841
1825 1842 global_svstat_ptr[req->rq_vers][NFS_BADCALLS].value.ui64 += error;
1826 1843
1827 1844 global_svstat_ptr[req->rq_vers][NFS_CALLS].value.ui64++;
1828 1845 }
1829 1846
1830 1847 static void
1831 1848 rfs_dispatch(struct svc_req *req, SVCXPRT *xprt)
1832 1849 {
1833 1850 common_dispatch(req, xprt, NFS_VERSMIN, NFS_VERSMAX,
1834 1851 "NFS", rfs_disptable);
1835 1852 }
1836 1853
1837 1854 static char *aclcallnames_v2[] = {
1838 1855 "ACL2_NULL",
1839 1856 "ACL2_GETACL",
1840 1857 "ACL2_SETACL",
1841 1858 "ACL2_GETATTR",
1842 1859 "ACL2_ACCESS",
1843 1860 "ACL2_GETXATTRDIR"
1844 1861 };
1845 1862
1846 1863 static struct rpcdisp acldisptab_v2[] = {
1847 1864 /*
1848 1865 * ACL VERSION 2
1849 1866 */
1850 1867
1851 1868 /* ACL2_NULL = 0 */
1852 1869 {rpc_null,
1853 1870 xdr_void, NULL_xdrproc_t, 0,
1854 1871 xdr_void, NULL_xdrproc_t, 0,
1855 1872 nullfree, RPC_IDEMPOTENT,
1856 1873 0},
1857 1874
1858 1875 /* ACL2_GETACL = 1 */
1859 1876 {acl2_getacl,
1860 1877 xdr_GETACL2args, xdr_fastGETACL2args, sizeof (GETACL2args),
1861 1878 xdr_GETACL2res, NULL_xdrproc_t, sizeof (GETACL2res),
1862 1879 acl2_getacl_free, RPC_IDEMPOTENT,
1863 1880 acl2_getacl_getfh},
1864 1881
1865 1882 /* ACL2_SETACL = 2 */
1866 1883 {acl2_setacl,
1867 1884 xdr_SETACL2args, NULL_xdrproc_t, sizeof (SETACL2args),
1868 1885 #ifdef _LITTLE_ENDIAN
1869 1886 xdr_SETACL2res, xdr_fastSETACL2res, sizeof (SETACL2res),
1870 1887 #else
1871 1888 xdr_SETACL2res, NULL_xdrproc_t, sizeof (SETACL2res),
1872 1889 #endif
1873 1890 nullfree, RPC_MAPRESP,
1874 1891 acl2_setacl_getfh},
1875 1892
1876 1893 /* ACL2_GETATTR = 3 */
1877 1894 {acl2_getattr,
1878 1895 xdr_GETATTR2args, xdr_fastGETATTR2args, sizeof (GETATTR2args),
1879 1896 #ifdef _LITTLE_ENDIAN
1880 1897 xdr_GETATTR2res, xdr_fastGETATTR2res, sizeof (GETATTR2res),
1881 1898 #else
1882 1899 xdr_GETATTR2res, NULL_xdrproc_t, sizeof (GETATTR2res),
1883 1900 #endif
1884 1901 nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_MAPRESP,
1885 1902 acl2_getattr_getfh},
1886 1903
1887 1904 /* ACL2_ACCESS = 4 */
1888 1905 {acl2_access,
1889 1906 xdr_ACCESS2args, xdr_fastACCESS2args, sizeof (ACCESS2args),
1890 1907 #ifdef _LITTLE_ENDIAN
1891 1908 xdr_ACCESS2res, xdr_fastACCESS2res, sizeof (ACCESS2res),
1892 1909 #else
1893 1910 xdr_ACCESS2res, NULL_xdrproc_t, sizeof (ACCESS2res),
1894 1911 #endif
1895 1912 nullfree, RPC_IDEMPOTENT|RPC_MAPRESP,
1896 1913 acl2_access_getfh},
1897 1914
1898 1915 /* ACL2_GETXATTRDIR = 5 */
1899 1916 {acl2_getxattrdir,
1900 1917 xdr_GETXATTRDIR2args, NULL_xdrproc_t, sizeof (GETXATTRDIR2args),
1901 1918 xdr_GETXATTRDIR2res, NULL_xdrproc_t, sizeof (GETXATTRDIR2res),
1902 1919 nullfree, RPC_IDEMPOTENT,
1903 1920 acl2_getxattrdir_getfh},
1904 1921 };
1905 1922
1906 1923 static char *aclcallnames_v3[] = {
1907 1924 "ACL3_NULL",
1908 1925 "ACL3_GETACL",
1909 1926 "ACL3_SETACL",
1910 1927 "ACL3_GETXATTRDIR"
1911 1928 };
1912 1929
1913 1930 static struct rpcdisp acldisptab_v3[] = {
1914 1931 /*
1915 1932 * ACL VERSION 3
1916 1933 */
1917 1934
1918 1935 /* ACL3_NULL = 0 */
1919 1936 {rpc_null,
1920 1937 xdr_void, NULL_xdrproc_t, 0,
1921 1938 xdr_void, NULL_xdrproc_t, 0,
1922 1939 nullfree, RPC_IDEMPOTENT,
1923 1940 0},
1924 1941
1925 1942 /* ACL3_GETACL = 1 */
1926 1943 {acl3_getacl,
1927 1944 xdr_GETACL3args, NULL_xdrproc_t, sizeof (GETACL3args),
1928 1945 xdr_GETACL3res, NULL_xdrproc_t, sizeof (GETACL3res),
1929 1946 acl3_getacl_free, RPC_IDEMPOTENT,
1930 1947 acl3_getacl_getfh},
1931 1948
1932 1949 /* ACL3_SETACL = 2 */
1933 1950 {acl3_setacl,
1934 1951 xdr_SETACL3args, NULL_xdrproc_t, sizeof (SETACL3args),
1935 1952 xdr_SETACL3res, NULL_xdrproc_t, sizeof (SETACL3res),
1936 1953 nullfree, 0,
1937 1954 acl3_setacl_getfh},
1938 1955
1939 1956 /* ACL3_GETXATTRDIR = 3 */
1940 1957 {acl3_getxattrdir,
1941 1958 xdr_GETXATTRDIR3args, NULL_xdrproc_t, sizeof (GETXATTRDIR3args),
1942 1959 xdr_GETXATTRDIR3res, NULL_xdrproc_t, sizeof (GETXATTRDIR3res),
1943 1960 nullfree, RPC_IDEMPOTENT,
1944 1961 acl3_getxattrdir_getfh},
1945 1962 };
1946 1963
1947 1964 static struct rpc_disptable acl_disptable[] = {
1948 1965 {sizeof (acldisptab_v2) / sizeof (acldisptab_v2[0]),
1949 1966 aclcallnames_v2,
1950 1967 &aclproccnt_v2_ptr, acldisptab_v2},
1951 1968 {sizeof (acldisptab_v3) / sizeof (acldisptab_v3[0]),
1952 1969 aclcallnames_v3,
1953 1970 &aclproccnt_v3_ptr, acldisptab_v3},
1954 1971 };
1955 1972
1956 1973 static void
1957 1974 acl_dispatch(struct svc_req *req, SVCXPRT *xprt)
1958 1975 {
1959 1976 common_dispatch(req, xprt, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX,
1960 1977 "ACL", acl_disptable);
1961 1978 }
1962 1979
1963 1980 int
1964 1981 checkwin(int flavor, int window, struct svc_req *req)
1965 1982 {
1966 1983 struct authdes_cred *adc;
1967 1984
1968 1985 switch (flavor) {
1969 1986 case AUTH_DES:
1970 1987 adc = (struct authdes_cred *)req->rq_clntcred;
1971 1988 CTASSERT(sizeof (struct authdes_cred) <= RQCRED_SIZE);
1972 1989 if (adc->adc_fullname.window > window)
1973 1990 return (0);
1974 1991 break;
1975 1992
1976 1993 default:
1977 1994 break;
1978 1995 }
1979 1996 return (1);
1980 1997 }
1981 1998
1982 1999
1983 2000 /*
1984 2001 * checkauth() will check the access permission against the export
1985 2002 * information. Then map root uid/gid to appropriate uid/gid.
1986 2003 *
1987 2004 * This routine is used by NFS V3 and V2 code.
1988 2005 */
1989 2006 static int
1990 2007 checkauth(struct exportinfo *exi, struct svc_req *req, cred_t *cr, int anon_ok,
1991 2008 bool_t publicfh_ok, bool_t *ro)
1992 2009 {
1993 2010 int i, nfsflavor, rpcflavor, stat, access;
1994 2011 struct secinfo *secp;
1995 2012 caddr_t principal;
1996 2013 char buf[INET6_ADDRSTRLEN]; /* to hold both IPv4 and IPv6 addr */
1997 2014 int anon_res = 0;
1998 2015
1999 2016 uid_t uid;
2000 2017 gid_t gid;
2001 2018 uint_t ngids;
2002 2019 gid_t *gids;
2003 2020
2004 2021 /*
2005 2022 * Check for privileged port number
2006 2023 * N.B.: this assumes that we know the format of a netbuf.
2007 2024 */
2008 2025 if (nfs_portmon) {
2009 2026 struct sockaddr *ca;
2010 2027 ca = (struct sockaddr *)svc_getrpccaller(req->rq_xprt)->buf;
2011 2028
2012 2029 if (ca == NULL)
2013 2030 return (0);
2014 2031
2015 2032 if ((ca->sa_family == AF_INET &&
2016 2033 ntohs(((struct sockaddr_in *)ca)->sin_port) >=
2017 2034 IPPORT_RESERVED) ||
2018 2035 (ca->sa_family == AF_INET6 &&
2019 2036 ntohs(((struct sockaddr_in6 *)ca)->sin6_port) >=
2020 2037 IPPORT_RESERVED)) {
2021 2038 cmn_err(CE_NOTE,
2022 2039 "nfs_server: client %s%ssent NFS request from "
2023 2040 "unprivileged port",
2024 2041 client_name(req), client_addr(req, buf));
2025 2042 return (0);
2026 2043 }
2027 2044 }
2028 2045
2029 2046 /*
2030 2047 * return 1 on success or 0 on failure
2031 2048 */
2032 2049 stat = sec_svc_getcred(req, cr, &principal, &nfsflavor);
2033 2050
2034 2051 /*
2035 2052 * A failed AUTH_UNIX sec_svc_getcred() implies we couldn't set
2036 2053 * the credentials; below we map that to anonymous.
2037 2054 */
2038 2055 if (!stat && nfsflavor != AUTH_UNIX) {
2039 2056 cmn_err(CE_NOTE,
2040 2057 "nfs_server: couldn't get unix cred for %s",
2041 2058 client_name(req));
2042 2059 return (0);
2043 2060 }
2044 2061
2045 2062 /*
2046 2063 * Short circuit checkauth() on operations that support the
2047 2064 * public filehandle, and if the request for that operation
2048 2065 * is using the public filehandle. Note that we must call
2049 2066 * sec_svc_getcred() first so that xp_cookie is set to the
2050 2067 * right value. Normally xp_cookie is just the RPC flavor
2051 2068 * of the the request, but in the case of RPCSEC_GSS it
2052 2069 * could be a pseudo flavor.
2053 2070 */
2054 2071 if (publicfh_ok)
2055 2072 return (1);
2056 2073
2057 2074 rpcflavor = req->rq_cred.oa_flavor;
2058 2075 /*
2059 2076 * Check if the auth flavor is valid for this export
2060 2077 */
2061 2078 access = nfsauth_access(exi, req, cr, &uid, &gid, &ngids, &gids);
2062 2079 if (access & NFSAUTH_DROP)
2063 2080 return (-1); /* drop the request */
2064 2081
2065 2082 if (access & NFSAUTH_RO)
2066 2083 *ro = TRUE;
2067 2084
2068 2085 if (access & NFSAUTH_DENIED) {
2069 2086 /*
2070 2087 * If anon_ok == 1 and we got NFSAUTH_DENIED, it was
2071 2088 * probably due to the flavor not matching during
2072 2089 * the mount attempt. So map the flavor to AUTH_NONE
2073 2090 * so that the credentials get mapped to the anonymous
2074 2091 * user.
2075 2092 */
2076 2093 if (anon_ok == 1)
2077 2094 rpcflavor = AUTH_NONE;
2078 2095 else
2079 2096 return (0); /* deny access */
2080 2097
2081 2098 } else if (access & NFSAUTH_MAPNONE) {
2082 2099 /*
2083 2100 * Access was granted even though the flavor mismatched
2084 2101 * because AUTH_NONE was one of the exported flavors.
2085 2102 */
2086 2103 rpcflavor = AUTH_NONE;
2087 2104
2088 2105 } else if (access & NFSAUTH_WRONGSEC) {
2089 2106 /*
2090 2107 * NFSAUTH_WRONGSEC is used for NFSv4. If we get here,
2091 2108 * it means a client ignored the list of allowed flavors
2092 2109 * returned via the MOUNT protocol. So we just disallow it!
2093 2110 */
2094 2111 return (0);
2095 2112 }
2096 2113
2097 2114 if (rpcflavor != AUTH_SYS)
2098 2115 kmem_free(gids, ngids * sizeof (gid_t));
2099 2116
2100 2117 switch (rpcflavor) {
2101 2118 case AUTH_NONE:
2102 2119 anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2103 2120 exi->exi_export.ex_anon);
2104 2121 (void) crsetgroups(cr, 0, NULL);
2105 2122 break;
2106 2123
2107 2124 case AUTH_UNIX:
2108 2125 if (!stat || crgetuid(cr) == 0 && !(access & NFSAUTH_UIDMAP)) {
2109 2126 anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2110 2127 exi->exi_export.ex_anon);
2111 2128 (void) crsetgroups(cr, 0, NULL);
2112 2129 } else if (crgetuid(cr) == 0 && access & NFSAUTH_ROOT) {
2113 2130 /*
2114 2131 * It is root, so apply rootid to get real UID
2115 2132 * Find the secinfo structure. We should be able
2116 2133 * to find it by the time we reach here.
2117 2134 * nfsauth_access() has done the checking.
2118 2135 */
2119 2136 secp = NULL;
2120 2137 for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2121 2138 struct secinfo *sptr;
2122 2139 sptr = &exi->exi_export.ex_secinfo[i];
2123 2140 if (sptr->s_secinfo.sc_nfsnum == nfsflavor) {
2124 2141 secp = sptr;
2125 2142 break;
2126 2143 }
2127 2144 }
2128 2145 if (secp != NULL) {
2129 2146 (void) crsetugid(cr, secp->s_rootid,
2130 2147 secp->s_rootid);
2131 2148 (void) crsetgroups(cr, 0, NULL);
2132 2149 }
2133 2150 } else if (crgetuid(cr) != uid || crgetgid(cr) != gid) {
2134 2151 if (crsetugid(cr, uid, gid) != 0)
2135 2152 anon_res = crsetugid(cr,
2136 2153 exi->exi_export.ex_anon,
2137 2154 exi->exi_export.ex_anon);
2138 2155 (void) crsetgroups(cr, 0, NULL);
2139 2156 } else if (access & NFSAUTH_GROUPS) {
2140 2157 (void) crsetgroups(cr, ngids, gids);
2141 2158 }
2142 2159
2143 2160 kmem_free(gids, ngids * sizeof (gid_t));
2144 2161
2145 2162 break;
2146 2163
2147 2164 case AUTH_DES:
2148 2165 case RPCSEC_GSS:
2149 2166 /*
2150 2167 * Find the secinfo structure. We should be able
2151 2168 * to find it by the time we reach here.
2152 2169 * nfsauth_access() has done the checking.
2153 2170 */
2154 2171 secp = NULL;
2155 2172 for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2156 2173 if (exi->exi_export.ex_secinfo[i].s_secinfo.sc_nfsnum ==
2157 2174 nfsflavor) {
2158 2175 secp = &exi->exi_export.ex_secinfo[i];
2159 2176 break;
2160 2177 }
2161 2178 }
2162 2179
2163 2180 if (!secp) {
2164 2181 cmn_err(CE_NOTE, "nfs_server: client %s%shad "
2165 2182 "no secinfo data for flavor %d",
2166 2183 client_name(req), client_addr(req, buf),
2167 2184 nfsflavor);
2168 2185 return (0);
2169 2186 }
2170 2187
2171 2188 if (!checkwin(rpcflavor, secp->s_window, req)) {
2172 2189 cmn_err(CE_NOTE,
2173 2190 "nfs_server: client %s%sused invalid "
2174 2191 "auth window value",
2175 2192 client_name(req), client_addr(req, buf));
2176 2193 return (0);
2177 2194 }
2178 2195
2179 2196 /*
2180 2197 * Map root principals listed in the share's root= list to root,
2181 2198 * and map any others principals that were mapped to root by RPC
2182 2199 * to anon.
2183 2200 */
2184 2201 if (principal && sec_svc_inrootlist(rpcflavor, principal,
2185 2202 secp->s_rootcnt, secp->s_rootnames)) {
2186 2203 if (crgetuid(cr) == 0 && secp->s_rootid == 0)
2187 2204 return (1);
2188 2205
2189 2206
2190 2207 (void) crsetugid(cr, secp->s_rootid, secp->s_rootid);
2191 2208
2192 2209 /*
2193 2210 * NOTE: If and when kernel-land privilege tracing is
2194 2211 * added this may have to be replaced with code that
2195 2212 * retrieves root's supplementary groups (e.g., using
2196 2213 * kgss_get_group_info(). In the meantime principals
2197 2214 * mapped to uid 0 get all privileges, so setting cr's
2198 2215 * supplementary groups for them does nothing.
2199 2216 */
2200 2217 (void) crsetgroups(cr, 0, NULL);
2201 2218
2202 2219 return (1);
2203 2220 }
2204 2221
2205 2222 /*
2206 2223 * Not a root princ, or not in root list, map UID 0/nobody to
2207 2224 * the anon ID for the share. (RPC sets cr's UIDs and GIDs to
2208 2225 * UID_NOBODY and GID_NOBODY, respectively.)
2209 2226 */
2210 2227 if (crgetuid(cr) != 0 &&
2211 2228 (crgetuid(cr) != UID_NOBODY || crgetgid(cr) != GID_NOBODY))
2212 2229 return (1);
2213 2230
2214 2231 anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2215 2232 exi->exi_export.ex_anon);
2216 2233 (void) crsetgroups(cr, 0, NULL);
2217 2234 break;
2218 2235 default:
2219 2236 return (0);
2220 2237 } /* switch on rpcflavor */
2221 2238
2222 2239 /*
2223 2240 * Even if anon access is disallowed via ex_anon == -1, we allow
2224 2241 * this access if anon_ok is set. So set creds to the default
2225 2242 * "nobody" id.
2226 2243 */
2227 2244 if (anon_res != 0) {
2228 2245 if (anon_ok == 0) {
2229 2246 cmn_err(CE_NOTE,
2230 2247 "nfs_server: client %s%ssent wrong "
2231 2248 "authentication for %s",
2232 2249 client_name(req), client_addr(req, buf),
2233 2250 exi->exi_export.ex_path ?
2234 2251 exi->exi_export.ex_path : "?");
2235 2252 return (0);
2236 2253 }
2237 2254
2238 2255 if (crsetugid(cr, UID_NOBODY, GID_NOBODY) != 0)
2239 2256 return (0);
2240 2257 }
2241 2258
2242 2259 return (1);
2243 2260 }
2244 2261
2245 2262 /*
2246 2263 * returns 0 on failure, -1 on a drop, -2 on wrong security flavor,
2247 2264 * and 1 on success
2248 2265 */
2249 2266 int
2250 2267 checkauth4(struct compound_state *cs, struct svc_req *req)
2251 2268 {
2252 2269 int i, rpcflavor, access;
2253 2270 struct secinfo *secp;
2254 2271 char buf[MAXHOST + 1];
2255 2272 int anon_res = 0, nfsflavor;
2256 2273 struct exportinfo *exi;
2257 2274 cred_t *cr;
2258 2275 caddr_t principal;
2259 2276
2260 2277 uid_t uid;
2261 2278 gid_t gid;
2262 2279 uint_t ngids;
2263 2280 gid_t *gids;
2264 2281
2265 2282 exi = cs->exi;
2266 2283 cr = cs->cr;
2267 2284 principal = cs->principal;
2268 2285 nfsflavor = cs->nfsflavor;
2269 2286
2270 2287 ASSERT(cr != NULL);
2271 2288
2272 2289 rpcflavor = req->rq_cred.oa_flavor;
2273 2290 cs->access &= ~CS_ACCESS_LIMITED;
2274 2291
2275 2292 /*
2276 2293 * Check for privileged port number
2277 2294 * N.B.: this assumes that we know the format of a netbuf.
2278 2295 */
2279 2296 if (nfs_portmon) {
2280 2297 struct sockaddr *ca;
2281 2298 ca = (struct sockaddr *)svc_getrpccaller(req->rq_xprt)->buf;
2282 2299
2283 2300 if (ca == NULL)
2284 2301 return (0);
2285 2302
2286 2303 if ((ca->sa_family == AF_INET &&
2287 2304 ntohs(((struct sockaddr_in *)ca)->sin_port) >=
2288 2305 IPPORT_RESERVED) ||
2289 2306 (ca->sa_family == AF_INET6 &&
2290 2307 ntohs(((struct sockaddr_in6 *)ca)->sin6_port) >=
2291 2308 IPPORT_RESERVED)) {
2292 2309 cmn_err(CE_NOTE,
2293 2310 "nfs_server: client %s%ssent NFSv4 request from "
2294 2311 "unprivileged port",
2295 2312 client_name(req), client_addr(req, buf));
2296 2313 return (0);
2297 2314 }
2298 2315 }
2299 2316
2300 2317 /*
2301 2318 * Check the access right per auth flavor on the vnode of
2302 2319 * this export for the given request.
2303 2320 */
2304 2321 access = nfsauth4_access(cs->exi, cs->vp, req, cr, &uid, &gid, &ngids,
2305 2322 &gids);
2306 2323
2307 2324 if (access & NFSAUTH_WRONGSEC)
2308 2325 return (-2); /* no access for this security flavor */
2309 2326
2310 2327 if (access & NFSAUTH_DROP)
2311 2328 return (-1); /* drop the request */
2312 2329
2313 2330 if (access & NFSAUTH_DENIED) {
2314 2331
2315 2332 if (exi->exi_export.ex_seccnt > 0)
2316 2333 return (0); /* deny access */
2317 2334
2318 2335 } else if (access & NFSAUTH_LIMITED) {
2319 2336
2320 2337 cs->access |= CS_ACCESS_LIMITED;
2321 2338
2322 2339 } else if (access & NFSAUTH_MAPNONE) {
2323 2340 /*
2324 2341 * Access was granted even though the flavor mismatched
2325 2342 * because AUTH_NONE was one of the exported flavors.
2326 2343 */
2327 2344 rpcflavor = AUTH_NONE;
2328 2345 }
2329 2346
2330 2347 /*
2331 2348 * XXX probably need to redo some of it for nfsv4?
2332 2349 * return 1 on success or 0 on failure
2333 2350 */
2334 2351
2335 2352 if (rpcflavor != AUTH_SYS)
2336 2353 kmem_free(gids, ngids * sizeof (gid_t));
2337 2354
2338 2355 switch (rpcflavor) {
2339 2356 case AUTH_NONE:
2340 2357 anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2341 2358 exi->exi_export.ex_anon);
2342 2359 (void) crsetgroups(cr, 0, NULL);
2343 2360 break;
2344 2361
2345 2362 case AUTH_UNIX:
2346 2363 if (crgetuid(cr) == 0 && !(access & NFSAUTH_UIDMAP)) {
2347 2364 anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2348 2365 exi->exi_export.ex_anon);
2349 2366 (void) crsetgroups(cr, 0, NULL);
2350 2367 } else if (crgetuid(cr) == 0 && access & NFSAUTH_ROOT) {
2351 2368 /*
2352 2369 * It is root, so apply rootid to get real UID
2353 2370 * Find the secinfo structure. We should be able
2354 2371 * to find it by the time we reach here.
2355 2372 * nfsauth_access() has done the checking.
2356 2373 */
2357 2374 secp = NULL;
2358 2375 for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2359 2376 struct secinfo *sptr;
2360 2377 sptr = &exi->exi_export.ex_secinfo[i];
2361 2378 if (sptr->s_secinfo.sc_nfsnum == nfsflavor) {
2362 2379 secp = &exi->exi_export.ex_secinfo[i];
2363 2380 break;
2364 2381 }
2365 2382 }
2366 2383 if (secp != NULL) {
2367 2384 (void) crsetugid(cr, secp->s_rootid,
2368 2385 secp->s_rootid);
2369 2386 (void) crsetgroups(cr, 0, NULL);
2370 2387 }
2371 2388 } else if (crgetuid(cr) != uid || crgetgid(cr) != gid) {
2372 2389 if (crsetugid(cr, uid, gid) != 0)
2373 2390 anon_res = crsetugid(cr,
2374 2391 exi->exi_export.ex_anon,
2375 2392 exi->exi_export.ex_anon);
2376 2393 (void) crsetgroups(cr, 0, NULL);
2377 2394 } if (access & NFSAUTH_GROUPS) {
2378 2395 (void) crsetgroups(cr, ngids, gids);
2379 2396 }
2380 2397
2381 2398 kmem_free(gids, ngids * sizeof (gid_t));
2382 2399
2383 2400 break;
2384 2401
2385 2402 default:
2386 2403 /*
2387 2404 * Find the secinfo structure. We should be able
2388 2405 * to find it by the time we reach here.
2389 2406 * nfsauth_access() has done the checking.
2390 2407 */
2391 2408 secp = NULL;
2392 2409 for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2393 2410 if (exi->exi_export.ex_secinfo[i].s_secinfo.sc_nfsnum ==
2394 2411 nfsflavor) {
2395 2412 secp = &exi->exi_export.ex_secinfo[i];
2396 2413 break;
2397 2414 }
2398 2415 }
2399 2416
2400 2417 if (!secp) {
2401 2418 cmn_err(CE_NOTE, "nfs_server: client %s%shad "
2402 2419 "no secinfo data for flavor %d",
2403 2420 client_name(req), client_addr(req, buf),
2404 2421 nfsflavor);
2405 2422 return (0);
2406 2423 }
2407 2424
2408 2425 if (!checkwin(rpcflavor, secp->s_window, req)) {
2409 2426 cmn_err(CE_NOTE,
2410 2427 "nfs_server: client %s%sused invalid "
2411 2428 "auth window value",
2412 2429 client_name(req), client_addr(req, buf));
2413 2430 return (0);
2414 2431 }
2415 2432
2416 2433 /*
2417 2434 * Map root principals listed in the share's root= list to root,
2418 2435 * and map any others principals that were mapped to root by RPC
2419 2436 * to anon. If not going to anon, set to rootid (root_mapping).
2420 2437 */
2421 2438 if (principal && sec_svc_inrootlist(rpcflavor, principal,
2422 2439 secp->s_rootcnt, secp->s_rootnames)) {
2423 2440 if (crgetuid(cr) == 0 && secp->s_rootid == 0)
2424 2441 return (1);
2425 2442
2426 2443 (void) crsetugid(cr, secp->s_rootid, secp->s_rootid);
2427 2444
2428 2445 /*
2429 2446 * NOTE: If and when kernel-land privilege tracing is
2430 2447 * added this may have to be replaced with code that
2431 2448 * retrieves root's supplementary groups (e.g., using
2432 2449 * kgss_get_group_info(). In the meantime principals
2433 2450 * mapped to uid 0 get all privileges, so setting cr's
2434 2451 * supplementary groups for them does nothing.
2435 2452 */
2436 2453 (void) crsetgroups(cr, 0, NULL);
2437 2454
2438 2455 return (1);
2439 2456 }
2440 2457
2441 2458 /*
2442 2459 * Not a root princ, or not in root list, map UID 0/nobody to
2443 2460 * the anon ID for the share. (RPC sets cr's UIDs and GIDs to
2444 2461 * UID_NOBODY and GID_NOBODY, respectively.)
2445 2462 */
2446 2463 if (crgetuid(cr) != 0 &&
2447 2464 (crgetuid(cr) != UID_NOBODY || crgetgid(cr) != GID_NOBODY))
2448 2465 return (1);
2449 2466
2450 2467 anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2451 2468 exi->exi_export.ex_anon);
2452 2469 (void) crsetgroups(cr, 0, NULL);
2453 2470 break;
2454 2471 } /* switch on rpcflavor */
2455 2472
2456 2473 /*
2457 2474 * Even if anon access is disallowed via ex_anon == -1, we allow
2458 2475 * this access if anon_ok is set. So set creds to the default
2459 2476 * "nobody" id.
2460 2477 */
2461 2478
2462 2479 if (anon_res != 0) {
2463 2480 cmn_err(CE_NOTE,
2464 2481 "nfs_server: client %s%ssent wrong "
2465 2482 "authentication for %s",
2466 2483 client_name(req), client_addr(req, buf),
2467 2484 exi->exi_export.ex_path ?
2468 2485 exi->exi_export.ex_path : "?");
2469 2486 return (0);
2470 2487 }
2471 2488
2472 2489 return (1);
2473 2490 }
2474 2491
2475 2492
2476 2493 static char *
2477 2494 client_name(struct svc_req *req)
2478 2495 {
2479 2496 char *hostname = NULL;
2480 2497
2481 2498 /*
2482 2499 * If it's a Unix cred then use the
2483 2500 * hostname from the credential.
2484 2501 */
2485 2502 if (req->rq_cred.oa_flavor == AUTH_UNIX) {
2486 2503 hostname = ((struct authunix_parms *)
2487 2504 req->rq_clntcred)->aup_machname;
2488 2505 }
2489 2506 if (hostname == NULL)
2490 2507 hostname = "";
2491 2508
2492 2509 return (hostname);
2493 2510 }
2494 2511
2495 2512 static char *
2496 2513 client_addr(struct svc_req *req, char *buf)
2497 2514 {
2498 2515 struct sockaddr *ca;
2499 2516 uchar_t *b;
2500 2517 char *frontspace = "";
2501 2518
2502 2519 /*
2503 2520 * We assume we are called in tandem with client_name and the
2504 2521 * format string looks like "...client %s%sblah blah..."
2505 2522 *
2506 2523 * If it's a Unix cred then client_name returned
2507 2524 * a host name, so we need insert a space between host name
2508 2525 * and IP address.
2509 2526 */
2510 2527 if (req->rq_cred.oa_flavor == AUTH_UNIX)
2511 2528 frontspace = " ";
2512 2529
2513 2530 /*
2514 2531 * Convert the caller's IP address to a dotted string
2515 2532 */
2516 2533 ca = (struct sockaddr *)svc_getrpccaller(req->rq_xprt)->buf;
2517 2534
2518 2535 if (ca->sa_family == AF_INET) {
2519 2536 b = (uchar_t *)&((struct sockaddr_in *)ca)->sin_addr;
2520 2537 (void) sprintf(buf, "%s(%d.%d.%d.%d) ", frontspace,
2521 2538 b[0] & 0xFF, b[1] & 0xFF, b[2] & 0xFF, b[3] & 0xFF);
2522 2539 } else if (ca->sa_family == AF_INET6) {
2523 2540 struct sockaddr_in6 *sin6;
2524 2541 sin6 = (struct sockaddr_in6 *)ca;
2525 2542 (void) kinet_ntop6((uchar_t *)&sin6->sin6_addr,
2526 2543 buf, INET6_ADDRSTRLEN);
2527 2544
2528 2545 } else {
2529 2546
2530 2547 /*
2531 2548 * No IP address to print. If there was a host name
2532 2549 * printed, then we print a space.
2533 2550 */
2534 2551 (void) sprintf(buf, frontspace);
2535 2552 }
2536 2553
2537 2554 return (buf);
2538 2555 }
2539 2556
|
↓ open down ↓ |
1974 lines elided |
↑ open up ↑ |
2540 2557 /*
2541 2558 * NFS Server initialization routine. This routine should only be called
2542 2559 * once. It performs the following tasks:
2543 2560 * - Call sub-initialization routines (localize access to variables)
2544 2561 * - Initialize all locks
2545 2562 * - initialize the version 3 write verifier
2546 2563 */
2547 2564 void
2548 2565 nfs_srvinit(void)
2549 2566 {
2550 - /* NFS server zone-specific global variables */
2551 - zone_key_create(&nfssrv_zone_key, nfs_srv_zone_init,
2552 - NULL, nfs_srv_zone_fini);
2553 2567
2568 + /* Truly global stuff in this module (not per zone) */
2569 + rw_init(&nfssrv_globals_rwl, NULL, RW_DEFAULT, NULL);
2570 + list_create(&nfssrv_globals_list, sizeof (nfs_globals_t),
2571 + offsetof (nfs_globals_t, nfs_g_link));
2572 +
2573 + /* The order here is important */
2554 2574 nfs_exportinit();
2555 2575 rfs_srvrinit();
2556 2576 rfs3_srvrinit();
2557 2577 rfs4_srvrinit();
2558 2578 nfsauth_init();
2579 +
2580 + /*
2581 + * NFS server zone-specific global variables
2582 + * Note the zone_init is called for the GZ here.
2583 + */
2584 + zone_key_create(&nfssrv_zone_key, nfs_server_zone_init,
2585 + nfs_server_zone_shutdown, nfs_server_zone_fini);
2559 2586 }
2560 2587
2561 2588 /*
2562 2589 * NFS Server finalization routine. This routine is called to cleanup the
2563 2590 * initialization work previously performed if the NFS server module could
2564 2591 * not be loaded correctly.
2565 2592 */
2566 2593 void
2567 2594 nfs_srvfini(void)
2568 2595 {
2596 +
2597 + /*
2598 + * NFS server zone-specific global variables
2599 + * Note the zone_fini is called for the GZ here.
2600 + */
2601 + (void) zone_key_delete(nfssrv_zone_key);
2602 +
2603 + /* The order here is important (reverse of init) */
2569 2604 nfsauth_fini();
2570 2605 rfs4_srvrfini();
2571 2606 rfs3_srvrfini();
2572 2607 rfs_srvrfini();
2573 2608 nfs_exportfini();
2574 2609
2575 - (void) zone_key_delete(nfssrv_zone_key);
2610 + /* Truly global stuff in this module (not per zone) */
2611 + list_destroy(&nfssrv_globals_list);
2612 + rw_destroy(&nfssrv_globals_rwl);
2576 2613 }
2577 2614
2578 -/* ARGSUSED */
2615 +/*
2616 + * Zone init, shutdown, fini functions for the NFS server
2617 + *
2618 + * This design is careful to create the entire hierarhcy of
2619 + * NFS server "globals" (including those created by various
2620 + * per-module *_zone_init functions, etc.) so that all these
2621 + * objects have exactly the same lifetime.
2622 + *
2623 + * These objects are also kept on a list for two reasons:
2624 + * 1: It makes finding these in mdb _much_ easier.
2625 + * 2: It allows operating across all zone globals for
2626 + * functions like nfs_auth.c:exi_cache_reclaim
2627 + */
2579 2628 static void *
2580 -nfs_srv_zone_init(zoneid_t zoneid)
2629 +nfs_server_zone_init(zoneid_t zoneid)
2581 2630 {
2582 2631 nfs_globals_t *ng;
2583 2632
2584 2633 ng = kmem_zalloc(sizeof (*ng), KM_SLEEP);
2585 2634
2586 2635 ng->nfs_versmin = NFS_VERSMIN_DEFAULT;
2587 2636 ng->nfs_versmax = NFS_VERSMAX_DEFAULT;
2588 2637
2589 2638 /* Init the stuff to control start/stop */
2590 2639 ng->nfs_server_upordown = NFS_SERVER_STOPPED;
2591 2640 mutex_init(&ng->nfs_server_upordown_lock, NULL, MUTEX_DEFAULT, NULL);
2592 2641 cv_init(&ng->nfs_server_upordown_cv, NULL, CV_DEFAULT, NULL);
2593 2642 mutex_init(&ng->rdma_wait_mutex, NULL, MUTEX_DEFAULT, NULL);
2594 2643 cv_init(&ng->rdma_wait_cv, NULL, CV_DEFAULT, NULL);
2595 2644
2645 + ng->nfs_zoneid = zoneid;
2646 +
2647 + /*
2648 + * Order here is important.
2649 + * export init must precede srv init calls.
2650 + */
2651 + nfs_export_zone_init(ng);
2652 + rfs_srv_zone_init(ng);
2653 + rfs3_srv_zone_init(ng);
2654 + rfs4_srv_zone_init(ng);
2655 + nfsauth_zone_init(ng);
2656 +
2657 + rw_enter(&nfssrv_globals_rwl, RW_WRITER);
2658 + list_insert_tail(&nfssrv_globals_list, ng);
2659 + rw_exit(&nfssrv_globals_rwl);
2660 +
2596 2661 return (ng);
2597 2662 }
2598 2663
2599 2664 /* ARGSUSED */
2600 2665 static void
2601 -nfs_srv_zone_fini(zoneid_t zoneid, void *data)
2666 +nfs_server_zone_shutdown(zoneid_t zoneid, void *data)
2602 2667 {
2603 2668 nfs_globals_t *ng;
2604 2669
2605 2670 ng = (nfs_globals_t *)data;
2671 +
2672 + /*
2673 + * Order is like _fini, but only
2674 + * some modules need this hook.
2675 + */
2676 + nfsauth_zone_shutdown(ng);
2677 + nfs_export_zone_shutdown(ng);
2678 +}
2679 +
2680 +/* ARGSUSED */
2681 +static void
2682 +nfs_server_zone_fini(zoneid_t zoneid, void *data)
2683 +{
2684 + nfs_globals_t *ng;
2685 +
2686 + ng = (nfs_globals_t *)data;
2687 +
2688 + rw_enter(&nfssrv_globals_rwl, RW_WRITER);
2689 + list_remove(&nfssrv_globals_list, ng);
2690 + rw_exit(&nfssrv_globals_rwl);
2691 +
2692 + /*
2693 + * Order here is important.
2694 + * reverse order from init
2695 + */
2696 + nfsauth_zone_fini(ng);
2697 + rfs4_srv_zone_fini(ng);
2698 + rfs3_srv_zone_fini(ng);
2699 + rfs_srv_zone_fini(ng);
2700 + nfs_export_zone_fini(ng);
2701 +
2606 2702 mutex_destroy(&ng->nfs_server_upordown_lock);
2607 2703 cv_destroy(&ng->nfs_server_upordown_cv);
2608 2704 mutex_destroy(&ng->rdma_wait_mutex);
2609 2705 cv_destroy(&ng->rdma_wait_cv);
2610 2706
2611 2707 kmem_free(ng, sizeof (*ng));
2612 2708 }
2613 2709
2614 2710 /*
2615 2711 * Set up an iovec array of up to cnt pointers.
2616 2712 */
2617 2713 void
2618 2714 mblk_to_iov(mblk_t *m, int cnt, struct iovec *iovp)
2619 2715 {
2620 2716 while (m != NULL && cnt-- > 0) {
2621 2717 iovp->iov_base = (caddr_t)m->b_rptr;
2622 2718 iovp->iov_len = (m->b_wptr - m->b_rptr);
2623 2719 iovp++;
2624 2720 m = m->b_cont;
2625 2721 }
2626 2722 }
2627 2723
2628 2724 /*
2629 2725 * Common code between NFS Version 2 and NFS Version 3 for the public
2630 2726 * filehandle multicomponent lookups.
2631 2727 */
2632 2728
2633 2729 /*
2634 2730 * Public filehandle evaluation of a multi-component lookup, following
2635 2731 * symbolic links, if necessary. This may result in a vnode in another
2636 2732 * filesystem, which is OK as long as the other filesystem is exported.
2637 2733 *
2638 2734 * Note that the exi will be set either to NULL or a new reference to the
2639 2735 * exportinfo struct that corresponds to the vnode of the multi-component path.
2640 2736 * It is the callers responsibility to release this reference.
2641 2737 */
2642 2738 int
2643 2739 rfs_publicfh_mclookup(char *p, vnode_t *dvp, cred_t *cr, vnode_t **vpp,
2644 2740 struct exportinfo **exi, struct sec_ol *sec)
2645 2741 {
2646 2742 int pathflag;
2647 2743 vnode_t *mc_dvp = NULL;
2648 2744 vnode_t *realvp;
2649 2745 int error;
2650 2746
2651 2747 *exi = NULL;
2652 2748
2653 2749 /*
2654 2750 * check if the given path is a url or native path. Since p is
2655 2751 * modified by MCLpath(), it may be empty after returning from
2656 2752 * there, and should be checked.
2657 2753 */
2658 2754 if ((pathflag = MCLpath(&p)) == -1)
2659 2755 return (EIO);
2660 2756
2661 2757 /*
2662 2758 * If pathflag is SECURITY_QUERY, turn the SEC_QUERY bit
2663 2759 * on in sec->sec_flags. This bit will later serve as an
2664 2760 * indication in makefh_ol() or makefh3_ol() to overload the
2665 2761 * filehandle to contain the sec modes used by the server for
2666 2762 * the path.
2667 2763 */
2668 2764 if (pathflag == SECURITY_QUERY) {
2669 2765 if ((sec->sec_index = (uint_t)(*p)) > 0) {
2670 2766 sec->sec_flags |= SEC_QUERY;
2671 2767 p++;
2672 2768 if ((pathflag = MCLpath(&p)) == -1)
2673 2769 return (EIO);
2674 2770 } else {
2675 2771 cmn_err(CE_NOTE,
2676 2772 "nfs_server: invalid security index %d, "
2677 2773 "violating WebNFS SNEGO protocol.", sec->sec_index);
2678 2774 return (EIO);
2679 2775 }
2680 2776 }
2681 2777
2682 2778 if (p[0] == '\0') {
2683 2779 error = ENOENT;
2684 2780 goto publicfh_done;
2685 2781 }
2686 2782
2687 2783 error = rfs_pathname(p, &mc_dvp, vpp, dvp, cr, pathflag);
2688 2784
2689 2785 /*
2690 2786 * If name resolves to "/" we get EINVAL since we asked for
2691 2787 * the vnode of the directory that the file is in. Try again
2692 2788 * with NULL directory vnode.
2693 2789 */
2694 2790 if (error == EINVAL) {
2695 2791 error = rfs_pathname(p, NULL, vpp, dvp, cr, pathflag);
2696 2792 if (!error) {
2697 2793 ASSERT(*vpp != NULL);
2698 2794 if ((*vpp)->v_type == VDIR) {
2699 2795 VN_HOLD(*vpp);
2700 2796 mc_dvp = *vpp;
2701 2797 } else {
2702 2798 /*
2703 2799 * This should not happen, the filesystem is
2704 2800 * in an inconsistent state. Fail the lookup
2705 2801 * at this point.
2706 2802 */
2707 2803 VN_RELE(*vpp);
2708 2804 error = EINVAL;
2709 2805 }
2710 2806 }
2711 2807 }
2712 2808
2713 2809 if (error)
2714 2810 goto publicfh_done;
2715 2811
2716 2812 if (*vpp == NULL) {
2717 2813 error = ENOENT;
2718 2814 goto publicfh_done;
2719 2815 }
2720 2816
2721 2817 ASSERT(mc_dvp != NULL);
2722 2818 ASSERT(*vpp != NULL);
2723 2819
2724 2820 if ((*vpp)->v_type == VDIR) {
2725 2821 do {
2726 2822 /*
2727 2823 * *vpp may be an AutoFS node, so we perform
2728 2824 * a VOP_ACCESS() to trigger the mount of the intended
2729 2825 * filesystem, so we can perform the lookup in the
2730 2826 * intended filesystem.
2731 2827 */
2732 2828 (void) VOP_ACCESS(*vpp, 0, 0, cr, NULL);
2733 2829
2734 2830 /*
2735 2831 * If vnode is covered, get the
2736 2832 * the topmost vnode.
2737 2833 */
2738 2834 if (vn_mountedvfs(*vpp) != NULL) {
2739 2835 error = traverse(vpp);
2740 2836 if (error) {
2741 2837 VN_RELE(*vpp);
2742 2838 goto publicfh_done;
2743 2839 }
2744 2840 }
2745 2841
2746 2842 if (VOP_REALVP(*vpp, &realvp, NULL) == 0 &&
2747 2843 realvp != *vpp) {
2748 2844 /*
2749 2845 * If realvp is different from *vpp
2750 2846 * then release our reference on *vpp, so that
2751 2847 * the export access check be performed on the
2752 2848 * real filesystem instead.
2753 2849 */
2754 2850 VN_HOLD(realvp);
2755 2851 VN_RELE(*vpp);
2756 2852 *vpp = realvp;
2757 2853 } else {
2758 2854 break;
2759 2855 }
2760 2856 /* LINTED */
2761 2857 } while (TRUE);
2762 2858
2763 2859 /*
2764 2860 * Let nfs_vptexi() figure what the real parent is.
2765 2861 */
2766 2862 VN_RELE(mc_dvp);
2767 2863 mc_dvp = NULL;
2768 2864
2769 2865 } else {
2770 2866 /*
2771 2867 * If vnode is covered, get the
2772 2868 * the topmost vnode.
2773 2869 */
2774 2870 if (vn_mountedvfs(mc_dvp) != NULL) {
2775 2871 error = traverse(&mc_dvp);
2776 2872 if (error) {
2777 2873 VN_RELE(*vpp);
2778 2874 goto publicfh_done;
2779 2875 }
2780 2876 }
2781 2877
2782 2878 if (VOP_REALVP(mc_dvp, &realvp, NULL) == 0 &&
2783 2879 realvp != mc_dvp) {
2784 2880 /*
2785 2881 * *vpp is a file, obtain realvp of the parent
2786 2882 * directory vnode.
2787 2883 */
2788 2884 VN_HOLD(realvp);
2789 2885 VN_RELE(mc_dvp);
2790 2886 mc_dvp = realvp;
2791 2887 }
2792 2888 }
2793 2889
2794 2890 /*
2795 2891 * The pathname may take us from the public filesystem to another.
2796 2892 * If that's the case then just set the exportinfo to the new export
2797 2893 * and build filehandle for it. Thanks to per-access checking there's
2798 2894 * no security issues with doing this. If the client is not allowed
2799 2895 * access to this new export then it will get an access error when it
2800 2896 * tries to use the filehandle
2801 2897 */
2802 2898 if (error = nfs_check_vpexi(mc_dvp, *vpp, kcred, exi)) {
2803 2899 VN_RELE(*vpp);
2804 2900 goto publicfh_done;
2805 2901 }
2806 2902
2807 2903 /*
2808 2904 * Not allowed access to pseudo exports.
2809 2905 */
2810 2906 if (PSEUDO(*exi)) {
2811 2907 error = ENOENT;
2812 2908 VN_RELE(*vpp);
2813 2909 goto publicfh_done;
2814 2910 }
2815 2911
2816 2912 /*
2817 2913 * Do a lookup for the index file. We know the index option doesn't
2818 2914 * allow paths through handling in the share command, so mc_dvp will
2819 2915 * be the parent for the index file vnode, if its present. Use
2820 2916 * temporary pointers to preserve and reuse the vnode pointers of the
2821 2917 * original directory in case there's no index file. Note that the
2822 2918 * index file is a native path, and should not be interpreted by
2823 2919 * the URL parser in rfs_pathname()
2824 2920 */
2825 2921 if (((*exi)->exi_export.ex_flags & EX_INDEX) &&
2826 2922 ((*vpp)->v_type == VDIR) && (pathflag == URLPATH)) {
2827 2923 vnode_t *tvp, *tmc_dvp; /* temporary vnode pointers */
2828 2924
2829 2925 tmc_dvp = mc_dvp;
2830 2926 mc_dvp = tvp = *vpp;
2831 2927
2832 2928 error = rfs_pathname((*exi)->exi_export.ex_index, NULL, vpp,
2833 2929 mc_dvp, cr, NATIVEPATH);
2834 2930
2835 2931 if (error == ENOENT) {
2836 2932 *vpp = tvp;
2837 2933 mc_dvp = tmc_dvp;
2838 2934 error = 0;
2839 2935 } else { /* ok or error other than ENOENT */
2840 2936 if (tmc_dvp)
2841 2937 VN_RELE(tmc_dvp);
2842 2938 if (error)
2843 2939 goto publicfh_done;
2844 2940
2845 2941 /*
2846 2942 * Found a valid vp for index "filename". Sanity check
2847 2943 * for odd case where a directory is provided as index
2848 2944 * option argument and leads us to another filesystem
2849 2945 */
2850 2946
2851 2947 /* Release the reference on the old exi value */
2852 2948 ASSERT(*exi != NULL);
2853 2949 exi_rele(*exi);
2854 2950
2855 2951 if (error = nfs_check_vpexi(mc_dvp, *vpp, kcred, exi)) {
2856 2952 VN_RELE(*vpp);
2857 2953 goto publicfh_done;
2858 2954 }
2859 2955 }
2860 2956 }
2861 2957
2862 2958 publicfh_done:
2863 2959 if (mc_dvp)
2864 2960 VN_RELE(mc_dvp);
2865 2961
2866 2962 return (error);
2867 2963 }
2868 2964
2869 2965 /*
2870 2966 * Evaluate a multi-component path
2871 2967 */
2872 2968 int
2873 2969 rfs_pathname(
2874 2970 char *path, /* pathname to evaluate */
2875 2971 vnode_t **dirvpp, /* ret for ptr to parent dir vnode */
2876 2972 vnode_t **compvpp, /* ret for ptr to component vnode */
2877 2973 vnode_t *startdvp, /* starting vnode */
2878 2974 cred_t *cr, /* user's credential */
2879 2975 int pathflag) /* flag to identify path, e.g. URL */
2880 2976 {
2881 2977 char namebuf[TYPICALMAXPATHLEN];
2882 2978 struct pathname pn;
2883 2979 int error;
2884 2980
2885 2981 /*
2886 2982 * If pathname starts with '/', then set startdvp to root.
2887 2983 */
2888 2984 if (*path == '/') {
2889 2985 while (*path == '/')
2890 2986 path++;
2891 2987
2892 2988 startdvp = ZONE_ROOTVP();
2893 2989 }
2894 2990
2895 2991 error = pn_get_buf(path, UIO_SYSSPACE, &pn, namebuf, sizeof (namebuf));
2896 2992 if (error == 0) {
2897 2993 /*
2898 2994 * Call the URL parser for URL paths to modify the original
2899 2995 * string to handle any '%' encoded characters that exist.
2900 2996 * Done here to avoid an extra bcopy in the lookup.
2901 2997 * We need to be careful about pathlen's. We know that
2902 2998 * rfs_pathname() is called with a non-empty path. However,
2903 2999 * it could be emptied due to the path simply being all /'s,
2904 3000 * which is valid to proceed with the lookup, or due to the
2905 3001 * URL parser finding an encoded null character at the
2906 3002 * beginning of path which should not proceed with the lookup.
2907 3003 */
2908 3004 if (pn.pn_pathlen != 0 && pathflag == URLPATH) {
2909 3005 URLparse(pn.pn_path);
2910 3006 if ((pn.pn_pathlen = strlen(pn.pn_path)) == 0)
2911 3007 return (ENOENT);
2912 3008 }
2913 3009 VN_HOLD(startdvp);
2914 3010 error = lookuppnvp(&pn, NULL, NO_FOLLOW, dirvpp, compvpp,
2915 3011 ZONE_ROOTVP(), startdvp, cr);
2916 3012 }
2917 3013 if (error == ENAMETOOLONG) {
2918 3014 /*
2919 3015 * This thread used a pathname > TYPICALMAXPATHLEN bytes long.
2920 3016 */
2921 3017 if (error = pn_get(path, UIO_SYSSPACE, &pn))
2922 3018 return (error);
2923 3019 if (pn.pn_pathlen != 0 && pathflag == URLPATH) {
2924 3020 URLparse(pn.pn_path);
2925 3021 if ((pn.pn_pathlen = strlen(pn.pn_path)) == 0) {
2926 3022 pn_free(&pn);
2927 3023 return (ENOENT);
2928 3024 }
2929 3025 }
2930 3026 VN_HOLD(startdvp);
2931 3027 error = lookuppnvp(&pn, NULL, NO_FOLLOW, dirvpp, compvpp,
2932 3028 ZONE_ROOTVP(), startdvp, cr);
2933 3029 pn_free(&pn);
2934 3030 }
2935 3031
2936 3032 return (error);
2937 3033 }
2938 3034
2939 3035 /*
2940 3036 * Adapt the multicomponent lookup path depending on the pathtype
2941 3037 */
2942 3038 static int
2943 3039 MCLpath(char **path)
2944 3040 {
2945 3041 unsigned char c = (unsigned char)**path;
2946 3042
2947 3043 /*
2948 3044 * If the MCL path is between 0x20 and 0x7E (graphic printable
2949 3045 * character of the US-ASCII coded character set), its a URL path,
2950 3046 * per RFC 1738.
2951 3047 */
2952 3048 if (c >= 0x20 && c <= 0x7E)
2953 3049 return (URLPATH);
2954 3050
2955 3051 /*
2956 3052 * If the first octet of the MCL path is not an ASCII character
2957 3053 * then it must be interpreted as a tag value that describes the
2958 3054 * format of the remaining octets of the MCL path.
2959 3055 *
2960 3056 * If the first octet of the MCL path is 0x81 it is a query
2961 3057 * for the security info.
2962 3058 */
2963 3059 switch (c) {
2964 3060 case 0x80: /* native path, i.e. MCL via mount protocol */
2965 3061 (*path)++;
2966 3062 return (NATIVEPATH);
2967 3063 case 0x81: /* security query */
2968 3064 (*path)++;
2969 3065 return (SECURITY_QUERY);
2970 3066 default:
2971 3067 return (-1);
2972 3068 }
2973 3069 }
2974 3070
2975 3071 #define fromhex(c) ((c >= '0' && c <= '9') ? (c - '0') : \
2976 3072 ((c >= 'A' && c <= 'F') ? (c - 'A' + 10) :\
2977 3073 ((c >= 'a' && c <= 'f') ? (c - 'a' + 10) : 0)))
2978 3074
2979 3075 /*
2980 3076 * The implementation of URLparse guarantees that the final string will
2981 3077 * fit in the original one. Replaces '%' occurrences followed by 2 characters
2982 3078 * with its corresponding hexadecimal character.
2983 3079 */
2984 3080 static void
2985 3081 URLparse(char *str)
2986 3082 {
2987 3083 char *p, *q;
2988 3084
2989 3085 p = q = str;
2990 3086 while (*p) {
2991 3087 *q = *p;
2992 3088 if (*p++ == '%') {
2993 3089 if (*p) {
2994 3090 *q = fromhex(*p) * 16;
2995 3091 p++;
2996 3092 if (*p) {
2997 3093 *q += fromhex(*p);
2998 3094 p++;
2999 3095 }
3000 3096 }
3001 3097 }
3002 3098 q++;
3003 3099 }
3004 3100 *q = '\0';
3005 3101 }
3006 3102
3007 3103
3008 3104 /*
3009 3105 * Get the export information for the lookup vnode, and verify its
3010 3106 * useable.
3011 3107 */
3012 3108 int
3013 3109 nfs_check_vpexi(vnode_t *mc_dvp, vnode_t *vp, cred_t *cr,
3014 3110 struct exportinfo **exi)
3015 3111 {
3016 3112 int walk;
3017 3113 int error = 0;
3018 3114
3019 3115 *exi = nfs_vptoexi(mc_dvp, vp, cr, &walk, NULL, FALSE);
3020 3116 if (*exi == NULL)
3021 3117 error = EACCES;
3022 3118 else {
3023 3119 /*
3024 3120 * If nosub is set for this export then
3025 3121 * a lookup relative to the public fh
3026 3122 * must not terminate below the
3027 3123 * exported directory.
3028 3124 */
3029 3125 if ((*exi)->exi_export.ex_flags & EX_NOSUB && walk > 0)
3030 3126 error = EACCES;
3031 3127 }
3032 3128
3033 3129 return (error);
3034 3130 }
3035 3131
3036 3132 /*
3037 3133 * Used by NFSv3 and NFSv4 server to query label of
3038 3134 * a pathname component during lookup/access ops.
3039 3135 */
3040 3136 ts_label_t *
3041 3137 nfs_getflabel(vnode_t *vp, struct exportinfo *exi)
3042 3138 {
3043 3139 zone_t *zone;
3044 3140 ts_label_t *zone_label;
3045 3141 char *path;
3046 3142
3047 3143 mutex_enter(&vp->v_lock);
3048 3144 if (vp->v_path != vn_vpath_empty) {
3049 3145 zone = zone_find_by_any_path(vp->v_path, B_FALSE);
3050 3146 mutex_exit(&vp->v_lock);
3051 3147 } else {
3052 3148 /*
3053 3149 * v_path not cached. Fall back on pathname of exported
3054 3150 * file system as we rely on pathname from which we can
3055 3151 * derive a label. The exported file system portion of
3056 3152 * path is sufficient to obtain a label.
3057 3153 */
3058 3154 path = exi->exi_export.ex_path;
3059 3155 if (path == NULL) {
3060 3156 mutex_exit(&vp->v_lock);
3061 3157 return (NULL);
3062 3158 }
3063 3159 zone = zone_find_by_any_path(path, B_FALSE);
3064 3160 mutex_exit(&vp->v_lock);
3065 3161 }
3066 3162 /*
3067 3163 * Caller has verified that the file is either
3068 3164 * exported or visible. So if the path falls in
3069 3165 * global zone, admin_low is returned; otherwise
3070 3166 * the zone's label is returned.
3071 3167 */
3072 3168 zone_label = zone->zone_slabel;
3073 3169 label_hold(zone_label);
3074 3170 zone_rele(zone);
3075 3171 return (zone_label);
3076 3172 }
3077 3173
3078 3174 /*
3079 3175 * TX NFS routine used by NFSv3 and NFSv4 to do label check
3080 3176 * on client label and server's file object lable.
3081 3177 */
3082 3178 boolean_t
3083 3179 do_rfs_label_check(bslabel_t *clabel, vnode_t *vp, int flag,
3084 3180 struct exportinfo *exi)
3085 3181 {
3086 3182 bslabel_t *slabel;
3087 3183 ts_label_t *tslabel;
3088 3184 boolean_t result;
3089 3185
3090 3186 if ((tslabel = nfs_getflabel(vp, exi)) == NULL) {
3091 3187 return (B_FALSE);
3092 3188 }
3093 3189 slabel = label2bslabel(tslabel);
3094 3190 DTRACE_PROBE4(tx__rfs__log__info__labelcheck, char *,
3095 3191 "comparing server's file label(1) with client label(2) (vp(3))",
3096 3192 bslabel_t *, slabel, bslabel_t *, clabel, vnode_t *, vp);
3097 3193
3098 3194 if (flag == EQUALITY_CHECK)
3099 3195 result = blequal(clabel, slabel);
3100 3196 else
3101 3197 result = bldominates(clabel, slabel);
3102 3198 label_rele(tslabel);
3103 3199 return (result);
3104 3200 }
3105 3201
3106 3202 /*
3107 3203 * Callback function to return the loaned buffers.
3108 3204 * Calls VOP_RETZCBUF() only after all uio_iov[]
3109 3205 * buffers are returned. nu_ref maintains the count.
3110 3206 */
3111 3207 void
3112 3208 rfs_free_xuio(void *free_arg)
3113 3209 {
3114 3210 uint_t ref;
3115 3211 nfs_xuio_t *nfsuiop = (nfs_xuio_t *)free_arg;
3116 3212
3117 3213 ref = atomic_dec_uint_nv(&nfsuiop->nu_ref);
3118 3214
3119 3215 /*
3120 3216 * Call VOP_RETZCBUF() only when all the iov buffers
3121 3217 * are sent OTW.
3122 3218 */
3123 3219 if (ref != 0)
3124 3220 return;
3125 3221
3126 3222 if (((uio_t *)nfsuiop)->uio_extflg & UIO_XUIO) {
3127 3223 (void) VOP_RETZCBUF(nfsuiop->nu_vp, (xuio_t *)free_arg, NULL,
3128 3224 NULL);
3129 3225 VN_RELE(nfsuiop->nu_vp);
3130 3226 }
3131 3227
3132 3228 kmem_cache_free(nfs_xuio_cache, free_arg);
3133 3229 }
3134 3230
3135 3231 xuio_t *
3136 3232 rfs_setup_xuio(vnode_t *vp)
3137 3233 {
3138 3234 nfs_xuio_t *nfsuiop;
3139 3235
3140 3236 nfsuiop = kmem_cache_alloc(nfs_xuio_cache, KM_SLEEP);
3141 3237
3142 3238 bzero(nfsuiop, sizeof (nfs_xuio_t));
3143 3239 nfsuiop->nu_vp = vp;
3144 3240
3145 3241 /*
3146 3242 * ref count set to 1. more may be added
3147 3243 * if multiple mblks refer to multiple iov's.
3148 3244 * This is done in uio_to_mblk().
3149 3245 */
3150 3246
3151 3247 nfsuiop->nu_ref = 1;
3152 3248
3153 3249 nfsuiop->nu_frtn.free_func = rfs_free_xuio;
3154 3250 nfsuiop->nu_frtn.free_arg = (char *)nfsuiop;
3155 3251
3156 3252 nfsuiop->nu_uio.xu_type = UIOTYPE_ZEROCOPY;
3157 3253
3158 3254 return (&nfsuiop->nu_uio);
3159 3255 }
3160 3256
3161 3257 mblk_t *
3162 3258 uio_to_mblk(uio_t *uiop)
3163 3259 {
3164 3260 struct iovec *iovp;
3165 3261 int i;
3166 3262 mblk_t *mp, *mp1;
3167 3263 nfs_xuio_t *nfsuiop = (nfs_xuio_t *)uiop;
3168 3264
3169 3265 if (uiop->uio_iovcnt == 0)
3170 3266 return (NULL);
3171 3267
3172 3268 iovp = uiop->uio_iov;
3173 3269 mp = mp1 = esballoca((uchar_t *)iovp->iov_base, iovp->iov_len,
3174 3270 BPRI_MED, &nfsuiop->nu_frtn);
3175 3271 ASSERT(mp != NULL);
3176 3272
3177 3273 mp->b_wptr += iovp->iov_len;
3178 3274 mp->b_datap->db_type = M_DATA;
3179 3275
3180 3276 for (i = 1; i < uiop->uio_iovcnt; i++) {
3181 3277 iovp = (uiop->uio_iov + i);
3182 3278
3183 3279 mp1->b_cont = esballoca(
3184 3280 (uchar_t *)iovp->iov_base, iovp->iov_len, BPRI_MED,
3185 3281 &nfsuiop->nu_frtn);
3186 3282
3187 3283 mp1 = mp1->b_cont;
3188 3284 ASSERT(mp1 != NULL);
3189 3285 mp1->b_wptr += iovp->iov_len;
3190 3286 mp1->b_datap->db_type = M_DATA;
3191 3287 }
3192 3288
3193 3289 nfsuiop->nu_ref = uiop->uio_iovcnt;
3194 3290
3195 3291 return (mp);
3196 3292 }
3197 3293
3198 3294 /*
3199 3295 * Allocate memory to hold data for a read request of len bytes.
3200 3296 *
3201 3297 * We don't allocate buffers greater than kmem_max_cached in size to avoid
3202 3298 * allocating memory from the kmem_oversized arena. If we allocate oversized
3203 3299 * buffers, we incur heavy cross-call activity when freeing these large buffers
3204 3300 * in the TCP receive path. Note that we can't set b_wptr here since the
3205 3301 * length of the data returned may differ from the length requested when
3206 3302 * reading the end of a file; we set b_wptr in rfs_rndup_mblks() once the
3207 3303 * length of the read is known.
3208 3304 */
3209 3305 mblk_t *
3210 3306 rfs_read_alloc(uint_t len, struct iovec **iov, int *iovcnt)
3211 3307 {
3212 3308 struct iovec *iovarr;
3213 3309 mblk_t *mp, **mpp = ∓
3214 3310 size_t mpsize;
3215 3311 uint_t remain = len;
3216 3312 int i, err = 0;
3217 3313
3218 3314 *iovcnt = howmany(len, kmem_max_cached);
3219 3315
3220 3316 iovarr = kmem_alloc(*iovcnt * sizeof (struct iovec), KM_SLEEP);
3221 3317 *iov = iovarr;
3222 3318
3223 3319 for (i = 0; i < *iovcnt; remain -= mpsize, i++) {
3224 3320 ASSERT(remain <= len);
3225 3321 /*
3226 3322 * We roundup the size we allocate to a multiple of
3227 3323 * BYTES_PER_XDR_UNIT (4 bytes) so that the call to
3228 3324 * xdrmblk_putmblk() never fails.
3229 3325 */
3230 3326 ASSERT(kmem_max_cached % BYTES_PER_XDR_UNIT == 0);
3231 3327 mpsize = MIN(kmem_max_cached, remain);
3232 3328 *mpp = allocb_wait(RNDUP(mpsize), BPRI_MED, STR_NOSIG, &err);
3233 3329 ASSERT(*mpp != NULL);
3234 3330 ASSERT(err == 0);
3235 3331
3236 3332 iovarr[i].iov_base = (caddr_t)(*mpp)->b_rptr;
3237 3333 iovarr[i].iov_len = mpsize;
3238 3334 mpp = &(*mpp)->b_cont;
3239 3335 }
3240 3336 return (mp);
3241 3337 }
3242 3338
3243 3339 void
3244 3340 rfs_rndup_mblks(mblk_t *mp, uint_t len, int buf_loaned)
3245 3341 {
3246 3342 int i;
3247 3343 int alloc_err = 0;
3248 3344 mblk_t *rmp;
3249 3345 uint_t mpsize, remainder;
3250 3346
3251 3347 remainder = P2NPHASE(len, BYTES_PER_XDR_UNIT);
3252 3348
3253 3349 /*
3254 3350 * Non copy-reduction case. This function assumes that blocks were
3255 3351 * allocated in multiples of BYTES_PER_XDR_UNIT bytes, which makes this
3256 3352 * padding safe without bounds checking.
3257 3353 */
3258 3354 if (!buf_loaned) {
3259 3355 /*
3260 3356 * Set the size of each mblk in the chain until we've consumed
3261 3357 * the specified length for all but the last one.
3262 3358 */
3263 3359 while ((mpsize = MBLKSIZE(mp)) < len) {
3264 3360 ASSERT(mpsize % BYTES_PER_XDR_UNIT == 0);
3265 3361 mp->b_wptr += mpsize;
3266 3362 len -= mpsize;
3267 3363 mp = mp->b_cont;
3268 3364 ASSERT(mp != NULL);
3269 3365 }
3270 3366
3271 3367 ASSERT(len + remainder <= mpsize);
3272 3368 mp->b_wptr += len;
3273 3369 for (i = 0; i < remainder; i++)
3274 3370 *mp->b_wptr++ = '\0';
3275 3371 return;
3276 3372 }
3277 3373
3278 3374 /*
3279 3375 * No remainder mblk required.
3280 3376 */
3281 3377 if (remainder == 0)
3282 3378 return;
3283 3379
3284 3380 /*
3285 3381 * Get to the last mblk in the chain.
3286 3382 */
3287 3383 while (mp->b_cont != NULL)
3288 3384 mp = mp->b_cont;
3289 3385
3290 3386 /*
3291 3387 * In case of copy-reduction mblks, the size of the mblks are fixed
3292 3388 * and are of the size of the loaned buffers. Allocate a remainder
3293 3389 * mblk and chain it to the data buffers. This is sub-optimal, but not
3294 3390 * expected to happen commonly.
3295 3391 */
3296 3392 rmp = allocb_wait(remainder, BPRI_MED, STR_NOSIG, &alloc_err);
3297 3393 ASSERT(rmp != NULL);
3298 3394 ASSERT(alloc_err == 0);
3299 3395
3300 3396 for (i = 0; i < remainder; i++)
3301 3397 *rmp->b_wptr++ = '\0';
3302 3398
3303 3399 rmp->b_datap->db_type = M_DATA;
3304 3400 mp->b_cont = rmp;
3305 3401 }
|
↓ open down ↓ |
690 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX