/* * Get an nfsv4 vnode of the given fid from the visible list of an * nfs filesystem or get the exi_vp if it is the root node. */ int nfs4_vget_pseudo(struct exportinfo *exi, vnode_t **vpp, fid_t *fidp) { fid_t exp_fid; struct exp_visible *visp; int error; /* check if the given fid is in the visible list */ for (visp = exi->exi_visible; visp; visp = visp->vis_next) { if (EQFID(fidp, &visp->vis_fid)) { VN_HOLD(visp->vis_vp); *vpp = visp->vis_vp; return (0); } } /* check if the given fid is the same as the exported node */ bzero(&exp_fid, sizeof (exp_fid)); exp_fid.fid_len = MAXFIDSZ; error = vop_fid_pseudo(exi->exi_vp, &exp_fid); if (error) return (error); if (EQFID(fidp, &exp_fid)) { VN_HOLD(exi->exi_vp); *vpp = exi->exi_vp; return (0); } return (ENOENT); }
/* * Get the change attribute from visible and returns TRUE. * If the change value is not available returns FALSE. */ bool_t nfs_visible_change(struct exportinfo *exi, vnode_t *vp, timespec_t *change) { struct exp_visible *visp; fid_t fid; treenode_t *node; /* * First check to see if vp is export root. */ if (VN_CMP(vp, exi->exi_vp)) goto exproot; /* * Only a PSEUDO node has a visible list or an exported VROOT * node may have a visible list. */ if (!PSEUDO(exi)) exi = get_root_export(exi); /* Get the fid of the vnode */ bzero(&fid, sizeof (fid)); fid.fid_len = MAXFIDSZ; if (vop_fid_pseudo(vp, &fid) != 0) return (FALSE); /* * We can't trust VN_CMP() above because of LOFS. * Even though VOP_CMP will do the right thing for LOFS * objects, VN_CMP will short circuit out early when the * vnode ops ptrs are different. Just in case we're dealing * with LOFS, compare exi_fid/fsid here. */ if (EQFID(&exi->exi_fid, &fid) && EQFSID(&exi->exi_fsid, &vp->v_vfsp->vfs_fsid)) goto exproot; /* See if it matches any fid in the visible list */ for (visp = exi->exi_visible; visp; visp = visp->vis_next) { if (EQFID(&fid, &visp->vis_fid)) { *change = visp->vis_change; return (TRUE); } } return (FALSE); exproot: /* The VROOT export have its visible available through treenode */ node = exi->exi_tree; if (node != ns_root) { ASSERT(node->tree_vis != NULL); *change = node->tree_vis->vis_change; } else { ASSERT(node->tree_vis == NULL); *change = ns_root_change; } return (TRUE); }
/* * Returns true if the supplied vnode is the * directory of an export point. */ int nfs_exported(struct exportinfo *exi, vnode_t *vp) { struct exp_visible *visp; fid_t fid; /* * First check to see if vp is the export root * This check required for the case of lookup .. * where .. is a V_ROOT vnode and a pseudo exportroot. * Pseudo export root objects do not have an entry * in the visible list even though every V_ROOT * pseudonode is visible. It is safe to compare * vp here because pseudo_exportfs put a hold on * it when exi_vp was initialized. * * Note: VN_CMP() won't match for LOFS shares, but they're * handled below w/EQFID/EQFSID. */ if (VN_CMP(vp, exi->exi_vp)) return (1); /* Get the fid of the vnode */ bzero(&fid, sizeof (fid)); fid.fid_len = MAXFIDSZ; if (vop_fid_pseudo(vp, &fid) != 0) return (0); if (EQFID(&fid, &exi->exi_fid) && EQFSID(&vp->v_vfsp->vfs_fsid, &exi->exi_fsid)) { return (1); } /* See if it matches any fid in the visible list */ for (visp = exi->exi_visible; visp; visp = visp->vis_next) { if (EQFID(&fid, &visp->vis_fid)) return (visp->vis_exported); } return (0); }
/* * Return true if the supplied vnode has a sub-directory exported. */ int has_visible(struct exportinfo *exi, vnode_t *vp) { struct exp_visible *visp; fid_t fid; bool_t vp_is_exported; vp_is_exported = VN_CMP(vp, exi->exi_vp); /* * An exported root vnode has a sub-dir shared if it has a visible list. * i.e. if it does not have a visible list, then there is no node in * this filesystem leads to any other shared node. */ if (vp_is_exported && (vp->v_flag & VROOT)) return (exi->exi_visible ? 1 : 0); /* * Only the exportinfo of a fs root node may have a visible list. * Either it is a pseudo root node, or a real exported root node. */ exi = get_root_export(exi); if (!exi->exi_visible) return (0); /* Get the fid of the vnode */ bzero(&fid, sizeof (fid)); fid.fid_len = MAXFIDSZ; if (vop_fid_pseudo(vp, &fid) != 0) { return (0); } /* * See if vp is in the visible list of the root node exportinfo. */ for (visp = exi->exi_visible; visp; visp = visp->vis_next) { if (EQFID(&fid, &visp->vis_fid)) { /* * If vp is an exported non-root node with only 1 path * count (for itself), it indicates no sub-dir shared * using this vp as a path. */ if (vp_is_exported && visp->vis_count < 2) break; return (1); } } return (0); }
/* * Returns true if the supplied vnode is visible * in this export. If vnode is visible, return * vis_exported in expseudo. */ int nfs_visible(struct exportinfo *exi, vnode_t *vp, int *expseudo) { struct exp_visible *visp; fid_t fid; /* * First check to see if vp is export root. * * A pseudo export root can never be exported * (it would be a real export then); however, * it is always visible. If a pseudo root object * was exported by server admin, then the entire * pseudo exportinfo (and all visible entries) would * be destroyed. A pseudo exportinfo only exists * to provide access to real (descendant) export(s). * * Previously, rootdir was special cased here; however, * the export root special case handles the rootdir * case also. */ if (VN_CMP(vp, exi->exi_vp)) { *expseudo = 0; return (1); } /* * Only a PSEUDO node has a visible list or an exported VROOT * node may have a visible list. */ if (! PSEUDO(exi)) exi = get_root_export(exi); /* Get the fid of the vnode */ bzero(&fid, sizeof (fid)); fid.fid_len = MAXFIDSZ; if (vop_fid_pseudo(vp, &fid) != 0) { *expseudo = 0; return (0); } /* * We can't trust VN_CMP() above because of LOFS. * Even though VOP_CMP will do the right thing for LOFS * objects, VN_CMP will short circuit out early when the * vnode ops ptrs are different. Just in case we're dealing * with LOFS, compare exi_fid/fsid here. * * expseudo is not set because this is not an export */ if (EQFID(&exi->exi_fid, &fid) && EQFSID(&exi->exi_fsid, &vp->v_vfsp->vfs_fsid)) { *expseudo = 0; return (1); } /* See if it matches any fid in the visible list */ for (visp = exi->exi_visible; visp; visp = visp->vis_next) { if (EQFID(&fid, &visp->vis_fid)) { *expseudo = visp->vis_exported; return (1); } } *expseudo = 0; return (0); }
/* * When we export a new directory we need to add a new * path segment through the pseudofs to reach the new * directory. This new path is reflected in a list of * directories added to the "visible" list. * * Here there are two lists of visible fids: one hanging off the * pseudo exportinfo, and the one we want to add. It's possible * that the two lists share a common path segment * and have some common directories. We need to combine * the lists so there's no duplicate entries. Where a common * path component is found, the vis_count field is bumped. * * This example shows that the treenode chain (tree_head) and * exp_visible chain (vis_head) can differ in length. The latter * can be shorter. The outer loop must loop over the vis_head chain. * * share /x/a * mount -F ufs /dev/dsk/... /x/y * mkdir -p /x/y/a/b * share /x/y/a/b * * When more_visible() is called during the second share, * the existing namespace is following: * exp_visible_t * treenode_t exportinfo_t v0 v1 * ns_root+---+ +------------+ +---+ +---+ * t0| / |........| E0 pseudo |->| x |->| a | * +---+ +------------+ +---+ +---+ * | / / * +---+ / / * t1| x |------------------------ / * +---+ / * | / * +---+ / * t2| a |------------------------- * +---+........+------------+ * | E1 real | * +------------+ * * This is being added: * * tree_head vis_head * +---+ +---+ * t3| x |->| x |v2 * +---+ +---+ * | | * +---+ +---+ v4 v5 * t4| y |->| y |v3 +------------+ +---+ +---+ * +---+\ +---+ | E2 pseudo |->| a |->| b | * | \....... >+------------+ +---+ +---+ * +---+ / / * t5| a |--------------------------- / * +---+ / * | / * +---+------------------------------- * t6| b | +------------+ * +---+..........>| E3 real | * +------------+ * * more_visible() will: * - kmem_free() t3 and v2 * - add t4, t5, t6 as a child of t1 (t4 will become sibling of t2) * - add v3 to the end of E0->exi_visible * * Note that v4 and v5 were already processed in pseudo_exportfs() and * added to E2. The outer loop of more_visible() will loop only over v2 * and v3. The inner loop of more_visible() always loops over v0 and v1. * * Illustration for this scenario: * * mkdir -p /v/a/b/c * share /v/a/b/c * mkdir /v/a/b/c1 * mkdir -p /v/a1 * mv /v/a/b /v/a1 * share /v/a1/b/c1 * * EXISTING * treenode * namespace: +-----------+ visibles * |exportinfo |-->v->a->b->c * connect_point->+---+--->+-----------+ * | / |T0 * +---+ * | NEW treenode chain: * child->+---+ * | v |T1 +---+<-curr * +---+ N1| v | * | +---+ * +---+ | * | a |T2 +---+<-tree_head * +---+ N2| a1| * | +---+ * +---+ | * | b |T3 +---+ * +---+ N3| b | * | +---+ * +---+ | * | c |T4 +---+ * +---+ N4| c1| * +---+ * * The picture above illustrates the position of following pointers after line * 'child = tree_find_child_by_vis(connect_point, curr->tree_vis);' * was executed for the first time in the outer 'for' loop: * * connect_point..parent treenode in the EXISTING namespace to which the 'curr' * should be connected. If 'connect_point' already has a child * with the same value of tree_vis as the curr->tree_vis is, * the 'curr' will not be added, but kmem_free()d. * child..........the result of tree_find_child_by_vis() * curr...........currently processed treenode from the NEW treenode chain * tree_head......current head of the NEW treenode chain, in this case it was * already moved down to its child - preparation for another loop * * What will happen to NEW treenodes N1, N2, N3, N4 in more_visible() later: * * N1: is merged - i.e. N1 is kmem_free()d. T0 has a child T1 with the same * tree_vis as N1 * N2: is added as a new child of T1 * Note: not just N2, but the whole chain N2->N3->N4 is added * N3: not processed separately (it was added together with N2) * Even that N3 and T3 have same tree_vis, they are NOT merged, but will * become duplicates. * N4: not processed separately */ static void more_visible(struct exportinfo *exi, treenode_t *tree_head) { struct exp_visible *vp1, *vp2, *vis_head, *tail, *next; int found; treenode_t *child, *curr, *connect_point; vis_head = tree_head->tree_vis; connect_point = exi->exi_tree; /* * If exportinfo doesn't already have a visible * list just assign the entire supplied list. */ if (exi->exi_visible == NULL) { tree_add_child(exi->exi_tree, tree_head); exi->exi_visible = vis_head; return; } /* The outer loop traverses the supplied list. */ for (vp1 = vis_head; vp1; vp1 = next) { found = 0; next = vp1->vis_next; /* The inner loop searches the exportinfo visible list. */ for (vp2 = exi->exi_visible; vp2; vp2 = vp2->vis_next) { tail = vp2; if (EQFID(&vp1->vis_fid, &vp2->vis_fid)) { found = 1; vp2->vis_count++; VN_RELE(vp1->vis_vp); /* Transfer vis_exported from vp1 to vp2. */ if (vp1->vis_exported && !vp2->vis_exported) vp2->vis_exported = 1; kmem_free(vp1, sizeof (*vp1)); tree_head->tree_vis = vp2; break; } } /* If not found - add to the end of the list */ if (! found) { tail->vis_next = vp1; vp1->vis_next = NULL; } curr = tree_head; tree_head = tree_head->tree_child_first; if (! connect_point) /* No longer merging */ continue; /* * The inner loop could set curr->tree_vis to the EXISTING * exp_visible vp2, so we can search among the children of * connect_point for the curr->tree_vis. No need for EQFID. */ child = tree_find_child_by_vis(connect_point, curr->tree_vis); /* * Merging cannot be done if a valid child->tree_exi would * be overwritten by a new curr->tree_exi. */ if (child && (child->tree_exi == NULL || curr->tree_exi == NULL)) { if (curr->tree_exi) { /* Transfer the exportinfo */ child->tree_exi = curr->tree_exi; child->tree_exi->exi_tree = child; } kmem_free(curr, sizeof (treenode_t)); connect_point = child; } else { /* Branching */ tree_add_child(connect_point, curr); connect_point = NULL; } } }