17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5bbf2a467SNagakiran Rajashekar * Common Development and Distribution License (the "License").
6bbf2a467SNagakiran Rajashekar * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22be6d98b1SNagakiran Rajashekar * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
25*ade42b55SSebastien Roy /*
26*ade42b55SSebastien Roy * Copyright (c) 2017 by Delphix. All rights reserved.
27*ade42b55SSebastien Roy */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include <sys/systm.h>
317c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #include <nfs/nfs.h>
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #include <nfs/nfs4.h>
367c478bd9Sstevel@tonic-gate #include <nfs/rnode4.h>
377c478bd9Sstevel@tonic-gate #include <nfs/nfs4_clnt.h>
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate static struct kmem_cache *svnode_cache;
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate struct sv_stats
427c478bd9Sstevel@tonic-gate {
437c478bd9Sstevel@tonic-gate int sv_activate;
447c478bd9Sstevel@tonic-gate int sv_find;
457c478bd9Sstevel@tonic-gate int sv_match;
467c478bd9Sstevel@tonic-gate int sv_inactive;
477c478bd9Sstevel@tonic-gate int sv_exchange;
487c478bd9Sstevel@tonic-gate } sv_stats;
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate static int sv_match(nfs4_fname_t *, nfs4_sharedfh_t *, svnode_t *);
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate * Map a vnode back to the shadow which points to it. This is
547c478bd9Sstevel@tonic-gate * hard now that the vnode is not embedded in the shadow vnode.
557c478bd9Sstevel@tonic-gate */
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate svnode_t *
vtosv(vnode_t * vp)597c478bd9Sstevel@tonic-gate vtosv(vnode_t *vp)
607c478bd9Sstevel@tonic-gate {
617c478bd9Sstevel@tonic-gate rnode4_t *rp = VTOR4(vp);
627c478bd9Sstevel@tonic-gate svnode_t *svp, *svp_found = NULL;
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate /* Check to see if it's the master shadow vnode first. */
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate if (RTOV4(rp) == vp)
677c478bd9Sstevel@tonic-gate return (&rp->r_svnode);
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate mutex_enter(&rp->r_svlock);
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate for (svp = rp->r_svnode.sv_forw; svp != &rp->r_svnode;
727c478bd9Sstevel@tonic-gate svp = svp->sv_forw)
737c478bd9Sstevel@tonic-gate if (svp->sv_r_vnode == vp) {
747c478bd9Sstevel@tonic-gate svp_found = svp;
757c478bd9Sstevel@tonic-gate break;
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate mutex_exit(&rp->r_svlock);
797c478bd9Sstevel@tonic-gate ASSERT(svp_found != NULL);
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate return (svp_found);
827c478bd9Sstevel@tonic-gate }
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate * sv_activate - find and activate the shadow vnode for the given
867c478bd9Sstevel@tonic-gate * directory file handle and name. May replace *vpp with a held reference
877c478bd9Sstevel@tonic-gate * to a different vnode, in which case the reference to the previous one is
887c478bd9Sstevel@tonic-gate * released.
897c478bd9Sstevel@tonic-gate */
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate void
sv_activate(vnode_t ** vpp,vnode_t * dvp,nfs4_fname_t ** namepp,int newnode)927c478bd9Sstevel@tonic-gate sv_activate(vnode_t **vpp, vnode_t *dvp, nfs4_fname_t **namepp, int newnode)
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate svnode_t *svp;
957c478bd9Sstevel@tonic-gate vnode_t *resvp;
96be6d98b1SNagakiran Rajashekar nfs4_fname_t *svpname;
977c478bd9Sstevel@tonic-gate rnode4_t *rp = VTOR4(*vpp);
98bbf2a467SNagakiran Rajashekar svp = VTOSV(*vpp);
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate ASSERT(namepp != NULL);
1017c478bd9Sstevel@tonic-gate ASSERT(*namepp != NULL);
1027c478bd9Sstevel@tonic-gate ASSERT(dvp != NULL);
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate sv_stats.sv_activate++;
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate ASSERT(RW_LOCK_HELD(&rp->r_hashq->r_lock));
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate * If make_rnode made a new rnode (ie. newnode != 0), then
1107c478bd9Sstevel@tonic-gate * the master vnode was (partially) initialized there. If
1117c478bd9Sstevel@tonic-gate * it was not a new rnode, then it returns the master vnode.
1127c478bd9Sstevel@tonic-gate * Call sv_find to find and/or initialize the shadow
1137c478bd9Sstevel@tonic-gate * vnode.
1147c478bd9Sstevel@tonic-gate */
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate if (newnode) {
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate * Initialize the shadow vnode.
1197c478bd9Sstevel@tonic-gate */
1207c478bd9Sstevel@tonic-gate svp->sv_forw = svp->sv_back = svp;
1217c478bd9Sstevel@tonic-gate ASSERT(svp->sv_dfh == NULL);
1227c478bd9Sstevel@tonic-gate svp->sv_dfh = VTOR4(dvp)->r_fh;
1237c478bd9Sstevel@tonic-gate sfh4_hold(svp->sv_dfh);
1247c478bd9Sstevel@tonic-gate ASSERT(svp->sv_name == NULL);
1257c478bd9Sstevel@tonic-gate svp->sv_name = *namepp;
1267c478bd9Sstevel@tonic-gate } else if ((*vpp)->v_type == VREG && !((*vpp)->v_flag & VROOT)) {
1277c478bd9Sstevel@tonic-gate resvp = sv_find(*vpp, dvp, namepp);
1287c478bd9Sstevel@tonic-gate ASSERT(resvp->v_type == VREG);
1297c478bd9Sstevel@tonic-gate VN_RELE(*vpp);
1307c478bd9Sstevel@tonic-gate *vpp = resvp;
1314151f947SPavel Filipensky } else {
132bbf2a467SNagakiran Rajashekar /*
1334151f947SPavel Filipensky * No shadow vnodes (i.e. hard links) in this branch.
1344151f947SPavel Filipensky * If sv_activate() is called for an existing rnode
1354151f947SPavel Filipensky * (newnode isn't set) but with a new name, the sv_name
1364151f947SPavel Filipensky * needs to be updated and the old sv_name released.
137bbf2a467SNagakiran Rajashekar *
138bbf2a467SNagakiran Rajashekar * fname mismatches can occur due to server side renames,
139bbf2a467SNagakiran Rajashekar * here is a chance to update the fname in case there is
140bbf2a467SNagakiran Rajashekar * a mismatch. Since this is not a newnode we hold r_svlock
141bbf2a467SNagakiran Rajashekar * to protect sv_name.
142bbf2a467SNagakiran Rajashekar */
143bbf2a467SNagakiran Rajashekar mutex_enter(&rp->r_svlock);
144be6d98b1SNagakiran Rajashekar svpname = svp->sv_name;
145bbf2a467SNagakiran Rajashekar if (svpname != *namepp) {
146bbf2a467SNagakiran Rajashekar /*
147bbf2a467SNagakiran Rajashekar * Call fn_rele() to release the hold for the
148bbf2a467SNagakiran Rajashekar * previous shadow vnode reference. Don't
149bbf2a467SNagakiran Rajashekar * release the hold on the fname pointed to by
150bbf2a467SNagakiran Rajashekar * namepp as we have new reference to it from
151bbf2a467SNagakiran Rajashekar * this shadow vnode.
152bbf2a467SNagakiran Rajashekar */
153bbf2a467SNagakiran Rajashekar svp->sv_name = *namepp;
154bbf2a467SNagakiran Rajashekar mutex_exit(&rp->r_svlock);
155bbf2a467SNagakiran Rajashekar fn_rele(&svpname);
156bbf2a467SNagakiran Rajashekar } else {
157bbf2a467SNagakiran Rajashekar mutex_exit(&rp->r_svlock);
158bbf2a467SNagakiran Rajashekar fn_rele(namepp);
159bbf2a467SNagakiran Rajashekar }
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate }
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate /*
1647c478bd9Sstevel@tonic-gate * sv_find - find the shadow vnode for the desired name and directory
1657c478bd9Sstevel@tonic-gate * file handle. If one does not exist, then create it. Returns the shadow
1667c478bd9Sstevel@tonic-gate * vnode. The caller is responsible for freeing the reference.
1677c478bd9Sstevel@tonic-gate * Consumes the name reference and nulls it out.
1687c478bd9Sstevel@tonic-gate *
1697c478bd9Sstevel@tonic-gate * Side effects: increments the reference count on the master vnode if the
1707c478bd9Sstevel@tonic-gate * shadow vnode had to be created.
1717c478bd9Sstevel@tonic-gate */
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate vnode_t *
sv_find(vnode_t * mvp,vnode_t * dvp,nfs4_fname_t ** namepp)1747c478bd9Sstevel@tonic-gate sv_find(vnode_t *mvp, vnode_t *dvp, nfs4_fname_t **namepp)
1757c478bd9Sstevel@tonic-gate {
1767c478bd9Sstevel@tonic-gate vnode_t *vp;
1777c478bd9Sstevel@tonic-gate rnode4_t *rp = VTOR4(mvp);
1787c478bd9Sstevel@tonic-gate svnode_t *svp;
179bbf2a467SNagakiran Rajashekar svnode_t *master_svp = VTOSV(mvp);
1807c478bd9Sstevel@tonic-gate rnode4_t *drp = VTOR4(dvp);
1817c478bd9Sstevel@tonic-gate nfs4_fname_t *nm;
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate ASSERT(dvp != NULL);
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate sv_stats.sv_find++;
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate ASSERT(namepp != NULL);
1887c478bd9Sstevel@tonic-gate ASSERT(*namepp != NULL);
1897c478bd9Sstevel@tonic-gate nm = *namepp;
1907c478bd9Sstevel@tonic-gate *namepp = NULL;
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate /*
1937c478bd9Sstevel@tonic-gate * At this point, all we know is that we have an rnode whose
1947c478bd9Sstevel@tonic-gate * file handle matches the file handle of the object we want.
1957c478bd9Sstevel@tonic-gate * We have to verify that component name and the directory
1967c478bd9Sstevel@tonic-gate * match. If so, then we are done.
1977c478bd9Sstevel@tonic-gate *
1987c478bd9Sstevel@tonic-gate * Note: mvp is always the master vnode.
1997c478bd9Sstevel@tonic-gate */
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate ASSERT(!IS_SHADOW(mvp, rp));
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate if (sv_match(nm, drp->r_fh, master_svp)) {
2047c478bd9Sstevel@tonic-gate VN_HOLD(mvp);
2057c478bd9Sstevel@tonic-gate fn_rele(&nm);
2067c478bd9Sstevel@tonic-gate return (mvp);
2077c478bd9Sstevel@tonic-gate }
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate /*
2107c478bd9Sstevel@tonic-gate * No match, search through the shadow vnode list.
2117c478bd9Sstevel@tonic-gate * Hold the r_svlock to prevent changes.
2127c478bd9Sstevel@tonic-gate */
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate mutex_enter(&rp->r_svlock);
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate for (svp = master_svp->sv_forw; svp != master_svp; svp = svp->sv_forw)
2177c478bd9Sstevel@tonic-gate if (sv_match(nm, drp->r_fh, svp)) {
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate /*
2207c478bd9Sstevel@tonic-gate * A matching shadow vnode is found, bump the
2217c478bd9Sstevel@tonic-gate * reference count on it and return it.
2227c478bd9Sstevel@tonic-gate */
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate vp = SVTOV(svp);
2257c478bd9Sstevel@tonic-gate VN_HOLD(vp);
2267c478bd9Sstevel@tonic-gate fn_rele(&nm);
2277c478bd9Sstevel@tonic-gate mutex_exit(&rp->r_svlock);
2287c478bd9Sstevel@tonic-gate return (vp);
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate
2317c478bd9Sstevel@tonic-gate /*
2327c478bd9Sstevel@tonic-gate * No match searching the list, go allocate a new shadow
2337c478bd9Sstevel@tonic-gate */
2347c478bd9Sstevel@tonic-gate svp = kmem_cache_alloc(svnode_cache, KM_SLEEP);
2357c478bd9Sstevel@tonic-gate svp->sv_r_vnode = vn_alloc(KM_SLEEP);
2367c478bd9Sstevel@tonic-gate vp = SVTOV(svp);
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate /* Initialize the vnode */
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate vn_setops(vp, nfs4_vnodeops);
2417c478bd9Sstevel@tonic-gate vp->v_data = (caddr_t)rp;
2427c478bd9Sstevel@tonic-gate vp->v_vfsp = mvp->v_vfsp;
2437c478bd9Sstevel@tonic-gate ASSERT(nfs4_consistent_type(mvp));
2447c478bd9Sstevel@tonic-gate vp->v_type = mvp->v_type;
2457c478bd9Sstevel@tonic-gate vp->v_pages = (page_t *)-1; /* No pages, please */
2467c478bd9Sstevel@tonic-gate vn_exists(vp);
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate /* Initialize the shadow vnode */
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate svp->sv_dfh = VTOR4(dvp)->r_fh;
2517c478bd9Sstevel@tonic-gate sfh4_hold(svp->sv_dfh);
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate svp->sv_name = nm;
2547c478bd9Sstevel@tonic-gate VN_HOLD(mvp);
2557c478bd9Sstevel@tonic-gate insque(svp, master_svp);
2567c478bd9Sstevel@tonic-gate mutex_exit(&rp->r_svlock);
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate return (vp);
2597c478bd9Sstevel@tonic-gate }
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate /*
2627c478bd9Sstevel@tonic-gate * sv_match - check to see if the shadow vnode matches the desired
2637c478bd9Sstevel@tonic-gate * name and directory file handle. Returns non-zero if there's a match,
2647c478bd9Sstevel@tonic-gate * zero if it's not a match.
2657c478bd9Sstevel@tonic-gate */
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate static int
sv_match(nfs4_fname_t * nm,nfs4_sharedfh_t * fhp,svnode_t * svp)2687c478bd9Sstevel@tonic-gate sv_match(nfs4_fname_t *nm, nfs4_sharedfh_t *fhp, svnode_t *svp)
2697c478bd9Sstevel@tonic-gate {
2707c478bd9Sstevel@tonic-gate sv_stats.sv_match++;
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate return (svp->sv_name != NULL && svp->sv_name == nm &&
2737c478bd9Sstevel@tonic-gate SFH4_SAME(svp->sv_dfh, fhp));
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate /*
2777c478bd9Sstevel@tonic-gate * sv_inactive - deactivate a shadow vnode. sv_inactive is called
2787c478bd9Sstevel@tonic-gate * from nfs4_inactive. Whenever a shadow vnode is de-activated,
2797c478bd9Sstevel@tonic-gate * sv_inactive cleans up the mess and releases the reference on the
2807c478bd9Sstevel@tonic-gate * master vnode.
2817c478bd9Sstevel@tonic-gate */
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate void
sv_inactive(vnode_t * vp)2847c478bd9Sstevel@tonic-gate sv_inactive(vnode_t *vp)
2857c478bd9Sstevel@tonic-gate {
2867c478bd9Sstevel@tonic-gate svnode_t *svp;
2877c478bd9Sstevel@tonic-gate rnode4_t *rp;
2887c478bd9Sstevel@tonic-gate vnode_t *mvp;
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate sv_stats.sv_inactive++;
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate svp = VTOSV(vp);
2937c478bd9Sstevel@tonic-gate rp = VTOR4(vp);
2947c478bd9Sstevel@tonic-gate mvp = rp->r_vnode;
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate ASSERT(mvp != vp);
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate /*
2997c478bd9Sstevel@tonic-gate * Remove the shadow vnode from the list. The serialization
3007c478bd9Sstevel@tonic-gate * is provided by the svnode list lock. This could be done
3017c478bd9Sstevel@tonic-gate * with the r_statelock, but that would require more locking
3027c478bd9Sstevel@tonic-gate * in the activation path.
3037c478bd9Sstevel@tonic-gate */
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate mutex_enter(&rp->r_svlock);
3067c478bd9Sstevel@tonic-gate mutex_enter(&vp->v_lock);
3077c478bd9Sstevel@tonic-gate /* check if someone slipped in while locks were dropped */
3087c478bd9Sstevel@tonic-gate if (vp->v_count > 1) {
309*ade42b55SSebastien Roy VN_RELE_LOCKED(vp);
3107c478bd9Sstevel@tonic-gate mutex_exit(&vp->v_lock);
3117c478bd9Sstevel@tonic-gate mutex_exit(&rp->r_svlock);
3127c478bd9Sstevel@tonic-gate return;
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate remque(svp);
3157c478bd9Sstevel@tonic-gate mutex_exit(&vp->v_lock);
3167c478bd9Sstevel@tonic-gate mutex_exit(&rp->r_svlock);
3177c478bd9Sstevel@tonic-gate
3187c478bd9Sstevel@tonic-gate sv_uninit(svp);
3197c478bd9Sstevel@tonic-gate svp->sv_forw = svp->sv_back = NULL;
3207c478bd9Sstevel@tonic-gate kmem_cache_free(svnode_cache, svp);
3217c478bd9Sstevel@tonic-gate vn_invalid(vp);
3227c478bd9Sstevel@tonic-gate vn_free(vp);
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate /* release the reference held by this shadow on the master */
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate VN_RELE(mvp);
3277c478bd9Sstevel@tonic-gate }
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate /*
3307c478bd9Sstevel@tonic-gate * sv_uninit - free any data structures allocated by the shadow vnode.
3317c478bd9Sstevel@tonic-gate */
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate void
sv_uninit(svnode_t * svp)3347c478bd9Sstevel@tonic-gate sv_uninit(svnode_t *svp)
3357c478bd9Sstevel@tonic-gate {
3367c478bd9Sstevel@tonic-gate if (svp->sv_name != NULL)
3377c478bd9Sstevel@tonic-gate fn_rele(&svp->sv_name);
3387c478bd9Sstevel@tonic-gate if (svp->sv_dfh != NULL)
3397c478bd9Sstevel@tonic-gate sfh4_rele(&svp->sv_dfh);
3407c478bd9Sstevel@tonic-gate }
3417c478bd9Sstevel@tonic-gate
3427c478bd9Sstevel@tonic-gate /*
3437c478bd9Sstevel@tonic-gate * sv_exchange - exchange a shadow vnode for the master vnode. This
3447c478bd9Sstevel@tonic-gate * occurs during nfs4_open, since only the master vnode owns the files
3457c478bd9Sstevel@tonic-gate * resources (eg. pages).
3467c478bd9Sstevel@tonic-gate */
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate void
sv_exchange(vnode_t ** vpp)3497c478bd9Sstevel@tonic-gate sv_exchange(vnode_t **vpp)
3507c478bd9Sstevel@tonic-gate {
3517c478bd9Sstevel@tonic-gate vnode_t *mvp;
3527c478bd9Sstevel@tonic-gate
3537c478bd9Sstevel@tonic-gate sv_stats.sv_exchange++;
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate /* RTOV always returns the master vnode */
3567c478bd9Sstevel@tonic-gate mvp = RTOV4(VTOR4(*vpp));
3577c478bd9Sstevel@tonic-gate VN_HOLD(mvp)
3587c478bd9Sstevel@tonic-gate VN_RELE(*vpp);
3597c478bd9Sstevel@tonic-gate *vpp = mvp;
3607c478bd9Sstevel@tonic-gate }
3617c478bd9Sstevel@tonic-gate
3627c478bd9Sstevel@tonic-gate int
nfs4_shadow_init(void)3637c478bd9Sstevel@tonic-gate nfs4_shadow_init(void)
3647c478bd9Sstevel@tonic-gate {
3657c478bd9Sstevel@tonic-gate /*
3667c478bd9Sstevel@tonic-gate * Allocate shadow vnode cache
3677c478bd9Sstevel@tonic-gate */
3687c478bd9Sstevel@tonic-gate svnode_cache = kmem_cache_create("svnode_cache",
3697c478bd9Sstevel@tonic-gate sizeof (svnode_t), 0, NULL, NULL, NULL, NULL, NULL, 0);
3707c478bd9Sstevel@tonic-gate
3717c478bd9Sstevel@tonic-gate return (0);
3727c478bd9Sstevel@tonic-gate }
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate int
nfs4_shadow_fini(void)3757c478bd9Sstevel@tonic-gate nfs4_shadow_fini(void)
3767c478bd9Sstevel@tonic-gate {
3777c478bd9Sstevel@tonic-gate kmem_cache_destroy(svnode_cache);
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate return (0);
3807c478bd9Sstevel@tonic-gate }
381