Print this page
Bad assertions
nfs_export_zone_init() can't assume called in zone-context.
curzone reality check and teardown changes to use the RIGHT zone
| 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
|
↓ open down ↓ |
684 lines elided |
↑ open up ↑ |
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 +#ifdef DEBUG
696 + zone_t *zone = NULL;
697 +#endif
695 698
696 699 for (;;) {
697 700 tnode = tnode->tree_parent;
701 +#ifdef DEBUG
702 + if (zone == NULL && tnode->tree_exi != NULL)
703 + zone = tnode->tree_exi->exi_zone;
704 +#endif
698 705 if (TREE_ROOT(tnode)) {
706 + ASSERT3P(zone, ==, tnode->tree_exi->exi_zone);
699 707 exi_ret = tnode->tree_exi;
700 708 break;
701 709 }
702 710 }
703 711
704 712 ASSERT(exi_ret); /* Every visible should have its home exportinfo */
705 713 return (exi_ret);
706 714 }
707 715
708 716 /*
709 717 * For NFS V4.
710 718 * Add or remove the newly exported or unexported security flavors of the
711 719 * given exportinfo from its ancestors upto the system root.
712 720 */
713 721 void
714 722 srv_secinfo_treeclimb(nfs_export_t *ne, exportinfo_t *exip, secinfo_t *sec,
715 723 int seccnt, bool_t isadd)
716 724 {
717 725 treenode_t *tnode = exip->exi_tree;
718 726
719 727 ASSERT(RW_WRITE_HELD(&ne->exported_lock));
720 728 ASSERT(tnode != NULL);
721 729
722 730 if (seccnt == 0)
723 731 return;
724 732
725 733 /*
726 734 * If flavors are being added and the new export root isn't
727 735 * also VROOT, its implicitly allowed flavors are inherited from
728 736 * its pseudonode.
729 737 * Note - for VROOT exports the implicitly allowed flavors were
730 738 * transferred from the PSEUDO export in exportfs()
731 739 */
732 740 if (isadd && !(exip->exi_vp->v_flag & VROOT) &&
733 741 !VN_IS_CURZONEROOT(exip->exi_vp) &&
734 742 tnode->tree_vis->vis_seccnt > 0) {
735 743 srv_secinfo_add(&exip->exi_export.ex_secinfo,
736 744 &exip->exi_export.ex_seccnt, tnode->tree_vis->vis_secinfo,
737 745 tnode->tree_vis->vis_seccnt, FALSE);
738 746 }
739 747
740 748 /*
741 749 * Move to parent node and propagate sec flavor
742 750 * to exportinfo and to visible structures.
743 751 */
744 752 tnode = tnode->tree_parent;
745 753
746 754 while (tnode != NULL) {
747 755
748 756 /* If there is exportinfo, update it */
749 757 if (tnode->tree_exi != NULL) {
750 758 secinfo_t **pxsec =
751 759 &tnode->tree_exi->exi_export.ex_secinfo;
752 760 int *pxcnt = &tnode->tree_exi->exi_export.ex_seccnt;
753 761 int is_pseudo = PSEUDO(tnode->tree_exi);
754 762 if (isadd)
755 763 srv_secinfo_add(pxsec, pxcnt, sec, seccnt,
756 764 is_pseudo);
757 765 else
758 766 srv_secinfo_remove(pxsec, pxcnt, sec, seccnt);
759 767 }
760 768
761 769 /* Update every visible - only root node has no visible */
762 770 if (tnode->tree_vis != NULL) {
763 771 secinfo_t **pxsec = &tnode->tree_vis->vis_secinfo;
764 772 int *pxcnt = &tnode->tree_vis->vis_seccnt;
765 773 if (isadd)
766 774 srv_secinfo_add(pxsec, pxcnt, sec, seccnt,
767 775 FALSE);
768 776 else
769 777 srv_secinfo_remove(pxsec, pxcnt, sec, seccnt);
770 778 }
771 779 tnode = tnode->tree_parent;
772 780 }
773 781 }
774 782
775 783 /* hash_name is a text substitution for either fid_hash or path_hash */
776 784 #define exp_hash_unlink(exi, hash_name) \
777 785 if (*(exi)->hash_name.bckt == (exi)) \
778 786 *(exi)->hash_name.bckt = (exi)->hash_name.next; \
779 787 if ((exi)->hash_name.prev) \
780 788 (exi)->hash_name.prev->hash_name.next = (exi)->hash_name.next; \
781 789 if ((exi)->hash_name.next) \
782 790 (exi)->hash_name.next->hash_name.prev = (exi)->hash_name.prev; \
783 791 (exi)->hash_name.bckt = NULL;
784 792
785 793 #define exp_hash_link(exi, hash_name, bucket) \
786 794 (exi)->hash_name.bckt = (bucket); \
787 795 (exi)->hash_name.prev = NULL; \
788 796 (exi)->hash_name.next = *(bucket); \
789 797 if ((exi)->hash_name.next) \
790 798 (exi)->hash_name.next->hash_name.prev = (exi); \
791 799 *(bucket) = (exi);
792 800
793 801 void
794 802 export_link(nfs_export_t *ne, exportinfo_t *exi)
795 803 {
796 804 exportinfo_t **bckt;
797 805
798 806 ASSERT(RW_WRITE_HELD(&ne->exported_lock));
799 807
800 808 bckt = &ne->exptable[exptablehash(&exi->exi_fsid, &exi->exi_fid)];
801 809 exp_hash_link(exi, fid_hash, bckt);
802 810
803 811 bckt = &ne->exptable_path_hash[pkp_tab_hash(exi->exi_export.ex_path,
804 812 strlen(exi->exi_export.ex_path))];
805 813 exp_hash_link(exi, path_hash, bckt);
806 814 }
807 815
808 816 /*
809 817 * Helper functions for exi_id handling
810 818 */
811 819 static int
812 820 exi_id_compar(const void *v1, const void *v2)
813 821 {
814 822 const struct exportinfo *e1 = v1;
815 823 const struct exportinfo *e2 = v2;
816 824
817 825 if (e1->exi_id < e2->exi_id)
818 826 return (-1);
819 827 if (e1->exi_id > e2->exi_id)
820 828 return (1);
821 829
822 830 return (0);
823 831 }
824 832
825 833 int
826 834 exi_id_get_next()
827 835 {
828 836 struct exportinfo e;
829 837 int ret = exi_id_next;
830 838
831 839 ASSERT(MUTEX_HELD(&nfs_exi_id_lock));
832 840
833 841 do {
834 842 exi_id_next++;
835 843 if (exi_id_next == 0)
836 844 exi_id_overflow = TRUE;
837 845
838 846 if (!exi_id_overflow)
839 847 break;
840 848
841 849 if (exi_id_next == ret)
842 850 cmn_err(CE_PANIC, "exi_id exhausted");
843 851
844 852 e.exi_id = exi_id_next;
845 853 } while (avl_find(&exi_id_tree, &e, NULL) != NULL);
846 854
847 855 return (ret);
848 856 }
849 857
850 858 /*ARGSUSED*/
851 859 static void *
852 860 nfs_export_zone_init(zoneid_t zoneid)
853 861 {
854 862 int i;
855 863 nfs_export_t *ne;
856 864
857 865 ne = kmem_zalloc(sizeof (*ne), KM_SLEEP);
858 866
859 867 rw_init(&ne->exported_lock, NULL, RW_DEFAULT, NULL);
860 868
861 869 /*
862 870 * Allocate the place holder for the public file handle, which
863 871 * is all zeroes. It is initially set to the root filesystem.
864 872 */
865 873 ne->exi_root = kmem_zalloc(sizeof (*ne->exi_root), KM_SLEEP);
866 874 ne->exi_public = ne->exi_root;
867 875
|
↓ open down ↓ |
159 lines elided |
↑ open up ↑ |
868 876 ne->exi_root->exi_export.ex_flags = EX_PUBLIC;
869 877 ne->exi_root->exi_export.ex_pathlen = 1; /* length of "/" */
870 878 ne->exi_root->exi_export.ex_path =
871 879 kmem_alloc(ne->exi_root->exi_export.ex_pathlen + 1, KM_SLEEP);
872 880 ne->exi_root->exi_export.ex_path[0] = '/';
873 881 ne->exi_root->exi_export.ex_path[1] = '\0';
874 882
875 883 ne->exi_root->exi_count = 1;
876 884 mutex_init(&ne->exi_root->exi_lock, NULL, MUTEX_DEFAULT, NULL);
877 885
878 - ne->exi_root->exi_vp = ZONE_ROOTVP();
886 + ne->exi_root->exi_zone = zone_find_by_id_nolock(zoneid);
887 + ne->exi_root->exi_vp = ne->exi_root->exi_zone->zone_rootvp;
879 888 ne->exi_rootfid.fid_len = MAXFIDSZ;
880 889 if (vop_fid_pseudo(ne->exi_root->exi_vp, &ne->exi_rootfid) != 0) {
881 890 mutex_destroy(&ne->exi_root->exi_lock);
882 891 kmem_free(ne->exi_root->exi_export.ex_path,
883 892 ne->exi_root->exi_export.ex_pathlen + 1);
884 893 kmem_free(ne->exi_root, sizeof (*ne->exi_root));
885 894 return (NULL);
886 895 }
887 896
888 897 /* Initialize auth cache and auth cache lock */
889 898 for (i = 0; i < AUTH_TABLESIZE; i++) {
890 899 ne->exi_root->exi_cache[i] = kmem_alloc(sizeof (avl_tree_t),
891 900 KM_SLEEP);
892 901 avl_create(ne->exi_root->exi_cache[i],
893 902 nfsauth_cache_clnt_compar, sizeof (struct auth_cache_clnt),
894 903 offsetof(struct auth_cache_clnt, authc_link));
895 904 }
896 905 rw_init(&ne->exi_root->exi_cache_lock, NULL, RW_DEFAULT, NULL);
897 906
898 907 /* Setup the fhandle template */
899 908 ne->exi_root->exi_fh.fh_fsid = rootdir->v_vfsp->vfs_fsid;
900 909 ne->exi_root->exi_fh.fh_xlen = ne->exi_rootfid.fid_len;
901 910 bcopy(ne->exi_rootfid.fid_data, ne->exi_root->exi_fh.fh_xdata,
902 911 ne->exi_rootfid.fid_len);
903 912 ne->exi_root->exi_fh.fh_len = sizeof (ne->exi_root->exi_fh.fh_data);
904 913
905 914 rw_enter(&ne->exported_lock, RW_WRITER);
906 915
907 916 /* Publish the exportinfo in the hash table */
908 917 export_link(ne, ne->exi_root);
909 918
910 919 /* Initialize exi_id and exi_kstats */
911 920 mutex_enter(&nfs_exi_id_lock);
912 921 ne->exi_root->exi_id = exi_id_get_next();
913 922 avl_add(&exi_id_tree, ne->exi_root);
914 923 mutex_exit(&nfs_exi_id_lock);
915 924
916 925 rw_exit(&ne->exported_lock);
917 926 ne->ns_root = NULL;
918 927
919 928 return (ne);
920 929 }
921 930
922 931 /*ARGSUSED*/
923 932 static void
924 933 nfs_export_zone_fini(zoneid_t zoneid, void *data)
925 934 {
926 935 int i;
927 936 nfs_export_t *ne = data;
928 937 struct exportinfo *exi;
929 938
930 939 rw_enter(&ne->exported_lock, RW_WRITER);
931 940 mutex_enter(&nfs_exi_id_lock);
932 941
933 942 avl_remove(&exi_id_tree, ne->exi_root);
934 943 export_unlink(ne, ne->exi_root);
935 944
936 945 mutex_exit(&nfs_exi_id_lock);
937 946 rw_exit(&ne->exported_lock);
938 947
939 948 /* Deallocate the place holder for the public file handle */
940 949 srv_secinfo_list_free(ne->exi_root->exi_export.ex_secinfo,
941 950 ne->exi_root->exi_export.ex_seccnt);
942 951 mutex_destroy(&ne->exi_root->exi_lock);
943 952
944 953 rw_destroy(&ne->exi_root->exi_cache_lock);
945 954 for (i = 0; i < AUTH_TABLESIZE; i++) {
946 955 avl_destroy(ne->exi_root->exi_cache[i]);
947 956 kmem_free(ne->exi_root->exi_cache[i], sizeof (avl_tree_t));
948 957 }
949 958
950 959 kmem_free(ne->exi_root->exi_export.ex_path,
951 960 ne->exi_root->exi_export.ex_pathlen + 1);
952 961 kmem_free(ne->exi_root, sizeof (*ne->exi_root));
953 962
954 963 exi = avl_first(&exi_id_tree);
955 964 while (exi != NULL) {
956 965 struct exportinfo *nexi = AVL_NEXT(&exi_id_tree, exi);
957 966 if (zoneid == exi->exi_zoneid)
958 967 (void) unexport(ne, exi);
959 968 exi = nexi;
960 969 }
961 970
962 971 rw_destroy(&ne->exported_lock);
963 972 kmem_free(ne, sizeof (*ne));
964 973 }
965 974
966 975 /*
967 976 * Initialization routine for export routines.
968 977 * Should only be called once.
969 978 */
970 979 void
971 980 nfs_exportinit(void)
972 981 {
973 982 mutex_init(&nfs_exi_id_lock, NULL, MUTEX_DEFAULT, NULL);
974 983
975 984 /* exi_id handling initialization */
976 985 exi_id_next = 0;
977 986 exi_id_overflow = FALSE;
978 987 avl_create(&exi_id_tree, exi_id_compar, sizeof (struct exportinfo),
979 988 offsetof(struct exportinfo, exi_id_link));
980 989
981 990 zone_key_create(&nfs_export_key, nfs_export_zone_init,
982 991 NULL, nfs_export_zone_fini);
983 992
984 993 nfslog_init();
985 994 }
986 995
987 996 /*
988 997 * Finalization routine for export routines.
989 998 */
990 999 void
991 1000 nfs_exportfini(void)
992 1001 {
993 1002 (void) zone_key_delete(nfs_export_key);
994 1003 avl_destroy(&exi_id_tree);
995 1004 mutex_destroy(&nfs_exi_id_lock);
996 1005 }
997 1006
998 1007 /*
999 1008 * Check if 2 gss mechanism identifiers are the same.
1000 1009 *
1001 1010 * return FALSE if not the same.
1002 1011 * return TRUE if the same.
1003 1012 */
1004 1013 static bool_t
1005 1014 nfs_mech_equal(rpc_gss_OID mech1, rpc_gss_OID mech2)
1006 1015 {
1007 1016 if ((mech1->length == 0) && (mech2->length == 0))
1008 1017 return (TRUE);
1009 1018
1010 1019 if (mech1->length != mech2->length)
1011 1020 return (FALSE);
1012 1021
1013 1022 return (bcmp(mech1->elements, mech2->elements, mech1->length) == 0);
1014 1023 }
1015 1024
1016 1025 /*
1017 1026 * This routine is used by rpc to map rpc security number
1018 1027 * to nfs specific security flavor number.
1019 1028 *
1020 1029 * The gss callback prototype is
1021 1030 * callback(struct svc_req *, gss_cred_id_t *, gss_ctx_id_t *,
1022 1031 * rpc_gss_lock_t *, void **),
1023 1032 * since nfs does not use the gss_cred_id_t/gss_ctx_id_t arguments
1024 1033 * we cast them to void.
1025 1034 */
1026 1035 /*ARGSUSED*/
1027 1036 bool_t
1028 1037 rfs_gsscallback(struct svc_req *req, gss_cred_id_t deleg, void *gss_context,
1029 1038 rpc_gss_lock_t *lock, void **cookie)
1030 1039 {
1031 1040 int i, j;
1032 1041 rpc_gss_rawcred_t *raw_cred;
1033 1042 struct exportinfo *exi;
1034 1043 nfs_export_t *ne = nfs_get_export();
1035 1044
1036 1045 /*
1037 1046 * We don't deal with delegated credentials.
1038 1047 */
1039 1048 if (deleg != GSS_C_NO_CREDENTIAL)
1040 1049 return (FALSE);
1041 1050
1042 1051 raw_cred = lock->raw_cred;
1043 1052 *cookie = NULL;
1044 1053
1045 1054 rw_enter(&ne->exported_lock, RW_READER);
1046 1055
1047 1056 for (i = 0; i < EXPTABLESIZE; i++) {
1048 1057 exi = ne->exptable[i];
1049 1058 while (exi) {
1050 1059 if (exi->exi_export.ex_seccnt > 0) {
1051 1060 struct secinfo *secp;
1052 1061 seconfig_t *se;
1053 1062 int seccnt;
1054 1063
1055 1064 secp = exi->exi_export.ex_secinfo;
1056 1065 seccnt = exi->exi_export.ex_seccnt;
1057 1066 for (j = 0; j < seccnt; j++) {
1058 1067 /*
1059 1068 * If there is a map of the triplet
1060 1069 * (mechanism, service, qop) between
1061 1070 * raw_cred and the exported flavor,
1062 1071 * get the psudo flavor number.
1063 1072 * Also qop should not be NULL, it
1064 1073 * should be "default" or something
1065 1074 * else.
1066 1075 */
1067 1076 se = &secp[j].s_secinfo;
1068 1077 if ((se->sc_rpcnum == RPCSEC_GSS) &&
1069 1078
1070 1079 (nfs_mech_equal(
1071 1080 se->sc_gss_mech_type,
1072 1081 raw_cred->mechanism)) &&
1073 1082
1074 1083 (se->sc_service ==
1075 1084 raw_cred->service) &&
1076 1085 (raw_cred->qop == se->sc_qop)) {
1077 1086
1078 1087 *cookie = (void *)(uintptr_t)
1079 1088 se->sc_nfsnum;
1080 1089 goto done;
1081 1090 }
1082 1091 }
1083 1092 }
1084 1093 exi = exi->fid_hash.next;
1085 1094 }
1086 1095 }
1087 1096 done:
1088 1097 rw_exit(&ne->exported_lock);
1089 1098
1090 1099 /*
1091 1100 * If no nfs pseudo number mapping can be found in the export
1092 1101 * table, assign the nfsflavor to NFS_FLAVOR_NOMAP. In V4, we may
1093 1102 * recover the flavor mismatch from NFS layer (NFS4ERR_WRONGSEC).
1094 1103 *
1095 1104 * For example:
1096 1105 * server first shares with krb5i;
1097 1106 * client mounts with krb5i;
1098 1107 * server re-shares with krb5p;
1099 1108 * client tries with krb5i, but no mapping can be found;
1100 1109 * rpcsec_gss module calls this routine to do the mapping,
1101 1110 * if this routine fails, request is rejected from
1102 1111 * the rpc layer.
1103 1112 * What we need is to let the nfs layer rejects the request.
1104 1113 * For V4, we can reject with NFS4ERR_WRONGSEC and the client
1105 1114 * may recover from it by getting the new flavor via SECINFO.
1106 1115 *
1107 1116 * nfs pseudo number for RPCSEC_GSS mapping (see nfssec.conf)
1108 1117 * is owned by IANA (see RFC 2623).
1109 1118 *
1110 1119 * XXX NFS_FLAVOR_NOMAP is defined in Solaris to work around
1111 1120 * the implementation issue. This number should not overlap with
1112 1121 * any new IANA defined pseudo flavor numbers.
1113 1122 */
1114 1123 if (*cookie == NULL)
1115 1124 *cookie = (void *)NFS_FLAVOR_NOMAP;
1116 1125
1117 1126 lock->locked = TRUE;
1118 1127
1119 1128 return (TRUE);
1120 1129 }
1121 1130
1122 1131
1123 1132 /*
1124 1133 * Exportfs system call; credentials should be checked before
1125 1134 * calling this function.
1126 1135 */
1127 1136 int
1128 1137 exportfs(struct exportfs_args *args, model_t model, cred_t *cr)
1129 1138 {
1130 1139 vnode_t *vp;
1131 1140 vnode_t *dvp;
1132 1141 struct exportdata *kex;
1133 1142 struct exportinfo *exi = NULL;
1134 1143 struct exportinfo *ex, *ex1, *ex2;
1135 1144 fid_t fid;
1136 1145 fsid_t fsid;
1137 1146 int error;
1138 1147 size_t allocsize;
1139 1148 struct secinfo *sp;
1140 1149 struct secinfo *exs;
1141 1150 rpc_gss_callback_t cb;
1142 1151 char *pathbuf;
1143 1152 char *log_buffer;
1144 1153 char *tagbuf;
1145 1154 int callback;
1146 1155 int allocd_seccnt;
1147 1156 STRUCT_HANDLE(exportfs_args, uap);
1148 1157 STRUCT_DECL(exportdata, uexi);
1149 1158 struct secinfo newsec[MAX_FLAVORS];
1150 1159 int newcnt;
1151 1160 struct secinfo oldsec[MAX_FLAVORS];
1152 1161 int oldcnt;
1153 1162 int i;
1154 1163 struct pathname lookpn;
1155 1164 nfs_export_t *ne = nfs_get_export();
1156 1165
1157 1166 STRUCT_SET_HANDLE(uap, model, args);
1158 1167
1159 1168 /* Read in pathname from userspace */
1160 1169 if (error = pn_get(STRUCT_FGETP(uap, dname), UIO_USERSPACE, &lookpn))
1161 1170 return (error);
1162 1171
1163 1172 /* Walk the export list looking for that pathname */
1164 1173 rw_enter(&ne->exported_lock, RW_READER);
1165 1174 DTRACE_PROBE(nfss__i__exported_lock1_start);
1166 1175 for (ex1 = ne->exptable_path_hash[pkp_tab_hash(lookpn.pn_path,
1167 1176 strlen(lookpn.pn_path))]; ex1; ex1 = ex1->path_hash.next) {
1168 1177 if (ex1 != ne->exi_root && 0 ==
1169 1178 strcmp(ex1->exi_export.ex_path, lookpn.pn_path)) {
1170 1179 exi_hold(ex1);
1171 1180 break;
1172 1181 }
1173 1182 }
1174 1183 DTRACE_PROBE(nfss__i__exported_lock1_stop);
1175 1184 rw_exit(&ne->exported_lock);
1176 1185
1177 1186 /* Is this an unshare? */
1178 1187 if (STRUCT_FGETP(uap, uex) == NULL) {
1179 1188 pn_free(&lookpn);
1180 1189 if (ex1 == NULL)
1181 1190 return (EINVAL);
1182 1191 error = unexport(ne, ex1);
1183 1192 exi_rele(ex1);
1184 1193 return (error);
1185 1194 }
1186 1195
1187 1196 /* It is a share or a re-share */
1188 1197 error = lookupname(STRUCT_FGETP(uap, dname), UIO_USERSPACE,
1189 1198 FOLLOW, &dvp, &vp);
1190 1199 if (error == EINVAL) {
1191 1200 /*
1192 1201 * if fname resolves to / we get EINVAL error
1193 1202 * since we wanted the parent vnode. Try again
1194 1203 * with NULL dvp.
1195 1204 */
1196 1205 error = lookupname(STRUCT_FGETP(uap, dname), UIO_USERSPACE,
1197 1206 FOLLOW, NULL, &vp);
1198 1207 dvp = NULL;
1199 1208 }
1200 1209 if (!error && vp == NULL) {
1201 1210 /* Last component of fname not found */
1202 1211 if (dvp != NULL)
1203 1212 VN_RELE(dvp);
1204 1213 error = ENOENT;
1205 1214 }
1206 1215 if (error) {
1207 1216 pn_free(&lookpn);
1208 1217 if (ex1)
1209 1218 exi_rele(ex1);
1210 1219 return (error);
1211 1220 }
1212 1221
1213 1222 /*
1214 1223 * 'vp' may be an AUTOFS node, so we perform a
1215 1224 * VOP_ACCESS() to trigger the mount of the
1216 1225 * intended filesystem, so we can share the intended
1217 1226 * filesystem instead of the AUTOFS filesystem.
1218 1227 */
1219 1228 (void) VOP_ACCESS(vp, 0, 0, cr, NULL);
1220 1229
1221 1230 /*
1222 1231 * We're interested in the top most filesystem.
1223 1232 * This is specially important when uap->dname is a trigger
1224 1233 * AUTOFS node, since we're really interested in sharing the
1225 1234 * filesystem AUTOFS mounted as result of the VOP_ACCESS()
1226 1235 * call not the AUTOFS node itself.
1227 1236 */
1228 1237 if (vn_mountedvfs(vp) != NULL) {
1229 1238 if (error = traverse(&vp)) {
1230 1239 VN_RELE(vp);
1231 1240 if (dvp != NULL)
1232 1241 VN_RELE(dvp);
1233 1242 pn_free(&lookpn);
1234 1243 if (ex1)
1235 1244 exi_rele(ex1);
1236 1245 return (error);
1237 1246 }
1238 1247 }
1239 1248
1240 1249 /* Do not allow sharing another vnode for already shared path */
1241 1250 if (ex1 && !PSEUDO(ex1) && !VN_CMP(ex1->exi_vp, vp)) {
1242 1251 VN_RELE(vp);
1243 1252 if (dvp != NULL)
1244 1253 VN_RELE(dvp);
1245 1254 pn_free(&lookpn);
1246 1255 exi_rele(ex1);
1247 1256 return (EEXIST);
1248 1257 }
1249 1258 if (ex1)
1250 1259 exi_rele(ex1);
1251 1260
1252 1261 /*
1253 1262 * Get the vfs id
1254 1263 */
1255 1264 bzero(&fid, sizeof (fid));
1256 1265 fid.fid_len = MAXFIDSZ;
1257 1266 error = VOP_FID(vp, &fid, NULL);
1258 1267 fsid = vp->v_vfsp->vfs_fsid;
1259 1268
1260 1269 if (error) {
1261 1270 VN_RELE(vp);
1262 1271 if (dvp != NULL)
1263 1272 VN_RELE(dvp);
1264 1273 /*
1265 1274 * If VOP_FID returns ENOSPC then the fid supplied
1266 1275 * is too small. For now we simply return EREMOTE.
1267 1276 */
1268 1277 if (error == ENOSPC)
1269 1278 error = EREMOTE;
1270 1279 pn_free(&lookpn);
1271 1280 return (error);
1272 1281 }
1273 1282
1274 1283 /*
1275 1284 * Do not allow re-sharing a shared vnode under a different path
1276 1285 * PSEUDO export has ex_path fabricated, e.g. "/tmp (pseudo)", skip it.
1277 1286 */
1278 1287 rw_enter(&ne->exported_lock, RW_READER);
1279 1288 DTRACE_PROBE(nfss__i__exported_lock2_start);
1280 1289 for (ex2 = ne->exptable[exptablehash(&fsid, &fid)]; ex2;
1281 1290 ex2 = ex2->fid_hash.next) {
1282 1291 if (ex2 != ne->exi_root && !PSEUDO(ex2) &&
1283 1292 VN_CMP(ex2->exi_vp, vp) &&
1284 1293 strcmp(ex2->exi_export.ex_path, lookpn.pn_path) != 0) {
1285 1294 DTRACE_PROBE(nfss__i__exported_lock2_stop);
1286 1295 rw_exit(&ne->exported_lock);
1287 1296 VN_RELE(vp);
1288 1297 if (dvp != NULL)
1289 1298 VN_RELE(dvp);
1290 1299 pn_free(&lookpn);
1291 1300 return (EEXIST);
1292 1301 }
|
↓ open down ↓ |
404 lines elided |
↑ open up ↑ |
1293 1302 }
1294 1303 DTRACE_PROBE(nfss__i__exported_lock2_stop);
1295 1304 rw_exit(&ne->exported_lock);
1296 1305 pn_free(&lookpn);
1297 1306
1298 1307 exi = kmem_zalloc(sizeof (*exi), KM_SLEEP);
1299 1308 exi->exi_fsid = fsid;
1300 1309 exi->exi_fid = fid;
1301 1310 exi->exi_vp = vp;
1302 1311 exi->exi_count = 1;
1303 - exi->exi_zoneid = crgetzoneid(cr);
1312 + exi->exi_zone = crgetzone(cr);
1313 + ASSERT(exi->exi_zone != NULL); /* XXX KEBE ASKS... */
1314 + ASSERT3P(exi->exi_zone, ==, curzone); /* ... are these legit? */
1304 1315 exi->exi_volatile_dev = (vfssw[vp->v_vfsp->vfs_fstype].vsw_flag &
1305 1316 VSW_VOLATILEDEV) ? 1 : 0;
1306 1317 mutex_init(&exi->exi_lock, NULL, MUTEX_DEFAULT, NULL);
1307 1318 exi->exi_dvp = dvp;
1308 1319
1309 1320 /*
1310 1321 * Initialize auth cache and auth cache lock
1311 1322 */
1312 1323 for (i = 0; i < AUTH_TABLESIZE; i++) {
1313 1324 exi->exi_cache[i] = kmem_alloc(sizeof (avl_tree_t), KM_SLEEP);
1314 1325 avl_create(exi->exi_cache[i], nfsauth_cache_clnt_compar,
1315 1326 sizeof (struct auth_cache_clnt),
1316 1327 offsetof(struct auth_cache_clnt, authc_link));
1317 1328 }
1318 1329 rw_init(&exi->exi_cache_lock, NULL, RW_DEFAULT, NULL);
1319 1330
1320 1331 /*
1321 1332 * Build up the template fhandle
1322 1333 */
1323 1334 exi->exi_fh.fh_fsid = fsid;
1324 1335 if (exi->exi_fid.fid_len > sizeof (exi->exi_fh.fh_xdata)) {
1325 1336 error = EREMOTE;
1326 1337 goto out1;
1327 1338 }
1328 1339 exi->exi_fh.fh_xlen = exi->exi_fid.fid_len;
1329 1340 bcopy(exi->exi_fid.fid_data, exi->exi_fh.fh_xdata,
1330 1341 exi->exi_fid.fid_len);
1331 1342
1332 1343 exi->exi_fh.fh_len = sizeof (exi->exi_fh.fh_data);
1333 1344
1334 1345 kex = &exi->exi_export;
1335 1346
1336 1347 /*
1337 1348 * Load in everything, and do sanity checking
1338 1349 */
1339 1350 STRUCT_INIT(uexi, model);
1340 1351 if (copyin(STRUCT_FGETP(uap, uex), STRUCT_BUF(uexi),
1341 1352 STRUCT_SIZE(uexi))) {
1342 1353 error = EFAULT;
1343 1354 goto out1;
1344 1355 }
1345 1356
1346 1357 kex->ex_version = STRUCT_FGET(uexi, ex_version);
1347 1358 if (kex->ex_version != EX_CURRENT_VERSION) {
1348 1359 error = EINVAL;
1349 1360 cmn_err(CE_WARN,
1350 1361 "NFS: exportfs requires export struct version 2 - got %d\n",
1351 1362 kex->ex_version);
1352 1363 goto out1;
1353 1364 }
1354 1365
1355 1366 /*
1356 1367 * Must have at least one security entry
1357 1368 */
1358 1369 kex->ex_seccnt = STRUCT_FGET(uexi, ex_seccnt);
1359 1370 if (kex->ex_seccnt < 1) {
1360 1371 error = EINVAL;
1361 1372 goto out1;
1362 1373 }
1363 1374
1364 1375 kex->ex_path = STRUCT_FGETP(uexi, ex_path);
1365 1376 kex->ex_pathlen = STRUCT_FGET(uexi, ex_pathlen);
1366 1377 kex->ex_flags = STRUCT_FGET(uexi, ex_flags);
1367 1378 kex->ex_anon = STRUCT_FGET(uexi, ex_anon);
1368 1379 kex->ex_secinfo = STRUCT_FGETP(uexi, ex_secinfo);
1369 1380 kex->ex_index = STRUCT_FGETP(uexi, ex_index);
1370 1381 kex->ex_log_buffer = STRUCT_FGETP(uexi, ex_log_buffer);
1371 1382 kex->ex_log_bufferlen = STRUCT_FGET(uexi, ex_log_bufferlen);
1372 1383 kex->ex_tag = STRUCT_FGETP(uexi, ex_tag);
1373 1384 kex->ex_taglen = STRUCT_FGET(uexi, ex_taglen);
1374 1385
1375 1386 /*
1376 1387 * Copy the exported pathname into
1377 1388 * an appropriately sized buffer.
1378 1389 */
1379 1390 pathbuf = kmem_alloc(MAXPATHLEN, KM_SLEEP);
1380 1391 if (copyinstr(kex->ex_path, pathbuf, MAXPATHLEN, &kex->ex_pathlen)) {
1381 1392 kmem_free(pathbuf, MAXPATHLEN);
1382 1393 error = EFAULT;
1383 1394 goto out1;
1384 1395 }
1385 1396 kex->ex_path = kmem_alloc(kex->ex_pathlen + 1, KM_SLEEP);
1386 1397 bcopy(pathbuf, kex->ex_path, kex->ex_pathlen);
1387 1398 kex->ex_path[kex->ex_pathlen] = '\0';
1388 1399 kmem_free(pathbuf, MAXPATHLEN);
1389 1400
1390 1401 /*
1391 1402 * Get the path to the logging buffer and the tag
1392 1403 */
1393 1404 if (kex->ex_flags & EX_LOG) {
1394 1405 log_buffer = kmem_alloc(MAXPATHLEN, KM_SLEEP);
1395 1406 if (copyinstr(kex->ex_log_buffer, log_buffer, MAXPATHLEN,
1396 1407 &kex->ex_log_bufferlen)) {
1397 1408 kmem_free(log_buffer, MAXPATHLEN);
1398 1409 error = EFAULT;
1399 1410 goto out2;
1400 1411 }
1401 1412 kex->ex_log_buffer =
1402 1413 kmem_alloc(kex->ex_log_bufferlen + 1, KM_SLEEP);
1403 1414 bcopy(log_buffer, kex->ex_log_buffer, kex->ex_log_bufferlen);
1404 1415 kex->ex_log_buffer[kex->ex_log_bufferlen] = '\0';
1405 1416 kmem_free(log_buffer, MAXPATHLEN);
1406 1417
1407 1418 tagbuf = kmem_alloc(MAXPATHLEN, KM_SLEEP);
1408 1419 if (copyinstr(kex->ex_tag, tagbuf, MAXPATHLEN,
1409 1420 &kex->ex_taglen)) {
1410 1421 kmem_free(tagbuf, MAXPATHLEN);
1411 1422 error = EFAULT;
1412 1423 goto out3;
1413 1424 }
1414 1425 kex->ex_tag = kmem_alloc(kex->ex_taglen + 1, KM_SLEEP);
1415 1426 bcopy(tagbuf, kex->ex_tag, kex->ex_taglen);
1416 1427 kex->ex_tag[kex->ex_taglen] = '\0';
1417 1428 kmem_free(tagbuf, MAXPATHLEN);
1418 1429 }
1419 1430
1420 1431 /*
1421 1432 * Load the security information for each flavor
1422 1433 */
1423 1434 allocsize = kex->ex_seccnt * SIZEOF_STRUCT(secinfo, model);
1424 1435 sp = kmem_zalloc(allocsize, KM_SLEEP);
1425 1436 if (copyin(kex->ex_secinfo, sp, allocsize)) {
1426 1437 kmem_free(sp, allocsize);
1427 1438 error = EFAULT;
1428 1439 goto out4;
1429 1440 }
1430 1441
1431 1442 /*
1432 1443 * All of these nested structures need to be converted to
1433 1444 * the kernel native format.
1434 1445 */
1435 1446 if (model != DATAMODEL_NATIVE) {
1436 1447 size_t allocsize2;
1437 1448 struct secinfo *sp2;
1438 1449
1439 1450 allocsize2 = kex->ex_seccnt * sizeof (struct secinfo);
1440 1451 sp2 = kmem_zalloc(allocsize2, KM_SLEEP);
1441 1452
1442 1453 for (i = 0; i < kex->ex_seccnt; i++) {
1443 1454 STRUCT_HANDLE(secinfo, usi);
1444 1455
1445 1456 STRUCT_SET_HANDLE(usi, model,
1446 1457 (struct secinfo *)((caddr_t)sp +
1447 1458 (i * SIZEOF_STRUCT(secinfo, model))));
1448 1459 bcopy(STRUCT_FGET(usi, s_secinfo.sc_name),
1449 1460 sp2[i].s_secinfo.sc_name, MAX_NAME_LEN);
1450 1461 sp2[i].s_secinfo.sc_nfsnum =
1451 1462 STRUCT_FGET(usi, s_secinfo.sc_nfsnum);
1452 1463 sp2[i].s_secinfo.sc_rpcnum =
1453 1464 STRUCT_FGET(usi, s_secinfo.sc_rpcnum);
1454 1465 bcopy(STRUCT_FGET(usi, s_secinfo.sc_gss_mech),
1455 1466 sp2[i].s_secinfo.sc_gss_mech, MAX_NAME_LEN);
1456 1467 sp2[i].s_secinfo.sc_gss_mech_type =
1457 1468 STRUCT_FGETP(usi, s_secinfo.sc_gss_mech_type);
1458 1469 sp2[i].s_secinfo.sc_qop =
1459 1470 STRUCT_FGET(usi, s_secinfo.sc_qop);
1460 1471 sp2[i].s_secinfo.sc_service =
1461 1472 STRUCT_FGET(usi, s_secinfo.sc_service);
1462 1473
1463 1474 sp2[i].s_flags = STRUCT_FGET(usi, s_flags);
1464 1475 sp2[i].s_window = STRUCT_FGET(usi, s_window);
1465 1476 sp2[i].s_rootid = STRUCT_FGET(usi, s_rootid);
1466 1477 sp2[i].s_rootcnt = STRUCT_FGET(usi, s_rootcnt);
1467 1478 sp2[i].s_rootnames = STRUCT_FGETP(usi, s_rootnames);
1468 1479 }
1469 1480 kmem_free(sp, allocsize);
1470 1481 sp = sp2;
1471 1482 allocsize = allocsize2;
1472 1483 }
1473 1484
1474 1485 kex->ex_secinfo = sp;
1475 1486
1476 1487 /*
1477 1488 * And now copy rootnames for each individual secinfo.
1478 1489 */
1479 1490 callback = 0;
1480 1491 allocd_seccnt = 0;
1481 1492 while (allocd_seccnt < kex->ex_seccnt) {
1482 1493
1483 1494 exs = &sp[allocd_seccnt];
1484 1495 if (exs->s_rootcnt > 0) {
1485 1496 if (!sec_svc_loadrootnames(exs->s_secinfo.sc_rpcnum,
1486 1497 exs->s_rootcnt, &exs->s_rootnames, model)) {
1487 1498 error = EFAULT;
1488 1499 goto out5;
1489 1500 }
1490 1501 }
1491 1502
1492 1503 if (exs->s_secinfo.sc_rpcnum == RPCSEC_GSS) {
1493 1504 rpc_gss_OID mech_tmp;
1494 1505 STRUCT_DECL(rpc_gss_OID_s, umech_tmp);
1495 1506 caddr_t elements_tmp;
1496 1507
1497 1508 /* Copyin mechanism type */
1498 1509 STRUCT_INIT(umech_tmp, model);
1499 1510 mech_tmp = kmem_alloc(sizeof (*mech_tmp), KM_SLEEP);
1500 1511 if (copyin(exs->s_secinfo.sc_gss_mech_type,
1501 1512 STRUCT_BUF(umech_tmp), STRUCT_SIZE(umech_tmp))) {
1502 1513 kmem_free(mech_tmp, sizeof (*mech_tmp));
1503 1514 error = EFAULT;
1504 1515 goto out5;
1505 1516 }
1506 1517 mech_tmp->length = STRUCT_FGET(umech_tmp, length);
1507 1518 mech_tmp->elements = STRUCT_FGETP(umech_tmp, elements);
1508 1519
1509 1520 elements_tmp = kmem_alloc(mech_tmp->length, KM_SLEEP);
1510 1521 if (copyin(mech_tmp->elements, elements_tmp,
1511 1522 mech_tmp->length)) {
1512 1523 kmem_free(elements_tmp, mech_tmp->length);
1513 1524 kmem_free(mech_tmp, sizeof (*mech_tmp));
1514 1525 error = EFAULT;
1515 1526 goto out5;
1516 1527 }
1517 1528 mech_tmp->elements = elements_tmp;
1518 1529 exs->s_secinfo.sc_gss_mech_type = mech_tmp;
1519 1530 allocd_seccnt++;
1520 1531
1521 1532 callback = 1;
1522 1533 } else
1523 1534 allocd_seccnt++;
1524 1535 }
1525 1536
1526 1537 /*
1527 1538 * Init the secinfo reference count and mark these flavors
1528 1539 * explicitly exported flavors.
1529 1540 */
1530 1541 for (i = 0; i < kex->ex_seccnt; i++) {
1531 1542 kex->ex_secinfo[i].s_flags |= M_4SEC_EXPORTED;
1532 1543 kex->ex_secinfo[i].s_refcnt = 1;
1533 1544 }
1534 1545
1535 1546 /*
1536 1547 * Set up rpcsec_gss callback routine entry if any.
1537 1548 */
1538 1549 if (callback) {
1539 1550 cb.callback = rfs_gsscallback;
1540 1551 cb.program = NFS_ACL_PROGRAM;
1541 1552 for (cb.version = NFS_ACL_VERSMIN;
1542 1553 cb.version <= NFS_ACL_VERSMAX; cb.version++) {
1543 1554 (void) sec_svc_control(RPC_SVC_SET_GSS_CALLBACK,
1544 1555 (void *)&cb);
1545 1556 }
1546 1557
1547 1558 cb.program = NFS_PROGRAM;
1548 1559 for (cb.version = NFS_VERSMIN;
1549 1560 cb.version <= NFS_VERSMAX; cb.version++) {
1550 1561 (void) sec_svc_control(RPC_SVC_SET_GSS_CALLBACK,
1551 1562 (void *)&cb);
1552 1563 }
1553 1564 }
1554 1565
1555 1566 /*
1556 1567 * Check the index flag. Do this here to avoid holding the
1557 1568 * lock while dealing with the index option (as we do with
1558 1569 * the public option).
1559 1570 */
1560 1571 if (kex->ex_flags & EX_INDEX) {
1561 1572 if (!kex->ex_index) { /* sanity check */
1562 1573 error = EINVAL;
1563 1574 goto out5;
1564 1575 }
1565 1576 if (error = loadindex(kex))
1566 1577 goto out5;
1567 1578 }
1568 1579
1569 1580 if (kex->ex_flags & EX_LOG) {
1570 1581 if (error = nfslog_setup(exi))
1571 1582 goto out6;
1572 1583 }
1573 1584
1574 1585 /*
1575 1586 * Insert the new entry at the front of the export list
1576 1587 */
1577 1588 rw_enter(&ne->exported_lock, RW_WRITER);
1578 1589 DTRACE_PROBE(nfss__i__exported_lock3_start);
1579 1590
1580 1591 export_link(ne, exi);
1581 1592
1582 1593 /*
1583 1594 * Check the rest of the list for an old entry for the fs.
1584 1595 * If one is found then unlink it, wait until this is the
1585 1596 * only reference and then free it.
1586 1597 */
1587 1598 for (ex = exi->fid_hash.next; ex != NULL; ex = ex->fid_hash.next) {
1588 1599 if (ex != ne->exi_root && VN_CMP(ex->exi_vp, vp)) {
1589 1600 mutex_enter(&nfs_exi_id_lock);
1590 1601 avl_remove(&exi_id_tree, ex);
1591 1602 mutex_exit(&nfs_exi_id_lock);
1592 1603 export_unlink(ne, ex);
1593 1604 break;
1594 1605 }
1595 1606 }
1596 1607
1597 1608 /*
1598 1609 * If the public filehandle is pointing at the
1599 1610 * old entry, then point it back at the root.
1600 1611 */
1601 1612 if (ex != NULL && ex == ne->exi_public)
1602 1613 ne->exi_public = ne->exi_root;
1603 1614
1604 1615 /*
1605 1616 * If the public flag is on, make the global exi_public
1606 1617 * point to this entry and turn off the public bit so that
1607 1618 * we can distinguish it from the place holder export.
1608 1619 */
1609 1620 if (kex->ex_flags & EX_PUBLIC) {
1610 1621 ne->exi_public = exi;
1611 1622 kex->ex_flags &= ~EX_PUBLIC;
1612 1623 }
1613 1624
1614 1625 #ifdef VOLATILE_FH_TEST
1615 1626 /*
1616 1627 * Set up the volatile_id value if volatile on share.
1617 1628 * The list of volatile renamed filehandles is always destroyed,
1618 1629 * if the fs was reshared.
1619 1630 */
1620 1631 if (kex->ex_flags & EX_VOLFH)
1621 1632 exi->exi_volatile_id = gethrestime_sec();
1622 1633
1623 1634 mutex_init(&exi->exi_vol_rename_lock, NULL, MUTEX_DEFAULT, NULL);
1624 1635 #endif /* VOLATILE_FH_TEST */
1625 1636
1626 1637 /*
1627 1638 * If this is a new export, then climb up
1628 1639 * the tree and check if any pseudo exports
1629 1640 * need to be created to provide a path for
1630 1641 * NFS v4 clients.
1631 1642 */
1632 1643 if (ex == NULL) {
1633 1644 error = treeclimb_export(exi);
1634 1645 if (error)
1635 1646 goto out7;
1636 1647 } else {
1637 1648 /* If it's a re-export update namespace tree */
1638 1649 exi->exi_tree = ex->exi_tree;
1639 1650 exi->exi_tree->tree_exi = exi;
1640 1651
1641 1652 /* Update the change timestamp */
1642 1653 tree_update_change(ne, exi->exi_tree, NULL);
1643 1654 }
1644 1655
1645 1656 /*
1646 1657 * build a unique flavor list from the flavors specified
1647 1658 * in the share cmd. unique means that each flavor only
1648 1659 * appears once in the secinfo list -- no duplicates allowed.
1649 1660 */
1650 1661 newcnt = build_seclist_nodups(&exi->exi_export, newsec, FALSE);
1651 1662
1652 1663 srv_secinfo_treeclimb(ne, exi, newsec, newcnt, TRUE);
1653 1664
1654 1665 /*
1655 1666 * If re-sharing an old export entry, update the secinfo data
1656 1667 * depending on if the old entry is a pseudo node or not.
1657 1668 */
1658 1669 if (ex != NULL) {
1659 1670 oldcnt = build_seclist_nodups(&ex->exi_export, oldsec, FALSE);
1660 1671 if (PSEUDO(ex)) {
1661 1672 /*
1662 1673 * The dir being shared is a pseudo export root (which
1663 1674 * will be transformed into a real export root). The
1664 1675 * flavor(s) of the new share were propagated to the
1665 1676 * ancestors by srv_secinfo_treeclimb() above. Now
1666 1677 * transfer the implicit flavor refs from the old
1667 1678 * pseudo exprot root to the new (real) export root.
1668 1679 */
1669 1680 srv_secinfo_add(&exi->exi_export.ex_secinfo,
1670 1681 &exi->exi_export.ex_seccnt, oldsec, oldcnt, TRUE);
1671 1682 } else {
1672 1683 /*
1673 1684 * First transfer implicit flavor refs to new export.
1674 1685 * Remove old flavor refs last.
1675 1686 */
1676 1687 srv_secinfo_exp2exp(&exi->exi_export, oldsec, oldcnt);
1677 1688 srv_secinfo_treeclimb(ne, ex, oldsec, oldcnt, FALSE);
1678 1689 }
1679 1690 }
1680 1691
1681 1692 /*
1682 1693 * If it's a re-export and the old entry has a pseudonode list,
1683 1694 * transfer it to the new export.
1684 1695 */
1685 1696 if (ex != NULL && (ex->exi_visible != NULL)) {
1686 1697 exi->exi_visible = ex->exi_visible;
1687 1698 ex->exi_visible = NULL;
1688 1699 }
1689 1700
1690 1701 /*
1691 1702 * Initialize exi_id and exi_kstats
1692 1703 */
1693 1704 if (ex != NULL) {
1694 1705 exi->exi_id = ex->exi_id;
1695 1706 } else {
1696 1707 mutex_enter(&nfs_exi_id_lock);
1697 1708 exi->exi_id = exi_id_get_next();
1698 1709 mutex_exit(&nfs_exi_id_lock);
1699 1710 }
1700 1711 mutex_enter(&nfs_exi_id_lock);
1701 1712 avl_add(&exi_id_tree, exi);
1702 1713 mutex_exit(&nfs_exi_id_lock);
1703 1714
1704 1715 DTRACE_PROBE(nfss__i__exported_lock3_stop);
1705 1716 rw_exit(&ne->exported_lock);
1706 1717
1707 1718 if (ne->exi_public == exi || kex->ex_flags & EX_LOG) {
1708 1719 /*
1709 1720 * Log share operation to this buffer only.
1710 1721 */
1711 1722 nfslog_share_record(exi, cr);
1712 1723 }
1713 1724
1714 1725 if (ex != NULL)
1715 1726 exi_rele(ex);
1716 1727
1717 1728 return (0);
1718 1729
1719 1730 out7:
1720 1731 /* Unlink the new export in exptable. */
1721 1732 export_unlink(ne, exi);
1722 1733 DTRACE_PROBE(nfss__i__exported_lock3_stop);
1723 1734 rw_exit(&ne->exported_lock);
1724 1735 out6:
1725 1736 if (kex->ex_flags & EX_INDEX)
1726 1737 kmem_free(kex->ex_index, strlen(kex->ex_index) + 1);
1727 1738 out5:
1728 1739 /* free partially completed allocation */
1729 1740 while (--allocd_seccnt >= 0) {
1730 1741 exs = &kex->ex_secinfo[allocd_seccnt];
1731 1742 srv_secinfo_entry_free(exs);
1732 1743 }
1733 1744
1734 1745 if (kex->ex_secinfo) {
1735 1746 kmem_free(kex->ex_secinfo,
1736 1747 kex->ex_seccnt * sizeof (struct secinfo));
1737 1748 }
1738 1749
1739 1750 out4:
1740 1751 if ((kex->ex_flags & EX_LOG) && kex->ex_tag != NULL)
1741 1752 kmem_free(kex->ex_tag, kex->ex_taglen + 1);
1742 1753 out3:
1743 1754 if ((kex->ex_flags & EX_LOG) && kex->ex_log_buffer != NULL)
1744 1755 kmem_free(kex->ex_log_buffer, kex->ex_log_bufferlen + 1);
1745 1756 out2:
1746 1757 kmem_free(kex->ex_path, kex->ex_pathlen + 1);
1747 1758 out1:
1748 1759 VN_RELE(vp);
1749 1760 if (dvp != NULL)
1750 1761 VN_RELE(dvp);
1751 1762 mutex_destroy(&exi->exi_lock);
1752 1763 rw_destroy(&exi->exi_cache_lock);
1753 1764 for (i = 0; i < AUTH_TABLESIZE; i++) {
1754 1765 avl_destroy(exi->exi_cache[i]);
1755 1766 kmem_free(exi->exi_cache[i], sizeof (avl_tree_t));
1756 1767 }
1757 1768
1758 1769 kmem_free(exi, sizeof (*exi));
1759 1770
1760 1771 return (error);
1761 1772 }
1762 1773
1763 1774 /*
1764 1775 * Remove the exportinfo from the export list
1765 1776 */
1766 1777 void
1767 1778 export_unlink(nfs_export_t *ne, struct exportinfo *exi)
1768 1779 {
1769 1780 ASSERT(RW_WRITE_HELD(&ne->exported_lock));
1770 1781
1771 1782 exp_hash_unlink(exi, fid_hash);
1772 1783 exp_hash_unlink(exi, path_hash);
1773 1784 }
1774 1785
1775 1786 /*
1776 1787 * Unexport an exported filesystem
1777 1788 */
1778 1789 static int
1779 1790 unexport(nfs_export_t *ne, struct exportinfo *exi)
1780 1791 {
1781 1792 struct secinfo cursec[MAX_FLAVORS];
1782 1793 int curcnt;
1783 1794
1784 1795 rw_enter(&ne->exported_lock, RW_WRITER);
1785 1796
1786 1797 /* Check if exi is still linked in the export table */
1787 1798 if (!EXP_LINKED(exi) || PSEUDO(exi)) {
1788 1799 rw_exit(&ne->exported_lock);
1789 1800 return (EINVAL);
1790 1801 }
1791 1802
1792 1803 mutex_enter(&nfs_exi_id_lock);
1793 1804 avl_remove(&exi_id_tree, exi);
1794 1805 mutex_exit(&nfs_exi_id_lock);
1795 1806 export_unlink(ne, exi);
1796 1807
1797 1808 /*
1798 1809 * Remove security flavors before treeclimb_unexport() is called
1799 1810 * because srv_secinfo_treeclimb needs the namespace tree
1800 1811 */
1801 1812 curcnt = build_seclist_nodups(&exi->exi_export, cursec, TRUE);
1802 1813 srv_secinfo_treeclimb(ne, exi, cursec, curcnt, FALSE);
1803 1814
1804 1815 /*
1805 1816 * If there's a visible list, then need to leave
1806 1817 * a pseudo export here to retain the visible list
|
↓ open down ↓ |
493 lines elided |
↑ open up ↑ |
1807 1818 * for paths to exports below.
1808 1819 */
1809 1820 if (exi->exi_visible != NULL) {
1810 1821 struct exportinfo *newexi;
1811 1822
1812 1823 newexi = pseudo_exportfs(ne, exi->exi_vp, &exi->exi_fid,
1813 1824 exi->exi_visible, &exi->exi_export);
1814 1825 exi->exi_visible = NULL;
1815 1826
1816 1827 /* interconnect the existing treenode with the new exportinfo */
1828 + newexi->exi_zone = exi->exi_zone;
1817 1829 newexi->exi_tree = exi->exi_tree;
1818 1830 newexi->exi_tree->tree_exi = newexi;
1819 1831
1820 1832 /* Update the change timestamp */
1821 1833 tree_update_change(ne, exi->exi_tree, NULL);
1822 1834 } else {
1823 1835 treeclimb_unexport(ne, exi);
1824 1836 }
1825 1837
1826 1838 rw_exit(&ne->exported_lock);
1827 1839
1828 1840 /*
1829 1841 * Need to call into the NFSv4 server and release all data
1830 1842 * held on this particular export. This is important since
1831 1843 * the v4 server may be holding file locks or vnodes under
1832 1844 * this export.
1833 1845 */
1834 1846 rfs4_clean_state_exi(exi);
1835 1847
|
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
1836 1848 /*
1837 1849 * Notify the lock manager that the filesystem is being
1838 1850 * unexported.
1839 1851 */
1840 1852 lm_unexport(exi);
1841 1853
1842 1854 /*
1843 1855 * If this was a public export, restore
1844 1856 * the public filehandle to the root.
1845 1857 */
1858 +
1859 + /*
1860 + * XXX KEBE ASKS --> Should CRED() instead be
1861 + * exi->exi_zone->zone_kcred?
1862 + */
1846 1863 if (exi == ne->exi_public) {
1847 1864 ne->exi_public = ne->exi_root;
1848 1865
1849 1866 nfslog_share_record(ne->exi_public, CRED());
1850 1867 }
1851 1868
1852 1869 if (exi->exi_export.ex_flags & EX_LOG)
1853 1870 nfslog_unshare_record(exi, CRED());
1854 1871
1855 1872 exi_rele(exi);
1856 1873 return (0);
1857 1874 }
1858 1875
1859 1876 /*
1860 1877 * Get file handle system call.
1861 1878 * Takes file name and returns a file handle for it.
1862 1879 * Credentials must be verified before calling.
1863 1880 */
1864 1881 int
1865 1882 nfs_getfh(struct nfs_getfh_args *args, model_t model, cred_t *cr)
1866 1883 {
1867 1884 nfs_fh3 fh;
1868 1885 char buf[NFS3_MAXFHSIZE];
1869 1886 char *logptr, logbuf[NFS3_MAXFHSIZE];
1870 1887 int l = NFS3_MAXFHSIZE;
1871 1888 vnode_t *vp;
1872 1889 vnode_t *dvp;
1873 1890 struct exportinfo *exi;
1874 1891 int error;
1875 1892 int vers;
1876 1893 STRUCT_HANDLE(nfs_getfh_args, uap);
1877 1894
1878 1895 #ifdef lint
1879 1896 model = model; /* STRUCT macros don't always use it */
1880 1897 #endif
1881 1898
1882 1899 STRUCT_SET_HANDLE(uap, model, args);
1883 1900
1884 1901 error = lookupname(STRUCT_FGETP(uap, fname), UIO_USERSPACE,
1885 1902 FOLLOW, &dvp, &vp);
1886 1903 if (error == EINVAL) {
1887 1904 /*
1888 1905 * if fname resolves to / we get EINVAL error
1889 1906 * since we wanted the parent vnode. Try again
1890 1907 * with NULL dvp.
1891 1908 */
1892 1909 error = lookupname(STRUCT_FGETP(uap, fname), UIO_USERSPACE,
1893 1910 FOLLOW, NULL, &vp);
1894 1911 dvp = NULL;
1895 1912 }
1896 1913 if (!error && vp == NULL) {
1897 1914 /*
1898 1915 * Last component of fname not found
1899 1916 */
1900 1917 if (dvp != NULL) {
1901 1918 VN_RELE(dvp);
1902 1919 }
1903 1920 error = ENOENT;
1904 1921 }
1905 1922 if (error)
1906 1923 return (error);
1907 1924
1908 1925 /*
1909 1926 * 'vp' may be an AUTOFS node, so we perform a
1910 1927 * VOP_ACCESS() to trigger the mount of the
1911 1928 * intended filesystem, so we can share the intended
1912 1929 * filesystem instead of the AUTOFS filesystem.
1913 1930 */
1914 1931 (void) VOP_ACCESS(vp, 0, 0, cr, NULL);
1915 1932
1916 1933 /*
1917 1934 * We're interested in the top most filesystem.
1918 1935 * This is specially important when uap->dname is a trigger
1919 1936 * AUTOFS node, since we're really interested in sharing the
1920 1937 * filesystem AUTOFS mounted as result of the VOP_ACCESS()
1921 1938 * call not the AUTOFS node itself.
1922 1939 */
1923 1940 if (vn_mountedvfs(vp) != NULL) {
1924 1941 if (error = traverse(&vp)) {
1925 1942 VN_RELE(vp);
1926 1943 if (dvp != NULL)
1927 1944 VN_RELE(dvp);
1928 1945 return (error);
1929 1946 }
1930 1947 }
1931 1948
1932 1949 vers = STRUCT_FGET(uap, vers);
1933 1950 exi = nfs_vptoexi(dvp, vp, cr, NULL, &error, FALSE);
1934 1951 if (!error) {
1935 1952 if (vers == NFS_VERSION) {
1936 1953 error = makefh((fhandle_t *)buf, vp, exi);
1937 1954 l = NFS_FHSIZE;
1938 1955 logptr = buf;
1939 1956 } else if (vers == NFS_V3) {
1940 1957 int i, sz, pad;
1941 1958
1942 1959 error = makefh3(&fh, vp, exi);
1943 1960 l = RNDUP(fh.fh3_length);
1944 1961 if (!error && (l > sizeof (fhandle3_t)))
1945 1962 error = EREMOTE;
1946 1963 logptr = logbuf;
1947 1964 if (!error) {
1948 1965 i = 0;
1949 1966 sz = sizeof (fsid_t);
1950 1967 bcopy(&fh.fh3_fsid, &buf[i], sz);
1951 1968 i += sz;
1952 1969
1953 1970 /*
1954 1971 * For backwards compatibility, the
1955 1972 * fid length may be less than
1956 1973 * NFS_FHMAXDATA, but it was always
1957 1974 * encoded as NFS_FHMAXDATA bytes.
1958 1975 */
1959 1976
1960 1977 sz = sizeof (ushort_t);
1961 1978 bcopy(&fh.fh3_len, &buf[i], sz);
1962 1979 i += sz;
1963 1980 bcopy(fh.fh3_data, &buf[i], fh.fh3_len);
1964 1981 i += fh.fh3_len;
1965 1982 pad = (NFS_FHMAXDATA - fh.fh3_len);
1966 1983 if (pad > 0) {
1967 1984 bzero(&buf[i], pad);
1968 1985 i += pad;
1969 1986 l += pad;
1970 1987 }
1971 1988
1972 1989 sz = sizeof (ushort_t);
1973 1990 bcopy(&fh.fh3_xlen, &buf[i], sz);
1974 1991 i += sz;
1975 1992 bcopy(fh.fh3_xdata, &buf[i], fh.fh3_xlen);
1976 1993 i += fh.fh3_xlen;
1977 1994 pad = (NFS_FHMAXDATA - fh.fh3_xlen);
1978 1995 if (pad > 0) {
1979 1996 bzero(&buf[i], pad);
1980 1997 i += pad;
1981 1998 l += pad;
1982 1999 }
1983 2000 }
1984 2001 /*
1985 2002 * If we need to do NFS logging, the filehandle
1986 2003 * must be downsized to 32 bytes.
1987 2004 */
1988 2005 if (!error && exi->exi_export.ex_flags & EX_LOG) {
1989 2006 i = 0;
1990 2007 sz = sizeof (fsid_t);
1991 2008 bcopy(&fh.fh3_fsid, &logbuf[i], sz);
1992 2009 i += sz;
1993 2010 sz = sizeof (ushort_t);
1994 2011 bcopy(&fh.fh3_len, &logbuf[i], sz);
1995 2012 i += sz;
1996 2013 sz = NFS_FHMAXDATA;
1997 2014 bcopy(fh.fh3_data, &logbuf[i], sz);
1998 2015 i += sz;
1999 2016 sz = sizeof (ushort_t);
2000 2017 bcopy(&fh.fh3_xlen, &logbuf[i], sz);
2001 2018 i += sz;
2002 2019 sz = NFS_FHMAXDATA;
2003 2020 bcopy(fh.fh3_xdata, &logbuf[i], sz);
2004 2021 i += sz;
2005 2022 }
2006 2023 }
2007 2024 if (!error && exi->exi_export.ex_flags & EX_LOG) {
2008 2025 nfslog_getfh(exi, (fhandle_t *)logptr,
2009 2026 STRUCT_FGETP(uap, fname), UIO_USERSPACE, cr);
2010 2027 }
2011 2028 exi_rele(exi);
2012 2029 if (!error) {
2013 2030 if (copyout(&l, STRUCT_FGETP(uap, lenp), sizeof (int)))
2014 2031 error = EFAULT;
2015 2032 if (copyout(buf, STRUCT_FGETP(uap, fhp), l))
2016 2033 error = EFAULT;
2017 2034 }
2018 2035 }
2019 2036 VN_RELE(vp);
2020 2037 if (dvp != NULL) {
2021 2038 VN_RELE(dvp);
2022 2039 }
2023 2040 return (error);
2024 2041 }
2025 2042
2026 2043 /*
2027 2044 * Strategy: if vp is in the export list, then
2028 2045 * return the associated file handle. Otherwise, ".."
2029 2046 * once up the vp and try again, until the root of the
2030 2047 * filesystem is reached.
2031 2048 */
2032 2049 struct exportinfo *
2033 2050 nfs_vptoexi(vnode_t *dvp, vnode_t *vp, cred_t *cr, int *walk,
2034 2051 int *err, bool_t v4srv)
2035 2052 {
2036 2053 fid_t fid;
2037 2054 int error;
2038 2055 struct exportinfo *exi;
2039 2056
2040 2057 ASSERT(vp);
2041 2058 VN_HOLD(vp);
2042 2059 if (dvp != NULL) {
2043 2060 VN_HOLD(dvp);
2044 2061 }
2045 2062 if (walk != NULL)
2046 2063 *walk = 0;
2047 2064
2048 2065 for (;;) {
2049 2066 bzero(&fid, sizeof (fid));
2050 2067 fid.fid_len = MAXFIDSZ;
2051 2068 error = vop_fid_pseudo(vp, &fid);
2052 2069 if (error) {
2053 2070 /*
2054 2071 * If vop_fid_pseudo returns ENOSPC then the fid
2055 2072 * supplied is too small. For now we simply
2056 2073 * return EREMOTE.
2057 2074 */
2058 2075 if (error == ENOSPC)
2059 2076 error = EREMOTE;
2060 2077 break;
2061 2078 }
2062 2079
2063 2080 if (v4srv)
2064 2081 exi = checkexport4(&vp->v_vfsp->vfs_fsid, &fid, vp);
2065 2082 else
2066 2083 exi = checkexport(&vp->v_vfsp->vfs_fsid, &fid);
2067 2084
2068 2085 if (exi != NULL) {
2069 2086 /*
2070 2087 * Found the export info
2071 2088 */
2072 2089 break;
2073 2090 }
2074 2091
2075 2092 /*
2076 2093 * We have just failed finding a matching export.
2077 2094 * If we're at the root of this filesystem, then
2078 2095 * it's time to stop (with failure).
2079 2096 */
2080 2097 if ((vp->v_flag & VROOT) || VN_IS_CURZONEROOT(vp)) {
2081 2098 error = EINVAL;
2082 2099 break;
2083 2100 }
2084 2101
2085 2102 if (walk != NULL)
2086 2103 (*walk)++;
2087 2104
2088 2105 /*
2089 2106 * Now, do a ".." up vp. If dvp is supplied, use it,
2090 2107 * otherwise, look it up.
2091 2108 */
2092 2109 if (dvp == NULL) {
2093 2110 error = VOP_LOOKUP(vp, "..", &dvp, NULL, 0, NULL, cr,
2094 2111 NULL, NULL, NULL);
2095 2112 if (error)
2096 2113 break;
2097 2114 }
2098 2115 VN_RELE(vp);
2099 2116 vp = dvp;
2100 2117 dvp = NULL;
2101 2118 }
2102 2119 VN_RELE(vp);
2103 2120 if (dvp != NULL) {
2104 2121 VN_RELE(dvp);
2105 2122 }
2106 2123 if (error != 0) {
2107 2124 if (err != NULL)
2108 2125 *err = error;
2109 2126 return (NULL);
2110 2127 }
2111 2128 return (exi);
2112 2129 }
2113 2130
2114 2131 int
2115 2132 chk_clnt_sec(exportinfo_t *exi, struct svc_req *req)
2116 2133 {
2117 2134 int i, nfsflavor;
2118 2135 struct secinfo *sp;
2119 2136
2120 2137 /*
2121 2138 * Get the nfs flavor number from xprt.
2122 2139 */
2123 2140 nfsflavor = (int)(uintptr_t)req->rq_xprt->xp_cookie;
2124 2141
2125 2142 sp = exi->exi_export.ex_secinfo;
2126 2143 for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2127 2144 if ((nfsflavor == sp[i].s_secinfo.sc_nfsnum) &&
2128 2145 SEC_REF_EXPORTED(sp + i))
2129 2146 return (TRUE);
2130 2147 }
2131 2148 return (FALSE);
2132 2149 }
2133 2150
2134 2151 /*
2135 2152 * Make an fhandle from a vnode
2136 2153 */
2137 2154 int
2138 2155 makefh(fhandle_t *fh, vnode_t *vp, exportinfo_t *exi)
2139 2156 {
2140 2157 int error;
2141 2158
2142 2159 *fh = exi->exi_fh; /* struct copy */
2143 2160
2144 2161 error = VOP_FID(vp, (fid_t *)&fh->fh_len, NULL);
2145 2162 if (error) {
2146 2163 /*
2147 2164 * Should be something other than EREMOTE
2148 2165 */
2149 2166 return (EREMOTE);
2150 2167 }
2151 2168 return (0);
2152 2169 }
2153 2170
2154 2171 /*
2155 2172 * This routine makes an overloaded V2 fhandle which contains
2156 2173 * sec modes.
2157 2174 *
2158 2175 * Note that the first four octets contain the length octet,
2159 2176 * the status octet, and two padded octets to make them XDR
2160 2177 * four-octet aligned.
2161 2178 *
2162 2179 * 1 2 3 4 32
2163 2180 * +---+---+---+---+---+---+---+---+ +---+---+---+---+ +---+
2164 2181 * | l | s | | | sec_1 |...| sec_n |...| |
2165 2182 * +---+---+---+---+---+---+---+---+ +---+---+---+---+ +---+
2166 2183 *
2167 2184 * where
2168 2185 *
2169 2186 * the status octet s indicates whether there are more security
2170 2187 * flavors (1 means yes, 0 means no) that require the client to
2171 2188 * perform another 0x81 LOOKUP to get them,
2172 2189 *
2173 2190 * the length octet l is the length describing the number of
2174 2191 * valid octets that follow. (l = 4 * n, where n is the number
2175 2192 * of security flavors sent in the current overloaded filehandle.)
2176 2193 *
2177 2194 * sec_index should always be in the inclusive range: [1 - ex_seccnt],
2178 2195 * and it tells server where to start within the secinfo array.
2179 2196 * Usually it will always be 1; however, if more flavors are used
2180 2197 * for the public export than can be encoded in the overloaded FH
2181 2198 * (7 for NFS2), subsequent SNEGO MCLs will have a larger index
2182 2199 * so the server will pick up where it left off from the previous
2183 2200 * MCL reply.
2184 2201 *
2185 2202 * With NFS4 support, implicitly allowed flavors are also in
2186 2203 * the secinfo array; however, they should not be returned in
2187 2204 * SNEGO MCL replies.
2188 2205 */
2189 2206 int
2190 2207 makefh_ol(fhandle_t *fh, exportinfo_t *exi, uint_t sec_index)
2191 2208 {
2192 2209 secinfo_t sec[MAX_FLAVORS];
2193 2210 int totalcnt, i, *ipt, cnt, seccnt, secidx, fh_max_cnt;
2194 2211 char *c;
2195 2212
2196 2213 if (fh == NULL || exi == NULL || sec_index < 1)
2197 2214 return (EREMOTE);
2198 2215
2199 2216 /*
2200 2217 * WebNFS clients need to know the unique set of explicitly
2201 2218 * shared flavors in used for the public export. When
2202 2219 * "TRUE" is passed to build_seclist_nodups(), only explicitly
2203 2220 * shared flavors are included in the list.
2204 2221 */
2205 2222 seccnt = build_seclist_nodups(&exi->exi_export, sec, TRUE);
2206 2223 if (sec_index > seccnt)
2207 2224 return (EREMOTE);
2208 2225
2209 2226 fh_max_cnt = (NFS_FHSIZE / sizeof (int)) - 1;
2210 2227 totalcnt = seccnt - sec_index + 1;
2211 2228 cnt = totalcnt > fh_max_cnt ? fh_max_cnt : totalcnt;
2212 2229
2213 2230 c = (char *)fh;
2214 2231 /*
2215 2232 * Encode the length octet representing the number of
2216 2233 * security flavors (in bytes) in this overloaded fh.
2217 2234 */
2218 2235 *c = cnt * sizeof (int);
2219 2236
2220 2237 /*
2221 2238 * Encode the status octet that indicates whether there
2222 2239 * are more security flavors the client needs to get.
2223 2240 */
2224 2241 *(c + 1) = totalcnt > fh_max_cnt;
2225 2242
2226 2243 /*
2227 2244 * put security flavors in the overloaded fh
2228 2245 */
2229 2246 ipt = (int *)(c + sizeof (int32_t));
2230 2247 secidx = sec_index - 1;
2231 2248 for (i = 0; i < cnt; i++) {
2232 2249 ipt[i] = htonl(sec[i + secidx].s_secinfo.sc_nfsnum);
2233 2250 }
2234 2251 return (0);
2235 2252 }
2236 2253
2237 2254 /*
2238 2255 * Make an nfs_fh3 from a vnode
2239 2256 */
2240 2257 int
2241 2258 makefh3(nfs_fh3 *fh, vnode_t *vp, struct exportinfo *exi)
2242 2259 {
2243 2260 int error;
2244 2261 fid_t fid;
2245 2262
2246 2263 bzero(&fid, sizeof (fid));
2247 2264 fid.fid_len = sizeof (fh->fh3_data);
2248 2265 error = VOP_FID(vp, &fid, NULL);
2249 2266 if (error)
2250 2267 return (EREMOTE);
2251 2268
2252 2269 bzero(fh, sizeof (nfs_fh3));
2253 2270 fh->fh3_fsid = exi->exi_fsid;
2254 2271 fh->fh3_len = fid.fid_len;
2255 2272 bcopy(fid.fid_data, fh->fh3_data, fh->fh3_len);
2256 2273
2257 2274 fh->fh3_xlen = exi->exi_fid.fid_len;
2258 2275 ASSERT(fh->fh3_xlen <= sizeof (fh->fh3_xdata));
2259 2276 bcopy(exi->exi_fid.fid_data, fh->fh3_xdata, fh->fh3_xlen);
2260 2277
2261 2278 fh->fh3_length = sizeof (fh->fh3_fsid)
2262 2279 + sizeof (fh->fh3_len) + fh->fh3_len
2263 2280 + sizeof (fh->fh3_xlen) + fh->fh3_xlen;
2264 2281 fh->fh3_flags = 0;
2265 2282
2266 2283 return (0);
2267 2284 }
2268 2285
2269 2286 /*
2270 2287 * This routine makes an overloaded V3 fhandle which contains
2271 2288 * sec modes.
2272 2289 *
2273 2290 * 1 4
2274 2291 * +--+--+--+--+
2275 2292 * | len |
2276 2293 * +--+--+--+--+
2277 2294 * up to 64
2278 2295 * +--+--+--+--+--+--+--+--+--+--+--+--+ +--+--+--+--+
2279 2296 * |s | | | | sec_1 | sec_2 | ... | sec_n |
2280 2297 * +--+--+--+--+--+--+--+--+--+--+--+--+ +--+--+--+--+
2281 2298 *
2282 2299 * len = 4 * (n+1), where n is the number of security flavors
2283 2300 * sent in the current overloaded filehandle.
2284 2301 *
2285 2302 * the status octet s indicates whether there are more security
2286 2303 * mechanisms (1 means yes, 0 means no) that require the client
2287 2304 * to perform another 0x81 LOOKUP to get them.
2288 2305 *
2289 2306 * Three octets are padded after the status octet.
2290 2307 */
2291 2308 int
2292 2309 makefh3_ol(nfs_fh3 *fh, struct exportinfo *exi, uint_t sec_index)
2293 2310 {
2294 2311 secinfo_t sec[MAX_FLAVORS];
2295 2312 int totalcnt, cnt, *ipt, i, seccnt, fh_max_cnt, secidx;
2296 2313 char *c;
2297 2314
2298 2315 if (fh == NULL || exi == NULL || sec_index < 1)
2299 2316 return (EREMOTE);
2300 2317
2301 2318 /*
2302 2319 * WebNFS clients need to know the unique set of explicitly
2303 2320 * shared flavors in used for the public export. When
2304 2321 * "TRUE" is passed to build_seclist_nodups(), only explicitly
2305 2322 * shared flavors are included in the list.
2306 2323 */
2307 2324 seccnt = build_seclist_nodups(&exi->exi_export, sec, TRUE);
2308 2325
2309 2326 if (sec_index > seccnt)
2310 2327 return (EREMOTE);
2311 2328
2312 2329 fh_max_cnt = (NFS3_FHSIZE / sizeof (int)) - 1;
2313 2330 totalcnt = seccnt - sec_index + 1;
2314 2331 cnt = totalcnt > fh_max_cnt ? fh_max_cnt : totalcnt;
2315 2332
2316 2333 /*
2317 2334 * Place the length in fh3_length representing the number
2318 2335 * of security flavors (in bytes) in this overloaded fh.
2319 2336 */
2320 2337 fh->fh3_flags = FH_WEBNFS;
2321 2338 fh->fh3_length = (cnt+1) * sizeof (int32_t);
2322 2339
2323 2340 c = (char *)&fh->fh3_u.nfs_fh3_i.fh3_i;
2324 2341 /*
2325 2342 * Encode the status octet that indicates whether there
2326 2343 * are more security flavors the client needs to get.
2327 2344 */
2328 2345 *c = totalcnt > fh_max_cnt;
2329 2346
2330 2347 /*
2331 2348 * put security flavors in the overloaded fh
2332 2349 */
2333 2350 secidx = sec_index - 1;
2334 2351 ipt = (int *)(c + sizeof (int32_t));
2335 2352 for (i = 0; i < cnt; i++) {
2336 2353 ipt[i] = htonl(sec[i + secidx].s_secinfo.sc_nfsnum);
2337 2354 }
2338 2355 return (0);
2339 2356 }
2340 2357
2341 2358 /*
2342 2359 * Make an nfs_fh4 from a vnode
2343 2360 */
2344 2361 int
2345 2362 makefh4(nfs_fh4 *fh, vnode_t *vp, struct exportinfo *exi)
2346 2363 {
2347 2364 int error;
2348 2365 nfs_fh4_fmt_t *fh_fmtp = (nfs_fh4_fmt_t *)fh->nfs_fh4_val;
2349 2366 fid_t fid;
2350 2367
2351 2368 bzero(&fid, sizeof (fid));
2352 2369 fid.fid_len = MAXFIDSZ;
2353 2370 /*
2354 2371 * vop_fid_pseudo() is used to set up NFSv4 namespace, so
2355 2372 * use vop_fid_pseudo() here to get the fid instead of VOP_FID.
2356 2373 */
2357 2374 error = vop_fid_pseudo(vp, &fid);
2358 2375 if (error)
2359 2376 return (error);
2360 2377
2361 2378 fh->nfs_fh4_len = NFS_FH4_LEN;
2362 2379
2363 2380 fh_fmtp->fh4_i.fhx_fsid = exi->exi_fh.fh_fsid;
2364 2381 fh_fmtp->fh4_i.fhx_xlen = exi->exi_fh.fh_xlen;
2365 2382
2366 2383 bzero(fh_fmtp->fh4_i.fhx_data, sizeof (fh_fmtp->fh4_i.fhx_data));
2367 2384 bzero(fh_fmtp->fh4_i.fhx_xdata, sizeof (fh_fmtp->fh4_i.fhx_xdata));
2368 2385 ASSERT(exi->exi_fh.fh_xlen <= sizeof (fh_fmtp->fh4_i.fhx_xdata));
2369 2386 bcopy(exi->exi_fh.fh_xdata, fh_fmtp->fh4_i.fhx_xdata,
2370 2387 exi->exi_fh.fh_xlen);
2371 2388
2372 2389 fh_fmtp->fh4_len = fid.fid_len;
2373 2390 ASSERT(fid.fid_len <= sizeof (fh_fmtp->fh4_data));
2374 2391 bcopy(fid.fid_data, fh_fmtp->fh4_data, fid.fid_len);
2375 2392 fh_fmtp->fh4_flag = 0;
2376 2393
2377 2394 #ifdef VOLATILE_FH_TEST
2378 2395 /*
2379 2396 * XXX (temporary?)
2380 2397 * Use the rnode volatile_id value to add volatility to the fh.
2381 2398 *
2382 2399 * For testing purposes there are currently two scenarios, based
2383 2400 * on whether the filesystem was shared with "volatile_fh"
2384 2401 * or "expire_on_rename". In the first case, use the value of
2385 2402 * export struct share_time as the volatile_id. In the second
2386 2403 * case use the vnode volatile_id value (which is set to the
2387 2404 * time in which the file was renamed).
2388 2405 *
2389 2406 * Note that the above are temporary constructs for testing only
2390 2407 * XXX
2391 2408 */
2392 2409 if (exi->exi_export.ex_flags & EX_VOLRNM) {
2393 2410 fh_fmtp->fh4_volatile_id = find_volrnm_fh_id(exi, fh);
2394 2411 } else if (exi->exi_export.ex_flags & EX_VOLFH) {
2395 2412 fh_fmtp->fh4_volatile_id = exi->exi_volatile_id;
2396 2413 } else {
2397 2414 fh_fmtp->fh4_volatile_id = 0;
2398 2415 }
2399 2416 #endif /* VOLATILE_FH_TEST */
2400 2417
2401 2418 return (0);
2402 2419 }
2403 2420
2404 2421 /*
2405 2422 * Convert an fhandle into a vnode.
2406 2423 * Uses the file id (fh_len + fh_data) in the fhandle to get the vnode.
2407 2424 * WARNING: users of this routine must do a VN_RELE on the vnode when they
2408 2425 * are done with it.
2409 2426 */
2410 2427 vnode_t *
2411 2428 nfs_fhtovp(fhandle_t *fh, struct exportinfo *exi)
2412 2429 {
2413 2430 vfs_t *vfsp;
2414 2431 vnode_t *vp;
2415 2432 int error;
2416 2433 fid_t *fidp;
2417 2434
2418 2435 TRACE_0(TR_FAC_NFS, TR_FHTOVP_START,
2419 2436 "fhtovp_start");
2420 2437
2421 2438 if (exi == NULL) {
2422 2439 TRACE_1(TR_FAC_NFS, TR_FHTOVP_END,
2423 2440 "fhtovp_end:(%S)", "exi NULL");
2424 2441 return (NULL); /* not exported */
2425 2442 }
2426 2443
2427 2444 ASSERT(exi->exi_vp != NULL);
2428 2445
2429 2446 if (PUBLIC_FH2(fh)) {
2430 2447 if (exi->exi_export.ex_flags & EX_PUBLIC) {
2431 2448 TRACE_1(TR_FAC_NFS, TR_FHTOVP_END,
2432 2449 "fhtovp_end:(%S)", "root not exported");
2433 2450 return (NULL);
2434 2451 }
2435 2452 vp = exi->exi_vp;
2436 2453 VN_HOLD(vp);
2437 2454 return (vp);
2438 2455 }
2439 2456
2440 2457 vfsp = exi->exi_vp->v_vfsp;
2441 2458 ASSERT(vfsp != NULL);
2442 2459 fidp = (fid_t *)&fh->fh_len;
2443 2460
2444 2461 error = VFS_VGET(vfsp, &vp, fidp);
2445 2462 if (error || vp == NULL) {
2446 2463 TRACE_1(TR_FAC_NFS, TR_FHTOVP_END,
2447 2464 "fhtovp_end:(%S)", "VFS_GET failed or vp NULL");
2448 2465 return (NULL);
2449 2466 }
2450 2467 TRACE_1(TR_FAC_NFS, TR_FHTOVP_END,
2451 2468 "fhtovp_end:(%S)", "end");
2452 2469 return (vp);
2453 2470 }
2454 2471
2455 2472 /*
2456 2473 * Convert an nfs_fh3 into a vnode.
2457 2474 * Uses the file id (fh_len + fh_data) in the file handle to get the vnode.
2458 2475 * WARNING: users of this routine must do a VN_RELE on the vnode when they
2459 2476 * are done with it.
2460 2477 */
2461 2478 vnode_t *
2462 2479 nfs3_fhtovp(nfs_fh3 *fh, struct exportinfo *exi)
2463 2480 {
2464 2481 vfs_t *vfsp;
2465 2482 vnode_t *vp;
2466 2483 int error;
2467 2484 fid_t *fidp;
2468 2485
2469 2486 if (exi == NULL)
2470 2487 return (NULL); /* not exported */
2471 2488
2472 2489 ASSERT(exi->exi_vp != NULL);
2473 2490
2474 2491 if (PUBLIC_FH3(fh)) {
2475 2492 if (exi->exi_export.ex_flags & EX_PUBLIC)
2476 2493 return (NULL);
2477 2494 vp = exi->exi_vp;
2478 2495 VN_HOLD(vp);
2479 2496 return (vp);
2480 2497 }
2481 2498
2482 2499 if (fh->fh3_length < NFS3_OLDFHSIZE ||
2483 2500 fh->fh3_length > NFS3_MAXFHSIZE)
2484 2501 return (NULL);
2485 2502
2486 2503 vfsp = exi->exi_vp->v_vfsp;
2487 2504 ASSERT(vfsp != NULL);
2488 2505 fidp = FH3TOFIDP(fh);
2489 2506
2490 2507 error = VFS_VGET(vfsp, &vp, fidp);
2491 2508 if (error || vp == NULL)
2492 2509 return (NULL);
2493 2510
2494 2511 return (vp);
2495 2512 }
2496 2513
2497 2514 /*
2498 2515 * Convert an nfs_fh4 into a vnode.
2499 2516 * Uses the file id (fh_len + fh_data) in the file handle to get the vnode.
2500 2517 * WARNING: users of this routine must do a VN_RELE on the vnode when they
2501 2518 * are done with it.
2502 2519 */
2503 2520 vnode_t *
2504 2521 nfs4_fhtovp(nfs_fh4 *fh, struct exportinfo *exi, nfsstat4 *statp)
2505 2522 {
2506 2523 vfs_t *vfsp;
2507 2524 vnode_t *vp = NULL;
2508 2525 int error;
2509 2526 fid_t *fidp;
2510 2527 nfs_fh4_fmt_t *fh_fmtp;
2511 2528 #ifdef VOLATILE_FH_TEST
2512 2529 uint32_t volatile_id = 0;
2513 2530 #endif /* VOLATILE_FH_TEST */
2514 2531
2515 2532 if (exi == NULL) {
2516 2533 *statp = NFS4ERR_STALE;
2517 2534 return (NULL); /* not exported */
2518 2535 }
2519 2536 ASSERT(exi->exi_vp != NULL);
2520 2537
2521 2538 /* caller should have checked this */
2522 2539 ASSERT(fh->nfs_fh4_len >= NFS_FH4_LEN);
2523 2540
2524 2541 fh_fmtp = (nfs_fh4_fmt_t *)fh->nfs_fh4_val;
2525 2542 vfsp = exi->exi_vp->v_vfsp;
2526 2543 ASSERT(vfsp != NULL);
2527 2544 fidp = (fid_t *)&fh_fmtp->fh4_len;
2528 2545
2529 2546 #ifdef VOLATILE_FH_TEST
2530 2547 /* XXX check if volatile - should be changed later */
2531 2548 if (exi->exi_export.ex_flags & (EX_VOLRNM | EX_VOLFH)) {
2532 2549 /*
2533 2550 * Filesystem is shared with volatile filehandles
2534 2551 */
2535 2552 if (exi->exi_export.ex_flags & EX_VOLRNM)
2536 2553 volatile_id = find_volrnm_fh_id(exi, fh);
2537 2554 else
2538 2555 volatile_id = exi->exi_volatile_id;
2539 2556
2540 2557 if (fh_fmtp->fh4_volatile_id != volatile_id) {
2541 2558 *statp = NFS4ERR_FHEXPIRED;
2542 2559 return (NULL);
2543 2560 }
2544 2561 }
2545 2562 /*
2546 2563 * XXX even if test_volatile_fh false, the fh may contain a
2547 2564 * volatile id if obtained when the test was set.
2548 2565 */
2549 2566 fh_fmtp->fh4_volatile_id = (uchar_t)0;
2550 2567 #endif /* VOLATILE_FH_TEST */
2551 2568
2552 2569 error = VFS_VGET(vfsp, &vp, fidp);
2553 2570 /*
2554 2571 * If we can not get vp from VFS_VGET, perhaps this is
2555 2572 * an nfs v2/v3/v4 node in an nfsv4 pseudo filesystem.
2556 2573 * Check it out.
2557 2574 */
2558 2575 if (error && PSEUDO(exi))
2559 2576 error = nfs4_vget_pseudo(exi, &vp, fidp);
2560 2577
2561 2578 if (error || vp == NULL) {
2562 2579 *statp = NFS4ERR_STALE;
2563 2580 return (NULL);
2564 2581 }
2565 2582 /* XXX - disgusting hack */
2566 2583 if (vp->v_type == VNON && vp->v_flag & V_XATTRDIR)
2567 2584 vp->v_type = VDIR;
2568 2585 *statp = NFS4_OK;
2569 2586 return (vp);
2570 2587 }
2571 2588
2572 2589 /*
2573 2590 * Find the export structure associated with the given filesystem.
2574 2591 * If found, then increment the ref count (exi_count).
2575 2592 */
2576 2593 struct exportinfo *
2577 2594 checkexport(fsid_t *fsid, fid_t *fid)
2578 2595 {
2579 2596 struct exportinfo *exi;
2580 2597 nfs_export_t *ne = nfs_get_export();
2581 2598
2582 2599 rw_enter(&ne->exported_lock, RW_READER);
2583 2600 for (exi = ne->exptable[exptablehash(fsid, fid)];
2584 2601 exi != NULL;
2585 2602 exi = exi->fid_hash.next) {
2586 2603 if (exportmatch(exi, fsid, fid)) {
2587 2604 /*
2588 2605 * If this is the place holder for the
2589 2606 * public file handle, then return the
2590 2607 * real export entry for the public file
2591 2608 * handle.
2592 2609 */
2593 2610 if (exi->exi_export.ex_flags & EX_PUBLIC) {
2594 2611 exi = ne->exi_public;
2595 2612 }
2596 2613
2597 2614 exi_hold(exi);
2598 2615 rw_exit(&ne->exported_lock);
2599 2616 return (exi);
2600 2617 }
2601 2618 }
2602 2619 rw_exit(&ne->exported_lock);
2603 2620 return (NULL);
2604 2621 }
2605 2622
2606 2623
2607 2624 /*
2608 2625 * "old school" version of checkexport() for NFS4. NFS4
2609 2626 * rfs4_compound holds exported_lock for duration of compound
2610 2627 * processing. This version doesn't manipulate exi_count
2611 2628 * since NFS4 breaks fundamental assumptions in the exi_count
2612 2629 * design.
2613 2630 */
2614 2631 struct exportinfo *
2615 2632 checkexport4(fsid_t *fsid, fid_t *fid, vnode_t *vp)
2616 2633 {
2617 2634 struct exportinfo *exi;
2618 2635 nfs_export_t *ne = nfs_get_export();
2619 2636
2620 2637 ASSERT(RW_LOCK_HELD(&ne->exported_lock));
2621 2638
2622 2639 for (exi = ne->exptable[exptablehash(fsid, fid)];
2623 2640 exi != NULL;
2624 2641 exi = exi->fid_hash.next) {
2625 2642 if (exportmatch(exi, fsid, fid)) {
2626 2643 /*
2627 2644 * If this is the place holder for the
2628 2645 * public file handle, then return the
2629 2646 * real export entry for the public file
2630 2647 * handle.
2631 2648 */
2632 2649 if (exi->exi_export.ex_flags & EX_PUBLIC) {
2633 2650 exi = ne->exi_public;
2634 2651 }
2635 2652
2636 2653 /*
2637 2654 * If vp is given, check if vp is the
2638 2655 * same vnode as the exported node.
2639 2656 *
2640 2657 * Since VOP_FID of a lofs node returns the
2641 2658 * fid of its real node (ufs), the exported
2642 2659 * node for lofs and (pseudo) ufs may have
2643 2660 * the same fsid and fid.
2644 2661 */
2645 2662 if (vp == NULL || vp == exi->exi_vp)
2646 2663 return (exi);
2647 2664 }
2648 2665 }
2649 2666
2650 2667 return (NULL);
2651 2668 }
2652 2669
2653 2670 /*
2654 2671 * Free an entire export list node
2655 2672 */
2656 2673 void
2657 2674 exportfree(struct exportinfo *exi)
2658 2675 {
2659 2676 struct exportdata *ex;
2660 2677 struct charset_cache *cache;
2661 2678 int i;
2662 2679
2663 2680 ex = &exi->exi_export;
2664 2681
2665 2682 ASSERT(exi->exi_vp != NULL && !(exi->exi_export.ex_flags & EX_PUBLIC));
2666 2683 VN_RELE(exi->exi_vp);
2667 2684 if (exi->exi_dvp != NULL)
2668 2685 VN_RELE(exi->exi_dvp);
2669 2686
2670 2687 if (ex->ex_flags & EX_INDEX)
2671 2688 kmem_free(ex->ex_index, strlen(ex->ex_index) + 1);
2672 2689
2673 2690 kmem_free(ex->ex_path, ex->ex_pathlen + 1);
2674 2691 nfsauth_cache_free(exi);
2675 2692
2676 2693 /*
2677 2694 * if there is a character set mapping cached, clean it up.
2678 2695 */
2679 2696 for (cache = exi->exi_charset; cache != NULL;
2680 2697 cache = exi->exi_charset) {
2681 2698 if (cache->inbound != (kiconv_t)-1)
2682 2699 (void) kiconv_close(cache->inbound);
2683 2700 if (cache->outbound != (kiconv_t)-1)
2684 2701 (void) kiconv_close(cache->outbound);
2685 2702 exi->exi_charset = cache->next;
2686 2703 kmem_free(cache, sizeof (struct charset_cache));
2687 2704 }
2688 2705
2689 2706 if (exi->exi_logbuffer != NULL)
2690 2707 nfslog_disable(exi);
2691 2708
2692 2709 if (ex->ex_flags & EX_LOG) {
2693 2710 kmem_free(ex->ex_log_buffer, ex->ex_log_bufferlen + 1);
2694 2711 kmem_free(ex->ex_tag, ex->ex_taglen + 1);
2695 2712 }
2696 2713
2697 2714 if (exi->exi_visible)
2698 2715 free_visible(exi->exi_visible);
2699 2716
2700 2717 srv_secinfo_list_free(ex->ex_secinfo, ex->ex_seccnt);
2701 2718
2702 2719 #ifdef VOLATILE_FH_TEST
2703 2720 free_volrnm_list(exi);
2704 2721 mutex_destroy(&exi->exi_vol_rename_lock);
2705 2722 #endif /* VOLATILE_FH_TEST */
2706 2723
2707 2724 mutex_destroy(&exi->exi_lock);
2708 2725 rw_destroy(&exi->exi_cache_lock);
2709 2726 /*
2710 2727 * All nodes in the exi_cache AVL trees were removed and freed in the
2711 2728 * nfsauth_cache_free() call above. We will just destroy and free the
2712 2729 * empty AVL trees here.
2713 2730 */
2714 2731 for (i = 0; i < AUTH_TABLESIZE; i++) {
2715 2732 avl_destroy(exi->exi_cache[i]);
2716 2733 kmem_free(exi->exi_cache[i], sizeof (avl_tree_t));
2717 2734 }
2718 2735
2719 2736 kmem_free(exi, sizeof (*exi));
2720 2737 }
2721 2738
2722 2739 /*
2723 2740 * load the index file from user space into kernel space.
2724 2741 */
2725 2742 static int
2726 2743 loadindex(struct exportdata *kex)
2727 2744 {
2728 2745 int error;
2729 2746 char index[MAXNAMELEN+1];
2730 2747 size_t len;
2731 2748
2732 2749 /*
2733 2750 * copyinstr copies the complete string including the NULL and
2734 2751 * returns the len with the NULL byte included in the calculation
2735 2752 * as long as the max length is not exceeded.
2736 2753 */
2737 2754 if (error = copyinstr(kex->ex_index, index, sizeof (index), &len))
2738 2755 return (error);
2739 2756
2740 2757 kex->ex_index = kmem_alloc(len, KM_SLEEP);
2741 2758 bcopy(index, kex->ex_index, len);
2742 2759
2743 2760 return (0);
2744 2761 }
2745 2762
2746 2763 void
2747 2764 exi_hold(struct exportinfo *exi)
2748 2765 {
2749 2766 mutex_enter(&exi->exi_lock);
2750 2767 exi->exi_count++;
2751 2768 mutex_exit(&exi->exi_lock);
2752 2769 }
2753 2770
2754 2771 /*
2755 2772 * When a thread completes using exi, it should call exi_rele().
2756 2773 * exi_rele() decrements exi_count. It releases exi if exi_count == 0, i.e.
2757 2774 * if this is the last user of exi and exi is not on exportinfo list anymore
2758 2775 */
2759 2776 void
2760 2777 exi_rele(struct exportinfo *exi)
2761 2778 {
2762 2779 mutex_enter(&exi->exi_lock);
2763 2780 exi->exi_count--;
2764 2781 if (exi->exi_count == 0) {
2765 2782 mutex_exit(&exi->exi_lock);
2766 2783 exportfree(exi);
2767 2784 } else
2768 2785 mutex_exit(&exi->exi_lock);
2769 2786 }
2770 2787
2771 2788 #ifdef VOLATILE_FH_TEST
2772 2789 /*
2773 2790 * Test for volatile fh's - add file handle to list and set its volatile id
2774 2791 * to time it was renamed. If EX_VOLFH is also on and the fs is reshared,
2775 2792 * the vol_rename queue is purged.
2776 2793 *
2777 2794 * XXX This code is for unit testing purposes only... To correctly use it, it
2778 2795 * needs to tie a rename list to the export struct and (more
2779 2796 * important), protect access to the exi rename list using a write lock.
2780 2797 */
2781 2798
2782 2799 /*
2783 2800 * get the fh vol record if it's in the volatile on rename list. Don't check
2784 2801 * volatile_id in the file handle - compare only the file handles.
2785 2802 */
2786 2803 static struct ex_vol_rename *
2787 2804 find_volrnm_fh(struct exportinfo *exi, nfs_fh4 *fh4p)
2788 2805 {
2789 2806 struct ex_vol_rename *p = NULL;
2790 2807 fhandle4_t *fhp;
2791 2808
2792 2809 /* XXX shouldn't we assert &exported_lock held? */
2793 2810 ASSERT(MUTEX_HELD(&exi->exi_vol_rename_lock));
2794 2811
2795 2812 if (fh4p->nfs_fh4_len != NFS_FH4_LEN) {
2796 2813 return (NULL);
2797 2814 }
2798 2815 fhp = &((nfs_fh4_fmt_t *)fh4p->nfs_fh4_val)->fh4_i;
2799 2816 for (p = exi->exi_vol_rename; p != NULL; p = p->vrn_next) {
2800 2817 if (bcmp(fhp, &p->vrn_fh_fmt.fh4_i,
2801 2818 sizeof (fhandle4_t)) == 0)
2802 2819 break;
2803 2820 }
2804 2821 return (p);
2805 2822 }
2806 2823
2807 2824 /*
2808 2825 * get the volatile id for the fh (if there is - else return 0). Ignore the
2809 2826 * volatile_id in the file handle - compare only the file handles.
2810 2827 */
2811 2828 static uint32_t
2812 2829 find_volrnm_fh_id(struct exportinfo *exi, nfs_fh4 *fh4p)
2813 2830 {
2814 2831 struct ex_vol_rename *p;
2815 2832 uint32_t volatile_id;
2816 2833
2817 2834 mutex_enter(&exi->exi_vol_rename_lock);
2818 2835 p = find_volrnm_fh(exi, fh4p);
2819 2836 volatile_id = (p ? p->vrn_fh_fmt.fh4_volatile_id :
2820 2837 exi->exi_volatile_id);
2821 2838 mutex_exit(&exi->exi_vol_rename_lock);
2822 2839 return (volatile_id);
2823 2840 }
2824 2841
2825 2842 /*
2826 2843 * Free the volatile on rename list - will be called if a filesystem is
2827 2844 * unshared or reshared without EX_VOLRNM
2828 2845 */
2829 2846 static void
2830 2847 free_volrnm_list(struct exportinfo *exi)
2831 2848 {
2832 2849 struct ex_vol_rename *p, *pnext;
2833 2850
2834 2851 /* no need to hold mutex lock - this one is called from exportfree */
2835 2852 for (p = exi->exi_vol_rename; p != NULL; p = pnext) {
2836 2853 pnext = p->vrn_next;
2837 2854 kmem_free(p, sizeof (*p));
2838 2855 }
2839 2856 exi->exi_vol_rename = NULL;
2840 2857 }
2841 2858
2842 2859 /*
2843 2860 * Add a file handle to the volatile on rename list.
2844 2861 */
2845 2862 void
2846 2863 add_volrnm_fh(struct exportinfo *exi, vnode_t *vp)
2847 2864 {
2848 2865 struct ex_vol_rename *p;
2849 2866 char fhbuf[NFS4_FHSIZE];
2850 2867 nfs_fh4 fh4;
2851 2868 int error;
2852 2869
2853 2870 fh4.nfs_fh4_val = fhbuf;
2854 2871 error = makefh4(&fh4, vp, exi);
2855 2872 if ((error) || (fh4.nfs_fh4_len != sizeof (p->vrn_fh_fmt))) {
2856 2873 return;
2857 2874 }
2858 2875
2859 2876 mutex_enter(&exi->exi_vol_rename_lock);
2860 2877
2861 2878 p = find_volrnm_fh(exi, &fh4);
2862 2879
2863 2880 if (p == NULL) {
2864 2881 p = kmem_alloc(sizeof (*p), KM_SLEEP);
2865 2882 bcopy(fh4.nfs_fh4_val, &p->vrn_fh_fmt, sizeof (p->vrn_fh_fmt));
2866 2883 p->vrn_next = exi->exi_vol_rename;
2867 2884 exi->exi_vol_rename = p;
2868 2885 }
2869 2886
2870 2887 p->vrn_fh_fmt.fh4_volatile_id = gethrestime_sec();
2871 2888 mutex_exit(&exi->exi_vol_rename_lock);
2872 2889 }
2873 2890
2874 2891 #endif /* VOLATILE_FH_TEST */
|
↓ open down ↓ |
1019 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX