xref: /freebsd/sys/fs/unionfs/union_vnops.c (revision 3a946335aeb3e04ddc095b264e45967c1a2e6159)
1df8bae1dSRodney W. Grimes /*
2996c772fSJohn Dyson  * Copyright (c) 1992, 1993, 1994, 1995 Jan-Simon Pendry.
3996c772fSJohn Dyson  * Copyright (c) 1992, 1993, 1994, 1995
4996c772fSJohn Dyson  *	The Regents of the University of California.  All rights reserved.
5df8bae1dSRodney W. Grimes  *
6df8bae1dSRodney W. Grimes  * This code is derived from software contributed to Berkeley by
7df8bae1dSRodney W. Grimes  * Jan-Simon Pendry.
8df8bae1dSRodney W. Grimes  *
9df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
10df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
11df8bae1dSRodney W. Grimes  * are met:
12df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
13df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
14df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
15df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
16df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
17df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
18df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
19df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
20df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
21df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
22df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
23df8bae1dSRodney W. Grimes  *    without specific prior written permission.
24df8bae1dSRodney W. Grimes  *
25df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
36df8bae1dSRodney W. Grimes  *
37996c772fSJohn Dyson  *	@(#)union_vnops.c	8.32 (Berkeley) 6/23/95
383a946335SKATO Takenori  * $Id: union_vnops.c,v 1.21 1997/04/13 06:29:13 phk Exp $
39df8bae1dSRodney W. Grimes  */
40df8bae1dSRodney W. Grimes 
41df8bae1dSRodney W. Grimes #include <sys/param.h>
42df8bae1dSRodney W. Grimes #include <sys/systm.h>
43df8bae1dSRodney W. Grimes #include <sys/proc.h>
443ac4d1efSBruce Evans #include <sys/fcntl.h>
45df8bae1dSRodney W. Grimes #include <sys/time.h>
46996c772fSJohn Dyson #include <sys/stat.h>
47df8bae1dSRodney W. Grimes #include <sys/types.h>
489e67ea79SBruce Evans #include <sys/kernel.h>
49df8bae1dSRodney W. Grimes #include <sys/vnode.h>
50df8bae1dSRodney W. Grimes #include <sys/mount.h>
51df8bae1dSRodney W. Grimes #include <sys/namei.h>
52df8bae1dSRodney W. Grimes #include <sys/malloc.h>
53df8bae1dSRodney W. Grimes #include <sys/buf.h>
54df8bae1dSRodney W. Grimes #include <sys/queue.h>
55996c772fSJohn Dyson #include <sys/lock.h>
56df8bae1dSRodney W. Grimes #include <miscfs/union/union.h>
57df8bae1dSRodney W. Grimes 
58996c772fSJohn Dyson #define FIXUP(un, p) { \
59996c772fSJohn Dyson 	if (((un)->un_flags & UN_ULOCK) == 0) { \
60996c772fSJohn Dyson 		union_fixup(un, p); \
61df8bae1dSRodney W. Grimes 	} \
62df8bae1dSRodney W. Grimes }
63df8bae1dSRodney W. Grimes 
649b5e8b3aSBruce Evans extern int	union_abortop __P((struct vop_abortop_args *ap));
659b5e8b3aSBruce Evans extern int	union_access __P((struct vop_access_args *ap));
669b5e8b3aSBruce Evans extern int	union_advlock __P((struct vop_advlock_args *ap));
679b5e8b3aSBruce Evans extern int	union_bmap __P((struct vop_bmap_args *ap));
689b5e8b3aSBruce Evans extern int	union_close __P((struct vop_close_args *ap));
699b5e8b3aSBruce Evans extern int	union_create __P((struct vop_create_args *ap));
70996c772fSJohn Dyson static void	union_fixup __P((struct union_node *un, struct proc *p));
719b5e8b3aSBruce Evans extern int	union_fsync __P((struct vop_fsync_args *ap));
729b5e8b3aSBruce Evans extern int	union_getattr __P((struct vop_getattr_args *ap));
739b5e8b3aSBruce Evans extern int	union_inactive __P((struct vop_inactive_args *ap));
749b5e8b3aSBruce Evans extern int	union_ioctl __P((struct vop_ioctl_args *ap));
759b5e8b3aSBruce Evans extern int	union_islocked __P((struct vop_islocked_args *ap));
7672a5ee14SMike Pritchard extern int	union_lease __P((struct vop_lease_args *ap));
779b5e8b3aSBruce Evans extern int	union_link __P((struct vop_link_args *ap));
789b5e8b3aSBruce Evans extern int	union_lock __P((struct vop_lock_args *ap));
799b5e8b3aSBruce Evans extern int	union_lookup __P((struct vop_lookup_args *ap));
80996c772fSJohn Dyson static int	union_lookup1 __P((struct vnode *udvp, struct vnode **dvpp,
819b5e8b3aSBruce Evans 				   struct vnode **vpp,
829b5e8b3aSBruce Evans 				   struct componentname *cnp));
839b5e8b3aSBruce Evans extern int	union_mkdir __P((struct vop_mkdir_args *ap));
849b5e8b3aSBruce Evans extern int	union_mknod __P((struct vop_mknod_args *ap));
859b5e8b3aSBruce Evans extern int	union_mmap __P((struct vop_mmap_args *ap));
869b5e8b3aSBruce Evans extern int	union_open __P((struct vop_open_args *ap));
879b5e8b3aSBruce Evans extern int	union_pathconf __P((struct vop_pathconf_args *ap));
889b5e8b3aSBruce Evans extern int	union_print __P((struct vop_print_args *ap));
899b5e8b3aSBruce Evans extern int	union_read __P((struct vop_read_args *ap));
909b5e8b3aSBruce Evans extern int	union_readdir __P((struct vop_readdir_args *ap));
919b5e8b3aSBruce Evans extern int	union_readlink __P((struct vop_readlink_args *ap));
929b5e8b3aSBruce Evans extern int	union_reclaim __P((struct vop_reclaim_args *ap));
939b5e8b3aSBruce Evans extern int	union_remove __P((struct vop_remove_args *ap));
949b5e8b3aSBruce Evans extern int	union_rename __P((struct vop_rename_args *ap));
9572a5ee14SMike Pritchard extern int	union_revoke __P((struct vop_revoke_args *ap));
969b5e8b3aSBruce Evans extern int	union_rmdir __P((struct vop_rmdir_args *ap));
979b5e8b3aSBruce Evans extern int	union_seek __P((struct vop_seek_args *ap));
989b5e8b3aSBruce Evans extern int	union_select __P((struct vop_select_args *ap));
999b5e8b3aSBruce Evans extern int	union_setattr __P((struct vop_setattr_args *ap));
1009b5e8b3aSBruce Evans extern int	union_strategy __P((struct vop_strategy_args *ap));
1019b5e8b3aSBruce Evans extern int	union_symlink __P((struct vop_symlink_args *ap));
102996c772fSJohn Dyson extern int	union_unlock __P((struct vop_unlock_args *ap));
10372a5ee14SMike Pritchard extern int	union_whiteout __P((struct vop_whiteout_args *ap));
1049b5e8b3aSBruce Evans extern int	union_write __P((struct vop_read_args *ap));
1059b5e8b3aSBruce Evans 
106df8bae1dSRodney W. Grimes static void
107996c772fSJohn Dyson union_fixup(un, p)
108df8bae1dSRodney W. Grimes 	struct union_node *un;
109996c772fSJohn Dyson 	struct proc *p;
110df8bae1dSRodney W. Grimes {
111df8bae1dSRodney W. Grimes 
112996c772fSJohn Dyson 	vn_lock(un->un_uppervp, LK_EXCLUSIVE | LK_RETRY, p);
113df8bae1dSRodney W. Grimes 	un->un_flags |= UN_ULOCK;
114df8bae1dSRodney W. Grimes }
115df8bae1dSRodney W. Grimes 
116df8bae1dSRodney W. Grimes static int
117996c772fSJohn Dyson union_lookup1(udvp, dvpp, vpp, cnp)
118df8bae1dSRodney W. Grimes 	struct vnode *udvp;
119996c772fSJohn Dyson 	struct vnode **dvpp;
120df8bae1dSRodney W. Grimes 	struct vnode **vpp;
121df8bae1dSRodney W. Grimes 	struct componentname *cnp;
122df8bae1dSRodney W. Grimes {
123df8bae1dSRodney W. Grimes 	int error;
124996c772fSJohn Dyson 	struct proc *p = cnp->cn_proc;
125df8bae1dSRodney W. Grimes 	struct vnode *tdvp;
126996c772fSJohn Dyson 	struct vnode *dvp;
127df8bae1dSRodney W. Grimes 	struct mount *mp;
128df8bae1dSRodney W. Grimes 
129996c772fSJohn Dyson 	dvp = *dvpp;
130996c772fSJohn Dyson 
131df8bae1dSRodney W. Grimes 	/*
132df8bae1dSRodney W. Grimes 	 * If stepping up the directory tree, check for going
133df8bae1dSRodney W. Grimes 	 * back across the mount point, in which case do what
134df8bae1dSRodney W. Grimes 	 * lookup would do by stepping back down the mount
135df8bae1dSRodney W. Grimes 	 * hierarchy.
136df8bae1dSRodney W. Grimes 	 */
137df8bae1dSRodney W. Grimes 	if (cnp->cn_flags & ISDOTDOT) {
138996c772fSJohn Dyson 		while ((dvp != udvp) && (dvp->v_flag & VROOT)) {
139df8bae1dSRodney W. Grimes 			/*
140df8bae1dSRodney W. Grimes 			 * Don't do the NOCROSSMOUNT check
141df8bae1dSRodney W. Grimes 			 * at this level.  By definition,
142df8bae1dSRodney W. Grimes 			 * union fs deals with namespaces, not
143df8bae1dSRodney W. Grimes 			 * filesystems.
144df8bae1dSRodney W. Grimes 			 */
145df8bae1dSRodney W. Grimes 			tdvp = dvp;
146996c772fSJohn Dyson 			*dvpp = dvp = dvp->v_mount->mnt_vnodecovered;
147df8bae1dSRodney W. Grimes 			vput(tdvp);
148df8bae1dSRodney W. Grimes 			VREF(dvp);
149996c772fSJohn Dyson 			vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, p);
150df8bae1dSRodney W. Grimes 		}
151df8bae1dSRodney W. Grimes 	}
152df8bae1dSRodney W. Grimes 
153df8bae1dSRodney W. Grimes         error = VOP_LOOKUP(dvp, &tdvp, cnp);
154df8bae1dSRodney W. Grimes 	if (error)
155df8bae1dSRodney W. Grimes 		return (error);
156df8bae1dSRodney W. Grimes 
157df8bae1dSRodney W. Grimes 	/*
158df8bae1dSRodney W. Grimes 	 * The parent directory will have been unlocked, unless lookup
159df8bae1dSRodney W. Grimes 	 * found the last component.  In which case, re-lock the node
160df8bae1dSRodney W. Grimes 	 * here to allow it to be unlocked again (phew) in union_lookup.
161df8bae1dSRodney W. Grimes 	 */
162df8bae1dSRodney W. Grimes 	if (dvp != tdvp && !(cnp->cn_flags & ISLASTCN))
163996c772fSJohn Dyson 		vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, p);
164df8bae1dSRodney W. Grimes 
165df8bae1dSRodney W. Grimes 	dvp = tdvp;
166df8bae1dSRodney W. Grimes 
167df8bae1dSRodney W. Grimes 	/*
168df8bae1dSRodney W. Grimes 	 * Lastly check if the current node is a mount point in
169df8bae1dSRodney W. Grimes 	 * which case walk up the mount hierarchy making sure not to
170df8bae1dSRodney W. Grimes 	 * bump into the root of the mount tree (ie. dvp != udvp).
171df8bae1dSRodney W. Grimes 	 */
172df8bae1dSRodney W. Grimes 	while (dvp != udvp && (dvp->v_type == VDIR) &&
173df8bae1dSRodney W. Grimes 	       (mp = dvp->v_mountedhere)) {
174df8bae1dSRodney W. Grimes 
175996c772fSJohn Dyson 		if (vfs_busy(mp, 0, 0, p))
176df8bae1dSRodney W. Grimes 			continue;
177df8bae1dSRodney W. Grimes 
1783a773ad0SPoul-Henning Kamp 		error = VFS_ROOT(mp, &tdvp);
179996c772fSJohn Dyson 		vfs_unbusy(mp, p);
1803a773ad0SPoul-Henning Kamp 		if (error) {
181df8bae1dSRodney W. Grimes 			vput(dvp);
182df8bae1dSRodney W. Grimes 			return (error);
183df8bae1dSRodney W. Grimes 		}
184df8bae1dSRodney W. Grimes 
185df8bae1dSRodney W. Grimes 		vput(dvp);
186df8bae1dSRodney W. Grimes 		dvp = tdvp;
187df8bae1dSRodney W. Grimes 	}
188df8bae1dSRodney W. Grimes 
189df8bae1dSRodney W. Grimes 	*vpp = dvp;
190df8bae1dSRodney W. Grimes 	return (0);
191df8bae1dSRodney W. Grimes }
192df8bae1dSRodney W. Grimes 
193df8bae1dSRodney W. Grimes int
194df8bae1dSRodney W. Grimes union_lookup(ap)
195df8bae1dSRodney W. Grimes 	struct vop_lookup_args /* {
196df8bae1dSRodney W. Grimes 		struct vnodeop_desc *a_desc;
197df8bae1dSRodney W. Grimes 		struct vnode *a_dvp;
198df8bae1dSRodney W. Grimes 		struct vnode **a_vpp;
199df8bae1dSRodney W. Grimes 		struct componentname *a_cnp;
200df8bae1dSRodney W. Grimes 	} */ *ap;
201df8bae1dSRodney W. Grimes {
202df8bae1dSRodney W. Grimes 	int error;
203df8bae1dSRodney W. Grimes 	int uerror, lerror;
204df8bae1dSRodney W. Grimes 	struct vnode *uppervp, *lowervp;
205df8bae1dSRodney W. Grimes 	struct vnode *upperdvp, *lowerdvp;
206df8bae1dSRodney W. Grimes 	struct vnode *dvp = ap->a_dvp;
207df8bae1dSRodney W. Grimes 	struct union_node *dun = VTOUNION(dvp);
208df8bae1dSRodney W. Grimes 	struct componentname *cnp = ap->a_cnp;
209996c772fSJohn Dyson 	struct proc *p = cnp->cn_proc;
210df8bae1dSRodney W. Grimes 	int lockparent = cnp->cn_flags & LOCKPARENT;
211df8bae1dSRodney W. Grimes 	struct union_mount *um = MOUNTTOUNIONMOUNT(dvp->v_mount);
212996c772fSJohn Dyson 	struct ucred *saved_cred;
213996c772fSJohn Dyson 	int iswhiteout;
214996c772fSJohn Dyson 	struct vattr va;
215996c772fSJohn Dyson 
216996c772fSJohn Dyson #ifdef notyet
217996c772fSJohn Dyson 	if (cnp->cn_namelen == 3 &&
218996c772fSJohn Dyson 			cnp->cn_nameptr[2] == '.' &&
219996c772fSJohn Dyson 			cnp->cn_nameptr[1] == '.' &&
220996c772fSJohn Dyson 			cnp->cn_nameptr[0] == '.') {
221996c772fSJohn Dyson 		dvp = *ap->a_vpp = LOWERVP(ap->a_dvp);
222996c772fSJohn Dyson 		if (dvp == NULLVP)
223996c772fSJohn Dyson 			return (ENOENT);
224996c772fSJohn Dyson 		VREF(dvp);
225996c772fSJohn Dyson 		vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, p);
226996c772fSJohn Dyson 		if (!lockparent || !(cnp->cn_flags & ISLASTCN))
227996c772fSJohn Dyson 			VOP_UNLOCK(ap->a_dvp, 0, p);
228996c772fSJohn Dyson 		return (0);
229996c772fSJohn Dyson 	}
230996c772fSJohn Dyson #endif
231df8bae1dSRodney W. Grimes 
232df8bae1dSRodney W. Grimes 	cnp->cn_flags |= LOCKPARENT;
233df8bae1dSRodney W. Grimes 
234df8bae1dSRodney W. Grimes 	upperdvp = dun->un_uppervp;
235df8bae1dSRodney W. Grimes 	lowerdvp = dun->un_lowervp;
236df8bae1dSRodney W. Grimes 	uppervp = NULLVP;
237df8bae1dSRodney W. Grimes 	lowervp = NULLVP;
238996c772fSJohn Dyson 	iswhiteout = 0;
239df8bae1dSRodney W. Grimes 
240df8bae1dSRodney W. Grimes 	/*
241df8bae1dSRodney W. Grimes 	 * do the lookup in the upper level.
242df8bae1dSRodney W. Grimes 	 * if that level comsumes additional pathnames,
243df8bae1dSRodney W. Grimes 	 * then assume that something special is going
244df8bae1dSRodney W. Grimes 	 * on and just return that vnode.
245df8bae1dSRodney W. Grimes 	 */
246996c772fSJohn Dyson 	if (upperdvp != NULLVP) {
247996c772fSJohn Dyson 		FIXUP(dun, p);
248996c772fSJohn Dyson 		uerror = union_lookup1(um->um_uppervp, &upperdvp,
249df8bae1dSRodney W. Grimes 					&uppervp, cnp);
250df8bae1dSRodney W. Grimes 		/*if (uppervp == upperdvp)
251df8bae1dSRodney W. Grimes 			dun->un_flags |= UN_KLOCK;*/
252df8bae1dSRodney W. Grimes 
253df8bae1dSRodney W. Grimes 		if (cnp->cn_consume != 0) {
254df8bae1dSRodney W. Grimes 			*ap->a_vpp = uppervp;
255df8bae1dSRodney W. Grimes 			if (!lockparent)
256df8bae1dSRodney W. Grimes 				cnp->cn_flags &= ~LOCKPARENT;
257df8bae1dSRodney W. Grimes 			return (uerror);
258df8bae1dSRodney W. Grimes 		}
259996c772fSJohn Dyson 		if (uerror == ENOENT || uerror == EJUSTRETURN) {
260996c772fSJohn Dyson 			if (cnp->cn_flags & ISWHITEOUT) {
261996c772fSJohn Dyson 				iswhiteout = 1;
262996c772fSJohn Dyson 			} else if (lowerdvp != NULLVP) {
263996c772fSJohn Dyson 				lerror = VOP_GETATTR(upperdvp, &va,
264996c772fSJohn Dyson 					cnp->cn_cred, cnp->cn_proc);
265996c772fSJohn Dyson 				if (lerror == 0 && (va.va_flags & OPAQUE))
266996c772fSJohn Dyson 					iswhiteout = 1;
267996c772fSJohn Dyson 			}
268996c772fSJohn Dyson 		}
269df8bae1dSRodney W. Grimes 	} else {
270df8bae1dSRodney W. Grimes 		uerror = ENOENT;
271df8bae1dSRodney W. Grimes 	}
272df8bae1dSRodney W. Grimes 
273df8bae1dSRodney W. Grimes 	/*
274df8bae1dSRodney W. Grimes 	 * in a similar way to the upper layer, do the lookup
275df8bae1dSRodney W. Grimes 	 * in the lower layer.   this time, if there is some
276df8bae1dSRodney W. Grimes 	 * component magic going on, then vput whatever we got
277df8bae1dSRodney W. Grimes 	 * back from the upper layer and return the lower vnode
278df8bae1dSRodney W. Grimes 	 * instead.
279df8bae1dSRodney W. Grimes 	 */
280996c772fSJohn Dyson 	if (lowerdvp != NULLVP && !iswhiteout) {
281df8bae1dSRodney W. Grimes 		int nameiop;
282df8bae1dSRodney W. Grimes 
283996c772fSJohn Dyson 		vn_lock(lowerdvp, LK_EXCLUSIVE | LK_RETRY, p);
284df8bae1dSRodney W. Grimes 
285df8bae1dSRodney W. Grimes 		/*
286df8bae1dSRodney W. Grimes 		 * Only do a LOOKUP on the bottom node, since
287df8bae1dSRodney W. Grimes 		 * we won't be making changes to it anyway.
288df8bae1dSRodney W. Grimes 		 */
289df8bae1dSRodney W. Grimes 		nameiop = cnp->cn_nameiop;
290df8bae1dSRodney W. Grimes 		cnp->cn_nameiop = LOOKUP;
291df8bae1dSRodney W. Grimes 		if (um->um_op == UNMNT_BELOW) {
292df8bae1dSRodney W. Grimes 			saved_cred = cnp->cn_cred;
293df8bae1dSRodney W. Grimes 			cnp->cn_cred = um->um_cred;
294df8bae1dSRodney W. Grimes 		}
295996c772fSJohn Dyson 		lerror = union_lookup1(um->um_lowervp, &lowerdvp,
296df8bae1dSRodney W. Grimes 				&lowervp, cnp);
297df8bae1dSRodney W. Grimes 		if (um->um_op == UNMNT_BELOW)
298df8bae1dSRodney W. Grimes 			cnp->cn_cred = saved_cred;
299df8bae1dSRodney W. Grimes 		cnp->cn_nameiop = nameiop;
300df8bae1dSRodney W. Grimes 
301df8bae1dSRodney W. Grimes 		if (lowervp != lowerdvp)
302996c772fSJohn Dyson 			VOP_UNLOCK(lowerdvp, 0, p);
303df8bae1dSRodney W. Grimes 
304df8bae1dSRodney W. Grimes 		if (cnp->cn_consume != 0) {
305996c772fSJohn Dyson 			if (uppervp != NULLVP) {
306df8bae1dSRodney W. Grimes 				if (uppervp == upperdvp)
307df8bae1dSRodney W. Grimes 					vrele(uppervp);
308df8bae1dSRodney W. Grimes 				else
309df8bae1dSRodney W. Grimes 					vput(uppervp);
310df8bae1dSRodney W. Grimes 				uppervp = NULLVP;
311df8bae1dSRodney W. Grimes 			}
312df8bae1dSRodney W. Grimes 			*ap->a_vpp = lowervp;
313df8bae1dSRodney W. Grimes 			if (!lockparent)
314df8bae1dSRodney W. Grimes 				cnp->cn_flags &= ~LOCKPARENT;
315df8bae1dSRodney W. Grimes 			return (lerror);
316df8bae1dSRodney W. Grimes 		}
317df8bae1dSRodney W. Grimes 	} else {
318df8bae1dSRodney W. Grimes 		lerror = ENOENT;
319996c772fSJohn Dyson 		if ((cnp->cn_flags & ISDOTDOT) && dun->un_pvp != NULLVP) {
320996c772fSJohn Dyson 			lowervp = LOWERVP(dun->un_pvp);
321996c772fSJohn Dyson 			if (lowervp != NULLVP) {
322996c772fSJohn Dyson 				VREF(lowervp);
323996c772fSJohn Dyson 				vn_lock(lowervp, LK_EXCLUSIVE | LK_RETRY, p);
324996c772fSJohn Dyson 				lerror = 0;
325996c772fSJohn Dyson 			}
326996c772fSJohn Dyson 		}
327df8bae1dSRodney W. Grimes 	}
328df8bae1dSRodney W. Grimes 
329df8bae1dSRodney W. Grimes 	if (!lockparent)
330df8bae1dSRodney W. Grimes 		cnp->cn_flags &= ~LOCKPARENT;
331df8bae1dSRodney W. Grimes 
332df8bae1dSRodney W. Grimes 	/*
333df8bae1dSRodney W. Grimes 	 * at this point, we have uerror and lerror indicating
334df8bae1dSRodney W. Grimes 	 * possible errors with the lookups in the upper and lower
335df8bae1dSRodney W. Grimes 	 * layers.  additionally, uppervp and lowervp are (locked)
336df8bae1dSRodney W. Grimes 	 * references to existing vnodes in the upper and lower layers.
337df8bae1dSRodney W. Grimes 	 *
338df8bae1dSRodney W. Grimes 	 * there are now three cases to consider.
339df8bae1dSRodney W. Grimes 	 * 1. if both layers returned an error, then return whatever
340df8bae1dSRodney W. Grimes 	 *    error the upper layer generated.
341df8bae1dSRodney W. Grimes 	 *
342df8bae1dSRodney W. Grimes 	 * 2. if the top layer failed and the bottom layer succeeded
343df8bae1dSRodney W. Grimes 	 *    then two subcases occur.
344df8bae1dSRodney W. Grimes 	 *    a.  the bottom vnode is not a directory, in which
345df8bae1dSRodney W. Grimes 	 *	  case just return a new union vnode referencing
346df8bae1dSRodney W. Grimes 	 *	  an empty top layer and the existing bottom layer.
347df8bae1dSRodney W. Grimes 	 *    b.  the bottom vnode is a directory, in which case
348df8bae1dSRodney W. Grimes 	 *	  create a new directory in the top-level and
349df8bae1dSRodney W. Grimes 	 *	  continue as in case 3.
350df8bae1dSRodney W. Grimes 	 *
351df8bae1dSRodney W. Grimes 	 * 3. if the top layer succeeded then return a new union
352df8bae1dSRodney W. Grimes 	 *    vnode referencing whatever the new top layer and
353df8bae1dSRodney W. Grimes 	 *    whatever the bottom layer returned.
354df8bae1dSRodney W. Grimes 	 */
355df8bae1dSRodney W. Grimes 
356df8bae1dSRodney W. Grimes 	*ap->a_vpp = NULLVP;
357df8bae1dSRodney W. Grimes 
358df8bae1dSRodney W. Grimes 	/* case 1. */
359df8bae1dSRodney W. Grimes 	if ((uerror != 0) && (lerror != 0)) {
360df8bae1dSRodney W. Grimes 		return (uerror);
361df8bae1dSRodney W. Grimes 	}
362df8bae1dSRodney W. Grimes 
363df8bae1dSRodney W. Grimes 	/* case 2. */
364df8bae1dSRodney W. Grimes 	if (uerror != 0 /* && (lerror == 0) */ ) {
365df8bae1dSRodney W. Grimes 		if (lowervp->v_type == VDIR) { /* case 2b. */
366df8bae1dSRodney W. Grimes 			dun->un_flags &= ~UN_ULOCK;
367996c772fSJohn Dyson 			VOP_UNLOCK(upperdvp, 0, p);
368df8bae1dSRodney W. Grimes 			uerror = union_mkshadow(um, upperdvp, cnp, &uppervp);
369996c772fSJohn Dyson 			vn_lock(upperdvp, LK_EXCLUSIVE | LK_RETRY, p);
370df8bae1dSRodney W. Grimes 			dun->un_flags |= UN_ULOCK;
371df8bae1dSRodney W. Grimes 
372df8bae1dSRodney W. Grimes 			if (uerror) {
373996c772fSJohn Dyson 				if (lowervp != NULLVP) {
374df8bae1dSRodney W. Grimes 					vput(lowervp);
375df8bae1dSRodney W. Grimes 					lowervp = NULLVP;
376df8bae1dSRodney W. Grimes 				}
377df8bae1dSRodney W. Grimes 				return (uerror);
378df8bae1dSRodney W. Grimes 			}
379df8bae1dSRodney W. Grimes 		}
380df8bae1dSRodney W. Grimes 	}
381df8bae1dSRodney W. Grimes 
382996c772fSJohn Dyson 	if (lowervp != NULLVP)
383996c772fSJohn Dyson 		VOP_UNLOCK(lowervp, 0, p);
384df8bae1dSRodney W. Grimes 
385df8bae1dSRodney W. Grimes 	error = union_allocvp(ap->a_vpp, dvp->v_mount, dvp, upperdvp, cnp,
386996c772fSJohn Dyson 			      uppervp, lowervp, 1);
387df8bae1dSRodney W. Grimes 
388df8bae1dSRodney W. Grimes 	if (error) {
389996c772fSJohn Dyson 		if (uppervp != NULLVP)
390df8bae1dSRodney W. Grimes 			vput(uppervp);
391996c772fSJohn Dyson 		if (lowervp != NULLVP)
392df8bae1dSRodney W. Grimes 			vrele(lowervp);
393df8bae1dSRodney W. Grimes 	} else {
394df8bae1dSRodney W. Grimes 		if (*ap->a_vpp != dvp)
395df8bae1dSRodney W. Grimes 			if (!lockparent || !(cnp->cn_flags & ISLASTCN))
396996c772fSJohn Dyson 				VOP_UNLOCK(dvp, 0, p);
397df8bae1dSRodney W. Grimes 	}
398df8bae1dSRodney W. Grimes 
399df8bae1dSRodney W. Grimes 	return (error);
400df8bae1dSRodney W. Grimes }
401df8bae1dSRodney W. Grimes 
402df8bae1dSRodney W. Grimes int
403df8bae1dSRodney W. Grimes union_create(ap)
404df8bae1dSRodney W. Grimes 	struct vop_create_args /* {
405df8bae1dSRodney W. Grimes 		struct vnode *a_dvp;
406df8bae1dSRodney W. Grimes 		struct vnode **a_vpp;
407df8bae1dSRodney W. Grimes 		struct componentname *a_cnp;
408df8bae1dSRodney W. Grimes 		struct vattr *a_vap;
409df8bae1dSRodney W. Grimes 	} */ *ap;
410df8bae1dSRodney W. Grimes {
411df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_dvp);
412df8bae1dSRodney W. Grimes 	struct vnode *dvp = un->un_uppervp;
413996c772fSJohn Dyson 	struct componentname *cnp = ap->a_cnp;
414996c772fSJohn Dyson 	struct proc *p = cnp->cn_proc;
415df8bae1dSRodney W. Grimes 
416996c772fSJohn Dyson 	if (dvp != NULLVP) {
417df8bae1dSRodney W. Grimes 		int error;
418df8bae1dSRodney W. Grimes 		struct vnode *vp;
419996c772fSJohn Dyson 		struct mount *mp;
420df8bae1dSRodney W. Grimes 
421996c772fSJohn Dyson 		FIXUP(un, p);
422df8bae1dSRodney W. Grimes 
423df8bae1dSRodney W. Grimes 		VREF(dvp);
424df8bae1dSRodney W. Grimes 		un->un_flags |= UN_KLOCK;
425996c772fSJohn Dyson 		mp = ap->a_dvp->v_mount;
426df8bae1dSRodney W. Grimes 		vput(ap->a_dvp);
427996c772fSJohn Dyson 		error = VOP_CREATE(dvp, &vp, cnp, ap->a_vap);
428df8bae1dSRodney W. Grimes 		if (error)
429df8bae1dSRodney W. Grimes 			return (error);
430df8bae1dSRodney W. Grimes 
431996c772fSJohn Dyson 		error = union_allocvp(ap->a_vpp, mp, NULLVP, NULLVP, cnp, vp,
432996c772fSJohn Dyson 				NULLVP, 1);
433df8bae1dSRodney W. Grimes 		if (error)
434df8bae1dSRodney W. Grimes 			vput(vp);
435df8bae1dSRodney W. Grimes 		return (error);
436df8bae1dSRodney W. Grimes 	}
437df8bae1dSRodney W. Grimes 
438df8bae1dSRodney W. Grimes 	vput(ap->a_dvp);
439df8bae1dSRodney W. Grimes 	return (EROFS);
440df8bae1dSRodney W. Grimes }
441df8bae1dSRodney W. Grimes 
442df8bae1dSRodney W. Grimes int
443996c772fSJohn Dyson union_whiteout(ap)
444996c772fSJohn Dyson 	struct vop_whiteout_args /* {
445996c772fSJohn Dyson 		struct vnode *a_dvp;
446996c772fSJohn Dyson 		struct componentname *a_cnp;
447996c772fSJohn Dyson 		int a_flags;
448996c772fSJohn Dyson 	} */ *ap;
449996c772fSJohn Dyson {
450996c772fSJohn Dyson 	struct union_node *un = VTOUNION(ap->a_dvp);
451996c772fSJohn Dyson 	struct componentname *cnp = ap->a_cnp;
452996c772fSJohn Dyson 	struct proc *p = cnp->cn_proc;
453996c772fSJohn Dyson 
454996c772fSJohn Dyson 	if (un->un_uppervp == NULLVP)
455996c772fSJohn Dyson 		return (EOPNOTSUPP);
456996c772fSJohn Dyson 
457996c772fSJohn Dyson 	FIXUP(un, p);
458996c772fSJohn Dyson 	return (VOP_WHITEOUT(un->un_uppervp, cnp, ap->a_flags));
459996c772fSJohn Dyson }
460996c772fSJohn Dyson 
461996c772fSJohn Dyson int
462df8bae1dSRodney W. Grimes union_mknod(ap)
463df8bae1dSRodney W. Grimes 	struct vop_mknod_args /* {
464df8bae1dSRodney W. Grimes 		struct vnode *a_dvp;
465df8bae1dSRodney W. Grimes 		struct vnode **a_vpp;
466df8bae1dSRodney W. Grimes 		struct componentname *a_cnp;
467df8bae1dSRodney W. Grimes 		struct vattr *a_vap;
468df8bae1dSRodney W. Grimes 	} */ *ap;
469df8bae1dSRodney W. Grimes {
470df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_dvp);
471df8bae1dSRodney W. Grimes 	struct vnode *dvp = un->un_uppervp;
472996c772fSJohn Dyson 	struct componentname *cnp = ap->a_cnp;
473996c772fSJohn Dyson 	struct proc *p = cnp->cn_proc;
474df8bae1dSRodney W. Grimes 
475996c772fSJohn Dyson 	if (dvp != NULLVP) {
476df8bae1dSRodney W. Grimes 		int error;
477df8bae1dSRodney W. Grimes 		struct vnode *vp;
478996c772fSJohn Dyson 		struct mount *mp;
479df8bae1dSRodney W. Grimes 
480996c772fSJohn Dyson 		FIXUP(un, p);
481df8bae1dSRodney W. Grimes 
482df8bae1dSRodney W. Grimes 		VREF(dvp);
483df8bae1dSRodney W. Grimes 		un->un_flags |= UN_KLOCK;
484996c772fSJohn Dyson 		mp = ap->a_dvp->v_mount;
485df8bae1dSRodney W. Grimes 		vput(ap->a_dvp);
486996c772fSJohn Dyson 		error = VOP_MKNOD(dvp, &vp, cnp, ap->a_vap);
487df8bae1dSRodney W. Grimes 		if (error)
488df8bae1dSRodney W. Grimes 			return (error);
489df8bae1dSRodney W. Grimes 
490996c772fSJohn Dyson 		if (vp != NULLVP) {
491996c772fSJohn Dyson 			error = union_allocvp(ap->a_vpp, mp, NULLVP, NULLVP,
492996c772fSJohn Dyson 					cnp, vp, NULLVP, 1);
493df8bae1dSRodney W. Grimes 			if (error)
494df8bae1dSRodney W. Grimes 				vput(vp);
495df8bae1dSRodney W. Grimes 		}
496df8bae1dSRodney W. Grimes 		return (error);
497df8bae1dSRodney W. Grimes 	}
498df8bae1dSRodney W. Grimes 
499df8bae1dSRodney W. Grimes 	vput(ap->a_dvp);
500df8bae1dSRodney W. Grimes 	return (EROFS);
501df8bae1dSRodney W. Grimes }
502df8bae1dSRodney W. Grimes 
503df8bae1dSRodney W. Grimes int
504df8bae1dSRodney W. Grimes union_open(ap)
505df8bae1dSRodney W. Grimes 	struct vop_open_args /* {
506df8bae1dSRodney W. Grimes 		struct vnodeop_desc *a_desc;
507df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
508df8bae1dSRodney W. Grimes 		int a_mode;
509df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
510df8bae1dSRodney W. Grimes 		struct proc *a_p;
511df8bae1dSRodney W. Grimes 	} */ *ap;
512df8bae1dSRodney W. Grimes {
513df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_vp);
514df8bae1dSRodney W. Grimes 	struct vnode *tvp;
515df8bae1dSRodney W. Grimes 	int mode = ap->a_mode;
516df8bae1dSRodney W. Grimes 	struct ucred *cred = ap->a_cred;
517df8bae1dSRodney W. Grimes 	struct proc *p = ap->a_p;
518df8bae1dSRodney W. Grimes 	int error;
519df8bae1dSRodney W. Grimes 
520df8bae1dSRodney W. Grimes 	/*
521df8bae1dSRodney W. Grimes 	 * If there is an existing upper vp then simply open that.
522df8bae1dSRodney W. Grimes 	 */
523df8bae1dSRodney W. Grimes 	tvp = un->un_uppervp;
524df8bae1dSRodney W. Grimes 	if (tvp == NULLVP) {
525df8bae1dSRodney W. Grimes 		/*
526df8bae1dSRodney W. Grimes 		 * If the lower vnode is being opened for writing, then
527df8bae1dSRodney W. Grimes 		 * copy the file contents to the upper vnode and open that,
528df8bae1dSRodney W. Grimes 		 * otherwise can simply open the lower vnode.
529df8bae1dSRodney W. Grimes 		 */
530df8bae1dSRodney W. Grimes 		tvp = un->un_lowervp;
531df8bae1dSRodney W. Grimes 		if ((ap->a_mode & FWRITE) && (tvp->v_type == VREG)) {
532996c772fSJohn Dyson 			error = union_copyup(un, (mode&O_TRUNC) == 0, cred, p);
533df8bae1dSRodney W. Grimes 			if (error == 0)
534df8bae1dSRodney W. Grimes 				error = VOP_OPEN(un->un_uppervp, mode, cred, p);
535df8bae1dSRodney W. Grimes 			return (error);
536df8bae1dSRodney W. Grimes 		}
537df8bae1dSRodney W. Grimes 
538df8bae1dSRodney W. Grimes 		/*
539df8bae1dSRodney W. Grimes 		 * Just open the lower vnode
540df8bae1dSRodney W. Grimes 		 */
541df8bae1dSRodney W. Grimes 		un->un_openl++;
542996c772fSJohn Dyson 		vn_lock(tvp, LK_EXCLUSIVE | LK_RETRY, p);
543df8bae1dSRodney W. Grimes 		error = VOP_OPEN(tvp, mode, cred, p);
544996c772fSJohn Dyson 		VOP_UNLOCK(tvp, 0, p);
545df8bae1dSRodney W. Grimes 
546df8bae1dSRodney W. Grimes 		return (error);
547df8bae1dSRodney W. Grimes 	}
548df8bae1dSRodney W. Grimes 
549996c772fSJohn Dyson 	FIXUP(un, p);
550df8bae1dSRodney W. Grimes 
551df8bae1dSRodney W. Grimes 	error = VOP_OPEN(tvp, mode, cred, p);
552df8bae1dSRodney W. Grimes 
553df8bae1dSRodney W. Grimes 	return (error);
554df8bae1dSRodney W. Grimes }
555df8bae1dSRodney W. Grimes 
556df8bae1dSRodney W. Grimes int
557df8bae1dSRodney W. Grimes union_close(ap)
558df8bae1dSRodney W. Grimes 	struct vop_close_args /* {
559df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
560df8bae1dSRodney W. Grimes 		int  a_fflag;
561df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
562df8bae1dSRodney W. Grimes 		struct proc *a_p;
563df8bae1dSRodney W. Grimes 	} */ *ap;
564df8bae1dSRodney W. Grimes {
565df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_vp);
566df8bae1dSRodney W. Grimes 	struct vnode *vp;
567df8bae1dSRodney W. Grimes 
568996c772fSJohn Dyson 	if ((vp = un->un_uppervp) == NULLVP) {
569df8bae1dSRodney W. Grimes #ifdef UNION_DIAGNOSTIC
570df8bae1dSRodney W. Grimes 		if (un->un_openl <= 0)
571df8bae1dSRodney W. Grimes 			panic("union: un_openl cnt");
572df8bae1dSRodney W. Grimes #endif
573df8bae1dSRodney W. Grimes 		--un->un_openl;
574df8bae1dSRodney W. Grimes 		vp = un->un_lowervp;
575df8bae1dSRodney W. Grimes 	}
576df8bae1dSRodney W. Grimes 
577996c772fSJohn Dyson 	ap->a_vp = vp;
578996c772fSJohn Dyson 	return (VCALL(vp, VOFFSET(vop_close), ap));
579df8bae1dSRodney W. Grimes }
580df8bae1dSRodney W. Grimes 
581df8bae1dSRodney W. Grimes /*
582df8bae1dSRodney W. Grimes  * Check access permission on the union vnode.
583df8bae1dSRodney W. Grimes  * The access check being enforced is to check
584df8bae1dSRodney W. Grimes  * against both the underlying vnode, and any
585df8bae1dSRodney W. Grimes  * copied vnode.  This ensures that no additional
586df8bae1dSRodney W. Grimes  * file permissions are given away simply because
587df8bae1dSRodney W. Grimes  * the user caused an implicit file copy.
588df8bae1dSRodney W. Grimes  */
589df8bae1dSRodney W. Grimes int
590df8bae1dSRodney W. Grimes union_access(ap)
591df8bae1dSRodney W. Grimes 	struct vop_access_args /* {
592df8bae1dSRodney W. Grimes 		struct vnodeop_desc *a_desc;
593df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
594df8bae1dSRodney W. Grimes 		int a_mode;
595df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
596df8bae1dSRodney W. Grimes 		struct proc *a_p;
597df8bae1dSRodney W. Grimes 	} */ *ap;
598df8bae1dSRodney W. Grimes {
599df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_vp);
600996c772fSJohn Dyson 	struct proc *p = ap->a_p;
601df8bae1dSRodney W. Grimes 	int error = EACCES;
602df8bae1dSRodney W. Grimes 	struct vnode *vp;
603df8bae1dSRodney W. Grimes 
604996c772fSJohn Dyson 	if ((vp = un->un_uppervp) != NULLVP) {
605996c772fSJohn Dyson 		FIXUP(un, p);
606996c772fSJohn Dyson 		ap->a_vp = vp;
607996c772fSJohn Dyson 		return (VCALL(vp, VOFFSET(vop_access), ap));
608df8bae1dSRodney W. Grimes 	}
609df8bae1dSRodney W. Grimes 
610996c772fSJohn Dyson 	if ((vp = un->un_lowervp) != NULLVP) {
611996c772fSJohn Dyson 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
612996c772fSJohn Dyson 		ap->a_vp = vp;
613996c772fSJohn Dyson 		error = VCALL(vp, VOFFSET(vop_access), ap);
614df8bae1dSRodney W. Grimes 		if (error == 0) {
6153a946335SKATO Takenori 			struct union_mount *um = MOUNTTOUNIONMOUNT(ap->a_vp->v_mount);
616df8bae1dSRodney W. Grimes 
617996c772fSJohn Dyson 			if (um->um_op == UNMNT_BELOW) {
618996c772fSJohn Dyson 				ap->a_cred = um->um_cred;
619996c772fSJohn Dyson 				error = VCALL(vp, VOFFSET(vop_access), ap);
620df8bae1dSRodney W. Grimes 			}
621996c772fSJohn Dyson 		}
622996c772fSJohn Dyson 		VOP_UNLOCK(vp, 0, p);
623df8bae1dSRodney W. Grimes 		if (error)
624df8bae1dSRodney W. Grimes 			return (error);
625df8bae1dSRodney W. Grimes 	}
626df8bae1dSRodney W. Grimes 
627df8bae1dSRodney W. Grimes 	return (error);
628df8bae1dSRodney W. Grimes }
629df8bae1dSRodney W. Grimes 
630df8bae1dSRodney W. Grimes /*
631996c772fSJohn Dyson  * We handle getattr only to change the fsid and
632996c772fSJohn Dyson  * track object sizes
633df8bae1dSRodney W. Grimes  */
634df8bae1dSRodney W. Grimes int
635df8bae1dSRodney W. Grimes union_getattr(ap)
636df8bae1dSRodney W. Grimes 	struct vop_getattr_args /* {
637df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
638df8bae1dSRodney W. Grimes 		struct vattr *a_vap;
639df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
640df8bae1dSRodney W. Grimes 		struct proc *a_p;
641df8bae1dSRodney W. Grimes 	} */ *ap;
642df8bae1dSRodney W. Grimes {
643df8bae1dSRodney W. Grimes 	int error;
644df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_vp);
645df8bae1dSRodney W. Grimes 	struct vnode *vp = un->un_uppervp;
646996c772fSJohn Dyson 	struct proc *p = ap->a_p;
647df8bae1dSRodney W. Grimes 	struct vattr *vap;
648df8bae1dSRodney W. Grimes 	struct vattr va;
649df8bae1dSRodney W. Grimes 
650df8bae1dSRodney W. Grimes 
651df8bae1dSRodney W. Grimes 	/*
652df8bae1dSRodney W. Grimes 	 * Some programs walk the filesystem hierarchy by counting
653df8bae1dSRodney W. Grimes 	 * links to directories to avoid stat'ing all the time.
654df8bae1dSRodney W. Grimes 	 * This means the link count on directories needs to be "correct".
655df8bae1dSRodney W. Grimes 	 * The only way to do that is to call getattr on both layers
656df8bae1dSRodney W. Grimes 	 * and fix up the link count.  The link count will not necessarily
657df8bae1dSRodney W. Grimes 	 * be accurate but will be large enough to defeat the tree walkers.
658df8bae1dSRodney W. Grimes 	 */
659df8bae1dSRodney W. Grimes 
660df8bae1dSRodney W. Grimes 	vap = ap->a_vap;
661df8bae1dSRodney W. Grimes 
662df8bae1dSRodney W. Grimes 	vp = un->un_uppervp;
663df8bae1dSRodney W. Grimes 	if (vp != NULLVP) {
664996c772fSJohn Dyson 		/*
665996c772fSJohn Dyson 		 * It's not clear whether VOP_GETATTR is to be
666996c772fSJohn Dyson 		 * called with the vnode locked or not.  stat() calls
667996c772fSJohn Dyson 		 * it with (vp) locked, and fstat calls it with
668996c772fSJohn Dyson 		 * (vp) unlocked.
669996c772fSJohn Dyson 		 * In the mean time, compensate here by checking
670996c772fSJohn Dyson 		 * the union_node's lock flag.
671996c772fSJohn Dyson 		 */
672996c772fSJohn Dyson 		if (un->un_flags & UN_LOCKED)
673996c772fSJohn Dyson 			FIXUP(un, p);
674996c772fSJohn Dyson 
675df8bae1dSRodney W. Grimes 		error = VOP_GETATTR(vp, vap, ap->a_cred, ap->a_p);
676df8bae1dSRodney W. Grimes 		if (error)
677df8bae1dSRodney W. Grimes 			return (error);
678996c772fSJohn Dyson 		union_newsize(ap->a_vp, vap->va_size, VNOVAL);
679df8bae1dSRodney W. Grimes 	}
680df8bae1dSRodney W. Grimes 
681df8bae1dSRodney W. Grimes 	if (vp == NULLVP) {
682df8bae1dSRodney W. Grimes 		vp = un->un_lowervp;
683df8bae1dSRodney W. Grimes 	} else if (vp->v_type == VDIR) {
684df8bae1dSRodney W. Grimes 		vp = un->un_lowervp;
685df8bae1dSRodney W. Grimes 		vap = &va;
686df8bae1dSRodney W. Grimes 	} else {
687df8bae1dSRodney W. Grimes 		vp = NULLVP;
688df8bae1dSRodney W. Grimes 	}
689df8bae1dSRodney W. Grimes 
690df8bae1dSRodney W. Grimes 	if (vp != NULLVP) {
691df8bae1dSRodney W. Grimes 		error = VOP_GETATTR(vp, vap, ap->a_cred, ap->a_p);
692df8bae1dSRodney W. Grimes 		if (error)
693df8bae1dSRodney W. Grimes 			return (error);
694996c772fSJohn Dyson 		union_newsize(ap->a_vp, VNOVAL, vap->va_size);
695df8bae1dSRodney W. Grimes 	}
696df8bae1dSRodney W. Grimes 
697df8bae1dSRodney W. Grimes 	if ((vap != ap->a_vap) && (vap->va_type == VDIR))
698df8bae1dSRodney W. Grimes 		ap->a_vap->va_nlink += vap->va_nlink;
699df8bae1dSRodney W. Grimes 
700996c772fSJohn Dyson 	ap->a_vap->va_fsid = ap->a_vp->v_mount->mnt_stat.f_fsid.val[0];
701df8bae1dSRodney W. Grimes 	return (0);
702df8bae1dSRodney W. Grimes }
703df8bae1dSRodney W. Grimes 
704df8bae1dSRodney W. Grimes int
705df8bae1dSRodney W. Grimes union_setattr(ap)
706df8bae1dSRodney W. Grimes 	struct vop_setattr_args /* {
707df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
708df8bae1dSRodney W. Grimes 		struct vattr *a_vap;
709df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
710df8bae1dSRodney W. Grimes 		struct proc *a_p;
711df8bae1dSRodney W. Grimes 	} */ *ap;
712df8bae1dSRodney W. Grimes {
713df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_vp);
714996c772fSJohn Dyson 	struct proc *p = ap->a_p;
715df8bae1dSRodney W. Grimes 	int error;
716df8bae1dSRodney W. Grimes 
717df8bae1dSRodney W. Grimes 	/*
718df8bae1dSRodney W. Grimes 	 * Handle case of truncating lower object to zero size,
719df8bae1dSRodney W. Grimes 	 * by creating a zero length upper object.  This is to
720df8bae1dSRodney W. Grimes 	 * handle the case of open with O_TRUNC and O_CREAT.
721df8bae1dSRodney W. Grimes 	 */
722df8bae1dSRodney W. Grimes 	if ((un->un_uppervp == NULLVP) &&
723df8bae1dSRodney W. Grimes 	    /* assert(un->un_lowervp != NULLVP) */
724996c772fSJohn Dyson 	    (un->un_lowervp->v_type == VREG)) {
725996c772fSJohn Dyson 		error = union_copyup(un, (ap->a_vap->va_size != 0),
726996c772fSJohn Dyson 						ap->a_cred, ap->a_p);
727df8bae1dSRodney W. Grimes 		if (error)
728df8bae1dSRodney W. Grimes 			return (error);
729df8bae1dSRodney W. Grimes 	}
730df8bae1dSRodney W. Grimes 
731df8bae1dSRodney W. Grimes 	/*
732df8bae1dSRodney W. Grimes 	 * Try to set attributes in upper layer,
733df8bae1dSRodney W. Grimes 	 * otherwise return read-only filesystem error.
734df8bae1dSRodney W. Grimes 	 */
735df8bae1dSRodney W. Grimes 	if (un->un_uppervp != NULLVP) {
736996c772fSJohn Dyson 		FIXUP(un, p);
737df8bae1dSRodney W. Grimes 		error = VOP_SETATTR(un->un_uppervp, ap->a_vap,
738df8bae1dSRodney W. Grimes 					ap->a_cred, ap->a_p);
739996c772fSJohn Dyson 		if ((error == 0) && (ap->a_vap->va_size != VNOVAL))
740996c772fSJohn Dyson 			union_newsize(ap->a_vp, ap->a_vap->va_size, VNOVAL);
741df8bae1dSRodney W. Grimes 	} else {
742df8bae1dSRodney W. Grimes 		error = EROFS;
743df8bae1dSRodney W. Grimes 	}
744df8bae1dSRodney W. Grimes 
745df8bae1dSRodney W. Grimes 	return (error);
746df8bae1dSRodney W. Grimes }
747df8bae1dSRodney W. Grimes 
748df8bae1dSRodney W. Grimes int
749df8bae1dSRodney W. Grimes union_read(ap)
750df8bae1dSRodney W. Grimes 	struct vop_read_args /* {
751df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
752df8bae1dSRodney W. Grimes 		struct uio *a_uio;
753df8bae1dSRodney W. Grimes 		int  a_ioflag;
754df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
755df8bae1dSRodney W. Grimes 	} */ *ap;
756df8bae1dSRodney W. Grimes {
757df8bae1dSRodney W. Grimes 	int error;
758996c772fSJohn Dyson 	struct proc *p = ap->a_uio->uio_procp;
759df8bae1dSRodney W. Grimes 	struct vnode *vp = OTHERVP(ap->a_vp);
760df8bae1dSRodney W. Grimes 	int dolock = (vp == LOWERVP(ap->a_vp));
761df8bae1dSRodney W. Grimes 
762df8bae1dSRodney W. Grimes 	if (dolock)
763996c772fSJohn Dyson 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
764df8bae1dSRodney W. Grimes 	else
765996c772fSJohn Dyson 		FIXUP(VTOUNION(ap->a_vp), p);
766df8bae1dSRodney W. Grimes 	error = VOP_READ(vp, ap->a_uio, ap->a_ioflag, ap->a_cred);
767df8bae1dSRodney W. Grimes 	if (dolock)
768996c772fSJohn Dyson 		VOP_UNLOCK(vp, 0, p);
769996c772fSJohn Dyson 
770996c772fSJohn Dyson 	/*
771996c772fSJohn Dyson 	 * XXX
772996c772fSJohn Dyson 	 * perhaps the size of the underlying object has changed under
773996c772fSJohn Dyson 	 * our feet.  take advantage of the offset information present
774996c772fSJohn Dyson 	 * in the uio structure.
775996c772fSJohn Dyson 	 */
776996c772fSJohn Dyson 	if (error == 0) {
777996c772fSJohn Dyson 		struct union_node *un = VTOUNION(ap->a_vp);
778996c772fSJohn Dyson 		off_t cur = ap->a_uio->uio_offset;
779996c772fSJohn Dyson 
780996c772fSJohn Dyson 		if (vp == un->un_uppervp) {
781996c772fSJohn Dyson 			if (cur > un->un_uppersz)
782996c772fSJohn Dyson 				union_newsize(ap->a_vp, cur, VNOVAL);
783996c772fSJohn Dyson 		} else {
784996c772fSJohn Dyson 			if (cur > un->un_lowersz)
785996c772fSJohn Dyson 				union_newsize(ap->a_vp, VNOVAL, cur);
786996c772fSJohn Dyson 		}
787996c772fSJohn Dyson 	}
788df8bae1dSRodney W. Grimes 
789df8bae1dSRodney W. Grimes 	return (error);
790df8bae1dSRodney W. Grimes }
791df8bae1dSRodney W. Grimes 
792df8bae1dSRodney W. Grimes int
793df8bae1dSRodney W. Grimes union_write(ap)
794df8bae1dSRodney W. Grimes 	struct vop_read_args /* {
795df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
796df8bae1dSRodney W. Grimes 		struct uio *a_uio;
797df8bae1dSRodney W. Grimes 		int  a_ioflag;
798df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
799df8bae1dSRodney W. Grimes 	} */ *ap;
800df8bae1dSRodney W. Grimes {
801df8bae1dSRodney W. Grimes 	int error;
802996c772fSJohn Dyson 	struct vnode *vp;
803996c772fSJohn Dyson 	struct union_node *un = VTOUNION(ap->a_vp);
804996c772fSJohn Dyson 	struct proc *p = ap->a_uio->uio_procp;
805df8bae1dSRodney W. Grimes 
806996c772fSJohn Dyson 	vp = UPPERVP(ap->a_vp);
807996c772fSJohn Dyson 	if (vp == NULLVP)
808996c772fSJohn Dyson 		panic("union: missing upper layer in write");
809996c772fSJohn Dyson 
810996c772fSJohn Dyson 	FIXUP(un, p);
811df8bae1dSRodney W. Grimes 	error = VOP_WRITE(vp, ap->a_uio, ap->a_ioflag, ap->a_cred);
812996c772fSJohn Dyson 
813996c772fSJohn Dyson 	/*
814996c772fSJohn Dyson 	 * the size of the underlying object may be changed by the
815996c772fSJohn Dyson 	 * write.
816996c772fSJohn Dyson 	 */
817996c772fSJohn Dyson 	if (error == 0) {
818996c772fSJohn Dyson 		off_t cur = ap->a_uio->uio_offset;
819996c772fSJohn Dyson 
820996c772fSJohn Dyson 		if (cur > un->un_uppersz)
821996c772fSJohn Dyson 			union_newsize(ap->a_vp, cur, VNOVAL);
822996c772fSJohn Dyson 	}
823df8bae1dSRodney W. Grimes 
824df8bae1dSRodney W. Grimes 	return (error);
825df8bae1dSRodney W. Grimes }
826df8bae1dSRodney W. Grimes 
827df8bae1dSRodney W. Grimes int
828996c772fSJohn Dyson union_lease(ap)
829996c772fSJohn Dyson 	struct vop_lease_args /* {
830996c772fSJohn Dyson 		struct vnode *a_vp;
831996c772fSJohn Dyson 		struct proc *a_p;
832996c772fSJohn Dyson 		struct ucred *a_cred;
833996c772fSJohn Dyson 		int a_flag;
834996c772fSJohn Dyson 	} */ *ap;
835996c772fSJohn Dyson {
836996c772fSJohn Dyson 	register struct vnode *ovp = OTHERVP(ap->a_vp);
837996c772fSJohn Dyson 
838996c772fSJohn Dyson 	ap->a_vp = ovp;
839996c772fSJohn Dyson 	return (VCALL(ovp, VOFFSET(vop_lease), ap));
840996c772fSJohn Dyson }
841996c772fSJohn Dyson 
842996c772fSJohn Dyson int
843df8bae1dSRodney W. Grimes union_ioctl(ap)
844df8bae1dSRodney W. Grimes 	struct vop_ioctl_args /* {
845df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
846df8bae1dSRodney W. Grimes 		int  a_command;
847df8bae1dSRodney W. Grimes 		caddr_t  a_data;
848df8bae1dSRodney W. Grimes 		int  a_fflag;
849df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
850df8bae1dSRodney W. Grimes 		struct proc *a_p;
851df8bae1dSRodney W. Grimes 	} */ *ap;
852df8bae1dSRodney W. Grimes {
853996c772fSJohn Dyson 	register struct vnode *ovp = OTHERVP(ap->a_vp);
854df8bae1dSRodney W. Grimes 
855996c772fSJohn Dyson 	ap->a_vp = ovp;
856996c772fSJohn Dyson 	return (VCALL(ovp, VOFFSET(vop_ioctl), ap));
857df8bae1dSRodney W. Grimes }
858df8bae1dSRodney W. Grimes 
859df8bae1dSRodney W. Grimes int
860df8bae1dSRodney W. Grimes union_select(ap)
861df8bae1dSRodney W. Grimes 	struct vop_select_args /* {
862df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
863df8bae1dSRodney W. Grimes 		int  a_which;
864df8bae1dSRodney W. Grimes 		int  a_fflags;
865df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
866df8bae1dSRodney W. Grimes 		struct proc *a_p;
867df8bae1dSRodney W. Grimes 	} */ *ap;
868df8bae1dSRodney W. Grimes {
869996c772fSJohn Dyson 	register struct vnode *ovp = OTHERVP(ap->a_vp);
870df8bae1dSRodney W. Grimes 
871996c772fSJohn Dyson 	ap->a_vp = ovp;
872996c772fSJohn Dyson 	return (VCALL(ovp, VOFFSET(vop_select), ap));
873996c772fSJohn Dyson }
874996c772fSJohn Dyson 
875996c772fSJohn Dyson int
876996c772fSJohn Dyson union_revoke(ap)
877996c772fSJohn Dyson 	struct vop_revoke_args /* {
878996c772fSJohn Dyson 		struct vnode *a_vp;
879996c772fSJohn Dyson 		int a_flags;
880996c772fSJohn Dyson 		struct proc *a_p;
881996c772fSJohn Dyson 	} */ *ap;
882996c772fSJohn Dyson {
883996c772fSJohn Dyson 	struct vnode *vp = ap->a_vp;
884996c772fSJohn Dyson 
885996c772fSJohn Dyson 	if (UPPERVP(vp))
886996c772fSJohn Dyson 		VOP_REVOKE(UPPERVP(vp), ap->a_flags);
887996c772fSJohn Dyson 	if (LOWERVP(vp))
888996c772fSJohn Dyson 		VOP_REVOKE(LOWERVP(vp), ap->a_flags);
889996c772fSJohn Dyson 	vgone(vp);
890996c772fSJohn Dyson 	return (0);
891df8bae1dSRodney W. Grimes }
892df8bae1dSRodney W. Grimes 
893df8bae1dSRodney W. Grimes int
894df8bae1dSRodney W. Grimes union_mmap(ap)
895df8bae1dSRodney W. Grimes 	struct vop_mmap_args /* {
896df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
897df8bae1dSRodney W. Grimes 		int  a_fflags;
898df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
899df8bae1dSRodney W. Grimes 		struct proc *a_p;
900df8bae1dSRodney W. Grimes 	} */ *ap;
901df8bae1dSRodney W. Grimes {
902996c772fSJohn Dyson 	register struct vnode *ovp = OTHERVP(ap->a_vp);
903df8bae1dSRodney W. Grimes 
904996c772fSJohn Dyson 	ap->a_vp = ovp;
905996c772fSJohn Dyson 	return (VCALL(ovp, VOFFSET(vop_mmap), ap));
906df8bae1dSRodney W. Grimes }
907df8bae1dSRodney W. Grimes 
908df8bae1dSRodney W. Grimes int
909df8bae1dSRodney W. Grimes union_fsync(ap)
910df8bae1dSRodney W. Grimes 	struct vop_fsync_args /* {
911df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
912df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
913df8bae1dSRodney W. Grimes 		int  a_waitfor;
914df8bae1dSRodney W. Grimes 		struct proc *a_p;
915df8bae1dSRodney W. Grimes 	} */ *ap;
916df8bae1dSRodney W. Grimes {
917df8bae1dSRodney W. Grimes 	int error = 0;
918996c772fSJohn Dyson 	struct proc *p = ap->a_p;
919df8bae1dSRodney W. Grimes 	struct vnode *targetvp = OTHERVP(ap->a_vp);
920363ad700SPoul-Henning Kamp 	struct union_node *un;
921363ad700SPoul-Henning Kamp 	int isupperlocked = 0;
922df8bae1dSRodney W. Grimes 
923996c772fSJohn Dyson 	if (targetvp != NULLVP) {
924df8bae1dSRodney W. Grimes 		int dolock = (targetvp == LOWERVP(ap->a_vp));
925df8bae1dSRodney W. Grimes 
926363ad700SPoul-Henning Kamp 		un = VTOUNION(ap->a_vp);
927df8bae1dSRodney W. Grimes 		if (dolock)
928996c772fSJohn Dyson 			vn_lock(targetvp, LK_EXCLUSIVE | LK_RETRY, p);
929363ad700SPoul-Henning Kamp 		else if ((un->un_flags & UN_ULOCK) == 0 &&
930363ad700SPoul-Henning Kamp 				 VOP_ISLOCKED(targetvp) == 0) {
931363ad700SPoul-Henning Kamp 			isupperlocked = 1;
932363ad700SPoul-Henning Kamp 			vn_lock(targetvp, LK_EXCLUSIVE | LK_RETRY, p);
933363ad700SPoul-Henning Kamp 			un->un_flags |= UN_ULOCK;
934363ad700SPoul-Henning Kamp 		}
935996c772fSJohn Dyson 		error = VOP_FSYNC(targetvp, ap->a_cred, ap->a_waitfor, p);
936df8bae1dSRodney W. Grimes 		if (dolock)
937996c772fSJohn Dyson 			VOP_UNLOCK(targetvp, 0, p);
938363ad700SPoul-Henning Kamp 		else if (isupperlocked) {
939363ad700SPoul-Henning Kamp 			VOP_UNLOCK(targetvp, 0, p);
940363ad700SPoul-Henning Kamp 			un->un_flags &= ~UN_ULOCK;
941363ad700SPoul-Henning Kamp 		}
942df8bae1dSRodney W. Grimes 	}
943df8bae1dSRodney W. Grimes 
944df8bae1dSRodney W. Grimes 	return (error);
945df8bae1dSRodney W. Grimes }
946df8bae1dSRodney W. Grimes 
947df8bae1dSRodney W. Grimes int
948df8bae1dSRodney W. Grimes union_seek(ap)
949df8bae1dSRodney W. Grimes 	struct vop_seek_args /* {
950df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
951df8bae1dSRodney W. Grimes 		off_t  a_oldoff;
952df8bae1dSRodney W. Grimes 		off_t  a_newoff;
953df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
954df8bae1dSRodney W. Grimes 	} */ *ap;
955df8bae1dSRodney W. Grimes {
956996c772fSJohn Dyson 	register struct vnode *ovp = OTHERVP(ap->a_vp);
957df8bae1dSRodney W. Grimes 
958996c772fSJohn Dyson 	ap->a_vp = ovp;
959996c772fSJohn Dyson 	return (VCALL(ovp, VOFFSET(vop_seek), ap));
960df8bae1dSRodney W. Grimes }
961df8bae1dSRodney W. Grimes 
962df8bae1dSRodney W. Grimes int
963df8bae1dSRodney W. Grimes union_remove(ap)
964df8bae1dSRodney W. Grimes 	struct vop_remove_args /* {
965df8bae1dSRodney W. Grimes 		struct vnode *a_dvp;
966df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
967df8bae1dSRodney W. Grimes 		struct componentname *a_cnp;
968df8bae1dSRodney W. Grimes 	} */ *ap;
969df8bae1dSRodney W. Grimes {
970df8bae1dSRodney W. Grimes 	int error;
971df8bae1dSRodney W. Grimes 	struct union_node *dun = VTOUNION(ap->a_dvp);
972df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_vp);
973996c772fSJohn Dyson 	struct componentname *cnp = ap->a_cnp;
974996c772fSJohn Dyson 	struct proc *p = cnp->cn_proc;
975df8bae1dSRodney W. Grimes 
976996c772fSJohn Dyson 	if (dun->un_uppervp == NULLVP)
977996c772fSJohn Dyson 		panic("union remove: null upper vnode");
978996c772fSJohn Dyson 
979996c772fSJohn Dyson 	if (un->un_uppervp != NULLVP) {
980df8bae1dSRodney W. Grimes 		struct vnode *dvp = dun->un_uppervp;
981df8bae1dSRodney W. Grimes 		struct vnode *vp = un->un_uppervp;
982df8bae1dSRodney W. Grimes 
983996c772fSJohn Dyson 		FIXUP(dun, p);
984df8bae1dSRodney W. Grimes 		VREF(dvp);
985df8bae1dSRodney W. Grimes 		dun->un_flags |= UN_KLOCK;
986df8bae1dSRodney W. Grimes 		vput(ap->a_dvp);
987996c772fSJohn Dyson 		FIXUP(un, p);
988df8bae1dSRodney W. Grimes 		VREF(vp);
989df8bae1dSRodney W. Grimes 		un->un_flags |= UN_KLOCK;
990df8bae1dSRodney W. Grimes 		vput(ap->a_vp);
991df8bae1dSRodney W. Grimes 
992996c772fSJohn Dyson 		if (union_dowhiteout(un, cnp->cn_cred, cnp->cn_proc))
993996c772fSJohn Dyson 			cnp->cn_flags |= DOWHITEOUT;
994996c772fSJohn Dyson 		error = VOP_REMOVE(dvp, vp, cnp);
995df8bae1dSRodney W. Grimes 		if (!error)
996df8bae1dSRodney W. Grimes 			union_removed_upper(un);
997df8bae1dSRodney W. Grimes 	} else {
998996c772fSJohn Dyson 		FIXUP(dun, p);
999996c772fSJohn Dyson 		error = union_mkwhiteout(
1000996c772fSJohn Dyson 			MOUNTTOUNIONMOUNT(UNIONTOV(dun)->v_mount),
1001996c772fSJohn Dyson 			dun->un_uppervp, ap->a_cnp, un->un_path);
1002df8bae1dSRodney W. Grimes 		vput(ap->a_dvp);
1003df8bae1dSRodney W. Grimes 		vput(ap->a_vp);
1004df8bae1dSRodney W. Grimes 	}
1005df8bae1dSRodney W. Grimes 
1006df8bae1dSRodney W. Grimes 	return (error);
1007df8bae1dSRodney W. Grimes }
1008df8bae1dSRodney W. Grimes 
1009df8bae1dSRodney W. Grimes int
1010df8bae1dSRodney W. Grimes union_link(ap)
1011df8bae1dSRodney W. Grimes 	struct vop_link_args /* {
1012df8bae1dSRodney W. Grimes 		struct vnode *a_tdvp;
101347777413SDavid Greenman 		struct vnode *a_vp;
1014df8bae1dSRodney W. Grimes 		struct componentname *a_cnp;
1015df8bae1dSRodney W. Grimes 	} */ *ap;
1016df8bae1dSRodney W. Grimes {
1017996c772fSJohn Dyson 	int error = 0;
1018996c772fSJohn Dyson 	struct componentname *cnp = ap->a_cnp;
1019996c772fSJohn Dyson 	struct proc *p = cnp->cn_proc;
1020996c772fSJohn Dyson 	struct union_node *un;
1021996c772fSJohn Dyson 	struct vnode *vp;
1022996c772fSJohn Dyson 	struct vnode *tdvp;
1023df8bae1dSRodney W. Grimes 
1024996c772fSJohn Dyson 	un = VTOUNION(ap->a_tdvp);
1025df8bae1dSRodney W. Grimes 
1026996c772fSJohn Dyson 	if (ap->a_tdvp->v_op != ap->a_vp->v_op) {
1027996c772fSJohn Dyson 		vp = ap->a_vp;
1028df8bae1dSRodney W. Grimes 	} else {
1029996c772fSJohn Dyson 		struct union_node *tun = VTOUNION(ap->a_vp);
1030996c772fSJohn Dyson 		if (tun->un_uppervp == NULLVP) {
1031996c772fSJohn Dyson 			vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY, p);
1032996c772fSJohn Dyson 			if (un->un_uppervp == tun->un_dirvp) {
1033996c772fSJohn Dyson 				un->un_flags &= ~UN_ULOCK;
1034996c772fSJohn Dyson 				VOP_UNLOCK(un->un_uppervp, 0, p);
1035996c772fSJohn Dyson 			}
1036996c772fSJohn Dyson 			error = union_copyup(tun, 1, cnp->cn_cred, p);
1037996c772fSJohn Dyson 			if (un->un_uppervp == tun->un_dirvp) {
1038996c772fSJohn Dyson 				vn_lock(un->un_uppervp,
1039996c772fSJohn Dyson 						LK_EXCLUSIVE | LK_RETRY, p);
1040996c772fSJohn Dyson 				un->un_flags |= UN_ULOCK;
1041996c772fSJohn Dyson 			}
1042996c772fSJohn Dyson 			VOP_UNLOCK(ap->a_vp, 0, p);
1043996c772fSJohn Dyson 		}
1044996c772fSJohn Dyson 		vp = tun->un_uppervp;
1045df8bae1dSRodney W. Grimes 	}
1046df8bae1dSRodney W. Grimes 
1047996c772fSJohn Dyson 	tdvp = un->un_uppervp;
1048996c772fSJohn Dyson 	if (tdvp == NULLVP)
1049996c772fSJohn Dyson 		error = EROFS;
1050996c772fSJohn Dyson 
1051996c772fSJohn Dyson 	if (error) {
1052996c772fSJohn Dyson 		vput(ap->a_tdvp);
1053df8bae1dSRodney W. Grimes 		return (error);
1054df8bae1dSRodney W. Grimes 	}
1055df8bae1dSRodney W. Grimes 
1056996c772fSJohn Dyson 	FIXUP(un, p);
1057996c772fSJohn Dyson 	VREF(tdvp);
1058996c772fSJohn Dyson 	un->un_flags |= UN_KLOCK;
1059996c772fSJohn Dyson 	vput(ap->a_tdvp);
1060996c772fSJohn Dyson 
1061996c772fSJohn Dyson 	return (VOP_LINK(vp, tdvp, cnp));
1062996c772fSJohn Dyson }
1063996c772fSJohn Dyson 
1064df8bae1dSRodney W. Grimes int
1065df8bae1dSRodney W. Grimes union_rename(ap)
1066df8bae1dSRodney W. Grimes 	struct vop_rename_args  /* {
1067df8bae1dSRodney W. Grimes 		struct vnode *a_fdvp;
1068df8bae1dSRodney W. Grimes 		struct vnode *a_fvp;
1069df8bae1dSRodney W. Grimes 		struct componentname *a_fcnp;
1070df8bae1dSRodney W. Grimes 		struct vnode *a_tdvp;
1071df8bae1dSRodney W. Grimes 		struct vnode *a_tvp;
1072df8bae1dSRodney W. Grimes 		struct componentname *a_tcnp;
1073df8bae1dSRodney W. Grimes 	} */ *ap;
1074df8bae1dSRodney W. Grimes {
1075df8bae1dSRodney W. Grimes 	int error;
1076df8bae1dSRodney W. Grimes 
1077df8bae1dSRodney W. Grimes 	struct vnode *fdvp = ap->a_fdvp;
1078df8bae1dSRodney W. Grimes 	struct vnode *fvp = ap->a_fvp;
1079df8bae1dSRodney W. Grimes 	struct vnode *tdvp = ap->a_tdvp;
1080df8bae1dSRodney W. Grimes 	struct vnode *tvp = ap->a_tvp;
1081df8bae1dSRodney W. Grimes 
1082df8bae1dSRodney W. Grimes 	if (fdvp->v_op == union_vnodeop_p) {	/* always true */
1083df8bae1dSRodney W. Grimes 		struct union_node *un = VTOUNION(fdvp);
1084df8bae1dSRodney W. Grimes 		if (un->un_uppervp == NULLVP) {
1085996c772fSJohn Dyson 			/*
1086996c772fSJohn Dyson 			 * this should never happen in normal
1087996c772fSJohn Dyson 			 * operation but might if there was
1088996c772fSJohn Dyson 			 * a problem creating the top-level shadow
1089996c772fSJohn Dyson 			 * directory.
1090996c772fSJohn Dyson 			 */
1091996c772fSJohn Dyson 			error = EXDEV;
1092df8bae1dSRodney W. Grimes 			goto bad;
1093df8bae1dSRodney W. Grimes 		}
1094df8bae1dSRodney W. Grimes 
1095df8bae1dSRodney W. Grimes 		fdvp = un->un_uppervp;
1096df8bae1dSRodney W. Grimes 		VREF(fdvp);
1097df8bae1dSRodney W. Grimes 		vrele(ap->a_fdvp);
1098df8bae1dSRodney W. Grimes 	}
1099df8bae1dSRodney W. Grimes 
1100df8bae1dSRodney W. Grimes 	if (fvp->v_op == union_vnodeop_p) {	/* always true */
1101df8bae1dSRodney W. Grimes 		struct union_node *un = VTOUNION(fvp);
1102df8bae1dSRodney W. Grimes 		if (un->un_uppervp == NULLVP) {
1103996c772fSJohn Dyson 			/* XXX: should do a copyup */
1104996c772fSJohn Dyson 			error = EXDEV;
1105df8bae1dSRodney W. Grimes 			goto bad;
1106df8bae1dSRodney W. Grimes 		}
1107df8bae1dSRodney W. Grimes 
1108996c772fSJohn Dyson 		if (un->un_lowervp != NULLVP)
1109996c772fSJohn Dyson 			ap->a_fcnp->cn_flags |= DOWHITEOUT;
1110996c772fSJohn Dyson 
1111df8bae1dSRodney W. Grimes 		fvp = un->un_uppervp;
1112df8bae1dSRodney W. Grimes 		VREF(fvp);
1113df8bae1dSRodney W. Grimes 		vrele(ap->a_fvp);
1114df8bae1dSRodney W. Grimes 	}
1115df8bae1dSRodney W. Grimes 
1116df8bae1dSRodney W. Grimes 	if (tdvp->v_op == union_vnodeop_p) {
1117df8bae1dSRodney W. Grimes 		struct union_node *un = VTOUNION(tdvp);
1118df8bae1dSRodney W. Grimes 		if (un->un_uppervp == NULLVP) {
1119996c772fSJohn Dyson 			/*
1120996c772fSJohn Dyson 			 * this should never happen in normal
1121996c772fSJohn Dyson 			 * operation but might if there was
1122996c772fSJohn Dyson 			 * a problem creating the top-level shadow
1123996c772fSJohn Dyson 			 * directory.
1124996c772fSJohn Dyson 			 */
1125996c772fSJohn Dyson 			error = EXDEV;
1126df8bae1dSRodney W. Grimes 			goto bad;
1127df8bae1dSRodney W. Grimes 		}
1128df8bae1dSRodney W. Grimes 
1129df8bae1dSRodney W. Grimes 		tdvp = un->un_uppervp;
1130df8bae1dSRodney W. Grimes 		VREF(tdvp);
1131df8bae1dSRodney W. Grimes 		un->un_flags |= UN_KLOCK;
1132df8bae1dSRodney W. Grimes 		vput(ap->a_tdvp);
1133df8bae1dSRodney W. Grimes 	}
1134df8bae1dSRodney W. Grimes 
1135996c772fSJohn Dyson 	if (tvp != NULLVP && tvp->v_op == union_vnodeop_p) {
1136df8bae1dSRodney W. Grimes 		struct union_node *un = VTOUNION(tvp);
1137df8bae1dSRodney W. Grimes 
1138df8bae1dSRodney W. Grimes 		tvp = un->un_uppervp;
1139996c772fSJohn Dyson 		if (tvp != NULLVP) {
1140df8bae1dSRodney W. Grimes 			VREF(tvp);
1141df8bae1dSRodney W. Grimes 			un->un_flags |= UN_KLOCK;
1142996c772fSJohn Dyson 		}
1143df8bae1dSRodney W. Grimes 		vput(ap->a_tvp);
1144df8bae1dSRodney W. Grimes 	}
1145df8bae1dSRodney W. Grimes 
1146df8bae1dSRodney W. Grimes 	return (VOP_RENAME(fdvp, fvp, ap->a_fcnp, tdvp, tvp, ap->a_tcnp));
1147df8bae1dSRodney W. Grimes 
1148df8bae1dSRodney W. Grimes bad:
1149df8bae1dSRodney W. Grimes 	vrele(fdvp);
1150df8bae1dSRodney W. Grimes 	vrele(fvp);
1151df8bae1dSRodney W. Grimes 	vput(tdvp);
1152996c772fSJohn Dyson 	if (tvp != NULLVP)
1153df8bae1dSRodney W. Grimes 		vput(tvp);
1154df8bae1dSRodney W. Grimes 
1155df8bae1dSRodney W. Grimes 	return (error);
1156df8bae1dSRodney W. Grimes }
1157df8bae1dSRodney W. Grimes 
1158df8bae1dSRodney W. Grimes int
1159df8bae1dSRodney W. Grimes union_mkdir(ap)
1160df8bae1dSRodney W. Grimes 	struct vop_mkdir_args /* {
1161df8bae1dSRodney W. Grimes 		struct vnode *a_dvp;
1162df8bae1dSRodney W. Grimes 		struct vnode **a_vpp;
1163df8bae1dSRodney W. Grimes 		struct componentname *a_cnp;
1164df8bae1dSRodney W. Grimes 		struct vattr *a_vap;
1165df8bae1dSRodney W. Grimes 	} */ *ap;
1166df8bae1dSRodney W. Grimes {
1167df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_dvp);
1168df8bae1dSRodney W. Grimes 	struct vnode *dvp = un->un_uppervp;
1169996c772fSJohn Dyson 	struct componentname *cnp = ap->a_cnp;
1170996c772fSJohn Dyson 	struct proc *p = cnp->cn_proc;
1171df8bae1dSRodney W. Grimes 
1172996c772fSJohn Dyson 	if (dvp != NULLVP) {
1173df8bae1dSRodney W. Grimes 		int error;
1174df8bae1dSRodney W. Grimes 		struct vnode *vp;
1175df8bae1dSRodney W. Grimes 
1176996c772fSJohn Dyson 		FIXUP(un, p);
1177df8bae1dSRodney W. Grimes 		VREF(dvp);
1178df8bae1dSRodney W. Grimes 		un->un_flags |= UN_KLOCK;
1179996c772fSJohn Dyson 		VOP_UNLOCK(ap->a_dvp, 0, p);
1180996c772fSJohn Dyson 		error = VOP_MKDIR(dvp, &vp, cnp, ap->a_vap);
1181996c772fSJohn Dyson 		if (error) {
1182996c772fSJohn Dyson 			vrele(ap->a_dvp);
1183df8bae1dSRodney W. Grimes 			return (error);
1184996c772fSJohn Dyson 		}
1185df8bae1dSRodney W. Grimes 
1186996c772fSJohn Dyson 		error = union_allocvp(ap->a_vpp, ap->a_dvp->v_mount, ap->a_dvp,
1187996c772fSJohn Dyson 				NULLVP, cnp, vp, NULLVP, 1);
1188996c772fSJohn Dyson 		vrele(ap->a_dvp);
1189df8bae1dSRodney W. Grimes 		if (error)
1190df8bae1dSRodney W. Grimes 			vput(vp);
1191df8bae1dSRodney W. Grimes 		return (error);
1192df8bae1dSRodney W. Grimes 	}
1193df8bae1dSRodney W. Grimes 
1194df8bae1dSRodney W. Grimes 	vput(ap->a_dvp);
1195df8bae1dSRodney W. Grimes 	return (EROFS);
1196df8bae1dSRodney W. Grimes }
1197df8bae1dSRodney W. Grimes 
1198df8bae1dSRodney W. Grimes int
1199df8bae1dSRodney W. Grimes union_rmdir(ap)
1200df8bae1dSRodney W. Grimes 	struct vop_rmdir_args /* {
1201df8bae1dSRodney W. Grimes 		struct vnode *a_dvp;
1202df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
1203df8bae1dSRodney W. Grimes 		struct componentname *a_cnp;
1204df8bae1dSRodney W. Grimes 	} */ *ap;
1205df8bae1dSRodney W. Grimes {
1206df8bae1dSRodney W. Grimes 	int error;
1207df8bae1dSRodney W. Grimes 	struct union_node *dun = VTOUNION(ap->a_dvp);
1208df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_vp);
1209996c772fSJohn Dyson 	struct componentname *cnp = ap->a_cnp;
1210996c772fSJohn Dyson 	struct proc *p = cnp->cn_proc;
1211df8bae1dSRodney W. Grimes 
1212996c772fSJohn Dyson 	if (dun->un_uppervp == NULLVP)
1213996c772fSJohn Dyson 		panic("union rmdir: null upper vnode");
1214996c772fSJohn Dyson 
1215996c772fSJohn Dyson 	if (un->un_uppervp != NULLVP) {
1216df8bae1dSRodney W. Grimes 		struct vnode *dvp = dun->un_uppervp;
1217df8bae1dSRodney W. Grimes 		struct vnode *vp = un->un_uppervp;
1218df8bae1dSRodney W. Grimes 
1219996c772fSJohn Dyson 		FIXUP(dun, p);
1220df8bae1dSRodney W. Grimes 		VREF(dvp);
1221df8bae1dSRodney W. Grimes 		dun->un_flags |= UN_KLOCK;
1222df8bae1dSRodney W. Grimes 		vput(ap->a_dvp);
1223996c772fSJohn Dyson 		FIXUP(un, p);
1224df8bae1dSRodney W. Grimes 		VREF(vp);
1225df8bae1dSRodney W. Grimes 		un->un_flags |= UN_KLOCK;
1226df8bae1dSRodney W. Grimes 		vput(ap->a_vp);
1227df8bae1dSRodney W. Grimes 
1228996c772fSJohn Dyson 		if (union_dowhiteout(un, cnp->cn_cred, cnp->cn_proc))
1229996c772fSJohn Dyson 			cnp->cn_flags |= DOWHITEOUT;
1230df8bae1dSRodney W. Grimes 		error = VOP_RMDIR(dvp, vp, ap->a_cnp);
1231df8bae1dSRodney W. Grimes 		if (!error)
1232df8bae1dSRodney W. Grimes 			union_removed_upper(un);
1233df8bae1dSRodney W. Grimes 	} else {
1234996c772fSJohn Dyson 		FIXUP(dun, p);
1235996c772fSJohn Dyson 		error = union_mkwhiteout(
1236996c772fSJohn Dyson 			MOUNTTOUNIONMOUNT(UNIONTOV(dun)->v_mount),
1237996c772fSJohn Dyson 			dun->un_uppervp, ap->a_cnp, un->un_path);
1238df8bae1dSRodney W. Grimes 		vput(ap->a_dvp);
1239df8bae1dSRodney W. Grimes 		vput(ap->a_vp);
1240df8bae1dSRodney W. Grimes 	}
1241df8bae1dSRodney W. Grimes 
1242df8bae1dSRodney W. Grimes 	return (error);
1243df8bae1dSRodney W. Grimes }
1244df8bae1dSRodney W. Grimes 
1245df8bae1dSRodney W. Grimes int
1246df8bae1dSRodney W. Grimes union_symlink(ap)
1247df8bae1dSRodney W. Grimes 	struct vop_symlink_args /* {
1248df8bae1dSRodney W. Grimes 		struct vnode *a_dvp;
1249df8bae1dSRodney W. Grimes 		struct vnode **a_vpp;
1250df8bae1dSRodney W. Grimes 		struct componentname *a_cnp;
1251df8bae1dSRodney W. Grimes 		struct vattr *a_vap;
1252df8bae1dSRodney W. Grimes 		char *a_target;
1253df8bae1dSRodney W. Grimes 	} */ *ap;
1254df8bae1dSRodney W. Grimes {
1255df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_dvp);
1256df8bae1dSRodney W. Grimes 	struct vnode *dvp = un->un_uppervp;
1257996c772fSJohn Dyson 	struct componentname *cnp = ap->a_cnp;
1258996c772fSJohn Dyson 	struct proc *p = cnp->cn_proc;
1259df8bae1dSRodney W. Grimes 
1260996c772fSJohn Dyson 	if (dvp != NULLVP) {
1261df8bae1dSRodney W. Grimes 		int error;
1262df8bae1dSRodney W. Grimes 		struct vnode *vp;
1263df8bae1dSRodney W. Grimes 
1264996c772fSJohn Dyson 		FIXUP(un, p);
1265df8bae1dSRodney W. Grimes 		VREF(dvp);
1266df8bae1dSRodney W. Grimes 		un->un_flags |= UN_KLOCK;
1267df8bae1dSRodney W. Grimes 		vput(ap->a_dvp);
1268996c772fSJohn Dyson 		error = VOP_SYMLINK(dvp, &vp, cnp, ap->a_vap, ap->a_target);
1269df8bae1dSRodney W. Grimes 		*ap->a_vpp = NULLVP;
1270df8bae1dSRodney W. Grimes 		return (error);
1271df8bae1dSRodney W. Grimes 	}
1272df8bae1dSRodney W. Grimes 
1273df8bae1dSRodney W. Grimes 	vput(ap->a_dvp);
1274df8bae1dSRodney W. Grimes 	return (EROFS);
1275df8bae1dSRodney W. Grimes }
1276df8bae1dSRodney W. Grimes 
1277df8bae1dSRodney W. Grimes /*
1278df8bae1dSRodney W. Grimes  * union_readdir works in concert with getdirentries and
1279df8bae1dSRodney W. Grimes  * readdir(3) to provide a list of entries in the unioned
1280df8bae1dSRodney W. Grimes  * directories.  getdirentries is responsible for walking
1281df8bae1dSRodney W. Grimes  * down the union stack.  readdir(3) is responsible for
1282df8bae1dSRodney W. Grimes  * eliminating duplicate names from the returned data stream.
1283df8bae1dSRodney W. Grimes  */
1284df8bae1dSRodney W. Grimes int
1285df8bae1dSRodney W. Grimes union_readdir(ap)
1286df8bae1dSRodney W. Grimes 	struct vop_readdir_args /* {
1287df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
1288df8bae1dSRodney W. Grimes 		struct uio *a_uio;
1289df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
1290996c772fSJohn Dyson 		int *a_eofflag;
1291996c772fSJohn Dyson 		u_long *a_cookies;
1292996c772fSJohn Dyson 		int a_ncookies;
1293df8bae1dSRodney W. Grimes 	} */ *ap;
1294df8bae1dSRodney W. Grimes {
1295df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_vp);
1296996c772fSJohn Dyson 	struct vnode *uvp = un->un_uppervp;
1297996c772fSJohn Dyson 	struct proc *p = ap->a_uio->uio_procp;
1298df8bae1dSRodney W. Grimes 
1299996c772fSJohn Dyson 	if (uvp == NULLVP)
1300996c772fSJohn Dyson 		return (0);
1301df8bae1dSRodney W. Grimes 
1302996c772fSJohn Dyson 	FIXUP(un, p);
1303996c772fSJohn Dyson 	ap->a_vp = uvp;
1304996c772fSJohn Dyson 	return (VCALL(uvp, VOFFSET(vop_readdir), ap));
1305df8bae1dSRodney W. Grimes }
1306df8bae1dSRodney W. Grimes 
1307df8bae1dSRodney W. Grimes int
1308df8bae1dSRodney W. Grimes union_readlink(ap)
1309df8bae1dSRodney W. Grimes 	struct vop_readlink_args /* {
1310df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
1311df8bae1dSRodney W. Grimes 		struct uio *a_uio;
1312df8bae1dSRodney W. Grimes 		struct ucred *a_cred;
1313df8bae1dSRodney W. Grimes 	} */ *ap;
1314df8bae1dSRodney W. Grimes {
1315df8bae1dSRodney W. Grimes 	int error;
1316996c772fSJohn Dyson 	struct uio *uio = ap->a_uio;
1317996c772fSJohn Dyson 	struct proc *p = uio->uio_procp;
1318df8bae1dSRodney W. Grimes 	struct vnode *vp = OTHERVP(ap->a_vp);
1319df8bae1dSRodney W. Grimes 	int dolock = (vp == LOWERVP(ap->a_vp));
1320df8bae1dSRodney W. Grimes 
1321df8bae1dSRodney W. Grimes 	if (dolock)
1322996c772fSJohn Dyson 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
1323df8bae1dSRodney W. Grimes 	else
1324996c772fSJohn Dyson 		FIXUP(VTOUNION(ap->a_vp), p);
1325996c772fSJohn Dyson 	ap->a_vp = vp;
1326996c772fSJohn Dyson 	error = VCALL(vp, VOFFSET(vop_readlink), ap);
1327df8bae1dSRodney W. Grimes 	if (dolock)
1328996c772fSJohn Dyson 		VOP_UNLOCK(vp, 0, p);
1329df8bae1dSRodney W. Grimes 
1330df8bae1dSRodney W. Grimes 	return (error);
1331df8bae1dSRodney W. Grimes }
1332df8bae1dSRodney W. Grimes 
1333df8bae1dSRodney W. Grimes int
1334df8bae1dSRodney W. Grimes union_abortop(ap)
1335df8bae1dSRodney W. Grimes 	struct vop_abortop_args /* {
1336df8bae1dSRodney W. Grimes 		struct vnode *a_dvp;
1337df8bae1dSRodney W. Grimes 		struct componentname *a_cnp;
1338df8bae1dSRodney W. Grimes 	} */ *ap;
1339df8bae1dSRodney W. Grimes {
1340df8bae1dSRodney W. Grimes 	int error;
1341996c772fSJohn Dyson 	struct componentname *cnp = ap->a_cnp;
1342996c772fSJohn Dyson 	struct proc *p = cnp->cn_proc;
1343df8bae1dSRodney W. Grimes 	struct vnode *vp = OTHERVP(ap->a_dvp);
1344df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_dvp);
1345df8bae1dSRodney W. Grimes 	int islocked = un->un_flags & UN_LOCKED;
1346df8bae1dSRodney W. Grimes 	int dolock = (vp == LOWERVP(ap->a_dvp));
1347df8bae1dSRodney W. Grimes 
1348df8bae1dSRodney W. Grimes 	if (islocked) {
1349df8bae1dSRodney W. Grimes 		if (dolock)
1350996c772fSJohn Dyson 			vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
1351df8bae1dSRodney W. Grimes 		else
1352996c772fSJohn Dyson 			FIXUP(VTOUNION(ap->a_dvp), p);
1353df8bae1dSRodney W. Grimes 	}
1354996c772fSJohn Dyson 	ap->a_dvp = vp;
1355996c772fSJohn Dyson 	error = VCALL(vp, VOFFSET(vop_abortop), ap);
1356df8bae1dSRodney W. Grimes 	if (islocked && dolock)
1357996c772fSJohn Dyson 		VOP_UNLOCK(vp, 0, p);
1358df8bae1dSRodney W. Grimes 
1359df8bae1dSRodney W. Grimes 	return (error);
1360df8bae1dSRodney W. Grimes }
1361df8bae1dSRodney W. Grimes 
1362df8bae1dSRodney W. Grimes int
1363df8bae1dSRodney W. Grimes union_inactive(ap)
1364df8bae1dSRodney W. Grimes 	struct vop_inactive_args /* {
1365df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
1366996c772fSJohn Dyson 		struct proc *a_p;
1367df8bae1dSRodney W. Grimes 	} */ *ap;
1368df8bae1dSRodney W. Grimes {
1369996c772fSJohn Dyson 	struct vnode *vp = ap->a_vp;
1370996c772fSJohn Dyson 	struct proc *p = ap->a_p;
1371996c772fSJohn Dyson 	struct union_node *un = VTOUNION(vp);
1372996c772fSJohn Dyson 	struct vnode **vpp;
1373df8bae1dSRodney W. Grimes 
1374df8bae1dSRodney W. Grimes 	/*
1375df8bae1dSRodney W. Grimes 	 * Do nothing (and _don't_ bypass).
1376df8bae1dSRodney W. Grimes 	 * Wait to vrele lowervp until reclaim,
1377df8bae1dSRodney W. Grimes 	 * so that until then our union_node is in the
1378df8bae1dSRodney W. Grimes 	 * cache and reusable.
1379df8bae1dSRodney W. Grimes 	 *
1380df8bae1dSRodney W. Grimes 	 * NEEDSWORK: Someday, consider inactive'ing
1381df8bae1dSRodney W. Grimes 	 * the lowervp and then trying to reactivate it
1382df8bae1dSRodney W. Grimes 	 * with capabilities (v_id)
1383df8bae1dSRodney W. Grimes 	 * like they do in the name lookup cache code.
1384df8bae1dSRodney W. Grimes 	 * That's too much work for now.
1385df8bae1dSRodney W. Grimes 	 */
1386df8bae1dSRodney W. Grimes 
1387996c772fSJohn Dyson 	if (un->un_dircache != 0) {
1388996c772fSJohn Dyson 		for (vpp = un->un_dircache; *vpp != NULLVP; vpp++)
1389996c772fSJohn Dyson 			vrele(*vpp);
1390996c772fSJohn Dyson 		free(un->un_dircache, M_TEMP);
1391996c772fSJohn Dyson 		un->un_dircache = 0;
1392996c772fSJohn Dyson 	}
1393df8bae1dSRodney W. Grimes 
1394996c772fSJohn Dyson 	VOP_UNLOCK(vp, 0, p);
1395996c772fSJohn Dyson 
1396996c772fSJohn Dyson 	if ((un->un_flags & UN_CACHED) == 0)
1397996c772fSJohn Dyson 		vgone(vp);
1398df8bae1dSRodney W. Grimes 
1399df8bae1dSRodney W. Grimes 	return (0);
1400df8bae1dSRodney W. Grimes }
1401df8bae1dSRodney W. Grimes 
1402df8bae1dSRodney W. Grimes int
1403df8bae1dSRodney W. Grimes union_reclaim(ap)
1404df8bae1dSRodney W. Grimes 	struct vop_reclaim_args /* {
1405df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
1406df8bae1dSRodney W. Grimes 	} */ *ap;
1407df8bae1dSRodney W. Grimes {
1408df8bae1dSRodney W. Grimes 
1409df8bae1dSRodney W. Grimes 	union_freevp(ap->a_vp);
1410df8bae1dSRodney W. Grimes 
1411df8bae1dSRodney W. Grimes 	return (0);
1412df8bae1dSRodney W. Grimes }
1413df8bae1dSRodney W. Grimes 
1414df8bae1dSRodney W. Grimes int
1415df8bae1dSRodney W. Grimes union_lock(ap)
1416df8bae1dSRodney W. Grimes 	struct vop_lock_args *ap;
1417df8bae1dSRodney W. Grimes {
1418df8bae1dSRodney W. Grimes 	struct vnode *vp = ap->a_vp;
1419996c772fSJohn Dyson 	struct proc *p = ap->a_p;
1420996c772fSJohn Dyson 	int flags = ap->a_flags;
1421df8bae1dSRodney W. Grimes 	struct union_node *un;
1422996c772fSJohn Dyson 	int error;
1423996c772fSJohn Dyson 
1424996c772fSJohn Dyson 	vop_nolock(ap);
1425996c772fSJohn Dyson 	/*
1426996c772fSJohn Dyson 	 * Need to do real lockmgr-style locking here.
1427996c772fSJohn Dyson 	 * in the mean time, draining won't work quite right,
1428996c772fSJohn Dyson 	 * which could lead to a few race conditions.
1429996c772fSJohn Dyson 	 * the following test was here, but is not quite right, we
1430996c772fSJohn Dyson 	 * still need to take the lock:
1431996c772fSJohn Dyson 	if ((flags & LK_TYPE_MASK) == LK_DRAIN)
1432996c772fSJohn Dyson 		return (0);
1433996c772fSJohn Dyson 	 */
1434996c772fSJohn Dyson 	flags &= ~LK_INTERLOCK;
1435df8bae1dSRodney W. Grimes 
1436df8bae1dSRodney W. Grimes start:
1437df8bae1dSRodney W. Grimes 	un = VTOUNION(vp);
1438df8bae1dSRodney W. Grimes 
1439996c772fSJohn Dyson 	if (un->un_uppervp != NULLVP) {
1440996c772fSJohn Dyson 		if (((un->un_flags & UN_ULOCK) == 0) &&
1441996c772fSJohn Dyson 		    (vp->v_usecount != 0)) {
1442996c772fSJohn Dyson 			error = vn_lock(un->un_uppervp, flags, p);
1443996c772fSJohn Dyson 			if (error)
1444996c772fSJohn Dyson 				return (error);
1445df8bae1dSRodney W. Grimes 			un->un_flags |= UN_ULOCK;
1446df8bae1dSRodney W. Grimes 		}
1447df8bae1dSRodney W. Grimes #ifdef DIAGNOSTIC
1448996c772fSJohn Dyson 		if (un->un_flags & UN_KLOCK) {
1449996c772fSJohn Dyson 			vprint("union: dangling klock", vp);
1450996c772fSJohn Dyson 			panic("union: dangling upper lock (%lx)", vp);
1451996c772fSJohn Dyson 		}
1452df8bae1dSRodney W. Grimes #endif
1453df8bae1dSRodney W. Grimes 	}
1454df8bae1dSRodney W. Grimes 
1455df8bae1dSRodney W. Grimes 	if (un->un_flags & UN_LOCKED) {
1456df8bae1dSRodney W. Grimes #ifdef DIAGNOSTIC
1457df8bae1dSRodney W. Grimes 		if (curproc && un->un_pid == curproc->p_pid &&
1458df8bae1dSRodney W. Grimes 			    un->un_pid > -1 && curproc->p_pid > -1)
1459df8bae1dSRodney W. Grimes 			panic("union: locking against myself");
1460df8bae1dSRodney W. Grimes #endif
1461df8bae1dSRodney W. Grimes 		un->un_flags |= UN_WANT;
1462996c772fSJohn Dyson 		tsleep((caddr_t)&un->un_flags, PINOD, "unionlk2", 0);
1463df8bae1dSRodney W. Grimes 		goto start;
1464df8bae1dSRodney W. Grimes 	}
1465df8bae1dSRodney W. Grimes 
1466df8bae1dSRodney W. Grimes #ifdef DIAGNOSTIC
1467df8bae1dSRodney W. Grimes 	if (curproc)
1468df8bae1dSRodney W. Grimes 		un->un_pid = curproc->p_pid;
1469df8bae1dSRodney W. Grimes 	else
1470df8bae1dSRodney W. Grimes 		un->un_pid = -1;
1471df8bae1dSRodney W. Grimes #endif
1472df8bae1dSRodney W. Grimes 
1473df8bae1dSRodney W. Grimes 	un->un_flags |= UN_LOCKED;
1474df8bae1dSRodney W. Grimes 	return (0);
1475df8bae1dSRodney W. Grimes }
1476df8bae1dSRodney W. Grimes 
1477996c772fSJohn Dyson /*
1478996c772fSJohn Dyson  * When operations want to vput() a union node yet retain a lock on
1479996c772fSJohn Dyson  * the upper vnode (say, to do some further operations like link(),
1480996c772fSJohn Dyson  * mkdir(), ...), they set UN_KLOCK on the union node, then call
1481996c772fSJohn Dyson  * vput() which calls VOP_UNLOCK() and comes here.  union_unlock()
1482996c772fSJohn Dyson  * unlocks the union node (leaving the upper vnode alone), clears the
1483996c772fSJohn Dyson  * KLOCK flag, and then returns to vput().  The caller then does whatever
1484996c772fSJohn Dyson  * is left to do with the upper vnode, and ensures that it gets unlocked.
1485996c772fSJohn Dyson  *
1486996c772fSJohn Dyson  * If UN_KLOCK isn't set, then the upper vnode is unlocked here.
1487996c772fSJohn Dyson  */
1488df8bae1dSRodney W. Grimes int
1489df8bae1dSRodney W. Grimes union_unlock(ap)
1490996c772fSJohn Dyson 	struct vop_unlock_args /* {
1491996c772fSJohn Dyson 		struct vnode *a_vp;
1492996c772fSJohn Dyson 		int a_flags;
1493996c772fSJohn Dyson 		struct proc *a_p;
1494996c772fSJohn Dyson 	} */ *ap;
1495df8bae1dSRodney W. Grimes {
1496df8bae1dSRodney W. Grimes 	struct union_node *un = VTOUNION(ap->a_vp);
1497996c772fSJohn Dyson 	struct proc *p = ap->a_p;
1498df8bae1dSRodney W. Grimes 
1499df8bae1dSRodney W. Grimes #ifdef DIAGNOSTIC
1500df8bae1dSRodney W. Grimes 	if ((un->un_flags & UN_LOCKED) == 0)
1501df8bae1dSRodney W. Grimes 		panic("union: unlock unlocked node");
1502df8bae1dSRodney W. Grimes 	if (curproc && un->un_pid != curproc->p_pid &&
1503df8bae1dSRodney W. Grimes 			curproc->p_pid > -1 && un->un_pid > -1)
1504df8bae1dSRodney W. Grimes 		panic("union: unlocking other process's union node");
1505df8bae1dSRodney W. Grimes #endif
1506df8bae1dSRodney W. Grimes 
1507df8bae1dSRodney W. Grimes 	un->un_flags &= ~UN_LOCKED;
1508df8bae1dSRodney W. Grimes 
1509df8bae1dSRodney W. Grimes 	if ((un->un_flags & (UN_ULOCK|UN_KLOCK)) == UN_ULOCK)
1510996c772fSJohn Dyson 		VOP_UNLOCK(un->un_uppervp, 0, p);
1511df8bae1dSRodney W. Grimes 
1512df8bae1dSRodney W. Grimes 	un->un_flags &= ~(UN_ULOCK|UN_KLOCK);
1513df8bae1dSRodney W. Grimes 
1514df8bae1dSRodney W. Grimes 	if (un->un_flags & UN_WANT) {
1515df8bae1dSRodney W. Grimes 		un->un_flags &= ~UN_WANT;
1516df8bae1dSRodney W. Grimes 		wakeup((caddr_t) &un->un_flags);
1517df8bae1dSRodney W. Grimes 	}
1518df8bae1dSRodney W. Grimes 
1519df8bae1dSRodney W. Grimes #ifdef DIAGNOSTIC
1520df8bae1dSRodney W. Grimes 	un->un_pid = 0;
1521df8bae1dSRodney W. Grimes #endif
1522996c772fSJohn Dyson 	vop_nounlock(ap);
1523df8bae1dSRodney W. Grimes 
1524df8bae1dSRodney W. Grimes 	return (0);
1525df8bae1dSRodney W. Grimes }
1526df8bae1dSRodney W. Grimes 
1527df8bae1dSRodney W. Grimes int
1528df8bae1dSRodney W. Grimes union_bmap(ap)
1529df8bae1dSRodney W. Grimes 	struct vop_bmap_args /* {
1530df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
1531df8bae1dSRodney W. Grimes 		daddr_t  a_bn;
1532df8bae1dSRodney W. Grimes 		struct vnode **a_vpp;
1533df8bae1dSRodney W. Grimes 		daddr_t *a_bnp;
1534df8bae1dSRodney W. Grimes 		int *a_runp;
1535c83ebe77SJohn Dyson 		int *a_runb;
1536df8bae1dSRodney W. Grimes 	} */ *ap;
1537df8bae1dSRodney W. Grimes {
1538df8bae1dSRodney W. Grimes 	int error;
1539996c772fSJohn Dyson 	struct proc *p = curproc;		/* XXX */
1540df8bae1dSRodney W. Grimes 	struct vnode *vp = OTHERVP(ap->a_vp);
1541df8bae1dSRodney W. Grimes 	int dolock = (vp == LOWERVP(ap->a_vp));
1542df8bae1dSRodney W. Grimes 
1543df8bae1dSRodney W. Grimes 	if (dolock)
1544996c772fSJohn Dyson 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
1545df8bae1dSRodney W. Grimes 	else
1546996c772fSJohn Dyson 		FIXUP(VTOUNION(ap->a_vp), p);
1547996c772fSJohn Dyson 	ap->a_vp = vp;
1548996c772fSJohn Dyson 	error = VCALL(vp, VOFFSET(vop_bmap), ap);
1549df8bae1dSRodney W. Grimes 	if (dolock)
1550996c772fSJohn Dyson 		VOP_UNLOCK(vp, 0, p);
1551df8bae1dSRodney W. Grimes 
1552df8bae1dSRodney W. Grimes 	return (error);
1553df8bae1dSRodney W. Grimes }
1554df8bae1dSRodney W. Grimes 
1555df8bae1dSRodney W. Grimes int
1556df8bae1dSRodney W. Grimes union_print(ap)
1557df8bae1dSRodney W. Grimes 	struct vop_print_args /* {
1558df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
1559df8bae1dSRodney W. Grimes 	} */ *ap;
1560df8bae1dSRodney W. Grimes {
1561df8bae1dSRodney W. Grimes 	struct vnode *vp = ap->a_vp;
1562df8bae1dSRodney W. Grimes 
15633a773ad0SPoul-Henning Kamp 	printf("\ttag VT_UNION, vp=%p, uppervp=%p, lowervp=%p\n",
1564df8bae1dSRodney W. Grimes 			vp, UPPERVP(vp), LOWERVP(vp));
1565996c772fSJohn Dyson 	if (UPPERVP(vp) != NULLVP)
1566996c772fSJohn Dyson 		vprint("union: upper", UPPERVP(vp));
1567996c772fSJohn Dyson 	if (LOWERVP(vp) != NULLVP)
1568996c772fSJohn Dyson 		vprint("union: lower", LOWERVP(vp));
1569996c772fSJohn Dyson 
1570df8bae1dSRodney W. Grimes 	return (0);
1571df8bae1dSRodney W. Grimes }
1572df8bae1dSRodney W. Grimes 
1573df8bae1dSRodney W. Grimes int
1574df8bae1dSRodney W. Grimes union_islocked(ap)
1575df8bae1dSRodney W. Grimes 	struct vop_islocked_args /* {
1576df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
1577df8bae1dSRodney W. Grimes 	} */ *ap;
1578df8bae1dSRodney W. Grimes {
1579df8bae1dSRodney W. Grimes 
1580df8bae1dSRodney W. Grimes 	return ((VTOUNION(ap->a_vp)->un_flags & UN_LOCKED) ? 1 : 0);
1581df8bae1dSRodney W. Grimes }
1582df8bae1dSRodney W. Grimes 
1583df8bae1dSRodney W. Grimes int
1584df8bae1dSRodney W. Grimes union_pathconf(ap)
1585df8bae1dSRodney W. Grimes 	struct vop_pathconf_args /* {
1586df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
1587df8bae1dSRodney W. Grimes 		int a_name;
1588df8bae1dSRodney W. Grimes 		int *a_retval;
1589df8bae1dSRodney W. Grimes 	} */ *ap;
1590df8bae1dSRodney W. Grimes {
1591df8bae1dSRodney W. Grimes 	int error;
1592996c772fSJohn Dyson 	struct proc *p = curproc;		/* XXX */
1593df8bae1dSRodney W. Grimes 	struct vnode *vp = OTHERVP(ap->a_vp);
1594df8bae1dSRodney W. Grimes 	int dolock = (vp == LOWERVP(ap->a_vp));
1595df8bae1dSRodney W. Grimes 
1596df8bae1dSRodney W. Grimes 	if (dolock)
1597996c772fSJohn Dyson 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
1598df8bae1dSRodney W. Grimes 	else
1599996c772fSJohn Dyson 		FIXUP(VTOUNION(ap->a_vp), p);
1600996c772fSJohn Dyson 	ap->a_vp = vp;
1601996c772fSJohn Dyson 	error = VCALL(vp, VOFFSET(vop_pathconf), ap);
1602df8bae1dSRodney W. Grimes 	if (dolock)
1603996c772fSJohn Dyson 		VOP_UNLOCK(vp, 0, p);
1604df8bae1dSRodney W. Grimes 
1605df8bae1dSRodney W. Grimes 	return (error);
1606df8bae1dSRodney W. Grimes }
1607df8bae1dSRodney W. Grimes 
1608df8bae1dSRodney W. Grimes int
1609df8bae1dSRodney W. Grimes union_advlock(ap)
1610df8bae1dSRodney W. Grimes 	struct vop_advlock_args /* {
1611df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
1612df8bae1dSRodney W. Grimes 		caddr_t  a_id;
1613df8bae1dSRodney W. Grimes 		int  a_op;
1614df8bae1dSRodney W. Grimes 		struct flock *a_fl;
1615df8bae1dSRodney W. Grimes 		int  a_flags;
1616df8bae1dSRodney W. Grimes 	} */ *ap;
1617df8bae1dSRodney W. Grimes {
1618996c772fSJohn Dyson 	register struct vnode *ovp = OTHERVP(ap->a_vp);
1619df8bae1dSRodney W. Grimes 
1620996c772fSJohn Dyson 	ap->a_vp = ovp;
1621996c772fSJohn Dyson 	return (VCALL(ovp, VOFFSET(vop_advlock), ap));
1622df8bae1dSRodney W. Grimes }
1623df8bae1dSRodney W. Grimes 
1624df8bae1dSRodney W. Grimes 
1625df8bae1dSRodney W. Grimes /*
1626df8bae1dSRodney W. Grimes  * XXX - vop_strategy must be hand coded because it has no
1627df8bae1dSRodney W. Grimes  * vnode in its arguments.
1628df8bae1dSRodney W. Grimes  * This goes away with a merged VM/buffer cache.
1629df8bae1dSRodney W. Grimes  */
1630df8bae1dSRodney W. Grimes int
1631df8bae1dSRodney W. Grimes union_strategy(ap)
1632df8bae1dSRodney W. Grimes 	struct vop_strategy_args /* {
1633df8bae1dSRodney W. Grimes 		struct buf *a_bp;
1634df8bae1dSRodney W. Grimes 	} */ *ap;
1635df8bae1dSRodney W. Grimes {
1636df8bae1dSRodney W. Grimes 	struct buf *bp = ap->a_bp;
1637df8bae1dSRodney W. Grimes 	int error;
1638df8bae1dSRodney W. Grimes 	struct vnode *savedvp;
1639df8bae1dSRodney W. Grimes 
1640df8bae1dSRodney W. Grimes 	savedvp = bp->b_vp;
1641df8bae1dSRodney W. Grimes 	bp->b_vp = OTHERVP(bp->b_vp);
1642df8bae1dSRodney W. Grimes 
1643df8bae1dSRodney W. Grimes #ifdef DIAGNOSTIC
1644df8bae1dSRodney W. Grimes 	if (bp->b_vp == NULLVP)
1645df8bae1dSRodney W. Grimes 		panic("union_strategy: nil vp");
1646df8bae1dSRodney W. Grimes 	if (((bp->b_flags & B_READ) == 0) &&
1647df8bae1dSRodney W. Grimes 	    (bp->b_vp == LOWERVP(savedvp)))
1648df8bae1dSRodney W. Grimes 		panic("union_strategy: writing to lowervp");
1649df8bae1dSRodney W. Grimes #endif
1650df8bae1dSRodney W. Grimes 
1651df8bae1dSRodney W. Grimes 	error = VOP_STRATEGY(bp);
1652df8bae1dSRodney W. Grimes 	bp->b_vp = savedvp;
1653df8bae1dSRodney W. Grimes 
1654df8bae1dSRodney W. Grimes 	return (error);
1655df8bae1dSRodney W. Grimes }
1656df8bae1dSRodney W. Grimes 
1657df8bae1dSRodney W. Grimes /*
1658df8bae1dSRodney W. Grimes  * Global vfs data structures
1659df8bae1dSRodney W. Grimes  */
1660f57e6547SBruce Evans vop_t **union_vnodeop_p;
1661df8bae1dSRodney W. Grimes struct vnodeopv_entry_desc union_vnodeop_entries[] = {
1662f57e6547SBruce Evans 	{ &vop_default_desc, (vop_t *)vn_default_error },
1663f57e6547SBruce Evans 	{ &vop_lookup_desc, (vop_t *)union_lookup },		/* lookup */
1664f57e6547SBruce Evans 	{ &vop_create_desc, (vop_t *)union_create },		/* create */
1665996c772fSJohn Dyson 	{ &vop_whiteout_desc, (vop_t *)union_whiteout },	/* whiteout */
1666f57e6547SBruce Evans 	{ &vop_mknod_desc, (vop_t *)union_mknod },		/* mknod */
1667f57e6547SBruce Evans 	{ &vop_open_desc, (vop_t *)union_open },		/* open */
1668f57e6547SBruce Evans 	{ &vop_close_desc, (vop_t *)union_close },		/* close */
1669f57e6547SBruce Evans 	{ &vop_access_desc, (vop_t *)union_access },		/* access */
1670f57e6547SBruce Evans 	{ &vop_getattr_desc, (vop_t *)union_getattr },		/* getattr */
1671f57e6547SBruce Evans 	{ &vop_setattr_desc, (vop_t *)union_setattr },		/* setattr */
1672f57e6547SBruce Evans 	{ &vop_read_desc, (vop_t *)union_read },		/* read */
1673f57e6547SBruce Evans 	{ &vop_write_desc, (vop_t *)union_write },		/* write */
1674996c772fSJohn Dyson 	{ &vop_lease_desc, (vop_t *)union_lease },		/* lease */
1675f57e6547SBruce Evans 	{ &vop_ioctl_desc, (vop_t *)union_ioctl },		/* ioctl */
1676f57e6547SBruce Evans 	{ &vop_select_desc, (vop_t *)union_select },		/* select */
1677996c772fSJohn Dyson 	{ &vop_revoke_desc, (vop_t *)union_revoke },		/* revoke */
1678f57e6547SBruce Evans 	{ &vop_mmap_desc, (vop_t *)union_mmap },		/* mmap */
1679f57e6547SBruce Evans 	{ &vop_fsync_desc, (vop_t *)union_fsync },		/* fsync */
1680f57e6547SBruce Evans 	{ &vop_seek_desc, (vop_t *)union_seek },		/* seek */
1681f57e6547SBruce Evans 	{ &vop_remove_desc, (vop_t *)union_remove },		/* remove */
1682f57e6547SBruce Evans 	{ &vop_link_desc, (vop_t *)union_link },		/* link */
1683f57e6547SBruce Evans 	{ &vop_rename_desc, (vop_t *)union_rename },		/* rename */
1684f57e6547SBruce Evans 	{ &vop_mkdir_desc, (vop_t *)union_mkdir },		/* mkdir */
1685f57e6547SBruce Evans 	{ &vop_rmdir_desc, (vop_t *)union_rmdir },		/* rmdir */
1686f57e6547SBruce Evans 	{ &vop_symlink_desc, (vop_t *)union_symlink },		/* symlink */
1687f57e6547SBruce Evans 	{ &vop_readdir_desc, (vop_t *)union_readdir },		/* readdir */
1688f57e6547SBruce Evans 	{ &vop_readlink_desc, (vop_t *)union_readlink },	/* readlink */
1689f57e6547SBruce Evans 	{ &vop_abortop_desc, (vop_t *)union_abortop },		/* abortop */
1690f57e6547SBruce Evans 	{ &vop_inactive_desc, (vop_t *)union_inactive },	/* inactive */
1691f57e6547SBruce Evans 	{ &vop_reclaim_desc, (vop_t *)union_reclaim },		/* reclaim */
1692f57e6547SBruce Evans 	{ &vop_lock_desc, (vop_t *)union_lock },		/* lock */
1693f57e6547SBruce Evans 	{ &vop_unlock_desc, (vop_t *)union_unlock },		/* unlock */
1694f57e6547SBruce Evans 	{ &vop_bmap_desc, (vop_t *)union_bmap },		/* bmap */
1695f57e6547SBruce Evans 	{ &vop_strategy_desc, (vop_t *)union_strategy },	/* strategy */
1696f57e6547SBruce Evans 	{ &vop_print_desc, (vop_t *)union_print },		/* print */
1697f57e6547SBruce Evans 	{ &vop_islocked_desc, (vop_t *)union_islocked },	/* islocked */
1698f57e6547SBruce Evans 	{ &vop_pathconf_desc, (vop_t *)union_pathconf },	/* pathconf */
1699f57e6547SBruce Evans 	{ &vop_advlock_desc, (vop_t *)union_advlock },		/* advlock */
1700df8bae1dSRodney W. Grimes #ifdef notdef
1701f57e6547SBruce Evans 	{ &vop_blkatoff_desc, (vop_t *)union_blkatoff },	/* blkatoff */
1702f57e6547SBruce Evans 	{ &vop_valloc_desc, (vop_t *)union_valloc },		/* valloc */
1703f57e6547SBruce Evans 	{ &vop_vfree_desc, (vop_t *)union_vfree },		/* vfree */
1704f57e6547SBruce Evans 	{ &vop_truncate_desc, (vop_t *)union_truncate },	/* truncate */
1705f57e6547SBruce Evans 	{ &vop_update_desc, (vop_t *)union_update },		/* update */
1706f57e6547SBruce Evans 	{ &vop_bwrite_desc, (vop_t *)union_bwrite },		/* bwrite */
1707df8bae1dSRodney W. Grimes #endif
1708f57e6547SBruce Evans 	{ NULL, NULL }
1709df8bae1dSRodney W. Grimes };
1710df8bae1dSRodney W. Grimes struct vnodeopv_desc union_vnodeop_opv_desc =
1711df8bae1dSRodney W. Grimes 	{ &union_vnodeop_p, union_vnodeop_entries };
1712c901836cSGarrett Wollman 
1713c901836cSGarrett Wollman VNODEOP_SET(union_vnodeop_opv_desc);
1714