Print this page
Try to remove assumption that zone's root vnode is marked VROOT
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/nfs/nfs_export.c
+++ new/usr/src/uts/common/fs/nfs/nfs_export.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 /*
23 23 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 /*
27 27 * Copyright 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T.
28 28 * All rights reserved.
29 29 */
30 30
31 31 /*
32 32 * Copyright 2018 Nexenta Systems, Inc.
33 33 */
34 34
35 35 #include <sys/types.h>
36 36 #include <sys/param.h>
37 37 #include <sys/time.h>
38 38 #include <sys/vfs.h>
39 39 #include <sys/vnode.h>
40 40 #include <sys/socket.h>
41 41 #include <sys/errno.h>
42 42 #include <sys/uio.h>
43 43 #include <sys/proc.h>
44 44 #include <sys/user.h>
45 45 #include <sys/file.h>
46 46 #include <sys/tiuser.h>
47 47 #include <sys/kmem.h>
48 48 #include <sys/pathname.h>
49 49 #include <sys/debug.h>
50 50 #include <sys/vtrace.h>
51 51 #include <sys/cmn_err.h>
52 52 #include <sys/acl.h>
53 53 #include <sys/utsname.h>
54 54 #include <sys/sdt.h>
55 55 #include <netinet/in.h>
56 56 #include <sys/avl.h>
57 57
58 58 #include <rpc/types.h>
59 59 #include <rpc/auth.h>
60 60 #include <rpc/svc.h>
61 61
62 62 #include <nfs/nfs.h>
63 63 #include <nfs/export.h>
64 64 #include <nfs/nfssys.h>
65 65 #include <nfs/nfs_clnt.h>
66 66 #include <nfs/nfs_acl.h>
67 67 #include <nfs/nfs_log.h>
68 68 #include <nfs/lm.h>
69 69 #include <sys/sunddi.h>
70 70
71 71 static zone_key_t nfs_export_key;
72 72
73 73 /*
74 74 * exi_id support
75 75 *
76 76 * exi_id_next The next exi_id available.
77 77 * exi_id_overflow The exi_id_next already overflowed, so we should
78 78 * thoroughly check for duplicates.
79 79 * exi_id_tree AVL tree indexed by exi_id.
80 80 * nfs_exi_id_lock Lock to protect the export ID list
81 81 *
82 82 * All exi_id_next, exi_id_overflow, and exi_id_tree are protected by
83 83 * nfs_exi_id_lock.
84 84 */
85 85 static int exi_id_next;
86 86 static bool_t exi_id_overflow;
87 87 avl_tree_t exi_id_tree;
88 88 kmutex_t nfs_exi_id_lock;
89 89
90 90 static int unexport(nfs_export_t *, exportinfo_t *);
91 91 static void exportfree(exportinfo_t *);
92 92 static int loadindex(exportdata_t *);
93 93
94 94 extern void nfsauth_cache_free(exportinfo_t *);
95 95 extern int sec_svc_loadrootnames(int, int, caddr_t **, model_t);
96 96 extern void sec_svc_freerootnames(int, int, caddr_t *);
97 97
98 98 static int build_seclist_nodups(exportdata_t *, secinfo_t *, int);
99 99 static void srv_secinfo_add(secinfo_t **, int *, secinfo_t *, int, int);
100 100 static void srv_secinfo_remove(secinfo_t **, int *, secinfo_t *, int);
101 101 static void srv_secinfo_treeclimb(nfs_export_t *, exportinfo_t *,
102 102 secinfo_t *, int, bool_t);
103 103
104 104 #ifdef VOLATILE_FH_TEST
105 105 static struct ex_vol_rename *find_volrnm_fh(exportinfo_t *, nfs_fh4 *);
106 106 static uint32_t find_volrnm_fh_id(exportinfo_t *, nfs_fh4 *);
107 107 static void free_volrnm_list(exportinfo_t *);
108 108 #endif /* VOLATILE_FH_TEST */
109 109
110 110 fhandle_t nullfh2; /* for comparing V2 filehandles */
111 111
112 112 /*
113 113 * macro for static dtrace probes to trace server namespace ref count mods.
114 114 */
115 115 #define SECREF_TRACE(seclist, tag, flav, aftcnt) \
116 116 DTRACE_PROBE4(nfss__i__nmspc__secref, struct secinfo *, (seclist), \
117 117 char *, (tag), int, (int)(flav), int, (int)(aftcnt))
118 118
119 119
120 120 #define exptablehash(fsid, fid) (nfs_fhhash((fsid), (fid)) & (EXPTABLESIZE - 1))
121 121
122 122 extern nfs_export_t *
123 123 nfs_get_export(void)
124 124 {
125 125 return (zone_getspecific(nfs_export_key, curzone));
126 126 }
127 127
128 128 static uint8_t
129 129 xor_hash(uint8_t *data, int len)
130 130 {
131 131 uint8_t h = 0;
132 132
133 133 while (len--)
134 134 h ^= *data++;
135 135
136 136 return (h);
137 137 }
138 138
139 139 /*
140 140 * File handle hash function, XOR over all bytes in fsid and fid.
141 141 */
142 142 static unsigned
143 143 nfs_fhhash(fsid_t *fsid, fid_t *fid)
144 144 {
145 145 int len;
146 146 uint8_t h;
147 147
148 148 h = xor_hash((uint8_t *)fsid, sizeof (fsid_t));
149 149
150 150 /*
151 151 * Sanity check the length before using it
152 152 * blindly in case the client trashed it.
153 153 */
154 154 len = fid->fid_len > NFS_FH4MAXDATA ? 0 : fid->fid_len;
155 155 h ^= xor_hash((uint8_t *)fid->fid_data, len);
156 156
157 157 return ((unsigned)h);
158 158 }
159 159
160 160 /*
161 161 * Free the memory allocated within a secinfo entry.
162 162 */
163 163 void
164 164 srv_secinfo_entry_free(struct secinfo *secp)
165 165 {
166 166 if (secp->s_rootcnt > 0 && secp->s_rootnames != NULL) {
167 167 sec_svc_freerootnames(secp->s_secinfo.sc_rpcnum,
168 168 secp->s_rootcnt, secp->s_rootnames);
169 169 secp->s_rootcnt = 0;
170 170 }
171 171
172 172 if ((secp->s_secinfo.sc_rpcnum == RPCSEC_GSS) &&
173 173 (secp->s_secinfo.sc_gss_mech_type)) {
174 174 kmem_free(secp->s_secinfo.sc_gss_mech_type->elements,
175 175 secp->s_secinfo.sc_gss_mech_type->length);
176 176 kmem_free(secp->s_secinfo.sc_gss_mech_type,
177 177 sizeof (rpc_gss_OID_desc));
178 178 secp->s_secinfo.sc_gss_mech_type = NULL;
179 179 }
180 180 }
181 181
182 182 /*
183 183 * Free a list of secinfo allocated in the exportdata structure.
184 184 */
185 185 void
186 186 srv_secinfo_list_free(struct secinfo *secinfo, int cnt)
187 187 {
188 188 int i;
189 189
190 190 if (cnt == 0)
191 191 return;
192 192
193 193 for (i = 0; i < cnt; i++)
194 194 srv_secinfo_entry_free(&secinfo[i]);
195 195
196 196 kmem_free(secinfo, cnt * sizeof (struct secinfo));
197 197 }
198 198
199 199 /*
200 200 * Allocate and copy a secinfo data from "from" to "to".
201 201 *
202 202 * This routine is used by srv_secinfo_add() to add a new flavor to an
203 203 * ancestor's export node. The rootnames are not copied because the
204 204 * allowable rootname access only applies to the explicit exported node,
205 205 * not its ancestor's.
206 206 *
207 207 * "to" should have already been allocated and zeroed before calling
208 208 * this routine.
209 209 *
210 210 * This routine is used under the protection of exported_lock (RW_WRITER).
211 211 */
212 212 void
213 213 srv_secinfo_copy(struct secinfo *from, struct secinfo *to)
214 214 {
215 215 to->s_secinfo.sc_nfsnum = from->s_secinfo.sc_nfsnum;
216 216 to->s_secinfo.sc_rpcnum = from->s_secinfo.sc_rpcnum;
217 217
218 218 if (from->s_secinfo.sc_rpcnum == RPCSEC_GSS) {
219 219 to->s_secinfo.sc_service = from->s_secinfo.sc_service;
220 220 bcopy(from->s_secinfo.sc_name, to->s_secinfo.sc_name,
221 221 strlen(from->s_secinfo.sc_name));
222 222 bcopy(from->s_secinfo.sc_gss_mech, to->s_secinfo.sc_gss_mech,
223 223 strlen(from->s_secinfo.sc_gss_mech));
224 224
225 225 /* copy mechanism oid */
226 226 to->s_secinfo.sc_gss_mech_type =
227 227 kmem_alloc(sizeof (rpc_gss_OID_desc), KM_SLEEP);
228 228 to->s_secinfo.sc_gss_mech_type->length =
229 229 from->s_secinfo.sc_gss_mech_type->length;
230 230 to->s_secinfo.sc_gss_mech_type->elements =
231 231 kmem_alloc(from->s_secinfo.sc_gss_mech_type->length,
232 232 KM_SLEEP);
233 233 bcopy(from->s_secinfo.sc_gss_mech_type->elements,
234 234 to->s_secinfo.sc_gss_mech_type->elements,
235 235 from->s_secinfo.sc_gss_mech_type->length);
236 236 }
237 237
238 238 to->s_refcnt = from->s_refcnt;
239 239 to->s_window = from->s_window;
240 240 /* no need to copy the mode bits - s_flags */
241 241 }
242 242
243 243 /*
244 244 * Create a secinfo array without duplicates. The condensed
245 245 * flavor list is used to propagate flavor ref counts to an
246 246 * export's ancestor pseudonodes.
247 247 */
248 248 static int
249 249 build_seclist_nodups(exportdata_t *exd, secinfo_t *nodups, int exponly)
250 250 {
251 251 int ccnt, c;
252 252 int ncnt, n;
253 253 struct secinfo *cursec;
254 254
255 255 ncnt = 0;
256 256 ccnt = exd->ex_seccnt;
257 257 cursec = exd->ex_secinfo;
258 258
259 259 for (c = 0; c < ccnt; c++) {
260 260
261 261 if (exponly && ! SEC_REF_EXPORTED(&cursec[c]))
262 262 continue;
263 263
264 264 for (n = 0; n < ncnt; n++) {
265 265 if (nodups[n].s_secinfo.sc_nfsnum ==
266 266 cursec[c].s_secinfo.sc_nfsnum)
267 267 break;
268 268 }
269 269
270 270 /*
271 271 * The structure copy below also copys ptrs embedded
272 272 * within struct secinfo. The ptrs are copied but
273 273 * they are never freed from the nodups array. If
274 274 * an ancestor's secinfo array doesn't contain one
275 275 * of the nodups flavors, then the entry is properly
276 276 * copied into the ancestor's secinfo array.
277 277 * (see srv_secinfo_copy)
278 278 */
279 279 if (n == ncnt) {
280 280 nodups[n] = cursec[c];
281 281 ncnt++;
282 282 }
283 283 }
284 284 return (ncnt);
285 285 }
286 286
287 287 /*
288 288 * Add the new security flavors from newdata to the current list, pcursec.
289 289 * Upon return, *pcursec has the newly merged secinfo list.
290 290 *
291 291 * There should be at least 1 secinfo entry in newsec.
292 292 *
293 293 * This routine is used under the protection of exported_lock (RW_WRITER).
294 294 */
295 295 static void
296 296 srv_secinfo_add(secinfo_t **pcursec, int *pcurcnt, secinfo_t *newsec,
297 297 int newcnt, int is_pseudo)
298 298 {
299 299 int ccnt, c; /* sec count in current data - curdata */
300 300 int n; /* index for newsec - newsecinfo */
301 301 int tcnt; /* total sec count after merge */
302 302 int mcnt; /* total sec count after merge */
303 303 struct secinfo *msec; /* merged secinfo list */
304 304 struct secinfo *cursec;
305 305
306 306 cursec = *pcursec;
307 307 ccnt = *pcurcnt;
308 308
309 309 ASSERT(newcnt > 0);
310 310 tcnt = ccnt + newcnt;
311 311
312 312 for (n = 0; n < newcnt; n++) {
313 313 for (c = 0; c < ccnt; c++) {
314 314 if (newsec[n].s_secinfo.sc_nfsnum ==
315 315 cursec[c].s_secinfo.sc_nfsnum) {
316 316 cursec[c].s_refcnt += newsec[n].s_refcnt;
317 317 SECREF_TRACE(cursec, "add_ref",
318 318 cursec[c].s_secinfo.sc_nfsnum,
319 319 cursec[c].s_refcnt);
320 320 tcnt--;
321 321 break;
322 322 }
323 323 }
324 324 }
325 325
326 326 if (tcnt == ccnt)
327 327 return; /* no change; no new flavors */
328 328
329 329 msec = kmem_zalloc(tcnt * sizeof (struct secinfo), KM_SLEEP);
330 330
331 331 /* move current secinfo list data to the new list */
332 332 for (c = 0; c < ccnt; c++)
333 333 msec[c] = cursec[c];
334 334
335 335 /* Add the flavor that's not in the current data */
336 336 mcnt = ccnt;
337 337 for (n = 0; n < newcnt; n++) {
338 338 for (c = 0; c < ccnt; c++) {
339 339 if (newsec[n].s_secinfo.sc_nfsnum ==
340 340 cursec[c].s_secinfo.sc_nfsnum)
341 341 break;
342 342 }
343 343
344 344 /* This is the one. Add it. */
345 345 if (c == ccnt) {
346 346 srv_secinfo_copy(&newsec[n], &msec[mcnt]);
347 347
348 348 if (is_pseudo)
349 349 msec[mcnt].s_flags = M_RO;
350 350
351 351 SECREF_TRACE(msec, "new_ref",
352 352 msec[mcnt].s_secinfo.sc_nfsnum,
353 353 msec[mcnt].s_refcnt);
354 354 mcnt++;
355 355 }
356 356 }
357 357
358 358 ASSERT(mcnt == tcnt);
359 359
360 360 /*
361 361 * Done. Update curdata. Free the old secinfo list in
362 362 * curdata and return the new sec array info
363 363 */
364 364 if (ccnt > 0)
365 365 kmem_free(cursec, ccnt * sizeof (struct secinfo));
366 366 *pcurcnt = tcnt;
367 367 *pcursec = msec;
368 368 }
369 369
370 370 /*
371 371 * For NFS V4.
372 372 * Remove the security data of the unexported node from its ancestors.
373 373 * Assume there is at least one flavor entry in the current sec list
374 374 * (pcursec).
375 375 *
376 376 * This routine is used under the protection of exported_lock (RW_WRITER).
377 377 *
378 378 * Every element of remsec is an explicitly exported flavor. If
379 379 * srv_secinfo_remove() is called fom an exportfs error path, then
380 380 * the flavor list was derived from the user's share cmdline,
381 381 * and all flavors are explicit. If it was called from the unshare path,
382 382 * build_seclist_nodups() was called with the exponly flag.
383 383 */
384 384 static void
385 385 srv_secinfo_remove(secinfo_t **pcursec, int *pcurcnt, secinfo_t *remsec,
386 386 int remcnt)
387 387 {
388 388 int ccnt, c; /* sec count in current data - cursec */
389 389 int r; /* sec count in removal data - remsec */
390 390 int tcnt, mcnt; /* total sec count after removing */
391 391 struct secinfo *msec; /* final secinfo list after removing */
392 392 struct secinfo *cursec;
393 393
394 394 cursec = *pcursec;
395 395 ccnt = *pcurcnt;
396 396 tcnt = ccnt;
397 397
398 398 for (r = 0; r < remcnt; r++) {
399 399 /*
400 400 * At unshare/reshare time, only explicitly shared flavor ref
401 401 * counts are decremented and propagated to ancestors.
402 402 * Implicit flavor refs came from shared descendants, and
403 403 * they must be kept.
404 404 */
405 405 if (! SEC_REF_EXPORTED(&remsec[r]))
406 406 continue;
407 407
408 408 for (c = 0; c < ccnt; c++) {
409 409 if (remsec[r].s_secinfo.sc_nfsnum ==
410 410 cursec[c].s_secinfo.sc_nfsnum) {
411 411
412 412 /*
413 413 * Decrement secinfo reference count by 1.
414 414 * If this entry is invalid after decrementing
415 415 * the count (i.e. count < 1), this entry will
416 416 * be removed.
417 417 */
418 418 cursec[c].s_refcnt--;
419 419
420 420 SECREF_TRACE(cursec, "del_ref",
421 421 cursec[c].s_secinfo.sc_nfsnum,
422 422 cursec[c].s_refcnt);
423 423
424 424 ASSERT(cursec[c].s_refcnt >= 0);
425 425
426 426 if (SEC_REF_INVALID(&cursec[c]))
427 427 tcnt--;
428 428 break;
429 429 }
430 430 }
431 431 }
432 432
433 433 ASSERT(tcnt >= 0);
434 434 if (tcnt == ccnt)
435 435 return; /* no change; no flavors to remove */
436 436
437 437 if (tcnt == 0) {
438 438 srv_secinfo_list_free(cursec, ccnt);
439 439 *pcurcnt = 0;
440 440 *pcursec = NULL;
441 441 return;
442 442 }
443 443
444 444 msec = kmem_zalloc(tcnt * sizeof (struct secinfo), KM_SLEEP);
445 445
446 446 /* walk thru the given secinfo list to remove the flavors */
447 447 mcnt = 0;
448 448 for (c = 0; c < ccnt; c++) {
449 449 if (SEC_REF_INVALID(&cursec[c])) {
450 450 srv_secinfo_entry_free(&cursec[c]);
451 451 } else {
452 452 msec[mcnt] = cursec[c];
453 453 mcnt++;
454 454 }
455 455 }
456 456
457 457 ASSERT(mcnt == tcnt);
458 458 /*
459 459 * Done. Update curdata.
460 460 * Free the existing secinfo list in curdata. All pointers
461 461 * within the list have either been moved to msec or freed
462 462 * if it's invalid.
463 463 */
464 464 kmem_free(*pcursec, ccnt * sizeof (struct secinfo));
465 465 *pcursec = msec;
466 466 *pcurcnt = tcnt;
467 467 }
468 468
469 469
470 470 /*
471 471 * For the reshare case, sec flavor accounting happens in 3 steps:
472 472 * 1) propagate addition of new flavor refs up the ancestor tree
473 473 * 2) transfer flavor refs of descendants to new/reshared exportdata
474 474 * 3) propagate removal of old flavor refs up the ancestor tree
475 475 *
476 476 * srv_secinfo_exp2exp() implements step 2 of a reshare. At this point,
477 477 * the new flavor list has already been propagated up through the
478 478 * ancestor tree via srv_secinfo_treeclimb().
479 479 *
480 480 * If there is more than 1 export reference to an old flavor (i.e. some
481 481 * of its children shared with this flavor), this flavor information
482 482 * needs to be transferred to the new exportdata struct. A flavor in
483 483 * the old exportdata has descendant refs when its s_refcnt > 1 or it
484 484 * is implicitly shared (M_SEC4_EXPORTED not set in s_flags).
485 485 *
486 486 * SEC_REF_EXPORTED() is only true when M_SEC4_EXPORTED is set
487 487 * SEC_REF_SELF() is only true when both M_SEC4_EXPORTED is set and s_refcnt==1
488 488 *
489 489 * Transferring descendant flavor refcnts happens in 2 passes:
490 490 * a) flavors used before (oldsecinfo) and after (curdata->ex_secinfo) reshare
491 491 * b) flavors used before but not after reshare
492 492 *
493 493 * This routine is used under the protection of exported_lock (RW_WRITER).
494 494 */
495 495 void
496 496 srv_secinfo_exp2exp(exportdata_t *curdata, secinfo_t *oldsecinfo, int ocnt)
497 497 {
498 498 int ccnt, c; /* sec count in current data - curdata */
499 499 int o; /* sec count in old data - oldsecinfo */
500 500 int tcnt, mcnt; /* total sec count after the transfer */
501 501 struct secinfo *msec; /* merged secinfo list */
502 502
503 503 ccnt = curdata->ex_seccnt;
504 504
505 505 ASSERT(ocnt > 0);
506 506 ASSERT(!(curdata->ex_flags & EX_PSEUDO));
507 507
508 508 /*
509 509 * If the oldsecinfo has flavors with more than 1 reference count
510 510 * and the flavor is specified in the reshare, transfer the flavor
511 511 * refs to the new seclist (curdata.ex_secinfo).
512 512 */
513 513 tcnt = ccnt + ocnt;
514 514
515 515 for (o = 0; o < ocnt; o++) {
516 516
517 517 if (SEC_REF_SELF(&oldsecinfo[o])) {
518 518 tcnt--;
519 519 continue;
520 520 }
521 521
522 522 for (c = 0; c < ccnt; c++) {
523 523 if (oldsecinfo[o].s_secinfo.sc_nfsnum ==
524 524 curdata->ex_secinfo[c].s_secinfo.sc_nfsnum) {
525 525
526 526 /*
527 527 * add old reference to the current
528 528 * secinfo count
529 529 */
530 530 curdata->ex_secinfo[c].s_refcnt +=
531 531 oldsecinfo[o].s_refcnt;
532 532
533 533 /*
534 534 * Delete the old export flavor
535 535 * reference. The initial reference
536 536 * was created during srv_secinfo_add,
537 537 * and the count is decremented below
538 538 * to account for the initial reference.
539 539 */
540 540 if (SEC_REF_EXPORTED(&oldsecinfo[o]))
541 541 curdata->ex_secinfo[c].s_refcnt--;
542 542
543 543 SECREF_TRACE(curdata->ex_path,
544 544 "reshare_xfer_common_child_refs",
545 545 curdata->ex_secinfo[c].s_secinfo.sc_nfsnum,
546 546 curdata->ex_secinfo[c].s_refcnt);
547 547
548 548 ASSERT(curdata->ex_secinfo[c].s_refcnt >= 0);
549 549
550 550 tcnt--;
551 551 break;
552 552 }
553 553 }
554 554 }
555 555
556 556 if (tcnt == ccnt)
557 557 return; /* no more transfer to do */
558 558
559 559 /*
560 560 * oldsecinfo has flavors referenced by its children that are not
561 561 * in the current (new) export flavor list. Add these flavors.
562 562 */
563 563 msec = kmem_zalloc(tcnt * sizeof (struct secinfo), KM_SLEEP);
564 564
565 565 /* move current secinfo list data to the new list */
566 566 for (c = 0; c < ccnt; c++)
567 567 msec[c] = curdata->ex_secinfo[c];
568 568
569 569 /*
570 570 * Add the flavor that's not in the new export, but still
571 571 * referenced by its children.
572 572 */
573 573 mcnt = ccnt;
574 574 for (o = 0; o < ocnt; o++) {
575 575 if (! SEC_REF_SELF(&oldsecinfo[o])) {
576 576 for (c = 0; c < ccnt; c++) {
577 577 if (oldsecinfo[o].s_secinfo.sc_nfsnum ==
578 578 curdata->ex_secinfo[c].s_secinfo.sc_nfsnum)
579 579 break;
580 580 }
581 581
582 582 /*
583 583 * This is the one. Add it. Decrement the ref count
584 584 * by 1 if the flavor is an explicitly shared flavor
585 585 * for the oldsecinfo export node.
586 586 */
587 587 if (c == ccnt) {
588 588 srv_secinfo_copy(&oldsecinfo[o], &msec[mcnt]);
589 589 if (SEC_REF_EXPORTED(&oldsecinfo[o]))
590 590 msec[mcnt].s_refcnt--;
591 591
592 592 SECREF_TRACE(curdata,
593 593 "reshare_xfer_implicit_child_refs",
594 594 msec[mcnt].s_secinfo.sc_nfsnum,
595 595 msec[mcnt].s_refcnt);
596 596
597 597 ASSERT(msec[mcnt].s_refcnt >= 0);
598 598 mcnt++;
599 599 }
600 600 }
601 601 }
602 602
603 603 ASSERT(mcnt == tcnt);
604 604 /*
605 605 * Done. Update curdata, free the existing secinfo list in
606 606 * curdata and set the new value.
607 607 */
608 608 if (ccnt > 0)
609 609 kmem_free(curdata->ex_secinfo, ccnt * sizeof (struct secinfo));
610 610 curdata->ex_seccnt = tcnt;
611 611 curdata->ex_secinfo = msec;
612 612 }
613 613
614 614 /*
615 615 * When unsharing an old export node and the old node becomes a pseudo node,
616 616 * if there is more than 1 export reference to an old flavor (i.e. some of
617 617 * its children shared with this flavor), this flavor information needs to
618 618 * be transferred to the new shared node.
619 619 *
620 620 * This routine is used under the protection of exported_lock (RW_WRITER).
621 621 */
622 622 void
623 623 srv_secinfo_exp2pseu(exportdata_t *curdata, exportdata_t *olddata)
624 624 {
625 625 int ocnt, o; /* sec count in transfer data - trandata */
626 626 int tcnt, mcnt; /* total sec count after transfer */
627 627 struct secinfo *msec; /* merged secinfo list */
628 628
629 629 ASSERT(curdata->ex_flags & EX_PSEUDO);
630 630 ASSERT(curdata->ex_seccnt == 0);
631 631
632 632 ocnt = olddata->ex_seccnt;
633 633
634 634 /*
635 635 * If the olddata has flavors with more than 1 reference count,
636 636 * transfer the information to the curdata.
637 637 */
638 638 tcnt = ocnt;
639 639
640 640 for (o = 0; o < ocnt; o++) {
641 641 if (SEC_REF_SELF(&olddata->ex_secinfo[o]))
642 642 tcnt--;
643 643 }
644 644
645 645 if (tcnt == 0)
646 646 return; /* no transfer to do */
647 647
648 648 msec = kmem_zalloc(tcnt * sizeof (struct secinfo), KM_SLEEP);
649 649
650 650 mcnt = 0;
651 651 for (o = 0; o < ocnt; o++) {
652 652 if (! SEC_REF_SELF(&olddata->ex_secinfo[o])) {
653 653
654 654 /*
655 655 * Decrement the reference count by 1 if the flavor is
656 656 * an explicitly shared flavor for the olddata export
657 657 * node.
658 658 */
659 659 srv_secinfo_copy(&olddata->ex_secinfo[o], &msec[mcnt]);
660 660 msec[mcnt].s_flags = M_RO;
661 661 if (SEC_REF_EXPORTED(&olddata->ex_secinfo[o]))
662 662 msec[mcnt].s_refcnt--;
663 663
664 664 SECREF_TRACE(curdata, "unshare_morph_pseudo",
665 665 msec[mcnt].s_secinfo.sc_nfsnum,
666 666 msec[mcnt].s_refcnt);
667 667
668 668 ASSERT(msec[mcnt].s_refcnt >= 0);
669 669 mcnt++;
670 670 }
671 671 }
672 672
673 673 ASSERT(mcnt == tcnt);
674 674 /*
675 675 * Done. Update curdata.
676 676 * Free up the existing secinfo list in curdata and
677 677 * set the new value.
678 678 */
679 679 curdata->ex_seccnt = tcnt;
680 680 curdata->ex_secinfo = msec;
681 681 }
682 682
683 683 /*
684 684 * Find for given treenode the exportinfo which has its
685 685 * exp_visible linked on its exi_visible list.
686 686 *
687 687 * Note: We could add new pointer either to treenode or
688 688 * to exp_visible, which will point there directly.
689 689 * This would buy some speed for some memory.
690 690 */
691 691 exportinfo_t *
692 692 vis2exi(treenode_t *tnode)
693 693 {
694 694 exportinfo_t *exi_ret = NULL;
695 695
696 696 for (;;) {
697 697 tnode = tnode->tree_parent;
698 698 if (TREE_ROOT(tnode)) {
699 699 exi_ret = tnode->tree_exi;
700 700 break;
701 701 }
702 702 }
703 703
704 704 ASSERT(exi_ret); /* Every visible should have its home exportinfo */
705 705 return (exi_ret);
706 706 }
707 707
708 708 /*
709 709 * For NFS V4.
710 710 * Add or remove the newly exported or unexported security flavors of the
711 711 * given exportinfo from its ancestors upto the system root.
712 712 */
713 713 void
714 714 srv_secinfo_treeclimb(nfs_export_t *ne, exportinfo_t *exip, secinfo_t *sec,
715 715 int seccnt, bool_t isadd)
716 716 {
717 717 treenode_t *tnode = exip->exi_tree;
718 718
719 719 ASSERT(RW_WRITE_HELD(&ne->exported_lock));
720 720 ASSERT(tnode != NULL);
721 721
722 722 if (seccnt == 0)
|
↓ open down ↓ |
722 lines elided |
↑ open up ↑ |
723 723 return;
724 724
725 725 /*
726 726 * If flavors are being added and the new export root isn't
727 727 * also VROOT, its implicitly allowed flavors are inherited from
728 728 * its pseudonode.
729 729 * Note - for VROOT exports the implicitly allowed flavors were
730 730 * transferred from the PSEUDO export in exportfs()
731 731 */
732 732 if (isadd && !(exip->exi_vp->v_flag & VROOT) &&
733 + !VN_IS_CURZONEROOT(exip->exi_vp) &&
733 734 tnode->tree_vis->vis_seccnt > 0) {
734 735 srv_secinfo_add(&exip->exi_export.ex_secinfo,
735 736 &exip->exi_export.ex_seccnt, tnode->tree_vis->vis_secinfo,
736 737 tnode->tree_vis->vis_seccnt, FALSE);
737 738 }
738 739
739 740 /*
740 741 * Move to parent node and propagate sec flavor
741 742 * to exportinfo and to visible structures.
742 743 */
743 744 tnode = tnode->tree_parent;
744 745
745 746 while (tnode != NULL) {
746 747
747 748 /* If there is exportinfo, update it */
748 749 if (tnode->tree_exi != NULL) {
749 750 secinfo_t **pxsec =
750 751 &tnode->tree_exi->exi_export.ex_secinfo;
751 752 int *pxcnt = &tnode->tree_exi->exi_export.ex_seccnt;
752 753 int is_pseudo = PSEUDO(tnode->tree_exi);
753 754 if (isadd)
754 755 srv_secinfo_add(pxsec, pxcnt, sec, seccnt,
755 756 is_pseudo);
756 757 else
757 758 srv_secinfo_remove(pxsec, pxcnt, sec, seccnt);
758 759 }
759 760
760 761 /* Update every visible - only root node has no visible */
761 762 if (tnode->tree_vis != NULL) {
762 763 secinfo_t **pxsec = &tnode->tree_vis->vis_secinfo;
763 764 int *pxcnt = &tnode->tree_vis->vis_seccnt;
764 765 if (isadd)
765 766 srv_secinfo_add(pxsec, pxcnt, sec, seccnt,
766 767 FALSE);
767 768 else
768 769 srv_secinfo_remove(pxsec, pxcnt, sec, seccnt);
769 770 }
770 771 tnode = tnode->tree_parent;
771 772 }
772 773 }
773 774
774 775 /* hash_name is a text substitution for either fid_hash or path_hash */
775 776 #define exp_hash_unlink(exi, hash_name) \
776 777 if (*(exi)->hash_name.bckt == (exi)) \
777 778 *(exi)->hash_name.bckt = (exi)->hash_name.next; \
778 779 if ((exi)->hash_name.prev) \
779 780 (exi)->hash_name.prev->hash_name.next = (exi)->hash_name.next; \
780 781 if ((exi)->hash_name.next) \
781 782 (exi)->hash_name.next->hash_name.prev = (exi)->hash_name.prev; \
782 783 (exi)->hash_name.bckt = NULL;
783 784
784 785 #define exp_hash_link(exi, hash_name, bucket) \
785 786 (exi)->hash_name.bckt = (bucket); \
786 787 (exi)->hash_name.prev = NULL; \
787 788 (exi)->hash_name.next = *(bucket); \
788 789 if ((exi)->hash_name.next) \
789 790 (exi)->hash_name.next->hash_name.prev = (exi); \
790 791 *(bucket) = (exi);
791 792
792 793 void
793 794 export_link(nfs_export_t *ne, exportinfo_t *exi)
794 795 {
795 796 exportinfo_t **bckt;
796 797
797 798 ASSERT(RW_WRITE_HELD(&ne->exported_lock));
798 799
799 800 bckt = &ne->exptable[exptablehash(&exi->exi_fsid, &exi->exi_fid)];
800 801 exp_hash_link(exi, fid_hash, bckt);
801 802
802 803 bckt = &ne->exptable_path_hash[pkp_tab_hash(exi->exi_export.ex_path,
803 804 strlen(exi->exi_export.ex_path))];
804 805 exp_hash_link(exi, path_hash, bckt);
805 806 }
806 807
807 808 /*
808 809 * Helper functions for exi_id handling
809 810 */
810 811 static int
811 812 exi_id_compar(const void *v1, const void *v2)
812 813 {
813 814 const struct exportinfo *e1 = v1;
814 815 const struct exportinfo *e2 = v2;
815 816
816 817 if (e1->exi_id < e2->exi_id)
817 818 return (-1);
818 819 if (e1->exi_id > e2->exi_id)
819 820 return (1);
820 821
821 822 return (0);
822 823 }
823 824
824 825 int
825 826 exi_id_get_next()
826 827 {
827 828 struct exportinfo e;
828 829 int ret = exi_id_next;
829 830
830 831 ASSERT(MUTEX_HELD(&nfs_exi_id_lock));
831 832
832 833 do {
833 834 exi_id_next++;
834 835 if (exi_id_next == 0)
835 836 exi_id_overflow = TRUE;
836 837
837 838 if (!exi_id_overflow)
838 839 break;
839 840
840 841 if (exi_id_next == ret)
841 842 cmn_err(CE_PANIC, "exi_id exhausted");
842 843
843 844 e.exi_id = exi_id_next;
844 845 } while (avl_find(&exi_id_tree, &e, NULL) != NULL);
845 846
846 847 return (ret);
847 848 }
848 849
849 850 /*ARGSUSED*/
850 851 static void *
851 852 nfs_export_zone_init(zoneid_t zoneid)
852 853 {
853 854 int i;
854 855 nfs_export_t *ne;
855 856
856 857 ne = kmem_zalloc(sizeof (*ne), KM_SLEEP);
857 858
858 859 rw_init(&ne->exported_lock, NULL, RW_DEFAULT, NULL);
859 860
860 861 /*
861 862 * Allocate the place holder for the public file handle, which
862 863 * is all zeroes. It is initially set to the root filesystem.
863 864 */
864 865 ne->exi_root = kmem_zalloc(sizeof (*ne->exi_root), KM_SLEEP);
865 866 ne->exi_public = ne->exi_root;
866 867
867 868 ne->exi_root->exi_export.ex_flags = EX_PUBLIC;
868 869 ne->exi_root->exi_export.ex_pathlen = 1; /* length of "/" */
869 870 ne->exi_root->exi_export.ex_path =
870 871 kmem_alloc(ne->exi_root->exi_export.ex_pathlen + 1, KM_SLEEP);
871 872 ne->exi_root->exi_export.ex_path[0] = '/';
872 873 ne->exi_root->exi_export.ex_path[1] = '\0';
873 874
874 875 ne->exi_root->exi_count = 1;
875 876 mutex_init(&ne->exi_root->exi_lock, NULL, MUTEX_DEFAULT, NULL);
876 877
877 878 ne->exi_root->exi_vp = ZONE_ROOTVP();
878 879 ne->exi_rootfid.fid_len = MAXFIDSZ;
879 880 if (vop_fid_pseudo(ne->exi_root->exi_vp, &ne->exi_rootfid) != 0) {
880 881 mutex_destroy(&ne->exi_root->exi_lock);
881 882 kmem_free(ne->exi_root->exi_export.ex_path,
882 883 ne->exi_root->exi_export.ex_pathlen + 1);
883 884 kmem_free(ne->exi_root, sizeof (*ne->exi_root));
884 885 return (NULL);
885 886 }
886 887
887 888 /* Initialize auth cache and auth cache lock */
888 889 for (i = 0; i < AUTH_TABLESIZE; i++) {
889 890 ne->exi_root->exi_cache[i] = kmem_alloc(sizeof (avl_tree_t),
890 891 KM_SLEEP);
891 892 avl_create(ne->exi_root->exi_cache[i],
892 893 nfsauth_cache_clnt_compar, sizeof (struct auth_cache_clnt),
893 894 offsetof(struct auth_cache_clnt, authc_link));
894 895 }
895 896 rw_init(&ne->exi_root->exi_cache_lock, NULL, RW_DEFAULT, NULL);
896 897
897 898 /* Setup the fhandle template */
898 899 ne->exi_root->exi_fh.fh_fsid = rootdir->v_vfsp->vfs_fsid;
899 900 ne->exi_root->exi_fh.fh_xlen = ne->exi_rootfid.fid_len;
900 901 bcopy(ne->exi_rootfid.fid_data, ne->exi_root->exi_fh.fh_xdata,
901 902 ne->exi_rootfid.fid_len);
902 903 ne->exi_root->exi_fh.fh_len = sizeof (ne->exi_root->exi_fh.fh_data);
903 904
904 905 rw_enter(&ne->exported_lock, RW_WRITER);
905 906
906 907 /* Publish the exportinfo in the hash table */
907 908 export_link(ne, ne->exi_root);
908 909
909 910 /* Initialize exi_id and exi_kstats */
910 911 mutex_enter(&nfs_exi_id_lock);
911 912 ne->exi_root->exi_id = exi_id_get_next();
912 913 avl_add(&exi_id_tree, ne->exi_root);
913 914 mutex_exit(&nfs_exi_id_lock);
914 915
915 916 rw_exit(&ne->exported_lock);
916 917 ne->ns_root = NULL;
917 918
918 919 return (ne);
919 920 }
920 921
921 922 /*ARGSUSED*/
922 923 static void
923 924 nfs_export_zone_fini(zoneid_t zoneid, void *data)
924 925 {
925 926 int i;
926 927 nfs_export_t *ne = data;
927 928 struct exportinfo *exi;
928 929
929 930 rw_enter(&ne->exported_lock, RW_WRITER);
930 931 mutex_enter(&nfs_exi_id_lock);
931 932
932 933 avl_remove(&exi_id_tree, ne->exi_root);
933 934 export_unlink(ne, ne->exi_root);
934 935
935 936 mutex_exit(&nfs_exi_id_lock);
936 937 rw_exit(&ne->exported_lock);
937 938
938 939 /* Deallocate the place holder for the public file handle */
939 940 srv_secinfo_list_free(ne->exi_root->exi_export.ex_secinfo,
940 941 ne->exi_root->exi_export.ex_seccnt);
941 942 mutex_destroy(&ne->exi_root->exi_lock);
942 943
943 944 rw_destroy(&ne->exi_root->exi_cache_lock);
944 945 for (i = 0; i < AUTH_TABLESIZE; i++) {
945 946 avl_destroy(ne->exi_root->exi_cache[i]);
946 947 kmem_free(ne->exi_root->exi_cache[i], sizeof (avl_tree_t));
947 948 }
948 949
949 950 kmem_free(ne->exi_root->exi_export.ex_path,
950 951 ne->exi_root->exi_export.ex_pathlen + 1);
951 952 kmem_free(ne->exi_root, sizeof (*ne->exi_root));
952 953
953 954 exi = avl_first(&exi_id_tree);
954 955 while (exi != NULL) {
955 956 struct exportinfo *nexi = AVL_NEXT(&exi_id_tree, exi);
956 957 if (zoneid == exi->exi_zoneid)
957 958 (void) unexport(ne, exi);
958 959 exi = nexi;
959 960 }
960 961
961 962 rw_destroy(&ne->exported_lock);
962 963 kmem_free(ne, sizeof (*ne));
963 964 }
964 965
965 966 /*
966 967 * Initialization routine for export routines.
967 968 * Should only be called once.
968 969 */
969 970 void
970 971 nfs_exportinit(void)
971 972 {
972 973 mutex_init(&nfs_exi_id_lock, NULL, MUTEX_DEFAULT, NULL);
973 974
974 975 /* exi_id handling initialization */
975 976 exi_id_next = 0;
976 977 exi_id_overflow = FALSE;
977 978 avl_create(&exi_id_tree, exi_id_compar, sizeof (struct exportinfo),
978 979 offsetof(struct exportinfo, exi_id_link));
979 980
980 981 zone_key_create(&nfs_export_key, nfs_export_zone_init,
981 982 NULL, nfs_export_zone_fini);
982 983
983 984 nfslog_init();
984 985 }
985 986
986 987 /*
987 988 * Finalization routine for export routines.
988 989 */
989 990 void
990 991 nfs_exportfini(void)
991 992 {
992 993 (void) zone_key_delete(nfs_export_key);
993 994 avl_destroy(&exi_id_tree);
994 995 mutex_destroy(&nfs_exi_id_lock);
995 996 }
996 997
997 998 /*
998 999 * Check if 2 gss mechanism identifiers are the same.
999 1000 *
1000 1001 * return FALSE if not the same.
1001 1002 * return TRUE if the same.
1002 1003 */
1003 1004 static bool_t
1004 1005 nfs_mech_equal(rpc_gss_OID mech1, rpc_gss_OID mech2)
1005 1006 {
1006 1007 if ((mech1->length == 0) && (mech2->length == 0))
1007 1008 return (TRUE);
1008 1009
1009 1010 if (mech1->length != mech2->length)
1010 1011 return (FALSE);
1011 1012
1012 1013 return (bcmp(mech1->elements, mech2->elements, mech1->length) == 0);
1013 1014 }
1014 1015
1015 1016 /*
1016 1017 * This routine is used by rpc to map rpc security number
1017 1018 * to nfs specific security flavor number.
1018 1019 *
1019 1020 * The gss callback prototype is
1020 1021 * callback(struct svc_req *, gss_cred_id_t *, gss_ctx_id_t *,
1021 1022 * rpc_gss_lock_t *, void **),
1022 1023 * since nfs does not use the gss_cred_id_t/gss_ctx_id_t arguments
1023 1024 * we cast them to void.
1024 1025 */
1025 1026 /*ARGSUSED*/
1026 1027 bool_t
1027 1028 rfs_gsscallback(struct svc_req *req, gss_cred_id_t deleg, void *gss_context,
1028 1029 rpc_gss_lock_t *lock, void **cookie)
1029 1030 {
1030 1031 int i, j;
1031 1032 rpc_gss_rawcred_t *raw_cred;
1032 1033 struct exportinfo *exi;
1033 1034 nfs_export_t *ne = nfs_get_export();
1034 1035
1035 1036 /*
1036 1037 * We don't deal with delegated credentials.
1037 1038 */
1038 1039 if (deleg != GSS_C_NO_CREDENTIAL)
1039 1040 return (FALSE);
1040 1041
1041 1042 raw_cred = lock->raw_cred;
1042 1043 *cookie = NULL;
1043 1044
1044 1045 rw_enter(&ne->exported_lock, RW_READER);
1045 1046
1046 1047 for (i = 0; i < EXPTABLESIZE; i++) {
1047 1048 exi = ne->exptable[i];
1048 1049 while (exi) {
1049 1050 if (exi->exi_export.ex_seccnt > 0) {
1050 1051 struct secinfo *secp;
1051 1052 seconfig_t *se;
1052 1053 int seccnt;
1053 1054
1054 1055 secp = exi->exi_export.ex_secinfo;
1055 1056 seccnt = exi->exi_export.ex_seccnt;
1056 1057 for (j = 0; j < seccnt; j++) {
1057 1058 /*
1058 1059 * If there is a map of the triplet
1059 1060 * (mechanism, service, qop) between
1060 1061 * raw_cred and the exported flavor,
1061 1062 * get the psudo flavor number.
1062 1063 * Also qop should not be NULL, it
1063 1064 * should be "default" or something
1064 1065 * else.
1065 1066 */
1066 1067 se = &secp[j].s_secinfo;
1067 1068 if ((se->sc_rpcnum == RPCSEC_GSS) &&
1068 1069
1069 1070 (nfs_mech_equal(
1070 1071 se->sc_gss_mech_type,
1071 1072 raw_cred->mechanism)) &&
1072 1073
1073 1074 (se->sc_service ==
1074 1075 raw_cred->service) &&
1075 1076 (raw_cred->qop == se->sc_qop)) {
1076 1077
1077 1078 *cookie = (void *)(uintptr_t)
1078 1079 se->sc_nfsnum;
1079 1080 goto done;
1080 1081 }
1081 1082 }
1082 1083 }
1083 1084 exi = exi->fid_hash.next;
1084 1085 }
1085 1086 }
1086 1087 done:
1087 1088 rw_exit(&ne->exported_lock);
1088 1089
1089 1090 /*
1090 1091 * If no nfs pseudo number mapping can be found in the export
1091 1092 * table, assign the nfsflavor to NFS_FLAVOR_NOMAP. In V4, we may
1092 1093 * recover the flavor mismatch from NFS layer (NFS4ERR_WRONGSEC).
1093 1094 *
1094 1095 * For example:
1095 1096 * server first shares with krb5i;
1096 1097 * client mounts with krb5i;
1097 1098 * server re-shares with krb5p;
1098 1099 * client tries with krb5i, but no mapping can be found;
1099 1100 * rpcsec_gss module calls this routine to do the mapping,
1100 1101 * if this routine fails, request is rejected from
1101 1102 * the rpc layer.
1102 1103 * What we need is to let the nfs layer rejects the request.
1103 1104 * For V4, we can reject with NFS4ERR_WRONGSEC and the client
1104 1105 * may recover from it by getting the new flavor via SECINFO.
1105 1106 *
1106 1107 * nfs pseudo number for RPCSEC_GSS mapping (see nfssec.conf)
1107 1108 * is owned by IANA (see RFC 2623).
1108 1109 *
1109 1110 * XXX NFS_FLAVOR_NOMAP is defined in Solaris to work around
1110 1111 * the implementation issue. This number should not overlap with
1111 1112 * any new IANA defined pseudo flavor numbers.
1112 1113 */
1113 1114 if (*cookie == NULL)
1114 1115 *cookie = (void *)NFS_FLAVOR_NOMAP;
1115 1116
1116 1117 lock->locked = TRUE;
1117 1118
1118 1119 return (TRUE);
1119 1120 }
1120 1121
1121 1122
1122 1123 /*
1123 1124 * Exportfs system call; credentials should be checked before
1124 1125 * calling this function.
1125 1126 */
1126 1127 int
1127 1128 exportfs(struct exportfs_args *args, model_t model, cred_t *cr)
1128 1129 {
1129 1130 vnode_t *vp;
1130 1131 vnode_t *dvp;
1131 1132 struct exportdata *kex;
1132 1133 struct exportinfo *exi = NULL;
1133 1134 struct exportinfo *ex, *ex1, *ex2;
1134 1135 fid_t fid;
1135 1136 fsid_t fsid;
1136 1137 int error;
1137 1138 size_t allocsize;
1138 1139 struct secinfo *sp;
1139 1140 struct secinfo *exs;
1140 1141 rpc_gss_callback_t cb;
1141 1142 char *pathbuf;
1142 1143 char *log_buffer;
1143 1144 char *tagbuf;
1144 1145 int callback;
1145 1146 int allocd_seccnt;
1146 1147 STRUCT_HANDLE(exportfs_args, uap);
1147 1148 STRUCT_DECL(exportdata, uexi);
1148 1149 struct secinfo newsec[MAX_FLAVORS];
1149 1150 int newcnt;
1150 1151 struct secinfo oldsec[MAX_FLAVORS];
1151 1152 int oldcnt;
1152 1153 int i;
1153 1154 struct pathname lookpn;
1154 1155 nfs_export_t *ne = nfs_get_export();
1155 1156
1156 1157 STRUCT_SET_HANDLE(uap, model, args);
1157 1158
1158 1159 /* Read in pathname from userspace */
1159 1160 if (error = pn_get(STRUCT_FGETP(uap, dname), UIO_USERSPACE, &lookpn))
1160 1161 return (error);
1161 1162
1162 1163 /* Walk the export list looking for that pathname */
1163 1164 rw_enter(&ne->exported_lock, RW_READER);
1164 1165 DTRACE_PROBE(nfss__i__exported_lock1_start);
1165 1166 for (ex1 = ne->exptable_path_hash[pkp_tab_hash(lookpn.pn_path,
1166 1167 strlen(lookpn.pn_path))]; ex1; ex1 = ex1->path_hash.next) {
1167 1168 if (ex1 != ne->exi_root && 0 ==
1168 1169 strcmp(ex1->exi_export.ex_path, lookpn.pn_path)) {
1169 1170 exi_hold(ex1);
1170 1171 break;
1171 1172 }
1172 1173 }
1173 1174 DTRACE_PROBE(nfss__i__exported_lock1_stop);
1174 1175 rw_exit(&ne->exported_lock);
1175 1176
1176 1177 /* Is this an unshare? */
1177 1178 if (STRUCT_FGETP(uap, uex) == NULL) {
1178 1179 pn_free(&lookpn);
1179 1180 if (ex1 == NULL)
1180 1181 return (EINVAL);
1181 1182 error = unexport(ne, ex1);
1182 1183 exi_rele(ex1);
1183 1184 return (error);
1184 1185 }
1185 1186
1186 1187 /* It is a share or a re-share */
1187 1188 error = lookupname(STRUCT_FGETP(uap, dname), UIO_USERSPACE,
1188 1189 FOLLOW, &dvp, &vp);
1189 1190 if (error == EINVAL) {
1190 1191 /*
1191 1192 * if fname resolves to / we get EINVAL error
1192 1193 * since we wanted the parent vnode. Try again
1193 1194 * with NULL dvp.
1194 1195 */
1195 1196 error = lookupname(STRUCT_FGETP(uap, dname), UIO_USERSPACE,
1196 1197 FOLLOW, NULL, &vp);
1197 1198 dvp = NULL;
1198 1199 }
1199 1200 if (!error && vp == NULL) {
1200 1201 /* Last component of fname not found */
1201 1202 if (dvp != NULL)
1202 1203 VN_RELE(dvp);
1203 1204 error = ENOENT;
1204 1205 }
1205 1206 if (error) {
1206 1207 pn_free(&lookpn);
1207 1208 if (ex1)
1208 1209 exi_rele(ex1);
1209 1210 return (error);
1210 1211 }
1211 1212
1212 1213 /*
1213 1214 * 'vp' may be an AUTOFS node, so we perform a
1214 1215 * VOP_ACCESS() to trigger the mount of the
1215 1216 * intended filesystem, so we can share the intended
1216 1217 * filesystem instead of the AUTOFS filesystem.
1217 1218 */
1218 1219 (void) VOP_ACCESS(vp, 0, 0, cr, NULL);
1219 1220
1220 1221 /*
1221 1222 * We're interested in the top most filesystem.
1222 1223 * This is specially important when uap->dname is a trigger
1223 1224 * AUTOFS node, since we're really interested in sharing the
1224 1225 * filesystem AUTOFS mounted as result of the VOP_ACCESS()
1225 1226 * call not the AUTOFS node itself.
1226 1227 */
1227 1228 if (vn_mountedvfs(vp) != NULL) {
1228 1229 if (error = traverse(&vp)) {
1229 1230 VN_RELE(vp);
1230 1231 if (dvp != NULL)
1231 1232 VN_RELE(dvp);
1232 1233 pn_free(&lookpn);
1233 1234 if (ex1)
1234 1235 exi_rele(ex1);
1235 1236 return (error);
1236 1237 }
1237 1238 }
1238 1239
1239 1240 /* Do not allow sharing another vnode for already shared path */
1240 1241 if (ex1 && !PSEUDO(ex1) && !VN_CMP(ex1->exi_vp, vp)) {
1241 1242 VN_RELE(vp);
1242 1243 if (dvp != NULL)
1243 1244 VN_RELE(dvp);
1244 1245 pn_free(&lookpn);
1245 1246 exi_rele(ex1);
1246 1247 return (EEXIST);
1247 1248 }
1248 1249 if (ex1)
1249 1250 exi_rele(ex1);
1250 1251
1251 1252 /*
1252 1253 * Get the vfs id
1253 1254 */
1254 1255 bzero(&fid, sizeof (fid));
1255 1256 fid.fid_len = MAXFIDSZ;
1256 1257 error = VOP_FID(vp, &fid, NULL);
1257 1258 fsid = vp->v_vfsp->vfs_fsid;
1258 1259
1259 1260 if (error) {
1260 1261 VN_RELE(vp);
1261 1262 if (dvp != NULL)
1262 1263 VN_RELE(dvp);
1263 1264 /*
1264 1265 * If VOP_FID returns ENOSPC then the fid supplied
1265 1266 * is too small. For now we simply return EREMOTE.
1266 1267 */
1267 1268 if (error == ENOSPC)
1268 1269 error = EREMOTE;
1269 1270 pn_free(&lookpn);
1270 1271 return (error);
1271 1272 }
1272 1273
1273 1274 /*
1274 1275 * Do not allow re-sharing a shared vnode under a different path
1275 1276 * PSEUDO export has ex_path fabricated, e.g. "/tmp (pseudo)", skip it.
1276 1277 */
1277 1278 rw_enter(&ne->exported_lock, RW_READER);
1278 1279 DTRACE_PROBE(nfss__i__exported_lock2_start);
1279 1280 for (ex2 = ne->exptable[exptablehash(&fsid, &fid)]; ex2;
1280 1281 ex2 = ex2->fid_hash.next) {
1281 1282 if (ex2 != ne->exi_root && !PSEUDO(ex2) &&
1282 1283 VN_CMP(ex2->exi_vp, vp) &&
1283 1284 strcmp(ex2->exi_export.ex_path, lookpn.pn_path) != 0) {
1284 1285 DTRACE_PROBE(nfss__i__exported_lock2_stop);
1285 1286 rw_exit(&ne->exported_lock);
1286 1287 VN_RELE(vp);
1287 1288 if (dvp != NULL)
1288 1289 VN_RELE(dvp);
1289 1290 pn_free(&lookpn);
1290 1291 return (EEXIST);
1291 1292 }
1292 1293 }
1293 1294 DTRACE_PROBE(nfss__i__exported_lock2_stop);
1294 1295 rw_exit(&ne->exported_lock);
1295 1296 pn_free(&lookpn);
1296 1297
1297 1298 exi = kmem_zalloc(sizeof (*exi), KM_SLEEP);
1298 1299 exi->exi_fsid = fsid;
1299 1300 exi->exi_fid = fid;
1300 1301 exi->exi_vp = vp;
1301 1302 exi->exi_count = 1;
1302 1303 exi->exi_zoneid = crgetzoneid(cr);
1303 1304 exi->exi_volatile_dev = (vfssw[vp->v_vfsp->vfs_fstype].vsw_flag &
1304 1305 VSW_VOLATILEDEV) ? 1 : 0;
1305 1306 mutex_init(&exi->exi_lock, NULL, MUTEX_DEFAULT, NULL);
1306 1307 exi->exi_dvp = dvp;
1307 1308
1308 1309 /*
1309 1310 * Initialize auth cache and auth cache lock
1310 1311 */
1311 1312 for (i = 0; i < AUTH_TABLESIZE; i++) {
1312 1313 exi->exi_cache[i] = kmem_alloc(sizeof (avl_tree_t), KM_SLEEP);
1313 1314 avl_create(exi->exi_cache[i], nfsauth_cache_clnt_compar,
1314 1315 sizeof (struct auth_cache_clnt),
1315 1316 offsetof(struct auth_cache_clnt, authc_link));
1316 1317 }
1317 1318 rw_init(&exi->exi_cache_lock, NULL, RW_DEFAULT, NULL);
1318 1319
1319 1320 /*
1320 1321 * Build up the template fhandle
1321 1322 */
1322 1323 exi->exi_fh.fh_fsid = fsid;
1323 1324 if (exi->exi_fid.fid_len > sizeof (exi->exi_fh.fh_xdata)) {
1324 1325 error = EREMOTE;
1325 1326 goto out1;
1326 1327 }
1327 1328 exi->exi_fh.fh_xlen = exi->exi_fid.fid_len;
1328 1329 bcopy(exi->exi_fid.fid_data, exi->exi_fh.fh_xdata,
1329 1330 exi->exi_fid.fid_len);
1330 1331
1331 1332 exi->exi_fh.fh_len = sizeof (exi->exi_fh.fh_data);
1332 1333
1333 1334 kex = &exi->exi_export;
1334 1335
1335 1336 /*
1336 1337 * Load in everything, and do sanity checking
1337 1338 */
1338 1339 STRUCT_INIT(uexi, model);
1339 1340 if (copyin(STRUCT_FGETP(uap, uex), STRUCT_BUF(uexi),
1340 1341 STRUCT_SIZE(uexi))) {
1341 1342 error = EFAULT;
1342 1343 goto out1;
1343 1344 }
1344 1345
1345 1346 kex->ex_version = STRUCT_FGET(uexi, ex_version);
1346 1347 if (kex->ex_version != EX_CURRENT_VERSION) {
1347 1348 error = EINVAL;
1348 1349 cmn_err(CE_WARN,
1349 1350 "NFS: exportfs requires export struct version 2 - got %d\n",
1350 1351 kex->ex_version);
1351 1352 goto out1;
1352 1353 }
1353 1354
1354 1355 /*
1355 1356 * Must have at least one security entry
1356 1357 */
1357 1358 kex->ex_seccnt = STRUCT_FGET(uexi, ex_seccnt);
1358 1359 if (kex->ex_seccnt < 1) {
1359 1360 error = EINVAL;
1360 1361 goto out1;
1361 1362 }
1362 1363
1363 1364 kex->ex_path = STRUCT_FGETP(uexi, ex_path);
1364 1365 kex->ex_pathlen = STRUCT_FGET(uexi, ex_pathlen);
1365 1366 kex->ex_flags = STRUCT_FGET(uexi, ex_flags);
1366 1367 kex->ex_anon = STRUCT_FGET(uexi, ex_anon);
1367 1368 kex->ex_secinfo = STRUCT_FGETP(uexi, ex_secinfo);
1368 1369 kex->ex_index = STRUCT_FGETP(uexi, ex_index);
1369 1370 kex->ex_log_buffer = STRUCT_FGETP(uexi, ex_log_buffer);
1370 1371 kex->ex_log_bufferlen = STRUCT_FGET(uexi, ex_log_bufferlen);
1371 1372 kex->ex_tag = STRUCT_FGETP(uexi, ex_tag);
1372 1373 kex->ex_taglen = STRUCT_FGET(uexi, ex_taglen);
1373 1374
1374 1375 /*
1375 1376 * Copy the exported pathname into
1376 1377 * an appropriately sized buffer.
1377 1378 */
1378 1379 pathbuf = kmem_alloc(MAXPATHLEN, KM_SLEEP);
1379 1380 if (copyinstr(kex->ex_path, pathbuf, MAXPATHLEN, &kex->ex_pathlen)) {
1380 1381 kmem_free(pathbuf, MAXPATHLEN);
1381 1382 error = EFAULT;
1382 1383 goto out1;
1383 1384 }
1384 1385 kex->ex_path = kmem_alloc(kex->ex_pathlen + 1, KM_SLEEP);
1385 1386 bcopy(pathbuf, kex->ex_path, kex->ex_pathlen);
1386 1387 kex->ex_path[kex->ex_pathlen] = '\0';
1387 1388 kmem_free(pathbuf, MAXPATHLEN);
1388 1389
1389 1390 /*
1390 1391 * Get the path to the logging buffer and the tag
1391 1392 */
1392 1393 if (kex->ex_flags & EX_LOG) {
1393 1394 log_buffer = kmem_alloc(MAXPATHLEN, KM_SLEEP);
1394 1395 if (copyinstr(kex->ex_log_buffer, log_buffer, MAXPATHLEN,
1395 1396 &kex->ex_log_bufferlen)) {
1396 1397 kmem_free(log_buffer, MAXPATHLEN);
1397 1398 error = EFAULT;
1398 1399 goto out2;
1399 1400 }
1400 1401 kex->ex_log_buffer =
1401 1402 kmem_alloc(kex->ex_log_bufferlen + 1, KM_SLEEP);
1402 1403 bcopy(log_buffer, kex->ex_log_buffer, kex->ex_log_bufferlen);
1403 1404 kex->ex_log_buffer[kex->ex_log_bufferlen] = '\0';
1404 1405 kmem_free(log_buffer, MAXPATHLEN);
1405 1406
1406 1407 tagbuf = kmem_alloc(MAXPATHLEN, KM_SLEEP);
1407 1408 if (copyinstr(kex->ex_tag, tagbuf, MAXPATHLEN,
1408 1409 &kex->ex_taglen)) {
1409 1410 kmem_free(tagbuf, MAXPATHLEN);
1410 1411 error = EFAULT;
1411 1412 goto out3;
1412 1413 }
1413 1414 kex->ex_tag = kmem_alloc(kex->ex_taglen + 1, KM_SLEEP);
1414 1415 bcopy(tagbuf, kex->ex_tag, kex->ex_taglen);
1415 1416 kex->ex_tag[kex->ex_taglen] = '\0';
1416 1417 kmem_free(tagbuf, MAXPATHLEN);
1417 1418 }
1418 1419
1419 1420 /*
1420 1421 * Load the security information for each flavor
1421 1422 */
1422 1423 allocsize = kex->ex_seccnt * SIZEOF_STRUCT(secinfo, model);
1423 1424 sp = kmem_zalloc(allocsize, KM_SLEEP);
1424 1425 if (copyin(kex->ex_secinfo, sp, allocsize)) {
1425 1426 kmem_free(sp, allocsize);
1426 1427 error = EFAULT;
1427 1428 goto out4;
1428 1429 }
1429 1430
1430 1431 /*
1431 1432 * All of these nested structures need to be converted to
1432 1433 * the kernel native format.
1433 1434 */
1434 1435 if (model != DATAMODEL_NATIVE) {
1435 1436 size_t allocsize2;
1436 1437 struct secinfo *sp2;
1437 1438
1438 1439 allocsize2 = kex->ex_seccnt * sizeof (struct secinfo);
1439 1440 sp2 = kmem_zalloc(allocsize2, KM_SLEEP);
1440 1441
1441 1442 for (i = 0; i < kex->ex_seccnt; i++) {
1442 1443 STRUCT_HANDLE(secinfo, usi);
1443 1444
1444 1445 STRUCT_SET_HANDLE(usi, model,
1445 1446 (struct secinfo *)((caddr_t)sp +
1446 1447 (i * SIZEOF_STRUCT(secinfo, model))));
1447 1448 bcopy(STRUCT_FGET(usi, s_secinfo.sc_name),
1448 1449 sp2[i].s_secinfo.sc_name, MAX_NAME_LEN);
1449 1450 sp2[i].s_secinfo.sc_nfsnum =
1450 1451 STRUCT_FGET(usi, s_secinfo.sc_nfsnum);
1451 1452 sp2[i].s_secinfo.sc_rpcnum =
1452 1453 STRUCT_FGET(usi, s_secinfo.sc_rpcnum);
1453 1454 bcopy(STRUCT_FGET(usi, s_secinfo.sc_gss_mech),
1454 1455 sp2[i].s_secinfo.sc_gss_mech, MAX_NAME_LEN);
1455 1456 sp2[i].s_secinfo.sc_gss_mech_type =
1456 1457 STRUCT_FGETP(usi, s_secinfo.sc_gss_mech_type);
1457 1458 sp2[i].s_secinfo.sc_qop =
1458 1459 STRUCT_FGET(usi, s_secinfo.sc_qop);
1459 1460 sp2[i].s_secinfo.sc_service =
1460 1461 STRUCT_FGET(usi, s_secinfo.sc_service);
1461 1462
1462 1463 sp2[i].s_flags = STRUCT_FGET(usi, s_flags);
1463 1464 sp2[i].s_window = STRUCT_FGET(usi, s_window);
1464 1465 sp2[i].s_rootid = STRUCT_FGET(usi, s_rootid);
1465 1466 sp2[i].s_rootcnt = STRUCT_FGET(usi, s_rootcnt);
1466 1467 sp2[i].s_rootnames = STRUCT_FGETP(usi, s_rootnames);
1467 1468 }
1468 1469 kmem_free(sp, allocsize);
1469 1470 sp = sp2;
1470 1471 allocsize = allocsize2;
1471 1472 }
1472 1473
1473 1474 kex->ex_secinfo = sp;
1474 1475
1475 1476 /*
1476 1477 * And now copy rootnames for each individual secinfo.
1477 1478 */
1478 1479 callback = 0;
1479 1480 allocd_seccnt = 0;
1480 1481 while (allocd_seccnt < kex->ex_seccnt) {
1481 1482
1482 1483 exs = &sp[allocd_seccnt];
1483 1484 if (exs->s_rootcnt > 0) {
1484 1485 if (!sec_svc_loadrootnames(exs->s_secinfo.sc_rpcnum,
1485 1486 exs->s_rootcnt, &exs->s_rootnames, model)) {
1486 1487 error = EFAULT;
1487 1488 goto out5;
1488 1489 }
1489 1490 }
1490 1491
1491 1492 if (exs->s_secinfo.sc_rpcnum == RPCSEC_GSS) {
1492 1493 rpc_gss_OID mech_tmp;
1493 1494 STRUCT_DECL(rpc_gss_OID_s, umech_tmp);
1494 1495 caddr_t elements_tmp;
1495 1496
1496 1497 /* Copyin mechanism type */
1497 1498 STRUCT_INIT(umech_tmp, model);
1498 1499 mech_tmp = kmem_alloc(sizeof (*mech_tmp), KM_SLEEP);
1499 1500 if (copyin(exs->s_secinfo.sc_gss_mech_type,
1500 1501 STRUCT_BUF(umech_tmp), STRUCT_SIZE(umech_tmp))) {
1501 1502 kmem_free(mech_tmp, sizeof (*mech_tmp));
1502 1503 error = EFAULT;
1503 1504 goto out5;
1504 1505 }
1505 1506 mech_tmp->length = STRUCT_FGET(umech_tmp, length);
1506 1507 mech_tmp->elements = STRUCT_FGETP(umech_tmp, elements);
1507 1508
1508 1509 elements_tmp = kmem_alloc(mech_tmp->length, KM_SLEEP);
1509 1510 if (copyin(mech_tmp->elements, elements_tmp,
1510 1511 mech_tmp->length)) {
1511 1512 kmem_free(elements_tmp, mech_tmp->length);
1512 1513 kmem_free(mech_tmp, sizeof (*mech_tmp));
1513 1514 error = EFAULT;
1514 1515 goto out5;
1515 1516 }
1516 1517 mech_tmp->elements = elements_tmp;
1517 1518 exs->s_secinfo.sc_gss_mech_type = mech_tmp;
1518 1519 allocd_seccnt++;
1519 1520
1520 1521 callback = 1;
1521 1522 } else
1522 1523 allocd_seccnt++;
1523 1524 }
1524 1525
1525 1526 /*
1526 1527 * Init the secinfo reference count and mark these flavors
1527 1528 * explicitly exported flavors.
1528 1529 */
1529 1530 for (i = 0; i < kex->ex_seccnt; i++) {
1530 1531 kex->ex_secinfo[i].s_flags |= M_4SEC_EXPORTED;
1531 1532 kex->ex_secinfo[i].s_refcnt = 1;
1532 1533 }
1533 1534
1534 1535 /*
1535 1536 * Set up rpcsec_gss callback routine entry if any.
1536 1537 */
1537 1538 if (callback) {
1538 1539 cb.callback = rfs_gsscallback;
1539 1540 cb.program = NFS_ACL_PROGRAM;
1540 1541 for (cb.version = NFS_ACL_VERSMIN;
1541 1542 cb.version <= NFS_ACL_VERSMAX; cb.version++) {
1542 1543 (void) sec_svc_control(RPC_SVC_SET_GSS_CALLBACK,
1543 1544 (void *)&cb);
1544 1545 }
1545 1546
1546 1547 cb.program = NFS_PROGRAM;
1547 1548 for (cb.version = NFS_VERSMIN;
1548 1549 cb.version <= NFS_VERSMAX; cb.version++) {
1549 1550 (void) sec_svc_control(RPC_SVC_SET_GSS_CALLBACK,
1550 1551 (void *)&cb);
1551 1552 }
1552 1553 }
1553 1554
1554 1555 /*
1555 1556 * Check the index flag. Do this here to avoid holding the
1556 1557 * lock while dealing with the index option (as we do with
1557 1558 * the public option).
1558 1559 */
1559 1560 if (kex->ex_flags & EX_INDEX) {
1560 1561 if (!kex->ex_index) { /* sanity check */
1561 1562 error = EINVAL;
1562 1563 goto out5;
1563 1564 }
1564 1565 if (error = loadindex(kex))
1565 1566 goto out5;
1566 1567 }
1567 1568
1568 1569 if (kex->ex_flags & EX_LOG) {
1569 1570 if (error = nfslog_setup(exi))
1570 1571 goto out6;
1571 1572 }
1572 1573
1573 1574 /*
1574 1575 * Insert the new entry at the front of the export list
1575 1576 */
1576 1577 rw_enter(&ne->exported_lock, RW_WRITER);
1577 1578 DTRACE_PROBE(nfss__i__exported_lock3_start);
1578 1579
1579 1580 export_link(ne, exi);
1580 1581
1581 1582 /*
1582 1583 * Check the rest of the list for an old entry for the fs.
1583 1584 * If one is found then unlink it, wait until this is the
1584 1585 * only reference and then free it.
1585 1586 */
1586 1587 for (ex = exi->fid_hash.next; ex != NULL; ex = ex->fid_hash.next) {
1587 1588 if (ex != ne->exi_root && VN_CMP(ex->exi_vp, vp)) {
1588 1589 mutex_enter(&nfs_exi_id_lock);
1589 1590 avl_remove(&exi_id_tree, ex);
1590 1591 mutex_exit(&nfs_exi_id_lock);
1591 1592 export_unlink(ne, ex);
1592 1593 break;
1593 1594 }
1594 1595 }
1595 1596
1596 1597 /*
1597 1598 * If the public filehandle is pointing at the
1598 1599 * old entry, then point it back at the root.
1599 1600 */
1600 1601 if (ex != NULL && ex == ne->exi_public)
1601 1602 ne->exi_public = ne->exi_root;
1602 1603
1603 1604 /*
1604 1605 * If the public flag is on, make the global exi_public
1605 1606 * point to this entry and turn off the public bit so that
1606 1607 * we can distinguish it from the place holder export.
1607 1608 */
1608 1609 if (kex->ex_flags & EX_PUBLIC) {
1609 1610 ne->exi_public = exi;
1610 1611 kex->ex_flags &= ~EX_PUBLIC;
1611 1612 }
1612 1613
1613 1614 #ifdef VOLATILE_FH_TEST
1614 1615 /*
1615 1616 * Set up the volatile_id value if volatile on share.
1616 1617 * The list of volatile renamed filehandles is always destroyed,
1617 1618 * if the fs was reshared.
1618 1619 */
1619 1620 if (kex->ex_flags & EX_VOLFH)
1620 1621 exi->exi_volatile_id = gethrestime_sec();
1621 1622
1622 1623 mutex_init(&exi->exi_vol_rename_lock, NULL, MUTEX_DEFAULT, NULL);
1623 1624 #endif /* VOLATILE_FH_TEST */
1624 1625
1625 1626 /*
1626 1627 * If this is a new export, then climb up
1627 1628 * the tree and check if any pseudo exports
1628 1629 * need to be created to provide a path for
1629 1630 * NFS v4 clients.
1630 1631 */
1631 1632 if (ex == NULL) {
1632 1633 error = treeclimb_export(exi);
1633 1634 if (error)
1634 1635 goto out7;
1635 1636 } else {
1636 1637 /* If it's a re-export update namespace tree */
1637 1638 exi->exi_tree = ex->exi_tree;
1638 1639 exi->exi_tree->tree_exi = exi;
1639 1640
1640 1641 /* Update the change timestamp */
1641 1642 tree_update_change(ne, exi->exi_tree, NULL);
1642 1643 }
1643 1644
1644 1645 /*
1645 1646 * build a unique flavor list from the flavors specified
1646 1647 * in the share cmd. unique means that each flavor only
1647 1648 * appears once in the secinfo list -- no duplicates allowed.
1648 1649 */
1649 1650 newcnt = build_seclist_nodups(&exi->exi_export, newsec, FALSE);
1650 1651
1651 1652 srv_secinfo_treeclimb(ne, exi, newsec, newcnt, TRUE);
1652 1653
1653 1654 /*
1654 1655 * If re-sharing an old export entry, update the secinfo data
1655 1656 * depending on if the old entry is a pseudo node or not.
1656 1657 */
1657 1658 if (ex != NULL) {
1658 1659 oldcnt = build_seclist_nodups(&ex->exi_export, oldsec, FALSE);
1659 1660 if (PSEUDO(ex)) {
1660 1661 /*
1661 1662 * The dir being shared is a pseudo export root (which
1662 1663 * will be transformed into a real export root). The
1663 1664 * flavor(s) of the new share were propagated to the
1664 1665 * ancestors by srv_secinfo_treeclimb() above. Now
1665 1666 * transfer the implicit flavor refs from the old
1666 1667 * pseudo exprot root to the new (real) export root.
1667 1668 */
1668 1669 srv_secinfo_add(&exi->exi_export.ex_secinfo,
1669 1670 &exi->exi_export.ex_seccnt, oldsec, oldcnt, TRUE);
1670 1671 } else {
1671 1672 /*
1672 1673 * First transfer implicit flavor refs to new export.
1673 1674 * Remove old flavor refs last.
1674 1675 */
1675 1676 srv_secinfo_exp2exp(&exi->exi_export, oldsec, oldcnt);
1676 1677 srv_secinfo_treeclimb(ne, ex, oldsec, oldcnt, FALSE);
1677 1678 }
1678 1679 }
1679 1680
1680 1681 /*
1681 1682 * If it's a re-export and the old entry has a pseudonode list,
1682 1683 * transfer it to the new export.
1683 1684 */
1684 1685 if (ex != NULL && (ex->exi_visible != NULL)) {
1685 1686 exi->exi_visible = ex->exi_visible;
1686 1687 ex->exi_visible = NULL;
1687 1688 }
1688 1689
1689 1690 /*
1690 1691 * Initialize exi_id and exi_kstats
1691 1692 */
1692 1693 if (ex != NULL) {
1693 1694 exi->exi_id = ex->exi_id;
1694 1695 } else {
1695 1696 mutex_enter(&nfs_exi_id_lock);
1696 1697 exi->exi_id = exi_id_get_next();
1697 1698 mutex_exit(&nfs_exi_id_lock);
1698 1699 }
1699 1700 mutex_enter(&nfs_exi_id_lock);
1700 1701 avl_add(&exi_id_tree, exi);
1701 1702 mutex_exit(&nfs_exi_id_lock);
1702 1703
1703 1704 DTRACE_PROBE(nfss__i__exported_lock3_stop);
1704 1705 rw_exit(&ne->exported_lock);
1705 1706
1706 1707 if (ne->exi_public == exi || kex->ex_flags & EX_LOG) {
1707 1708 /*
1708 1709 * Log share operation to this buffer only.
1709 1710 */
1710 1711 nfslog_share_record(exi, cr);
1711 1712 }
1712 1713
1713 1714 if (ex != NULL)
1714 1715 exi_rele(ex);
1715 1716
1716 1717 return (0);
1717 1718
1718 1719 out7:
1719 1720 /* Unlink the new export in exptable. */
1720 1721 export_unlink(ne, exi);
1721 1722 DTRACE_PROBE(nfss__i__exported_lock3_stop);
1722 1723 rw_exit(&ne->exported_lock);
1723 1724 out6:
1724 1725 if (kex->ex_flags & EX_INDEX)
1725 1726 kmem_free(kex->ex_index, strlen(kex->ex_index) + 1);
1726 1727 out5:
1727 1728 /* free partially completed allocation */
1728 1729 while (--allocd_seccnt >= 0) {
1729 1730 exs = &kex->ex_secinfo[allocd_seccnt];
1730 1731 srv_secinfo_entry_free(exs);
1731 1732 }
1732 1733
1733 1734 if (kex->ex_secinfo) {
1734 1735 kmem_free(kex->ex_secinfo,
1735 1736 kex->ex_seccnt * sizeof (struct secinfo));
1736 1737 }
1737 1738
1738 1739 out4:
1739 1740 if ((kex->ex_flags & EX_LOG) && kex->ex_tag != NULL)
1740 1741 kmem_free(kex->ex_tag, kex->ex_taglen + 1);
1741 1742 out3:
1742 1743 if ((kex->ex_flags & EX_LOG) && kex->ex_log_buffer != NULL)
1743 1744 kmem_free(kex->ex_log_buffer, kex->ex_log_bufferlen + 1);
1744 1745 out2:
1745 1746 kmem_free(kex->ex_path, kex->ex_pathlen + 1);
1746 1747 out1:
1747 1748 VN_RELE(vp);
1748 1749 if (dvp != NULL)
1749 1750 VN_RELE(dvp);
1750 1751 mutex_destroy(&exi->exi_lock);
1751 1752 rw_destroy(&exi->exi_cache_lock);
1752 1753 for (i = 0; i < AUTH_TABLESIZE; i++) {
1753 1754 avl_destroy(exi->exi_cache[i]);
1754 1755 kmem_free(exi->exi_cache[i], sizeof (avl_tree_t));
1755 1756 }
1756 1757
1757 1758 kmem_free(exi, sizeof (*exi));
1758 1759
1759 1760 return (error);
1760 1761 }
1761 1762
1762 1763 /*
1763 1764 * Remove the exportinfo from the export list
1764 1765 */
1765 1766 void
1766 1767 export_unlink(nfs_export_t *ne, struct exportinfo *exi)
1767 1768 {
1768 1769 ASSERT(RW_WRITE_HELD(&ne->exported_lock));
1769 1770
1770 1771 exp_hash_unlink(exi, fid_hash);
1771 1772 exp_hash_unlink(exi, path_hash);
1772 1773 }
1773 1774
1774 1775 /*
1775 1776 * Unexport an exported filesystem
1776 1777 */
1777 1778 static int
1778 1779 unexport(nfs_export_t *ne, struct exportinfo *exi)
1779 1780 {
1780 1781 struct secinfo cursec[MAX_FLAVORS];
1781 1782 int curcnt;
1782 1783
1783 1784 rw_enter(&ne->exported_lock, RW_WRITER);
1784 1785
1785 1786 /* Check if exi is still linked in the export table */
1786 1787 if (!EXP_LINKED(exi) || PSEUDO(exi)) {
1787 1788 rw_exit(&ne->exported_lock);
1788 1789 return (EINVAL);
1789 1790 }
1790 1791
1791 1792 mutex_enter(&nfs_exi_id_lock);
1792 1793 avl_remove(&exi_id_tree, exi);
1793 1794 mutex_exit(&nfs_exi_id_lock);
1794 1795 export_unlink(ne, exi);
1795 1796
1796 1797 /*
1797 1798 * Remove security flavors before treeclimb_unexport() is called
1798 1799 * because srv_secinfo_treeclimb needs the namespace tree
1799 1800 */
1800 1801 curcnt = build_seclist_nodups(&exi->exi_export, cursec, TRUE);
1801 1802 srv_secinfo_treeclimb(ne, exi, cursec, curcnt, FALSE);
1802 1803
1803 1804 /*
1804 1805 * If there's a visible list, then need to leave
1805 1806 * a pseudo export here to retain the visible list
1806 1807 * for paths to exports below.
1807 1808 */
1808 1809 if (exi->exi_visible != NULL) {
1809 1810 struct exportinfo *newexi;
1810 1811
1811 1812 newexi = pseudo_exportfs(ne, exi->exi_vp, &exi->exi_fid,
1812 1813 exi->exi_visible, &exi->exi_export);
1813 1814 exi->exi_visible = NULL;
1814 1815
1815 1816 /* interconnect the existing treenode with the new exportinfo */
1816 1817 newexi->exi_tree = exi->exi_tree;
1817 1818 newexi->exi_tree->tree_exi = newexi;
1818 1819
1819 1820 /* Update the change timestamp */
1820 1821 tree_update_change(ne, exi->exi_tree, NULL);
1821 1822 } else {
1822 1823 treeclimb_unexport(ne, exi);
1823 1824 }
1824 1825
1825 1826 rw_exit(&ne->exported_lock);
1826 1827
1827 1828 /*
1828 1829 * Need to call into the NFSv4 server and release all data
1829 1830 * held on this particular export. This is important since
1830 1831 * the v4 server may be holding file locks or vnodes under
1831 1832 * this export.
1832 1833 */
1833 1834 rfs4_clean_state_exi(exi);
1834 1835
1835 1836 /*
1836 1837 * Notify the lock manager that the filesystem is being
1837 1838 * unexported.
1838 1839 */
1839 1840 lm_unexport(exi);
1840 1841
1841 1842 /*
1842 1843 * If this was a public export, restore
1843 1844 * the public filehandle to the root.
1844 1845 */
1845 1846 if (exi == ne->exi_public) {
1846 1847 ne->exi_public = ne->exi_root;
1847 1848
1848 1849 nfslog_share_record(ne->exi_public, CRED());
1849 1850 }
1850 1851
1851 1852 if (exi->exi_export.ex_flags & EX_LOG)
1852 1853 nfslog_unshare_record(exi, CRED());
1853 1854
1854 1855 exi_rele(exi);
1855 1856 return (0);
1856 1857 }
1857 1858
1858 1859 /*
1859 1860 * Get file handle system call.
1860 1861 * Takes file name and returns a file handle for it.
1861 1862 * Credentials must be verified before calling.
1862 1863 */
1863 1864 int
1864 1865 nfs_getfh(struct nfs_getfh_args *args, model_t model, cred_t *cr)
1865 1866 {
1866 1867 nfs_fh3 fh;
1867 1868 char buf[NFS3_MAXFHSIZE];
1868 1869 char *logptr, logbuf[NFS3_MAXFHSIZE];
1869 1870 int l = NFS3_MAXFHSIZE;
1870 1871 vnode_t *vp;
1871 1872 vnode_t *dvp;
1872 1873 struct exportinfo *exi;
1873 1874 int error;
1874 1875 int vers;
1875 1876 STRUCT_HANDLE(nfs_getfh_args, uap);
1876 1877
1877 1878 #ifdef lint
1878 1879 model = model; /* STRUCT macros don't always use it */
1879 1880 #endif
1880 1881
1881 1882 STRUCT_SET_HANDLE(uap, model, args);
1882 1883
1883 1884 error = lookupname(STRUCT_FGETP(uap, fname), UIO_USERSPACE,
1884 1885 FOLLOW, &dvp, &vp);
1885 1886 if (error == EINVAL) {
1886 1887 /*
1887 1888 * if fname resolves to / we get EINVAL error
1888 1889 * since we wanted the parent vnode. Try again
1889 1890 * with NULL dvp.
1890 1891 */
1891 1892 error = lookupname(STRUCT_FGETP(uap, fname), UIO_USERSPACE,
1892 1893 FOLLOW, NULL, &vp);
1893 1894 dvp = NULL;
1894 1895 }
1895 1896 if (!error && vp == NULL) {
1896 1897 /*
1897 1898 * Last component of fname not found
1898 1899 */
1899 1900 if (dvp != NULL) {
1900 1901 VN_RELE(dvp);
1901 1902 }
1902 1903 error = ENOENT;
1903 1904 }
1904 1905 if (error)
1905 1906 return (error);
1906 1907
1907 1908 /*
1908 1909 * 'vp' may be an AUTOFS node, so we perform a
1909 1910 * VOP_ACCESS() to trigger the mount of the
1910 1911 * intended filesystem, so we can share the intended
1911 1912 * filesystem instead of the AUTOFS filesystem.
1912 1913 */
1913 1914 (void) VOP_ACCESS(vp, 0, 0, cr, NULL);
1914 1915
1915 1916 /*
1916 1917 * We're interested in the top most filesystem.
1917 1918 * This is specially important when uap->dname is a trigger
1918 1919 * AUTOFS node, since we're really interested in sharing the
1919 1920 * filesystem AUTOFS mounted as result of the VOP_ACCESS()
1920 1921 * call not the AUTOFS node itself.
1921 1922 */
1922 1923 if (vn_mountedvfs(vp) != NULL) {
1923 1924 if (error = traverse(&vp)) {
1924 1925 VN_RELE(vp);
1925 1926 if (dvp != NULL)
1926 1927 VN_RELE(dvp);
1927 1928 return (error);
1928 1929 }
1929 1930 }
1930 1931
1931 1932 vers = STRUCT_FGET(uap, vers);
1932 1933 exi = nfs_vptoexi(dvp, vp, cr, NULL, &error, FALSE);
1933 1934 if (!error) {
1934 1935 if (vers == NFS_VERSION) {
1935 1936 error = makefh((fhandle_t *)buf, vp, exi);
1936 1937 l = NFS_FHSIZE;
1937 1938 logptr = buf;
1938 1939 } else if (vers == NFS_V3) {
1939 1940 int i, sz, pad;
1940 1941
1941 1942 error = makefh3(&fh, vp, exi);
1942 1943 l = RNDUP(fh.fh3_length);
1943 1944 if (!error && (l > sizeof (fhandle3_t)))
1944 1945 error = EREMOTE;
1945 1946 logptr = logbuf;
1946 1947 if (!error) {
1947 1948 i = 0;
1948 1949 sz = sizeof (fsid_t);
1949 1950 bcopy(&fh.fh3_fsid, &buf[i], sz);
1950 1951 i += sz;
1951 1952
1952 1953 /*
1953 1954 * For backwards compatibility, the
1954 1955 * fid length may be less than
1955 1956 * NFS_FHMAXDATA, but it was always
1956 1957 * encoded as NFS_FHMAXDATA bytes.
1957 1958 */
1958 1959
1959 1960 sz = sizeof (ushort_t);
1960 1961 bcopy(&fh.fh3_len, &buf[i], sz);
1961 1962 i += sz;
1962 1963 bcopy(fh.fh3_data, &buf[i], fh.fh3_len);
1963 1964 i += fh.fh3_len;
1964 1965 pad = (NFS_FHMAXDATA - fh.fh3_len);
1965 1966 if (pad > 0) {
1966 1967 bzero(&buf[i], pad);
1967 1968 i += pad;
1968 1969 l += pad;
1969 1970 }
1970 1971
1971 1972 sz = sizeof (ushort_t);
1972 1973 bcopy(&fh.fh3_xlen, &buf[i], sz);
1973 1974 i += sz;
1974 1975 bcopy(fh.fh3_xdata, &buf[i], fh.fh3_xlen);
1975 1976 i += fh.fh3_xlen;
1976 1977 pad = (NFS_FHMAXDATA - fh.fh3_xlen);
1977 1978 if (pad > 0) {
1978 1979 bzero(&buf[i], pad);
1979 1980 i += pad;
1980 1981 l += pad;
1981 1982 }
1982 1983 }
1983 1984 /*
1984 1985 * If we need to do NFS logging, the filehandle
1985 1986 * must be downsized to 32 bytes.
1986 1987 */
1987 1988 if (!error && exi->exi_export.ex_flags & EX_LOG) {
1988 1989 i = 0;
1989 1990 sz = sizeof (fsid_t);
1990 1991 bcopy(&fh.fh3_fsid, &logbuf[i], sz);
1991 1992 i += sz;
1992 1993 sz = sizeof (ushort_t);
1993 1994 bcopy(&fh.fh3_len, &logbuf[i], sz);
1994 1995 i += sz;
1995 1996 sz = NFS_FHMAXDATA;
1996 1997 bcopy(fh.fh3_data, &logbuf[i], sz);
1997 1998 i += sz;
1998 1999 sz = sizeof (ushort_t);
1999 2000 bcopy(&fh.fh3_xlen, &logbuf[i], sz);
2000 2001 i += sz;
2001 2002 sz = NFS_FHMAXDATA;
2002 2003 bcopy(fh.fh3_xdata, &logbuf[i], sz);
2003 2004 i += sz;
2004 2005 }
2005 2006 }
2006 2007 if (!error && exi->exi_export.ex_flags & EX_LOG) {
2007 2008 nfslog_getfh(exi, (fhandle_t *)logptr,
2008 2009 STRUCT_FGETP(uap, fname), UIO_USERSPACE, cr);
2009 2010 }
2010 2011 exi_rele(exi);
2011 2012 if (!error) {
2012 2013 if (copyout(&l, STRUCT_FGETP(uap, lenp), sizeof (int)))
2013 2014 error = EFAULT;
2014 2015 if (copyout(buf, STRUCT_FGETP(uap, fhp), l))
2015 2016 error = EFAULT;
2016 2017 }
2017 2018 }
2018 2019 VN_RELE(vp);
2019 2020 if (dvp != NULL) {
2020 2021 VN_RELE(dvp);
2021 2022 }
2022 2023 return (error);
2023 2024 }
2024 2025
2025 2026 /*
2026 2027 * Strategy: if vp is in the export list, then
2027 2028 * return the associated file handle. Otherwise, ".."
2028 2029 * once up the vp and try again, until the root of the
2029 2030 * filesystem is reached.
2030 2031 */
2031 2032 struct exportinfo *
2032 2033 nfs_vptoexi(vnode_t *dvp, vnode_t *vp, cred_t *cr, int *walk,
2033 2034 int *err, bool_t v4srv)
2034 2035 {
2035 2036 fid_t fid;
2036 2037 int error;
2037 2038 struct exportinfo *exi;
2038 2039
2039 2040 ASSERT(vp);
2040 2041 VN_HOLD(vp);
2041 2042 if (dvp != NULL) {
2042 2043 VN_HOLD(dvp);
2043 2044 }
2044 2045 if (walk != NULL)
2045 2046 *walk = 0;
2046 2047
2047 2048 for (;;) {
2048 2049 bzero(&fid, sizeof (fid));
2049 2050 fid.fid_len = MAXFIDSZ;
2050 2051 error = vop_fid_pseudo(vp, &fid);
2051 2052 if (error) {
2052 2053 /*
2053 2054 * If vop_fid_pseudo returns ENOSPC then the fid
2054 2055 * supplied is too small. For now we simply
2055 2056 * return EREMOTE.
2056 2057 */
2057 2058 if (error == ENOSPC)
2058 2059 error = EREMOTE;
2059 2060 break;
2060 2061 }
2061 2062
2062 2063 if (v4srv)
2063 2064 exi = checkexport4(&vp->v_vfsp->vfs_fsid, &fid, vp);
2064 2065 else
2065 2066 exi = checkexport(&vp->v_vfsp->vfs_fsid, &fid);
2066 2067
2067 2068 if (exi != NULL) {
2068 2069 /*
|
↓ open down ↓ |
1326 lines elided |
↑ open up ↑ |
2069 2070 * Found the export info
2070 2071 */
2071 2072 break;
2072 2073 }
2073 2074
2074 2075 /*
2075 2076 * We have just failed finding a matching export.
2076 2077 * If we're at the root of this filesystem, then
2077 2078 * it's time to stop (with failure).
2078 2079 */
2079 - if (vp->v_flag & VROOT) {
2080 + if ((vp->v_flag & VROOT) || VN_IS_CURZONEROOT(vp)) {
2080 2081 error = EINVAL;
2081 2082 break;
2082 2083 }
2083 2084
2084 2085 if (walk != NULL)
2085 2086 (*walk)++;
2086 2087
2087 2088 /*
2088 2089 * Now, do a ".." up vp. If dvp is supplied, use it,
2089 2090 * otherwise, look it up.
2090 2091 */
2091 2092 if (dvp == NULL) {
2092 2093 error = VOP_LOOKUP(vp, "..", &dvp, NULL, 0, NULL, cr,
2093 2094 NULL, NULL, NULL);
2094 2095 if (error)
2095 2096 break;
2096 2097 }
2097 2098 VN_RELE(vp);
2098 2099 vp = dvp;
2099 2100 dvp = NULL;
2100 2101 }
2101 2102 VN_RELE(vp);
2102 2103 if (dvp != NULL) {
2103 2104 VN_RELE(dvp);
2104 2105 }
2105 2106 if (error != 0) {
2106 2107 if (err != NULL)
2107 2108 *err = error;
2108 2109 return (NULL);
2109 2110 }
2110 2111 return (exi);
2111 2112 }
2112 2113
2113 2114 int
2114 2115 chk_clnt_sec(exportinfo_t *exi, struct svc_req *req)
2115 2116 {
2116 2117 int i, nfsflavor;
2117 2118 struct secinfo *sp;
2118 2119
2119 2120 /*
2120 2121 * Get the nfs flavor number from xprt.
2121 2122 */
2122 2123 nfsflavor = (int)(uintptr_t)req->rq_xprt->xp_cookie;
2123 2124
2124 2125 sp = exi->exi_export.ex_secinfo;
2125 2126 for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2126 2127 if ((nfsflavor == sp[i].s_secinfo.sc_nfsnum) &&
2127 2128 SEC_REF_EXPORTED(sp + i))
2128 2129 return (TRUE);
2129 2130 }
2130 2131 return (FALSE);
2131 2132 }
2132 2133
2133 2134 /*
2134 2135 * Make an fhandle from a vnode
2135 2136 */
2136 2137 int
2137 2138 makefh(fhandle_t *fh, vnode_t *vp, exportinfo_t *exi)
2138 2139 {
2139 2140 int error;
2140 2141
2141 2142 *fh = exi->exi_fh; /* struct copy */
2142 2143
2143 2144 error = VOP_FID(vp, (fid_t *)&fh->fh_len, NULL);
2144 2145 if (error) {
2145 2146 /*
2146 2147 * Should be something other than EREMOTE
2147 2148 */
2148 2149 return (EREMOTE);
2149 2150 }
2150 2151 return (0);
2151 2152 }
2152 2153
2153 2154 /*
2154 2155 * This routine makes an overloaded V2 fhandle which contains
2155 2156 * sec modes.
2156 2157 *
2157 2158 * Note that the first four octets contain the length octet,
2158 2159 * the status octet, and two padded octets to make them XDR
2159 2160 * four-octet aligned.
2160 2161 *
2161 2162 * 1 2 3 4 32
2162 2163 * +---+---+---+---+---+---+---+---+ +---+---+---+---+ +---+
2163 2164 * | l | s | | | sec_1 |...| sec_n |...| |
2164 2165 * +---+---+---+---+---+---+---+---+ +---+---+---+---+ +---+
2165 2166 *
2166 2167 * where
2167 2168 *
2168 2169 * the status octet s indicates whether there are more security
2169 2170 * flavors (1 means yes, 0 means no) that require the client to
2170 2171 * perform another 0x81 LOOKUP to get them,
2171 2172 *
2172 2173 * the length octet l is the length describing the number of
2173 2174 * valid octets that follow. (l = 4 * n, where n is the number
2174 2175 * of security flavors sent in the current overloaded filehandle.)
2175 2176 *
2176 2177 * sec_index should always be in the inclusive range: [1 - ex_seccnt],
2177 2178 * and it tells server where to start within the secinfo array.
2178 2179 * Usually it will always be 1; however, if more flavors are used
2179 2180 * for the public export than can be encoded in the overloaded FH
2180 2181 * (7 for NFS2), subsequent SNEGO MCLs will have a larger index
2181 2182 * so the server will pick up where it left off from the previous
2182 2183 * MCL reply.
2183 2184 *
2184 2185 * With NFS4 support, implicitly allowed flavors are also in
2185 2186 * the secinfo array; however, they should not be returned in
2186 2187 * SNEGO MCL replies.
2187 2188 */
2188 2189 int
2189 2190 makefh_ol(fhandle_t *fh, exportinfo_t *exi, uint_t sec_index)
2190 2191 {
2191 2192 secinfo_t sec[MAX_FLAVORS];
2192 2193 int totalcnt, i, *ipt, cnt, seccnt, secidx, fh_max_cnt;
2193 2194 char *c;
2194 2195
2195 2196 if (fh == NULL || exi == NULL || sec_index < 1)
2196 2197 return (EREMOTE);
2197 2198
2198 2199 /*
2199 2200 * WebNFS clients need to know the unique set of explicitly
2200 2201 * shared flavors in used for the public export. When
2201 2202 * "TRUE" is passed to build_seclist_nodups(), only explicitly
2202 2203 * shared flavors are included in the list.
2203 2204 */
2204 2205 seccnt = build_seclist_nodups(&exi->exi_export, sec, TRUE);
2205 2206 if (sec_index > seccnt)
2206 2207 return (EREMOTE);
2207 2208
2208 2209 fh_max_cnt = (NFS_FHSIZE / sizeof (int)) - 1;
2209 2210 totalcnt = seccnt - sec_index + 1;
2210 2211 cnt = totalcnt > fh_max_cnt ? fh_max_cnt : totalcnt;
2211 2212
2212 2213 c = (char *)fh;
2213 2214 /*
2214 2215 * Encode the length octet representing the number of
2215 2216 * security flavors (in bytes) in this overloaded fh.
2216 2217 */
2217 2218 *c = cnt * sizeof (int);
2218 2219
2219 2220 /*
2220 2221 * Encode the status octet that indicates whether there
2221 2222 * are more security flavors the client needs to get.
2222 2223 */
2223 2224 *(c + 1) = totalcnt > fh_max_cnt;
2224 2225
2225 2226 /*
2226 2227 * put security flavors in the overloaded fh
2227 2228 */
2228 2229 ipt = (int *)(c + sizeof (int32_t));
2229 2230 secidx = sec_index - 1;
2230 2231 for (i = 0; i < cnt; i++) {
2231 2232 ipt[i] = htonl(sec[i + secidx].s_secinfo.sc_nfsnum);
2232 2233 }
2233 2234 return (0);
2234 2235 }
2235 2236
2236 2237 /*
2237 2238 * Make an nfs_fh3 from a vnode
2238 2239 */
2239 2240 int
2240 2241 makefh3(nfs_fh3 *fh, vnode_t *vp, struct exportinfo *exi)
2241 2242 {
2242 2243 int error;
2243 2244 fid_t fid;
2244 2245
2245 2246 bzero(&fid, sizeof (fid));
2246 2247 fid.fid_len = sizeof (fh->fh3_data);
2247 2248 error = VOP_FID(vp, &fid, NULL);
2248 2249 if (error)
2249 2250 return (EREMOTE);
2250 2251
2251 2252 bzero(fh, sizeof (nfs_fh3));
2252 2253 fh->fh3_fsid = exi->exi_fsid;
2253 2254 fh->fh3_len = fid.fid_len;
2254 2255 bcopy(fid.fid_data, fh->fh3_data, fh->fh3_len);
2255 2256
2256 2257 fh->fh3_xlen = exi->exi_fid.fid_len;
2257 2258 ASSERT(fh->fh3_xlen <= sizeof (fh->fh3_xdata));
2258 2259 bcopy(exi->exi_fid.fid_data, fh->fh3_xdata, fh->fh3_xlen);
2259 2260
2260 2261 fh->fh3_length = sizeof (fh->fh3_fsid)
2261 2262 + sizeof (fh->fh3_len) + fh->fh3_len
2262 2263 + sizeof (fh->fh3_xlen) + fh->fh3_xlen;
2263 2264 fh->fh3_flags = 0;
2264 2265
2265 2266 return (0);
2266 2267 }
2267 2268
2268 2269 /*
2269 2270 * This routine makes an overloaded V3 fhandle which contains
2270 2271 * sec modes.
2271 2272 *
2272 2273 * 1 4
2273 2274 * +--+--+--+--+
2274 2275 * | len |
2275 2276 * +--+--+--+--+
2276 2277 * up to 64
2277 2278 * +--+--+--+--+--+--+--+--+--+--+--+--+ +--+--+--+--+
2278 2279 * |s | | | | sec_1 | sec_2 | ... | sec_n |
2279 2280 * +--+--+--+--+--+--+--+--+--+--+--+--+ +--+--+--+--+
2280 2281 *
2281 2282 * len = 4 * (n+1), where n is the number of security flavors
2282 2283 * sent in the current overloaded filehandle.
2283 2284 *
2284 2285 * the status octet s indicates whether there are more security
2285 2286 * mechanisms (1 means yes, 0 means no) that require the client
2286 2287 * to perform another 0x81 LOOKUP to get them.
2287 2288 *
2288 2289 * Three octets are padded after the status octet.
2289 2290 */
2290 2291 int
2291 2292 makefh3_ol(nfs_fh3 *fh, struct exportinfo *exi, uint_t sec_index)
2292 2293 {
2293 2294 secinfo_t sec[MAX_FLAVORS];
2294 2295 int totalcnt, cnt, *ipt, i, seccnt, fh_max_cnt, secidx;
2295 2296 char *c;
2296 2297
2297 2298 if (fh == NULL || exi == NULL || sec_index < 1)
2298 2299 return (EREMOTE);
2299 2300
2300 2301 /*
2301 2302 * WebNFS clients need to know the unique set of explicitly
2302 2303 * shared flavors in used for the public export. When
2303 2304 * "TRUE" is passed to build_seclist_nodups(), only explicitly
2304 2305 * shared flavors are included in the list.
2305 2306 */
2306 2307 seccnt = build_seclist_nodups(&exi->exi_export, sec, TRUE);
2307 2308
2308 2309 if (sec_index > seccnt)
2309 2310 return (EREMOTE);
2310 2311
2311 2312 fh_max_cnt = (NFS3_FHSIZE / sizeof (int)) - 1;
2312 2313 totalcnt = seccnt - sec_index + 1;
2313 2314 cnt = totalcnt > fh_max_cnt ? fh_max_cnt : totalcnt;
2314 2315
2315 2316 /*
2316 2317 * Place the length in fh3_length representing the number
2317 2318 * of security flavors (in bytes) in this overloaded fh.
2318 2319 */
2319 2320 fh->fh3_flags = FH_WEBNFS;
2320 2321 fh->fh3_length = (cnt+1) * sizeof (int32_t);
2321 2322
2322 2323 c = (char *)&fh->fh3_u.nfs_fh3_i.fh3_i;
2323 2324 /*
2324 2325 * Encode the status octet that indicates whether there
2325 2326 * are more security flavors the client needs to get.
2326 2327 */
2327 2328 *c = totalcnt > fh_max_cnt;
2328 2329
2329 2330 /*
2330 2331 * put security flavors in the overloaded fh
2331 2332 */
2332 2333 secidx = sec_index - 1;
2333 2334 ipt = (int *)(c + sizeof (int32_t));
2334 2335 for (i = 0; i < cnt; i++) {
2335 2336 ipt[i] = htonl(sec[i + secidx].s_secinfo.sc_nfsnum);
2336 2337 }
2337 2338 return (0);
2338 2339 }
2339 2340
2340 2341 /*
2341 2342 * Make an nfs_fh4 from a vnode
2342 2343 */
2343 2344 int
2344 2345 makefh4(nfs_fh4 *fh, vnode_t *vp, struct exportinfo *exi)
2345 2346 {
2346 2347 int error;
2347 2348 nfs_fh4_fmt_t *fh_fmtp = (nfs_fh4_fmt_t *)fh->nfs_fh4_val;
2348 2349 fid_t fid;
2349 2350
2350 2351 bzero(&fid, sizeof (fid));
2351 2352 fid.fid_len = MAXFIDSZ;
2352 2353 /*
2353 2354 * vop_fid_pseudo() is used to set up NFSv4 namespace, so
2354 2355 * use vop_fid_pseudo() here to get the fid instead of VOP_FID.
2355 2356 */
2356 2357 error = vop_fid_pseudo(vp, &fid);
2357 2358 if (error)
2358 2359 return (error);
2359 2360
2360 2361 fh->nfs_fh4_len = NFS_FH4_LEN;
2361 2362
2362 2363 fh_fmtp->fh4_i.fhx_fsid = exi->exi_fh.fh_fsid;
2363 2364 fh_fmtp->fh4_i.fhx_xlen = exi->exi_fh.fh_xlen;
2364 2365
2365 2366 bzero(fh_fmtp->fh4_i.fhx_data, sizeof (fh_fmtp->fh4_i.fhx_data));
2366 2367 bzero(fh_fmtp->fh4_i.fhx_xdata, sizeof (fh_fmtp->fh4_i.fhx_xdata));
2367 2368 ASSERT(exi->exi_fh.fh_xlen <= sizeof (fh_fmtp->fh4_i.fhx_xdata));
2368 2369 bcopy(exi->exi_fh.fh_xdata, fh_fmtp->fh4_i.fhx_xdata,
2369 2370 exi->exi_fh.fh_xlen);
2370 2371
2371 2372 fh_fmtp->fh4_len = fid.fid_len;
2372 2373 ASSERT(fid.fid_len <= sizeof (fh_fmtp->fh4_data));
2373 2374 bcopy(fid.fid_data, fh_fmtp->fh4_data, fid.fid_len);
2374 2375 fh_fmtp->fh4_flag = 0;
2375 2376
2376 2377 #ifdef VOLATILE_FH_TEST
2377 2378 /*
2378 2379 * XXX (temporary?)
2379 2380 * Use the rnode volatile_id value to add volatility to the fh.
2380 2381 *
2381 2382 * For testing purposes there are currently two scenarios, based
2382 2383 * on whether the filesystem was shared with "volatile_fh"
2383 2384 * or "expire_on_rename". In the first case, use the value of
2384 2385 * export struct share_time as the volatile_id. In the second
2385 2386 * case use the vnode volatile_id value (which is set to the
2386 2387 * time in which the file was renamed).
2387 2388 *
2388 2389 * Note that the above are temporary constructs for testing only
2389 2390 * XXX
2390 2391 */
2391 2392 if (exi->exi_export.ex_flags & EX_VOLRNM) {
2392 2393 fh_fmtp->fh4_volatile_id = find_volrnm_fh_id(exi, fh);
2393 2394 } else if (exi->exi_export.ex_flags & EX_VOLFH) {
2394 2395 fh_fmtp->fh4_volatile_id = exi->exi_volatile_id;
2395 2396 } else {
2396 2397 fh_fmtp->fh4_volatile_id = 0;
2397 2398 }
2398 2399 #endif /* VOLATILE_FH_TEST */
2399 2400
2400 2401 return (0);
2401 2402 }
2402 2403
2403 2404 /*
2404 2405 * Convert an fhandle into a vnode.
2405 2406 * Uses the file id (fh_len + fh_data) in the fhandle to get the vnode.
2406 2407 * WARNING: users of this routine must do a VN_RELE on the vnode when they
2407 2408 * are done with it.
2408 2409 */
2409 2410 vnode_t *
2410 2411 nfs_fhtovp(fhandle_t *fh, struct exportinfo *exi)
2411 2412 {
2412 2413 vfs_t *vfsp;
2413 2414 vnode_t *vp;
2414 2415 int error;
2415 2416 fid_t *fidp;
2416 2417
2417 2418 TRACE_0(TR_FAC_NFS, TR_FHTOVP_START,
2418 2419 "fhtovp_start");
2419 2420
2420 2421 if (exi == NULL) {
2421 2422 TRACE_1(TR_FAC_NFS, TR_FHTOVP_END,
2422 2423 "fhtovp_end:(%S)", "exi NULL");
2423 2424 return (NULL); /* not exported */
2424 2425 }
2425 2426
2426 2427 ASSERT(exi->exi_vp != NULL);
2427 2428
2428 2429 if (PUBLIC_FH2(fh)) {
2429 2430 if (exi->exi_export.ex_flags & EX_PUBLIC) {
2430 2431 TRACE_1(TR_FAC_NFS, TR_FHTOVP_END,
2431 2432 "fhtovp_end:(%S)", "root not exported");
2432 2433 return (NULL);
2433 2434 }
2434 2435 vp = exi->exi_vp;
2435 2436 VN_HOLD(vp);
2436 2437 return (vp);
2437 2438 }
2438 2439
2439 2440 vfsp = exi->exi_vp->v_vfsp;
2440 2441 ASSERT(vfsp != NULL);
2441 2442 fidp = (fid_t *)&fh->fh_len;
2442 2443
2443 2444 error = VFS_VGET(vfsp, &vp, fidp);
2444 2445 if (error || vp == NULL) {
2445 2446 TRACE_1(TR_FAC_NFS, TR_FHTOVP_END,
2446 2447 "fhtovp_end:(%S)", "VFS_GET failed or vp NULL");
2447 2448 return (NULL);
2448 2449 }
2449 2450 TRACE_1(TR_FAC_NFS, TR_FHTOVP_END,
2450 2451 "fhtovp_end:(%S)", "end");
2451 2452 return (vp);
2452 2453 }
2453 2454
2454 2455 /*
2455 2456 * Convert an nfs_fh3 into a vnode.
2456 2457 * Uses the file id (fh_len + fh_data) in the file handle to get the vnode.
2457 2458 * WARNING: users of this routine must do a VN_RELE on the vnode when they
2458 2459 * are done with it.
2459 2460 */
2460 2461 vnode_t *
2461 2462 nfs3_fhtovp(nfs_fh3 *fh, struct exportinfo *exi)
2462 2463 {
2463 2464 vfs_t *vfsp;
2464 2465 vnode_t *vp;
2465 2466 int error;
2466 2467 fid_t *fidp;
2467 2468
2468 2469 if (exi == NULL)
2469 2470 return (NULL); /* not exported */
2470 2471
2471 2472 ASSERT(exi->exi_vp != NULL);
2472 2473
2473 2474 if (PUBLIC_FH3(fh)) {
2474 2475 if (exi->exi_export.ex_flags & EX_PUBLIC)
2475 2476 return (NULL);
2476 2477 vp = exi->exi_vp;
2477 2478 VN_HOLD(vp);
2478 2479 return (vp);
2479 2480 }
2480 2481
2481 2482 if (fh->fh3_length < NFS3_OLDFHSIZE ||
2482 2483 fh->fh3_length > NFS3_MAXFHSIZE)
2483 2484 return (NULL);
2484 2485
2485 2486 vfsp = exi->exi_vp->v_vfsp;
2486 2487 ASSERT(vfsp != NULL);
2487 2488 fidp = FH3TOFIDP(fh);
2488 2489
2489 2490 error = VFS_VGET(vfsp, &vp, fidp);
2490 2491 if (error || vp == NULL)
2491 2492 return (NULL);
2492 2493
2493 2494 return (vp);
2494 2495 }
2495 2496
2496 2497 /*
2497 2498 * Convert an nfs_fh4 into a vnode.
2498 2499 * Uses the file id (fh_len + fh_data) in the file handle to get the vnode.
2499 2500 * WARNING: users of this routine must do a VN_RELE on the vnode when they
2500 2501 * are done with it.
2501 2502 */
2502 2503 vnode_t *
2503 2504 nfs4_fhtovp(nfs_fh4 *fh, struct exportinfo *exi, nfsstat4 *statp)
2504 2505 {
2505 2506 vfs_t *vfsp;
2506 2507 vnode_t *vp = NULL;
2507 2508 int error;
2508 2509 fid_t *fidp;
2509 2510 nfs_fh4_fmt_t *fh_fmtp;
2510 2511 #ifdef VOLATILE_FH_TEST
2511 2512 uint32_t volatile_id = 0;
2512 2513 #endif /* VOLATILE_FH_TEST */
2513 2514
2514 2515 if (exi == NULL) {
2515 2516 *statp = NFS4ERR_STALE;
2516 2517 return (NULL); /* not exported */
2517 2518 }
2518 2519 ASSERT(exi->exi_vp != NULL);
2519 2520
2520 2521 /* caller should have checked this */
2521 2522 ASSERT(fh->nfs_fh4_len >= NFS_FH4_LEN);
2522 2523
2523 2524 fh_fmtp = (nfs_fh4_fmt_t *)fh->nfs_fh4_val;
2524 2525 vfsp = exi->exi_vp->v_vfsp;
2525 2526 ASSERT(vfsp != NULL);
2526 2527 fidp = (fid_t *)&fh_fmtp->fh4_len;
2527 2528
2528 2529 #ifdef VOLATILE_FH_TEST
2529 2530 /* XXX check if volatile - should be changed later */
2530 2531 if (exi->exi_export.ex_flags & (EX_VOLRNM | EX_VOLFH)) {
2531 2532 /*
2532 2533 * Filesystem is shared with volatile filehandles
2533 2534 */
2534 2535 if (exi->exi_export.ex_flags & EX_VOLRNM)
2535 2536 volatile_id = find_volrnm_fh_id(exi, fh);
2536 2537 else
2537 2538 volatile_id = exi->exi_volatile_id;
2538 2539
2539 2540 if (fh_fmtp->fh4_volatile_id != volatile_id) {
2540 2541 *statp = NFS4ERR_FHEXPIRED;
2541 2542 return (NULL);
2542 2543 }
2543 2544 }
2544 2545 /*
2545 2546 * XXX even if test_volatile_fh false, the fh may contain a
2546 2547 * volatile id if obtained when the test was set.
2547 2548 */
2548 2549 fh_fmtp->fh4_volatile_id = (uchar_t)0;
2549 2550 #endif /* VOLATILE_FH_TEST */
2550 2551
2551 2552 error = VFS_VGET(vfsp, &vp, fidp);
2552 2553 /*
2553 2554 * If we can not get vp from VFS_VGET, perhaps this is
2554 2555 * an nfs v2/v3/v4 node in an nfsv4 pseudo filesystem.
2555 2556 * Check it out.
2556 2557 */
2557 2558 if (error && PSEUDO(exi))
2558 2559 error = nfs4_vget_pseudo(exi, &vp, fidp);
2559 2560
2560 2561 if (error || vp == NULL) {
2561 2562 *statp = NFS4ERR_STALE;
2562 2563 return (NULL);
2563 2564 }
2564 2565 /* XXX - disgusting hack */
2565 2566 if (vp->v_type == VNON && vp->v_flag & V_XATTRDIR)
2566 2567 vp->v_type = VDIR;
2567 2568 *statp = NFS4_OK;
2568 2569 return (vp);
2569 2570 }
2570 2571
2571 2572 /*
2572 2573 * Find the export structure associated with the given filesystem.
2573 2574 * If found, then increment the ref count (exi_count).
2574 2575 */
2575 2576 struct exportinfo *
2576 2577 checkexport(fsid_t *fsid, fid_t *fid)
2577 2578 {
2578 2579 struct exportinfo *exi;
2579 2580 nfs_export_t *ne = nfs_get_export();
2580 2581
2581 2582 rw_enter(&ne->exported_lock, RW_READER);
2582 2583 for (exi = ne->exptable[exptablehash(fsid, fid)];
2583 2584 exi != NULL;
2584 2585 exi = exi->fid_hash.next) {
2585 2586 if (exportmatch(exi, fsid, fid)) {
2586 2587 /*
2587 2588 * If this is the place holder for the
2588 2589 * public file handle, then return the
2589 2590 * real export entry for the public file
2590 2591 * handle.
2591 2592 */
2592 2593 if (exi->exi_export.ex_flags & EX_PUBLIC) {
2593 2594 exi = ne->exi_public;
2594 2595 }
2595 2596
2596 2597 exi_hold(exi);
2597 2598 rw_exit(&ne->exported_lock);
2598 2599 return (exi);
2599 2600 }
2600 2601 }
2601 2602 rw_exit(&ne->exported_lock);
2602 2603 return (NULL);
2603 2604 }
2604 2605
2605 2606
2606 2607 /*
2607 2608 * "old school" version of checkexport() for NFS4. NFS4
2608 2609 * rfs4_compound holds exported_lock for duration of compound
2609 2610 * processing. This version doesn't manipulate exi_count
2610 2611 * since NFS4 breaks fundamental assumptions in the exi_count
2611 2612 * design.
2612 2613 */
2613 2614 struct exportinfo *
2614 2615 checkexport4(fsid_t *fsid, fid_t *fid, vnode_t *vp)
2615 2616 {
2616 2617 struct exportinfo *exi;
2617 2618 nfs_export_t *ne = nfs_get_export();
2618 2619
2619 2620 ASSERT(RW_LOCK_HELD(&ne->exported_lock));
2620 2621
2621 2622 for (exi = ne->exptable[exptablehash(fsid, fid)];
2622 2623 exi != NULL;
2623 2624 exi = exi->fid_hash.next) {
2624 2625 if (exportmatch(exi, fsid, fid)) {
2625 2626 /*
2626 2627 * If this is the place holder for the
2627 2628 * public file handle, then return the
2628 2629 * real export entry for the public file
2629 2630 * handle.
2630 2631 */
2631 2632 if (exi->exi_export.ex_flags & EX_PUBLIC) {
2632 2633 exi = ne->exi_public;
2633 2634 }
2634 2635
2635 2636 /*
2636 2637 * If vp is given, check if vp is the
2637 2638 * same vnode as the exported node.
2638 2639 *
2639 2640 * Since VOP_FID of a lofs node returns the
2640 2641 * fid of its real node (ufs), the exported
2641 2642 * node for lofs and (pseudo) ufs may have
2642 2643 * the same fsid and fid.
2643 2644 */
2644 2645 if (vp == NULL || vp == exi->exi_vp)
2645 2646 return (exi);
2646 2647 }
2647 2648 }
2648 2649
2649 2650 return (NULL);
2650 2651 }
2651 2652
2652 2653 /*
2653 2654 * Free an entire export list node
2654 2655 */
2655 2656 void
2656 2657 exportfree(struct exportinfo *exi)
2657 2658 {
2658 2659 struct exportdata *ex;
2659 2660 struct charset_cache *cache;
2660 2661 int i;
2661 2662
2662 2663 ex = &exi->exi_export;
2663 2664
2664 2665 ASSERT(exi->exi_vp != NULL && !(exi->exi_export.ex_flags & EX_PUBLIC));
2665 2666 VN_RELE(exi->exi_vp);
2666 2667 if (exi->exi_dvp != NULL)
2667 2668 VN_RELE(exi->exi_dvp);
2668 2669
2669 2670 if (ex->ex_flags & EX_INDEX)
2670 2671 kmem_free(ex->ex_index, strlen(ex->ex_index) + 1);
2671 2672
2672 2673 kmem_free(ex->ex_path, ex->ex_pathlen + 1);
2673 2674 nfsauth_cache_free(exi);
2674 2675
2675 2676 /*
2676 2677 * if there is a character set mapping cached, clean it up.
2677 2678 */
2678 2679 for (cache = exi->exi_charset; cache != NULL;
2679 2680 cache = exi->exi_charset) {
2680 2681 if (cache->inbound != (kiconv_t)-1)
2681 2682 (void) kiconv_close(cache->inbound);
2682 2683 if (cache->outbound != (kiconv_t)-1)
2683 2684 (void) kiconv_close(cache->outbound);
2684 2685 exi->exi_charset = cache->next;
2685 2686 kmem_free(cache, sizeof (struct charset_cache));
2686 2687 }
2687 2688
2688 2689 if (exi->exi_logbuffer != NULL)
2689 2690 nfslog_disable(exi);
2690 2691
2691 2692 if (ex->ex_flags & EX_LOG) {
2692 2693 kmem_free(ex->ex_log_buffer, ex->ex_log_bufferlen + 1);
2693 2694 kmem_free(ex->ex_tag, ex->ex_taglen + 1);
2694 2695 }
2695 2696
2696 2697 if (exi->exi_visible)
2697 2698 free_visible(exi->exi_visible);
2698 2699
2699 2700 srv_secinfo_list_free(ex->ex_secinfo, ex->ex_seccnt);
2700 2701
2701 2702 #ifdef VOLATILE_FH_TEST
2702 2703 free_volrnm_list(exi);
2703 2704 mutex_destroy(&exi->exi_vol_rename_lock);
2704 2705 #endif /* VOLATILE_FH_TEST */
2705 2706
2706 2707 mutex_destroy(&exi->exi_lock);
2707 2708 rw_destroy(&exi->exi_cache_lock);
2708 2709 /*
2709 2710 * All nodes in the exi_cache AVL trees were removed and freed in the
2710 2711 * nfsauth_cache_free() call above. We will just destroy and free the
2711 2712 * empty AVL trees here.
2712 2713 */
2713 2714 for (i = 0; i < AUTH_TABLESIZE; i++) {
2714 2715 avl_destroy(exi->exi_cache[i]);
2715 2716 kmem_free(exi->exi_cache[i], sizeof (avl_tree_t));
2716 2717 }
2717 2718
2718 2719 kmem_free(exi, sizeof (*exi));
2719 2720 }
2720 2721
2721 2722 /*
2722 2723 * load the index file from user space into kernel space.
2723 2724 */
2724 2725 static int
2725 2726 loadindex(struct exportdata *kex)
2726 2727 {
2727 2728 int error;
2728 2729 char index[MAXNAMELEN+1];
2729 2730 size_t len;
2730 2731
2731 2732 /*
2732 2733 * copyinstr copies the complete string including the NULL and
2733 2734 * returns the len with the NULL byte included in the calculation
2734 2735 * as long as the max length is not exceeded.
2735 2736 */
2736 2737 if (error = copyinstr(kex->ex_index, index, sizeof (index), &len))
2737 2738 return (error);
2738 2739
2739 2740 kex->ex_index = kmem_alloc(len, KM_SLEEP);
2740 2741 bcopy(index, kex->ex_index, len);
2741 2742
2742 2743 return (0);
2743 2744 }
2744 2745
2745 2746 void
2746 2747 exi_hold(struct exportinfo *exi)
2747 2748 {
2748 2749 mutex_enter(&exi->exi_lock);
2749 2750 exi->exi_count++;
2750 2751 mutex_exit(&exi->exi_lock);
2751 2752 }
2752 2753
2753 2754 /*
2754 2755 * When a thread completes using exi, it should call exi_rele().
2755 2756 * exi_rele() decrements exi_count. It releases exi if exi_count == 0, i.e.
2756 2757 * if this is the last user of exi and exi is not on exportinfo list anymore
2757 2758 */
2758 2759 void
2759 2760 exi_rele(struct exportinfo *exi)
2760 2761 {
2761 2762 mutex_enter(&exi->exi_lock);
2762 2763 exi->exi_count--;
2763 2764 if (exi->exi_count == 0) {
2764 2765 mutex_exit(&exi->exi_lock);
2765 2766 exportfree(exi);
2766 2767 } else
2767 2768 mutex_exit(&exi->exi_lock);
2768 2769 }
2769 2770
2770 2771 #ifdef VOLATILE_FH_TEST
2771 2772 /*
2772 2773 * Test for volatile fh's - add file handle to list and set its volatile id
2773 2774 * to time it was renamed. If EX_VOLFH is also on and the fs is reshared,
2774 2775 * the vol_rename queue is purged.
2775 2776 *
2776 2777 * XXX This code is for unit testing purposes only... To correctly use it, it
2777 2778 * needs to tie a rename list to the export struct and (more
2778 2779 * important), protect access to the exi rename list using a write lock.
2779 2780 */
2780 2781
2781 2782 /*
2782 2783 * get the fh vol record if it's in the volatile on rename list. Don't check
2783 2784 * volatile_id in the file handle - compare only the file handles.
2784 2785 */
2785 2786 static struct ex_vol_rename *
2786 2787 find_volrnm_fh(struct exportinfo *exi, nfs_fh4 *fh4p)
2787 2788 {
2788 2789 struct ex_vol_rename *p = NULL;
2789 2790 fhandle4_t *fhp;
2790 2791
2791 2792 /* XXX shouldn't we assert &exported_lock held? */
2792 2793 ASSERT(MUTEX_HELD(&exi->exi_vol_rename_lock));
2793 2794
2794 2795 if (fh4p->nfs_fh4_len != NFS_FH4_LEN) {
2795 2796 return (NULL);
2796 2797 }
2797 2798 fhp = &((nfs_fh4_fmt_t *)fh4p->nfs_fh4_val)->fh4_i;
2798 2799 for (p = exi->exi_vol_rename; p != NULL; p = p->vrn_next) {
2799 2800 if (bcmp(fhp, &p->vrn_fh_fmt.fh4_i,
2800 2801 sizeof (fhandle4_t)) == 0)
2801 2802 break;
2802 2803 }
2803 2804 return (p);
2804 2805 }
2805 2806
2806 2807 /*
2807 2808 * get the volatile id for the fh (if there is - else return 0). Ignore the
2808 2809 * volatile_id in the file handle - compare only the file handles.
2809 2810 */
2810 2811 static uint32_t
2811 2812 find_volrnm_fh_id(struct exportinfo *exi, nfs_fh4 *fh4p)
2812 2813 {
2813 2814 struct ex_vol_rename *p;
2814 2815 uint32_t volatile_id;
2815 2816
2816 2817 mutex_enter(&exi->exi_vol_rename_lock);
2817 2818 p = find_volrnm_fh(exi, fh4p);
2818 2819 volatile_id = (p ? p->vrn_fh_fmt.fh4_volatile_id :
2819 2820 exi->exi_volatile_id);
2820 2821 mutex_exit(&exi->exi_vol_rename_lock);
2821 2822 return (volatile_id);
2822 2823 }
2823 2824
2824 2825 /*
2825 2826 * Free the volatile on rename list - will be called if a filesystem is
2826 2827 * unshared or reshared without EX_VOLRNM
2827 2828 */
2828 2829 static void
2829 2830 free_volrnm_list(struct exportinfo *exi)
2830 2831 {
2831 2832 struct ex_vol_rename *p, *pnext;
2832 2833
2833 2834 /* no need to hold mutex lock - this one is called from exportfree */
2834 2835 for (p = exi->exi_vol_rename; p != NULL; p = pnext) {
2835 2836 pnext = p->vrn_next;
2836 2837 kmem_free(p, sizeof (*p));
2837 2838 }
2838 2839 exi->exi_vol_rename = NULL;
2839 2840 }
2840 2841
2841 2842 /*
2842 2843 * Add a file handle to the volatile on rename list.
2843 2844 */
2844 2845 void
2845 2846 add_volrnm_fh(struct exportinfo *exi, vnode_t *vp)
2846 2847 {
2847 2848 struct ex_vol_rename *p;
2848 2849 char fhbuf[NFS4_FHSIZE];
2849 2850 nfs_fh4 fh4;
2850 2851 int error;
2851 2852
2852 2853 fh4.nfs_fh4_val = fhbuf;
2853 2854 error = makefh4(&fh4, vp, exi);
2854 2855 if ((error) || (fh4.nfs_fh4_len != sizeof (p->vrn_fh_fmt))) {
2855 2856 return;
2856 2857 }
2857 2858
2858 2859 mutex_enter(&exi->exi_vol_rename_lock);
2859 2860
2860 2861 p = find_volrnm_fh(exi, &fh4);
2861 2862
2862 2863 if (p == NULL) {
2863 2864 p = kmem_alloc(sizeof (*p), KM_SLEEP);
2864 2865 bcopy(fh4.nfs_fh4_val, &p->vrn_fh_fmt, sizeof (p->vrn_fh_fmt));
2865 2866 p->vrn_next = exi->exi_vol_rename;
2866 2867 exi->exi_vol_rename = p;
2867 2868 }
2868 2869
2869 2870 p->vrn_fh_fmt.fh4_volatile_id = gethrestime_sec();
2870 2871 mutex_exit(&exi->exi_vol_rename_lock);
2871 2872 }
2872 2873
2873 2874 #endif /* VOLATILE_FH_TEST */
|
↓ open down ↓ |
784 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX