Print this page
Caution with use after exi_rele()
Ooops exi_zoneid isn't a variable again yet
Be far more judicious in the use of curzone-using macros.
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/nfs/nfs4_srv_ns.c
+++ new/usr/src/uts/common/fs/nfs/nfs4_srv_ns.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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 /*
27 27 * Copyright 2018 Nexenta Systems, Inc.
28 28 * Copyright (c) 2015, Joyent, Inc.
29 29 */
30 30
31 31 #include <sys/systm.h>
32 32
33 33 #include <nfs/nfs.h>
34 34 #include <nfs/export.h>
35 35 #include <sys/cmn_err.h>
36 36 #include <sys/avl.h>
37 37
38 38 #define PSEUDOFS_SUFFIX " (pseudo)"
39 39
40 40 /*
41 41 * A version of VOP_FID that deals with a remote VOP_FID for nfs.
42 42 * If vp is an nfs node, nfs4_fid() returns EREMOTE, nfs3_fid() and nfs_fid()
43 43 * returns the filehandle of vp as its fid. When nfs uses fid to set the
44 44 * exportinfo filehandle template, a remote nfs filehandle would be too big for
45 45 * the fid of the exported directory. This routine remaps the value of the
46 46 * attribute va_nodeid of vp to be the fid of vp, so that the fid can fit.
47 47 *
48 48 * We need this fid mainly for setting up NFSv4 server namespace where an
49 49 * nfs filesystem is also part of it. Thus, need to be able to setup a pseudo
50 50 * exportinfo for an nfs node.
51 51 *
52 52 * e.g. mount a filesystem on top of a nfs dir, and then share the new mount
53 53 * (like exporting a local disk from a "diskless" client)
54 54 */
55 55 int
56 56 vop_fid_pseudo(vnode_t *vp, fid_t *fidp)
57 57 {
58 58 struct vattr va;
59 59 int error;
60 60
61 61 error = VOP_FID(vp, fidp, NULL);
62 62
63 63 /*
64 64 * XXX nfs4_fid() does nothing and returns EREMOTE.
65 65 * XXX nfs3_fid()/nfs_fid() returns nfs filehandle as its fid
66 66 * which has a bigger length than local fid.
67 67 * NFS_FH4MAXDATA is the size of
68 68 * fhandle4_t.fh_xdata[NFS_FH4MAXDATA].
69 69 *
70 70 * Note: nfs[2,3,4]_fid() only gets called for diskless clients.
71 71 */
72 72 if (error == EREMOTE ||
73 73 (error == 0 && fidp->fid_len > NFS_FH4MAXDATA)) {
74 74
75 75 va.va_mask = AT_NODEID;
76 76 error = VOP_GETATTR(vp, &va, 0, CRED(), NULL);
77 77 if (error)
78 78 return (error);
79 79
80 80 fidp->fid_len = sizeof (va.va_nodeid);
81 81 bcopy(&va.va_nodeid, fidp->fid_data, fidp->fid_len);
82 82 return (0);
83 83 }
84 84
85 85 return (error);
86 86 }
87 87
88 88 /*
89 89 * Get an nfsv4 vnode of the given fid from the visible list of an
90 90 * nfs filesystem or get the exi_vp if it is the root node.
91 91 */
92 92 int
93 93 nfs4_vget_pseudo(struct exportinfo *exi, vnode_t **vpp, fid_t *fidp)
94 94 {
95 95 fid_t exp_fid;
96 96 struct exp_visible *visp;
97 97 int error;
98 98
99 99 /* check if the given fid is in the visible list */
100 100
101 101 for (visp = exi->exi_visible; visp; visp = visp->vis_next) {
102 102 if (EQFID(fidp, &visp->vis_fid)) {
103 103 VN_HOLD(visp->vis_vp);
104 104 *vpp = visp->vis_vp;
105 105 return (0);
106 106 }
107 107 }
108 108
109 109 /* check if the given fid is the same as the exported node */
110 110
111 111 bzero(&exp_fid, sizeof (exp_fid));
112 112 exp_fid.fid_len = MAXFIDSZ;
113 113 error = vop_fid_pseudo(exi->exi_vp, &exp_fid);
114 114 if (error)
115 115 return (error);
116 116
117 117 if (EQFID(fidp, &exp_fid)) {
118 118 VN_HOLD(exi->exi_vp);
119 119 *vpp = exi->exi_vp;
120 120 return (0);
121 121 }
122 122
123 123 return (ENOENT);
124 124 }
125 125
126 126 /*
127 127 * Create a pseudo export entry
128 128 *
129 129 * This is an export entry that's created as the
130 130 * side-effect of a "real" export. As a part of
131 131 * a real export, the pathname to the export is
132 132 * checked to see if all the directory components
133 133 * are accessible via an NFSv4 client, i.e. are
134 134 * exported. If treeclimb_export() finds an unexported
135 135 * mountpoint along the path, then it calls this
136 136 * function to export it.
137 137 *
138 138 * This pseudo export differs from a real export in that
139 139 * it only allows read-only access. A "visible" list of
140 140 * directories is added to filter lookup and readdir results
141 141 * to only contain dirnames which lead to descendant shares.
142 142 *
143 143 * A visible list has a per-file-system scope. Any exportinfo
144 144 * struct (real or pseudo) can have a visible list as long as
145 145 * a) its export root is VROOT, or is the zone's root for in-zone NFS service
146 146 * b) a descendant of the export root is shared
147 147 */
148 148 struct exportinfo *
149 149 pseudo_exportfs(nfs_export_t *ne, vnode_t *vp, fid_t *fid,
150 150 struct exp_visible *vis_head, struct exportdata *exdata)
151 151 {
152 152 struct exportinfo *exi;
153 153 struct exportdata *kex;
154 154 fsid_t fsid;
155 155 int vpathlen;
156 156 int i;
157 157
158 158 ASSERT(RW_WRITE_HELD(&ne->exported_lock));
|
↓ open down ↓ |
158 lines elided |
↑ open up ↑ |
159 159
160 160 fsid = vp->v_vfsp->vfs_fsid;
161 161 exi = kmem_zalloc(sizeof (*exi), KM_SLEEP);
162 162 exi->exi_fsid = fsid;
163 163 exi->exi_fid = *fid;
164 164 exi->exi_vp = vp;
165 165 VN_HOLD(exi->exi_vp);
166 166 exi->exi_visible = vis_head;
167 167 exi->exi_count = 1;
168 168 /* Caller will set exi_zone... */
169 + /* XXX KEBE SAYS Uncomment me or fix in the caller */
170 + /* exi->exi_zoneid = ne->ne_globals->nfs_zoneid; */
169 171 exi->exi_volatile_dev = (vfssw[vp->v_vfsp->vfs_fstype].vsw_flag &
170 172 VSW_VOLATILEDEV) ? 1 : 0;
171 173 mutex_init(&exi->exi_lock, NULL, MUTEX_DEFAULT, NULL);
172 - exi->exi_zoneid = ne->ne_globals->nfs_zoneid;
173 174
174 175 /*
175 176 * Build up the template fhandle
176 177 */
177 178 exi->exi_fh.fh_fsid = fsid;
178 179 ASSERT(exi->exi_fid.fid_len <= sizeof (exi->exi_fh.fh_xdata));
179 180 exi->exi_fh.fh_xlen = exi->exi_fid.fid_len;
180 181 bcopy(exi->exi_fid.fid_data, exi->exi_fh.fh_xdata,
181 182 exi->exi_fid.fid_len);
182 183 exi->exi_fh.fh_len = sizeof (exi->exi_fh.fh_data);
183 184
184 185 kex = &exi->exi_export;
185 186 kex->ex_flags = EX_PSEUDO;
186 187
187 188 vpathlen = strlen(vp->v_path);
188 189 kex->ex_pathlen = vpathlen + strlen(PSEUDOFS_SUFFIX);
189 190 kex->ex_path = kmem_alloc(kex->ex_pathlen + 1, KM_SLEEP);
190 191
191 192 if (vpathlen)
192 193 (void) strncpy(kex->ex_path, vp->v_path, vpathlen);
193 194 (void) strcpy(kex->ex_path + vpathlen, PSEUDOFS_SUFFIX);
194 195
195 196 /* Transfer the secinfo data from exdata to this new pseudo node */
196 197 if (exdata)
197 198 srv_secinfo_exp2pseu(&exi->exi_export, exdata);
198 199
199 200 /*
200 201 * Initialize auth cache and auth cache lock
201 202 */
202 203 for (i = 0; i < AUTH_TABLESIZE; i++) {
203 204 exi->exi_cache[i] = kmem_alloc(sizeof (avl_tree_t), KM_SLEEP);
204 205 avl_create(exi->exi_cache[i], nfsauth_cache_clnt_compar,
205 206 sizeof (struct auth_cache_clnt),
206 207 offsetof(struct auth_cache_clnt, authc_link));
207 208 }
208 209 rw_init(&exi->exi_cache_lock, NULL, RW_DEFAULT, NULL);
209 210
210 211 /*
211 212 * Insert the new entry at the front of the export list
212 213 */
213 214 export_link(ne, exi);
214 215
215 216 /*
216 217 * Initialize exi_id and exi_kstats
217 218 */
218 219 mutex_enter(&nfs_exi_id_lock);
219 220 exi->exi_id = exi_id_get_next();
220 221 avl_add(&exi_id_tree, exi);
221 222 mutex_exit(&nfs_exi_id_lock);
222 223
223 224 return (exi);
224 225 }
225 226
226 227 /*
227 228 * Free a list of visible directories
228 229 */
229 230 void
230 231 free_visible(struct exp_visible *head)
231 232 {
232 233 struct exp_visible *visp, *next;
233 234
234 235 for (visp = head; visp; visp = next) {
235 236 if (visp->vis_vp != NULL)
236 237 VN_RELE(visp->vis_vp);
237 238
238 239 next = visp->vis_next;
239 240 srv_secinfo_list_free(visp->vis_secinfo, visp->vis_seccnt);
240 241 kmem_free(visp, sizeof (*visp));
241 242 }
242 243 }
243 244
244 245 /*
245 246 * Connects newchild (or subtree with newchild in head)
246 247 * to the parent node. We always add it to the beginning
247 248 * of sibling list.
248 249 */
249 250 static void
250 251 tree_add_child(treenode_t *parent, treenode_t *newchild)
251 252 {
252 253 newchild->tree_parent = parent;
253 254 newchild->tree_sibling = parent->tree_child_first;
254 255 parent->tree_child_first = newchild;
255 256 }
256 257
257 258 /* Look up among direct children a node with the exact tree_vis pointer */
258 259 static treenode_t *
259 260 tree_find_child_by_vis(treenode_t *t, exp_visible_t *vis)
260 261 {
261 262 for (t = t->tree_child_first; t; t = t->tree_sibling)
262 263 if (t->tree_vis == vis)
263 264 return (t);
264 265 return (NULL);
265 266 }
266 267
267 268 /*
268 269 * Add new node to the head of subtree pointed by 'n'. n can be NULL.
269 270 * Interconnects the new treenode with exp_visible and exportinfo
270 271 * if needed.
271 272 */
272 273 static treenode_t *
273 274 tree_prepend_node(treenode_t *n, exp_visible_t *v, exportinfo_t *e)
274 275 {
275 276 treenode_t *tnode = kmem_zalloc(sizeof (*tnode), KM_SLEEP);
276 277
277 278 if (n) {
278 279 tnode->tree_child_first = n;
279 280 n->tree_parent = tnode;
280 281 }
281 282 if (v) {
282 283 tnode->tree_vis = v;
283 284 }
284 285 if (e) {
285 286 tnode->tree_exi = e;
286 287 e->exi_tree = tnode;
287 288 }
288 289 return (tnode);
289 290 }
290 291
291 292 /*
292 293 * Removes node from the tree and frees the treenode struct.
293 294 * Does not free structures pointed by tree_exi and tree_vis,
294 295 * they should be already freed.
295 296 */
296 297 static void
297 298 tree_remove_node(nfs_export_t *ne, treenode_t *node)
298 299 {
299 300 treenode_t *parent = node->tree_parent;
300 301 treenode_t *s; /* s for sibling */
301 302
302 303 if (parent == NULL) {
303 304 kmem_free(node, sizeof (*node));
304 305 ne->ns_root = NULL;
305 306 return;
306 307 }
307 308 /* This node is first child */
308 309 if (parent->tree_child_first == node) {
309 310 parent->tree_child_first = node->tree_sibling;
310 311 /* This node is not first child */
311 312 } else {
312 313 s = parent->tree_child_first;
313 314 while (s->tree_sibling != node)
314 315 s = s->tree_sibling;
315 316 s->tree_sibling = s->tree_sibling->tree_sibling;
316 317 }
317 318 kmem_free(node, sizeof (*node));
318 319 }
319 320
320 321 /*
321 322 * When we export a new directory we need to add a new
322 323 * path segment through the pseudofs to reach the new
323 324 * directory. This new path is reflected in a list of
324 325 * directories added to the "visible" list.
325 326 *
326 327 * Here there are two lists of visible fids: one hanging off the
327 328 * pseudo exportinfo, and the one we want to add. It's possible
328 329 * that the two lists share a common path segment
329 330 * and have some common directories. We need to combine
330 331 * the lists so there's no duplicate entries. Where a common
331 332 * path component is found, the vis_count field is bumped.
332 333 *
333 334 * This example shows that the treenode chain (tree_head) and
334 335 * exp_visible chain (vis_head) can differ in length. The latter
335 336 * can be shorter. The outer loop must loop over the vis_head chain.
336 337 *
337 338 * share /x/a
338 339 * mount -F ufs /dev/dsk/... /x/y
339 340 * mkdir -p /x/y/a/b
340 341 * share /x/y/a/b
341 342 *
342 343 * When more_visible() is called during the second share,
343 344 * the existing namespace is following:
344 345 * exp_visible_t
345 346 * treenode_t exportinfo_t v0 v1
346 347 * ns_root+---+ +------------+ +---+ +---+
347 348 * t0| / |........| E0 pseudo |->| x |->| a |
348 349 * +---+ +------------+ +---+ +---+
349 350 * | / /
350 351 * +---+ / /
351 352 * t1| x |------------------------ /
352 353 * +---+ /
353 354 * | /
354 355 * +---+ /
355 356 * t2| a |-------------------------
356 357 * +---+........+------------+
357 358 * | E1 real |
358 359 * +------------+
359 360 *
360 361 * This is being added:
361 362 *
362 363 * tree_head vis_head
363 364 * +---+ +---+
364 365 * t3| x |->| x |v2
365 366 * +---+ +---+
366 367 * | |
367 368 * +---+ +---+ v4 v5
368 369 * t4| y |->| y |v3 +------------+ +---+ +---+
369 370 * +---+\ +---+ | E2 pseudo |->| a |->| b |
370 371 * | \....... >+------------+ +---+ +---+
371 372 * +---+ / /
372 373 * t5| a |--------------------------- /
373 374 * +---+ /
374 375 * | /
375 376 * +---+-------------------------------
376 377 * t6| b | +------------+
377 378 * +---+..........>| E3 real |
378 379 * +------------+
379 380 *
380 381 * more_visible() will:
381 382 * - kmem_free() t3 and v2
382 383 * - add t4, t5, t6 as a child of t1 (t4 will become sibling of t2)
383 384 * - add v3 to the end of E0->exi_visible
384 385 *
385 386 * Note that v4 and v5 were already processed in pseudo_exportfs() and
386 387 * added to E2. The outer loop of more_visible() will loop only over v2
387 388 * and v3. The inner loop of more_visible() always loops over v0 and v1.
388 389 *
389 390 * Illustration for this scenario:
390 391 *
391 392 * mkdir -p /v/a/b/c
392 393 * share /v/a/b/c
393 394 * mkdir /v/a/b/c1
394 395 * mkdir -p /v/a1
395 396 * mv /v/a/b /v/a1
396 397 * share /v/a1/b/c1
397 398 *
398 399 * EXISTING
399 400 * treenode
400 401 * namespace: +-----------+ visibles
401 402 * |exportinfo |-->v->a->b->c
402 403 * connect_point->+---+--->+-----------+
403 404 * | / |T0
404 405 * +---+
405 406 * | NEW treenode chain:
406 407 * child->+---+
407 408 * | v |T1 +---+<-curr
408 409 * +---+ N1| v |
409 410 * | +---+
410 411 * +---+ |
411 412 * | a |T2 +---+<-tree_head
412 413 * +---+ N2| a1|
413 414 * | +---+
414 415 * +---+ |
415 416 * | b |T3 +---+
416 417 * +---+ N3| b |
417 418 * | +---+
418 419 * +---+ |
419 420 * | c |T4 +---+
420 421 * +---+ N4| c1|
421 422 * +---+
422 423 *
423 424 * The picture above illustrates the position of following pointers after line
424 425 * 'child = tree_find_child_by_vis(connect_point, curr->tree_vis);'
425 426 * was executed for the first time in the outer 'for' loop:
426 427 *
427 428 * connect_point..parent treenode in the EXISTING namespace to which the 'curr'
428 429 * should be connected. If 'connect_point' already has a child
429 430 * with the same value of tree_vis as the curr->tree_vis is,
430 431 * the 'curr' will not be added, but kmem_free()d.
431 432 * child..........the result of tree_find_child_by_vis()
432 433 * curr...........currently processed treenode from the NEW treenode chain
433 434 * tree_head......current head of the NEW treenode chain, in this case it was
434 435 * already moved down to its child - preparation for another loop
435 436 *
436 437 * What will happen to NEW treenodes N1, N2, N3, N4 in more_visible() later:
437 438 *
438 439 * N1: is merged - i.e. N1 is kmem_free()d. T0 has a child T1 with the same
439 440 * tree_vis as N1
440 441 * N2: is added as a new child of T1
441 442 * Note: not just N2, but the whole chain N2->N3->N4 is added
442 443 * N3: not processed separately (it was added together with N2)
443 444 * Even that N3 and T3 have same tree_vis, they are NOT merged, but will
444 445 * become duplicates.
445 446 * N4: not processed separately
446 447 */
447 448 static void
448 449 more_visible(struct exportinfo *exi, treenode_t *tree_head)
449 450 {
450 451 struct exp_visible *vp1, *vp2, *vis_head, *tail, *next;
451 452 int found;
452 453 treenode_t *child, *curr, *connect_point;
453 454 nfs_export_t *ne = nfs_get_export();
454 455
455 456 vis_head = tree_head->tree_vis;
456 457 connect_point = exi->exi_tree;
457 458
458 459 /*
459 460 * If exportinfo doesn't already have a visible
460 461 * list just assign the entire supplied list.
461 462 */
462 463 if (exi->exi_visible == NULL) {
463 464 tree_add_child(connect_point, tree_head);
464 465 exi->exi_visible = vis_head;
465 466
466 467 /* Update the change timestamp */
467 468 tree_update_change(ne, connect_point, &vis_head->vis_change);
468 469
469 470 return;
470 471 }
471 472
472 473 /* The outer loop traverses the supplied list. */
473 474 for (vp1 = vis_head; vp1; vp1 = next) {
474 475 found = 0;
475 476 next = vp1->vis_next;
476 477
477 478 /* The inner loop searches the exportinfo visible list. */
478 479 for (vp2 = exi->exi_visible; vp2; vp2 = vp2->vis_next) {
479 480 tail = vp2;
480 481 if (EQFID(&vp1->vis_fid, &vp2->vis_fid)) {
481 482 found = 1;
482 483 vp2->vis_count++;
483 484 VN_RELE(vp1->vis_vp);
484 485 /* Transfer vis_exported from vp1 to vp2. */
485 486 if (vp1->vis_exported && !vp2->vis_exported)
486 487 vp2->vis_exported = 1;
487 488 kmem_free(vp1, sizeof (*vp1));
488 489 tree_head->tree_vis = vp2;
489 490 break;
490 491 }
491 492 }
492 493
493 494 /* If not found - add to the end of the list */
494 495 if (! found) {
495 496 tail->vis_next = vp1;
496 497 vp1->vis_next = NULL;
497 498 }
498 499
499 500 curr = tree_head;
500 501 tree_head = tree_head->tree_child_first;
501 502
502 503 if (! connect_point) /* No longer merging */
503 504 continue;
504 505 /*
505 506 * The inner loop could set curr->tree_vis to the EXISTING
506 507 * exp_visible vp2, so we can search among the children of
507 508 * connect_point for the curr->tree_vis. No need for EQFID.
508 509 */
509 510 child = tree_find_child_by_vis(connect_point, curr->tree_vis);
510 511
511 512 /*
512 513 * Merging cannot be done if a valid child->tree_exi would
513 514 * be overwritten by a new curr->tree_exi.
514 515 */
515 516 if (child &&
516 517 (child->tree_exi == NULL || curr->tree_exi == NULL)) {
517 518 if (curr->tree_exi) { /* Transfer the exportinfo */
518 519 child->tree_exi = curr->tree_exi;
519 520 child->tree_exi->exi_tree = child;
520 521 }
521 522 kmem_free(curr, sizeof (treenode_t));
522 523 connect_point = child;
523 524 } else { /* Branching */
524 525 tree_add_child(connect_point, curr);
525 526
526 527 /* Update the change timestamp */
527 528 tree_update_change(ne, connect_point,
528 529 &curr->tree_vis->vis_change);
529 530
530 531 connect_point = NULL;
531 532 }
532 533 }
533 534 }
534 535
535 536 /*
536 537 * Remove one visible entry from the pseudo exportfs.
537 538 *
538 539 * When we unexport a directory, we have to remove path
539 540 * components from the visible list in the pseudo exportfs
540 541 * entry. The supplied visible contains one fid of one path
541 542 * component. The visible list of the export
542 543 * is checked against provided visible, matching fid has its
543 544 * reference count decremented. If a reference count drops to
544 545 * zero, then it means no paths now use this directory, so its
545 546 * fid can be removed from the visible list.
546 547 *
547 548 * When the last path is removed, the visible list will be null.
548 549 */
549 550 static void
550 551 less_visible(struct exportinfo *exi, struct exp_visible *vp1)
551 552 {
552 553 struct exp_visible *vp2;
553 554 struct exp_visible *prev, *next;
554 555
555 556 for (vp2 = exi->exi_visible, prev = NULL; vp2; vp2 = next) {
556 557
557 558 next = vp2->vis_next;
558 559
559 560 if (vp1 == vp2) {
560 561 /*
561 562 * Decrement the ref count.
562 563 * Remove the entry if it's zero.
563 564 */
564 565 if (--vp2->vis_count <= 0) {
565 566 if (prev == NULL)
566 567 exi->exi_visible = next;
567 568 else
568 569 prev->vis_next = next;
569 570 VN_RELE(vp2->vis_vp);
570 571 srv_secinfo_list_free(vp2->vis_secinfo,
571 572 vp2->vis_seccnt);
572 573 kmem_free(vp2, sizeof (*vp1));
573 574 }
574 575 break;
575 576 }
576 577 prev = vp2;
577 578 }
578 579 }
579 580
580 581 /*
581 582 * This function checks the path to a new export to
582 583 * check whether all the pathname components are
583 584 * exported. It works by climbing the file tree one
584 585 * component at a time via "..", crossing mountpoints
585 586 * if necessary until an export entry is found, or the
586 587 * system root is reached.
587 588 *
588 589 * If an unexported mountpoint is found, then
589 590 * a new pseudo export is added and the pathname from
590 591 * the mountpoint down to the export is added to the
591 592 * visible list for the new pseudo export. If an existing
592 593 * pseudo export is found, then the pathname is added
593 594 * to its visible list.
594 595 *
595 596 * Note that there's some tests for exportdir.
596 597 * The exportinfo entry that's passed as a parameter
597 598 * is that of the real export and exportdir is set
598 599 * for this case.
599 600 *
600 601 * Here is an example of a possible setup:
601 602 *
602 603 * () - a new fs; fs mount point
603 604 * EXPORT - a real exported node
604 605 * PSEUDO - a pseudo node
605 606 * vis - visible list
606 607 * f# - security flavor#
607 608 * (f#) - security flavor# propagated from its descendents
608 609 * "" - covered vnode
609 610 *
610 611 *
611 612 * /
612 613 * |
613 614 * (a) PSEUDO (f1,f2)
614 615 * | vis: b,b,"c","n"
615 616 * |
616 617 * b
617 618 * ---------|------------------
618 619 * | |
619 620 * (c) EXPORT,f1(f2) (n) PSEUDO (f1,f2)
620 621 * | vis: "e","d" | vis: m,m,,p,q,"o"
621 622 * | |
622 623 * ------------------ -------------------
623 624 * | | | | |
624 625 * (d) (e) f m EXPORT,f1(f2) p
625 626 * EXPORT EXPORT | |
626 627 * f1 f2 | |
627 628 * | | |
628 629 * j (o) EXPORT,f2 q EXPORT f2
629 630 *
630 631 */
631 632 int
632 633 treeclimb_export(struct exportinfo *exip)
633 634 {
634 635 vnode_t *dvp, *vp;
635 636 fid_t fid;
636 637 int error;
637 638 int exportdir;
638 639 struct exportinfo *new_exi = exip;
639 640 struct exp_visible *visp;
640 641 struct exp_visible *vis_head = NULL;
641 642 struct vattr va;
642 643 treenode_t *tree_head = NULL;
643 644 timespec_t now;
644 645 nfs_export_t *ne = nfs_get_export();
645 646
646 647 ASSERT(RW_WRITE_HELD(&ne->exported_lock));
647 648 ASSERT3P(curzone, ==, exip->exi_zone);
648 649
649 650 gethrestime(&now);
650 651
651 652 vp = exip->exi_vp;
652 653 VN_HOLD(vp);
|
↓ open down ↓ |
470 lines elided |
↑ open up ↑ |
653 654 exportdir = 1;
654 655
655 656 for (;;) {
656 657
657 658 bzero(&fid, sizeof (fid));
658 659 fid.fid_len = MAXFIDSZ;
659 660 error = vop_fid_pseudo(vp, &fid);
660 661 if (error)
661 662 break;
662 663
664 + ASSERT3U(exip->exi_zoneid, ==, curzone->zone_id);
663 665 /*
664 666 * The root of the file system, or the zone's root for
665 667 * in-zone NFS service needs special handling
666 668 */
667 669 if (vp->v_flag & VROOT || VN_IS_CURZONEROOT(vp)) {
668 670 if (!exportdir) {
669 671 struct exportinfo *exi;
670 672
671 673 /*
672 674 * Check if this VROOT dir is already exported.
673 675 * If so, then attach the pseudonodes. If not,
674 676 * then continue .. traversal until we hit a
675 677 * VROOT export (pseudo or real).
676 678 */
677 679 exi = checkexport4(&vp->v_vfsp->vfs_fsid, &fid,
678 680 vp);
679 681 if (exi != NULL) {
680 682 /*
681 683 * Found an export info
682 684 *
683 685 * Extend the list of visible
684 686 * directories whether it's a pseudo
685 687 * or a real export.
686 688 */
687 689 more_visible(exi, tree_head);
688 690 break; /* and climb no further */
|
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
689 691 }
690 692
691 693 /*
692 694 * Found the root directory of a filesystem
693 695 * that isn't exported. Need to export
694 696 * this as a pseudo export so that an NFS v4
695 697 * client can do lookups in it.
696 698 */
697 699 new_exi = pseudo_exportfs(ne, vp, &fid,
698 700 vis_head, NULL);
701 + /* XXX KEBE SAYS NUKE ME */
699 702 new_exi->exi_zone = exip->exi_zone;
700 703 vis_head = NULL;
701 704 }
702 705
703 706 if (VN_IS_CURZONEROOT(vp)) {
704 707 /* at system root */
705 708 /*
706 709 * If sharing "/", new_exi is shared exportinfo
707 710 * (exip). Otherwise, new_exi is exportinfo
708 711 * created by pseudo_exportfs() above.
709 712 */
710 713 ne->ns_root = tree_prepend_node(tree_head, NULL,
711 714 new_exi);
712 715
713 716 /* Update the change timestamp */
714 717 tree_update_change(ne, ne->ns_root, &now);
715 718
716 719 break;
717 720 }
718 721
719 722 /*
720 723 * Traverse across the mountpoint and continue the
721 724 * climb on the mounted-on filesystem.
722 725 */
723 726 vp = untraverse(vp);
724 727 exportdir = 0;
725 728 continue;
726 729 }
727 730
728 731 /*
729 732 * Do a getattr to obtain the nodeid (inode num)
730 733 * for this vnode.
731 734 */
732 735 va.va_mask = AT_NODEID;
733 736 error = VOP_GETATTR(vp, &va, 0, CRED(), NULL);
734 737 if (error)
735 738 break;
736 739
737 740 /*
738 741 * Add this directory fid to visible list
739 742 */
740 743 visp = kmem_alloc(sizeof (*visp), KM_SLEEP);
741 744 VN_HOLD(vp);
742 745 visp->vis_vp = vp;
743 746 visp->vis_fid = fid; /* structure copy */
744 747 visp->vis_ino = va.va_nodeid;
745 748 visp->vis_count = 1;
746 749 visp->vis_exported = exportdir;
747 750 visp->vis_secinfo = NULL;
748 751 visp->vis_seccnt = 0;
749 752 visp->vis_change = now; /* structure copy */
750 753 visp->vis_next = vis_head;
751 754 vis_head = visp;
752 755
753 756 /*
754 757 * Will set treenode's pointer to exportinfo to
755 758 * 1. shared exportinfo (exip) - if first visit here
756 759 * 2. freshly allocated pseudo export (if any)
757 760 * 3. null otherwise
758 761 */
759 762 tree_head = tree_prepend_node(tree_head, visp, new_exi);
760 763 new_exi = NULL;
761 764
762 765 /*
763 766 * Now, do a ".." to find parent dir of vp.
764 767 */
765 768 error = VOP_LOOKUP(vp, "..", &dvp, NULL, 0, NULL, CRED(),
766 769 NULL, NULL, NULL);
767 770
768 771 if (error == ENOTDIR && exportdir) {
769 772 dvp = exip->exi_dvp;
770 773 ASSERT(dvp != NULL);
771 774 VN_HOLD(dvp);
772 775 error = 0;
773 776 }
774 777
775 778 if (error)
776 779 break;
777 780
778 781 exportdir = 0;
779 782 VN_RELE(vp);
780 783 vp = dvp;
781 784 }
782 785
783 786 VN_RELE(vp);
784 787
785 788 /*
786 789 * We can have set error due to error in:
787 790 * 1. vop_fid_pseudo()
788 791 * 2. VOP_GETATTR()
789 792 * 3. VOP_LOOKUP()
790 793 * We must free pseudo exportinfos, visibles and treenodes.
791 794 * Visibles are referenced from treenode_t::tree_vis and
792 795 * exportinfo_t::exi_visible. To avoid double freeing, only
793 796 * exi_visible pointer is used, via exi_rele(), for the clean-up.
794 797 */
795 798 if (error) {
796 799 /* Free unconnected visibles, if there are any. */
797 800 if (vis_head)
798 801 free_visible(vis_head);
799 802
800 803 /* Connect unconnected exportinfo, if there is any. */
801 804 if (new_exi && new_exi != exip)
802 805 tree_head = tree_prepend_node(tree_head, NULL, new_exi);
803 806
804 807 while (tree_head) {
805 808 treenode_t *t2 = tree_head;
806 809 exportinfo_t *e = tree_head->tree_exi;
807 810 /* exip will be freed in exportfs() */
808 811 if (e && e != exip) {
809 812 mutex_enter(&nfs_exi_id_lock);
810 813 avl_remove(&exi_id_tree, e);
811 814 mutex_exit(&nfs_exi_id_lock);
812 815 export_unlink(ne, e);
813 816 exi_rele(e);
814 817 }
815 818 tree_head = tree_head->tree_child_first;
816 819 kmem_free(t2, sizeof (*t2));
817 820 }
818 821 }
819 822
820 823 return (error);
821 824 }
822 825
823 826 /*
824 827 * Walk up the tree and:
825 828 * 1. release pseudo exportinfo if it has no child
826 829 * 2. release visible in parent's exportinfo
827 830 * 3. delete non-exported leaf nodes from tree
828 831 *
829 832 * Deleting of nodes will start only if the unshared
830 833 * node was a leaf node.
831 834 * Deleting of nodes will finish when we reach a node which
832 835 * has children or is a real export, then we might still need
833 836 * to continue releasing visibles, until we reach VROOT or zone's root node.
834 837 */
835 838 void
836 839 treeclimb_unexport(nfs_export_t *ne, struct exportinfo *exip)
837 840 {
838 841 treenode_t *tnode, *old_nd;
839 842 treenode_t *connect_point = NULL;
840 843
841 844 ASSERT(RW_WRITE_HELD(&ne->exported_lock));
842 845 ASSERT(curzone == exip->exi_zone || curzone == global_zone);
843 846
844 847 /*
845 848 * exi_tree can be null for the zone root
846 849 * which means we're already at the "top"
847 850 * and there's nothing more to "climb".
848 851 */
849 852 tnode = exip->exi_tree;
850 853 if (tnode == NULL) {
851 854 /* Should only happen for... */
852 855 ASSERT(exip == ne->exi_root);
853 856 return;
854 857 }
855 858
856 859 /*
857 860 * The unshared exportinfo was unlinked in unexport().
858 861 * Zeroing tree_exi ensures that we will skip it.
859 862 */
860 863 tnode->tree_exi = NULL;
861 864
862 865 if (tnode->tree_vis != NULL) /* system root has tree_vis == NULL */
863 866 tnode->tree_vis->vis_exported = 0;
864 867
865 868 while (tnode != NULL) {
866 869
867 870 /*
868 871 * Stop at VROOT (or zone root) node which is exported or has
869 872 * child.
870 873 */
871 874 if (TREE_ROOT(tnode) &&
872 875 (TREE_EXPORTED(tnode) || tnode->tree_child_first != NULL))
|
↓ open down ↓ |
164 lines elided |
↑ open up ↑ |
873 876 break;
874 877
875 878 /* Release pseudo export if it has no child */
876 879 if (TREE_ROOT(tnode) && !TREE_EXPORTED(tnode) &&
877 880 tnode->tree_child_first == NULL) {
878 881 mutex_enter(&nfs_exi_id_lock);
879 882 avl_remove(&exi_id_tree, tnode->tree_exi);
880 883 mutex_exit(&nfs_exi_id_lock);
881 884 export_unlink(ne, tnode->tree_exi);
882 885 exi_rele(tnode->tree_exi);
886 + tnode->tree_exi = NULL;
883 887 }
884 888
885 889 /* Release visible in parent's exportinfo */
886 890 if (tnode->tree_vis != NULL)
887 891 less_visible(vis2exi(tnode), tnode->tree_vis);
888 892
889 893 /* Continue with parent */
890 894 old_nd = tnode;
891 895 tnode = tnode->tree_parent;
892 896
893 897 /* Remove itself, if this is a leaf and non-exported node */
894 898 if (old_nd->tree_child_first == NULL &&
895 899 !TREE_EXPORTED(old_nd)) {
896 900 tree_remove_node(ne, old_nd);
897 901 connect_point = tnode;
898 902 }
899 903 }
|
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
900 904
901 905 /* Update the change timestamp */
902 906 if (connect_point != NULL)
903 907 tree_update_change(ne, connect_point, NULL);
904 908 }
905 909
906 910 /*
907 911 * Traverse backward across mountpoint from the
908 912 * root vnode of a filesystem to its mounted-on
909 913 * vnode.
914 + *
915 + * Callers to this function have confirmed the use of curzone is safe here.
910 916 */
911 917 vnode_t *
912 918 untraverse(vnode_t *vp)
913 919 {
914 920 vnode_t *tvp, *nextvp;
915 921
916 922 tvp = vp;
917 923 for (;;) {
918 924 if (!(tvp->v_flag & VROOT) && !VN_IS_CURZONEROOT(tvp))
919 925 break;
920 926
921 927 /* lock vfs to prevent unmount of this vfs */
922 928 vfs_lock_wait(tvp->v_vfsp);
923 929
924 930 if ((nextvp = tvp->v_vfsp->vfs_vnodecovered) == NULL) {
925 931 vfs_unlock(tvp->v_vfsp);
926 932 break;
927 933 }
928 934
929 935 /*
930 936 * Hold nextvp to prevent unmount. After unlock vfs and
931 937 * rele tvp, any number of overlays could be unmounted.
932 938 * Putting a hold on vfs_vnodecovered will only allow
933 939 * tvp's vfs to be unmounted. Of course if caller placed
934 940 * extra hold on vp before calling untraverse, the following
935 941 * hold would not be needed. Since prev actions of caller
936 942 * are unknown, we need to hold here just to be safe.
937 943 */
938 944 VN_HOLD(nextvp);
939 945 vfs_unlock(tvp->v_vfsp);
940 946 VN_RELE(tvp);
941 947 tvp = nextvp;
942 948 }
943 949
944 950 return (tvp);
945 951 }
946 952
947 953 /*
948 954 * Given an exportinfo, climb up to find the exportinfo for the VROOT
949 955 * (or zone root) of the filesystem.
950 956 *
951 957 * e.g. /
952 958 * |
953 959 * a (VROOT) pseudo-exportinfo
954 960 * |
955 961 * b
|
↓ open down ↓ |
36 lines elided |
↑ open up ↑ |
956 962 * |
957 963 * c #share /a/b/c
958 964 * |
959 965 * d
960 966 *
961 967 * where c is in the same filesystem as a.
962 968 * So, get_root_export(*exportinfo_for_c) returns exportinfo_for_a
963 969 *
964 970 * If d is shared, then c will be put into a's visible list.
965 971 * Note: visible list is per filesystem and is attached to the
966 - * VROOT exportinfo.
972 + * VROOT exportinfo. Returned exi does NOT have a new hold.
967 973 */
968 974 struct exportinfo *
969 975 get_root_export(struct exportinfo *exip)
970 976 {
971 977 treenode_t *tnode = exip->exi_tree;
972 978 exportinfo_t *exi = NULL;
973 979
974 980 while (tnode) {
975 981 if (TREE_ROOT(tnode)) {
976 982 exi = tnode->tree_exi;
977 983 break;
978 984 }
979 985 tnode = tnode->tree_parent;
980 986 }
981 987 ASSERT(exi);
982 988 return (exi);
983 989 }
984 990
985 991 /*
986 992 * Return true if the supplied vnode has a sub-directory exported.
987 993 */
988 994 int
989 995 has_visible(struct exportinfo *exi, vnode_t *vp)
990 996 {
991 997 struct exp_visible *visp;
992 998 fid_t fid;
993 999 bool_t vp_is_exported;
994 1000
995 1001 vp_is_exported = VN_CMP(vp, exi->exi_vp);
996 1002
997 1003 /*
998 1004 * An exported root vnode has a sub-dir shared if it has a visible
999 1005 * list. i.e. if it does not have a visible list, then there is no
1000 1006 * node in this filesystem leads to any other shared node.
1001 1007 */
1002 1008 ASSERT3P(curzone, ==, exi->exi_zone);
1003 1009 if (vp_is_exported &&
1004 1010 ((vp->v_flag & VROOT) || VN_IS_CURZONEROOT(vp))) {
1005 1011 return (exi->exi_visible ? 1 : 0);
1006 1012 }
1007 1013
1008 1014 /*
1009 1015 * Only the exportinfo of a fs root node may have a visible list.
1010 1016 * Either it is a pseudo root node, or a real exported root node.
1011 1017 */
1012 1018 exi = get_root_export(exi);
1013 1019
1014 1020 if (!exi->exi_visible)
1015 1021 return (0);
1016 1022
1017 1023 /* Get the fid of the vnode */
1018 1024 bzero(&fid, sizeof (fid));
1019 1025 fid.fid_len = MAXFIDSZ;
1020 1026 if (vop_fid_pseudo(vp, &fid) != 0) {
1021 1027 return (0);
1022 1028 }
1023 1029
1024 1030 /*
1025 1031 * See if vp is in the visible list of the root node exportinfo.
1026 1032 */
1027 1033 for (visp = exi->exi_visible; visp; visp = visp->vis_next) {
1028 1034 if (EQFID(&fid, &visp->vis_fid)) {
1029 1035 /*
1030 1036 * If vp is an exported non-root node with only 1 path
1031 1037 * count (for itself), it indicates no sub-dir shared
1032 1038 * using this vp as a path.
1033 1039 */
1034 1040 if (vp_is_exported && visp->vis_count < 2)
1035 1041 break;
1036 1042
1037 1043 return (1);
1038 1044 }
1039 1045 }
1040 1046
1041 1047 return (0);
1042 1048 }
1043 1049
1044 1050 /*
1045 1051 * Returns true if the supplied vnode is visible
1046 1052 * in this export. If vnode is visible, return
1047 1053 * vis_exported in expseudo.
1048 1054 */
1049 1055 int
1050 1056 nfs_visible(struct exportinfo *exi, vnode_t *vp, int *expseudo)
1051 1057 {
1052 1058 struct exp_visible *visp;
1053 1059 fid_t fid;
1054 1060
1055 1061 /*
1056 1062 * First check to see if vp is export root.
1057 1063 *
1058 1064 * A pseudo export root can never be exported
1059 1065 * (it would be a real export then); however,
1060 1066 * it is always visible. If a pseudo root object
1061 1067 * was exported by server admin, then the entire
1062 1068 * pseudo exportinfo (and all visible entries) would
1063 1069 * be destroyed. A pseudo exportinfo only exists
1064 1070 * to provide access to real (descendant) export(s).
1065 1071 *
1066 1072 * Previously, rootdir was special cased here; however,
1067 1073 * the export root special case handles the rootdir
1068 1074 * case also.
1069 1075 */
1070 1076 if (VN_CMP(vp, exi->exi_vp)) {
1071 1077 *expseudo = 0;
1072 1078 return (1);
1073 1079 }
1074 1080
1075 1081 /*
1076 1082 * Only a PSEUDO node has a visible list or an exported VROOT
1077 1083 * node may have a visible list.
1078 1084 */
1079 1085 if (!PSEUDO(exi))
1080 1086 exi = get_root_export(exi);
1081 1087
1082 1088 /* Get the fid of the vnode */
1083 1089
1084 1090 bzero(&fid, sizeof (fid));
1085 1091 fid.fid_len = MAXFIDSZ;
1086 1092 if (vop_fid_pseudo(vp, &fid) != 0) {
1087 1093 *expseudo = 0;
1088 1094 return (0);
1089 1095 }
1090 1096
1091 1097 /*
1092 1098 * We can't trust VN_CMP() above because of LOFS.
1093 1099 * Even though VOP_CMP will do the right thing for LOFS
1094 1100 * objects, VN_CMP will short circuit out early when the
1095 1101 * vnode ops ptrs are different. Just in case we're dealing
1096 1102 * with LOFS, compare exi_fid/fsid here.
1097 1103 *
1098 1104 * expseudo is not set because this is not an export
1099 1105 */
1100 1106 if (EQFID(&exi->exi_fid, &fid) &&
1101 1107 EQFSID(&exi->exi_fsid, &vp->v_vfsp->vfs_fsid)) {
1102 1108 *expseudo = 0;
1103 1109 return (1);
1104 1110 }
1105 1111
1106 1112
1107 1113 /* See if it matches any fid in the visible list */
1108 1114
1109 1115 for (visp = exi->exi_visible; visp; visp = visp->vis_next) {
1110 1116 if (EQFID(&fid, &visp->vis_fid)) {
1111 1117 *expseudo = visp->vis_exported;
1112 1118 return (1);
1113 1119 }
1114 1120 }
1115 1121
1116 1122 *expseudo = 0;
1117 1123
1118 1124 return (0);
1119 1125 }
1120 1126
1121 1127 /*
1122 1128 * Returns true if the supplied vnode is the
1123 1129 * directory of an export point.
1124 1130 */
1125 1131 int
1126 1132 nfs_exported(struct exportinfo *exi, vnode_t *vp)
1127 1133 {
1128 1134 struct exp_visible *visp;
1129 1135 fid_t fid;
1130 1136
1131 1137 /*
1132 1138 * First check to see if vp is the export root
1133 1139 * This check required for the case of lookup ..
1134 1140 * where .. is a V_ROOT vnode and a pseudo exportroot.
1135 1141 * Pseudo export root objects do not have an entry
1136 1142 * in the visible list even though every V_ROOT
1137 1143 * pseudonode is visible. It is safe to compare
1138 1144 * vp here because pseudo_exportfs put a hold on
1139 1145 * it when exi_vp was initialized.
1140 1146 *
1141 1147 * Note: VN_CMP() won't match for LOFS shares, but they're
1142 1148 * handled below w/EQFID/EQFSID.
1143 1149 */
1144 1150 if (VN_CMP(vp, exi->exi_vp))
1145 1151 return (1);
1146 1152
1147 1153 /* Get the fid of the vnode */
1148 1154
1149 1155 bzero(&fid, sizeof (fid));
1150 1156 fid.fid_len = MAXFIDSZ;
1151 1157 if (vop_fid_pseudo(vp, &fid) != 0)
1152 1158 return (0);
1153 1159
1154 1160 if (EQFID(&fid, &exi->exi_fid) &&
1155 1161 EQFSID(&vp->v_vfsp->vfs_fsid, &exi->exi_fsid)) {
1156 1162 return (1);
1157 1163 }
1158 1164
1159 1165 /* See if it matches any fid in the visible list */
1160 1166
1161 1167 for (visp = exi->exi_visible; visp; visp = visp->vis_next) {
1162 1168 if (EQFID(&fid, &visp->vis_fid))
1163 1169 return (visp->vis_exported);
1164 1170 }
1165 1171
1166 1172 return (0);
1167 1173 }
1168 1174
1169 1175 /*
1170 1176 * Returns true if the supplied inode is visible
1171 1177 * in this export. This function is used by
1172 1178 * readdir which uses inode numbers from the
1173 1179 * directory.
1174 1180 *
1175 1181 * NOTE: this code does not match inode number for ".",
1176 1182 * but it isn't required because NFS4 server rddir
1177 1183 * skips . and .. entries.
1178 1184 */
1179 1185 int
1180 1186 nfs_visible_inode(struct exportinfo *exi, ino64_t ino,
1181 1187 struct exp_visible **visp)
1182 1188 {
1183 1189 /*
1184 1190 * Only a PSEUDO node has a visible list or an exported VROOT
1185 1191 * node may have a visible list.
1186 1192 */
1187 1193 if (!PSEUDO(exi))
1188 1194 exi = get_root_export(exi);
1189 1195
1190 1196 for (*visp = exi->exi_visible; *visp != NULL; *visp = (*visp)->vis_next)
1191 1197 if ((u_longlong_t)ino == (*visp)->vis_ino) {
1192 1198 return (1);
1193 1199 }
1194 1200
1195 1201 return (0);
1196 1202 }
1197 1203
1198 1204 /*
1199 1205 * Get the change attribute from visible and returns TRUE.
1200 1206 * If the change value is not available returns FALSE.
1201 1207 */
1202 1208 bool_t
1203 1209 nfs_visible_change(struct exportinfo *exi, vnode_t *vp, timespec_t *change)
1204 1210 {
1205 1211 struct exp_visible *visp;
1206 1212 fid_t fid;
1207 1213 treenode_t *node;
1208 1214 nfs_export_t *ne = nfs_get_export();
1209 1215
1210 1216 /*
1211 1217 * First check to see if vp is export root.
1212 1218 */
1213 1219 if (VN_CMP(vp, exi->exi_vp))
1214 1220 goto exproot;
1215 1221
1216 1222 /*
1217 1223 * Only a PSEUDO node has a visible list or an exported VROOT
1218 1224 * node may have a visible list.
1219 1225 */
1220 1226 if (!PSEUDO(exi))
1221 1227 exi = get_root_export(exi);
1222 1228
1223 1229 /* Get the fid of the vnode */
1224 1230 bzero(&fid, sizeof (fid));
1225 1231 fid.fid_len = MAXFIDSZ;
1226 1232 if (vop_fid_pseudo(vp, &fid) != 0)
1227 1233 return (FALSE);
1228 1234
1229 1235 /*
1230 1236 * We can't trust VN_CMP() above because of LOFS.
1231 1237 * Even though VOP_CMP will do the right thing for LOFS
1232 1238 * objects, VN_CMP will short circuit out early when the
1233 1239 * vnode ops ptrs are different. Just in case we're dealing
1234 1240 * with LOFS, compare exi_fid/fsid here.
1235 1241 */
1236 1242 if (EQFID(&exi->exi_fid, &fid) &&
1237 1243 EQFSID(&exi->exi_fsid, &vp->v_vfsp->vfs_fsid))
1238 1244 goto exproot;
1239 1245
1240 1246 /* See if it matches any fid in the visible list */
1241 1247 for (visp = exi->exi_visible; visp; visp = visp->vis_next) {
1242 1248 if (EQFID(&fid, &visp->vis_fid)) {
1243 1249 *change = visp->vis_change;
1244 1250 return (TRUE);
1245 1251 }
1246 1252 }
1247 1253
1248 1254 return (FALSE);
1249 1255
1250 1256 exproot:
1251 1257 /* The VROOT export have its visible available through treenode */
1252 1258 node = exi->exi_tree;
1253 1259 if (node != ne->ns_root) {
1254 1260 ASSERT(node->tree_vis != NULL);
1255 1261 *change = node->tree_vis->vis_change;
1256 1262 } else {
1257 1263 ASSERT(node->tree_vis == NULL);
1258 1264 *change = ne->ns_root_change;
1259 1265 }
1260 1266 return (TRUE);
1261 1267 }
1262 1268
1263 1269 /*
1264 1270 * Update the change attribute value for a particular treenode. The change
1265 1271 * attribute value is stored in the visible attached to the treenode, or in the
1266 1272 * ns_root_change.
1267 1273 *
1268 1274 * If the change value is not supplied, the current time is used.
1269 1275 */
1270 1276 void
1271 1277 tree_update_change(nfs_export_t *ne, treenode_t *tnode, timespec_t *change)
1272 1278 {
1273 1279 timespec_t *vis_change;
1274 1280
1275 1281 ASSERT(tnode != NULL);
1276 1282 ASSERT((tnode != ne->ns_root && tnode->tree_vis != NULL) ||
1277 1283 (tnode == ne->ns_root && tnode->tree_vis == NULL));
1278 1284
1279 1285 vis_change = tnode == ne->ns_root ? &ne->ns_root_change
1280 1286 : &tnode->tree_vis->vis_change;
1281 1287
1282 1288 if (change != NULL)
1283 1289 *vis_change = *change;
1284 1290 else
1285 1291 gethrestime(vis_change);
1286 1292 }
|
↓ open down ↓ |
310 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX