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