165935Spendry /* 265935Spendry * Copyright (c) 1992, 1993, 1994 The Regents of the University of California. 365935Spendry * Copyright (c) 1992, 1993, 1994 Jan-Simon Pendry. 465935Spendry * All rights reserved. 565935Spendry * 665935Spendry * This code is derived from software contributed to Berkeley by 765963Spendry * Jan-Simon Pendry. 865935Spendry * 965935Spendry * %sccs.include.redist.c% 1065935Spendry * 11*66027Spendry * @(#)union_vnops.c 1.7 (Berkeley) 02/07/94 1265935Spendry */ 1365935Spendry 1465935Spendry #include <sys/param.h> 1565935Spendry #include <sys/systm.h> 1665935Spendry #include <sys/proc.h> 1765935Spendry #include <sys/file.h> 1865935Spendry #include <sys/time.h> 1965935Spendry #include <sys/types.h> 2065935Spendry #include <sys/vnode.h> 2165935Spendry #include <sys/mount.h> 2265935Spendry #include <sys/namei.h> 2365935Spendry #include <sys/malloc.h> 2465935Spendry #include <sys/buf.h> 2565935Spendry #include "union.h" 2665935Spendry 2765935Spendry static int 2865989Spendry union_lookup1(udvp, dvp, vpp, cnp) 2965989Spendry struct vnode *udvp; 3065935Spendry struct vnode *dvp; 3165935Spendry struct vnode **vpp; 3265935Spendry struct componentname *cnp; 3365935Spendry { 3465935Spendry int error; 3565935Spendry struct vnode *tdvp; 3665935Spendry struct mount *mp; 3765935Spendry 3865994Spendry /* 3965994Spendry * If stepping up the directory tree, check for going 4065994Spendry * back across the mount point, in which case do what 4165994Spendry * lookup would do by stepping back down the mount 4265994Spendry * hierarchy. 4365994Spendry */ 4465935Spendry if (cnp->cn_flags & ISDOTDOT) { 4565935Spendry for (;;) { 4665935Spendry if ((dvp->v_flag & VROOT) == 0 || 4765935Spendry (cnp->cn_flags & NOCROSSMOUNT)) 4865935Spendry break; 4965935Spendry 5065935Spendry tdvp = dvp; 5165935Spendry dvp = dvp->v_mount->mnt_vnodecovered; 5265935Spendry vput(tdvp); 5365935Spendry VREF(dvp); 5465935Spendry VOP_LOCK(dvp); 5565935Spendry } 5665935Spendry } 57*66027Spendry 5865935Spendry error = VOP_LOOKUP(dvp, &tdvp, cnp); 5965935Spendry if (error) 6065935Spendry return (error); 6165935Spendry 6265994Spendry /* 63*66027Spendry * The parent directory will have been unlocked, unless lookup 64*66027Spendry * found the last component. In which case, re-lock the node 65*66027Spendry * here to allow it to be unlocked again (phew) in union_lookup. 6665994Spendry */ 67*66027Spendry if (dvp != tdvp && !(cnp->cn_flags & ISLASTCN)) 6865994Spendry VOP_LOCK(dvp); 6965994Spendry 7065935Spendry dvp = tdvp; 7165994Spendry 7265994Spendry /* 7365994Spendry * Lastly check if the current node is a mount point in 7465994Spendry * which cse walk up the mount hierarchy making sure not to 7565994Spendry * bump into the root of the mount tree (ie. dvp != udvp). 7665994Spendry */ 7765989Spendry while (dvp != udvp && (dvp->v_type == VDIR) && 7865989Spendry (mp = dvp->v_mountedhere) && 7965935Spendry (cnp->cn_flags & NOCROSSMOUNT) == 0) { 8065935Spendry 8165935Spendry if (mp->mnt_flag & MNT_MLOCK) { 8265935Spendry mp->mnt_flag |= MNT_MWAIT; 8365935Spendry sleep((caddr_t) mp, PVFS); 8465935Spendry continue; 8565935Spendry } 8665935Spendry 8765935Spendry if (error = VFS_ROOT(mp, &tdvp)) { 8865935Spendry vput(dvp); 8965935Spendry return (error); 9065935Spendry } 9165935Spendry 9265965Spendry vput(dvp); 9365935Spendry dvp = tdvp; 9465935Spendry } 9565935Spendry 9665935Spendry *vpp = dvp; 9765935Spendry return (0); 9865935Spendry } 9965935Spendry 10065935Spendry int 10165935Spendry union_lookup(ap) 10265935Spendry struct vop_lookup_args /* { 10365935Spendry struct vnodeop_desc *a_desc; 10465935Spendry struct vnode *a_dvp; 10565935Spendry struct vnode **a_vpp; 10665935Spendry struct componentname *a_cnp; 10765935Spendry } */ *ap; 10865935Spendry { 10965965Spendry int error; 11065935Spendry int uerror, lerror; 11165935Spendry struct vnode *uppervp, *lowervp; 11265935Spendry struct vnode *upperdvp, *lowerdvp; 11365935Spendry struct vnode *dvp = ap->a_dvp; 11465989Spendry struct union_node *dun = VTOUNION(dvp); 11565935Spendry struct componentname *cnp = ap->a_cnp; 11665935Spendry int lockparent = cnp->cn_flags & LOCKPARENT; 11765994Spendry int rdonly = cnp->cn_flags & RDONLY; 11865997Spendry struct union_mount *um = MOUNTTOUNIONMOUNT(dvp->v_mount); 11965935Spendry 12065965Spendry cnp->cn_flags |= LOCKPARENT; 12165965Spendry 12265935Spendry upperdvp = dun->un_uppervp; 12365935Spendry lowerdvp = dun->un_lowervp; 12465997Spendry uppervp = NULLVP; 12565997Spendry lowervp = NULLVP; 12665935Spendry 12765935Spendry /* 12865935Spendry * do the lookup in the upper level. 12965935Spendry * if that level comsumes additional pathnames, 13065935Spendry * then assume that something special is going 13165935Spendry * on and just return that vnode. 13265935Spendry */ 13365935Spendry if (upperdvp) { 13465965Spendry VOP_LOCK(upperdvp); 13565997Spendry uerror = union_lookup1(um->um_uppervp, upperdvp, 13665997Spendry &uppervp, cnp); 13765989Spendry if (uppervp != upperdvp) 13865989Spendry VOP_UNLOCK(upperdvp); 13965965Spendry 14065935Spendry if (cnp->cn_consume != 0) { 14165935Spendry *ap->a_vpp = uppervp; 14265965Spendry if (!lockparent) 14365965Spendry cnp->cn_flags &= ~LOCKPARENT; 14465935Spendry return (uerror); 14565935Spendry } 14665935Spendry } else { 14765935Spendry uerror = ENOENT; 14865935Spendry } 14965935Spendry 15065935Spendry /* 15165935Spendry * in a similar way to the upper layer, do the lookup 15265935Spendry * in the lower layer. this time, if there is some 15365935Spendry * component magic going on, then vput whatever we got 15465935Spendry * back from the upper layer and return the lower vnode 15565935Spendry * instead. 15665935Spendry */ 15765935Spendry if (lowerdvp) { 15865965Spendry VOP_LOCK(lowerdvp); 15965997Spendry lerror = union_lookup1(um->um_lowervp, lowerdvp, 16065997Spendry &lowervp, cnp); 16165989Spendry if (lowervp != lowerdvp) 16265989Spendry VOP_UNLOCK(lowerdvp); 16365965Spendry 16465935Spendry if (cnp->cn_consume != 0) { 16565935Spendry if (uppervp) { 16665935Spendry vput(uppervp); 16765997Spendry uppervp = NULLVP; 16865935Spendry } 16965935Spendry *ap->a_vpp = lowervp; 17065965Spendry if (!lockparent) 17165965Spendry cnp->cn_flags &= ~LOCKPARENT; 17265935Spendry return (lerror); 17365935Spendry } 17465935Spendry } else { 17565935Spendry lerror = ENOENT; 17665935Spendry } 17765935Spendry 17865965Spendry if (!lockparent) 17965965Spendry cnp->cn_flags &= ~LOCKPARENT; 18065965Spendry 18165935Spendry /* 18265935Spendry * at this point, we have uerror and lerror indicating 18365935Spendry * possible errors with the lookups in the upper and lower 18465935Spendry * layers. additionally, uppervp and lowervp are (locked) 18565935Spendry * references to existing vnodes in the upper and lower layers. 18665935Spendry * 18765935Spendry * there are now three cases to consider. 18865935Spendry * 1. if both layers returned an error, then return whatever 18965935Spendry * error the upper layer generated. 19065935Spendry * 19165935Spendry * 2. if the top layer failed and the bottom layer succeeded 19265935Spendry * then two subcases occur. 19365935Spendry * a. the bottom vnode is not a directory, in which 19465935Spendry * case just return a new union vnode referencing 19565935Spendry * an empty top layer and the existing bottom layer. 19665935Spendry * b. the bottom vnode is a directory, in which case 19765935Spendry * create a new directory in the top-level and 19865935Spendry * continue as in case 3. 19965935Spendry * 20065935Spendry * 3. if the top layer succeeded then return a new union 20165935Spendry * vnode referencing whatever the new top layer and 20265935Spendry * whatever the bottom layer returned. 20365935Spendry */ 20465935Spendry 205*66027Spendry *ap->a_vpp = NULLVP; 206*66027Spendry 20765935Spendry /* case 1. */ 20865935Spendry if ((uerror != 0) && (lerror != 0)) { 20965935Spendry return (uerror); 21065935Spendry } 21165935Spendry 21265935Spendry /* case 2. */ 21365935Spendry if (uerror != 0 /* && (lerror == 0) */ ) { 21465935Spendry if (lowervp->v_type == VDIR) { /* case 2b. */ 21565997Spendry uerror = union_mkshadow(um, upperdvp, cnp, &uppervp); 21665935Spendry if (uerror) { 21765935Spendry if (lowervp) { 21865935Spendry vput(lowervp); 21965997Spendry lowervp = NULLVP; 22065935Spendry } 22165935Spendry return (uerror); 22265935Spendry } 22365935Spendry } 22465935Spendry } 22565935Spendry 22665965Spendry if (uppervp) 22765965Spendry VOP_UNLOCK(uppervp); 22865965Spendry if (lowervp) 22965965Spendry VOP_UNLOCK(lowervp); 23065965Spendry 23165997Spendry error = union_allocvp(ap->a_vpp, dvp->v_mount, dvp, upperdvp, cnp, 23265997Spendry uppervp, lowervp); 23365997Spendry 23465965Spendry if (error) { 23565965Spendry if (uppervp) 23665965Spendry vrele(uppervp); 23765965Spendry if (lowervp) 23865965Spendry vrele(lowervp); 23965965Spendry } else { 24065994Spendry if (*ap->a_vpp != dvp) 24165994Spendry if (!lockparent || !(cnp->cn_flags & ISLASTCN)) 24265994Spendry VOP_UNLOCK(dvp); 24365965Spendry } 24465965Spendry 24565965Spendry return (error); 24665935Spendry } 24765935Spendry 24865963Spendry int 24965963Spendry union_create(ap) 25065963Spendry struct vop_create_args /* { 25165963Spendry struct vnode *a_dvp; 25265963Spendry struct vnode **a_vpp; 25365963Spendry struct componentname *a_cnp; 25465963Spendry struct vattr *a_vap; 25565963Spendry } */ *ap; 25665963Spendry { 25765963Spendry struct union_node *un = VTOUNION(ap->a_dvp); 25865963Spendry struct vnode *dvp = un->un_uppervp; 25965963Spendry 26065963Spendry if (dvp) { 26165963Spendry int error; 26265963Spendry struct vnode *vp; 26365963Spendry 26465963Spendry VREF(dvp); 26565963Spendry VOP_LOCK(dvp); 26665963Spendry vput(ap->a_dvp); 26765963Spendry error = VOP_CREATE(dvp, &vp, ap->a_cnp, ap->a_vap); 26865963Spendry if (error) 26965963Spendry return (error); 27065963Spendry 27165997Spendry VOP_UNLOCK(vp); 27265997Spendry 27365963Spendry error = union_allocvp( 27465963Spendry ap->a_vpp, 27565989Spendry ap->a_dvp->v_mount, 27665989Spendry ap->a_dvp, 27765965Spendry NULLVP, 27865963Spendry ap->a_cnp, 27965963Spendry vp, 28065963Spendry NULLVP); 28165965Spendry if (error) 28265965Spendry vrele(vp); 28365963Spendry return (error); 28465963Spendry } 28565963Spendry 28665963Spendry vput(ap->a_dvp); 28765963Spendry return (EROFS); 28865963Spendry } 28965963Spendry 29065963Spendry int 29165963Spendry union_mknod(ap) 29265963Spendry struct vop_mknod_args /* { 29365963Spendry struct vnode *a_dvp; 29465963Spendry struct vnode **a_vpp; 29565963Spendry struct componentname *a_cnp; 29665963Spendry struct vattr *a_vap; 29765963Spendry } */ *ap; 29865963Spendry { 29965963Spendry struct union_node *un = VTOUNION(ap->a_dvp); 30065963Spendry struct vnode *dvp = un->un_uppervp; 30165963Spendry 30265963Spendry if (dvp) { 30365963Spendry int error; 30465963Spendry struct vnode *vp; 30565963Spendry 30665963Spendry VREF(dvp); 30765963Spendry VOP_LOCK(dvp); 30865963Spendry vput(ap->a_dvp); 30965963Spendry error = VOP_MKNOD(dvp, &vp, ap->a_cnp, ap->a_vap); 31065963Spendry if (error) 31165963Spendry return (error); 31265963Spendry 31365965Spendry if (vp) { 31465997Spendry VOP_UNLOCK(vp); 31565997Spendry 31665965Spendry error = union_allocvp( 31765965Spendry ap->a_vpp, 31865989Spendry ap->a_dvp->v_mount, 31965989Spendry ap->a_dvp, 32065965Spendry NULLVP, 32165965Spendry ap->a_cnp, 32265965Spendry vp, 32365965Spendry NULLVP); 32465965Spendry if (error) 32565965Spendry vrele(vp); 32665965Spendry } 32765963Spendry return (error); 32865963Spendry } 32965963Spendry 33065963Spendry vput(ap->a_dvp); 33165963Spendry return (EROFS); 33265963Spendry } 33365963Spendry 33465935Spendry int 33565935Spendry union_open(ap) 33665935Spendry struct vop_open_args /* { 33765935Spendry struct vnodeop_desc *a_desc; 33865935Spendry struct vnode *a_vp; 33965935Spendry int a_mode; 34065935Spendry struct ucred *a_cred; 34165935Spendry struct proc *a_p; 34265935Spendry } */ *ap; 34365935Spendry { 34465935Spendry struct union_node *un = VTOUNION(ap->a_vp); 34565965Spendry struct vnode *tvp; 34665935Spendry int mode = ap->a_mode; 34765935Spendry struct ucred *cred = ap->a_cred; 34865935Spendry struct proc *p = ap->a_p; 34965965Spendry int error; 35065935Spendry 35165935Spendry /* 35265935Spendry * If there is an existing upper vp then simply open that. 35365935Spendry */ 35465965Spendry tvp = un->un_uppervp; 35565965Spendry if (tvp == NULLVP) { 35665935Spendry /* 35765965Spendry * If the lower vnode is being opened for writing, then 35865965Spendry * copy the file contents to the upper vnode and open that, 35965965Spendry * otherwise can simply open the lower vnode. 36065935Spendry */ 36165965Spendry tvp = un->un_lowervp; 36265965Spendry if ((ap->a_mode & FWRITE) && (tvp->v_type == VREG)) { 36365994Spendry struct vnode *vp; 36465997Spendry int i; 36565963Spendry 36665965Spendry /* 36765965Spendry * Open the named file in the upper layer. Note that 36865965Spendry * the file may have come into existence *since* the 36965965Spendry * lookup was done, since the upper layer may really 37065965Spendry * be a loopback mount of some other filesystem... 37165965Spendry * so open the file with exclusive create and barf if 37265965Spendry * it already exists. 373*66027Spendry * XXX - perhaps should re-lookup the node (once more 37465965Spendry * with feeling) and simply open that. Who knows. 37565965Spendry */ 37665997Spendry error = union_vn_create(&vp, un, p); 37765965Spendry if (error) 37865965Spendry return (error); 37965994Spendry un->un_uppervp = vp; /* XXX */ 38065965Spendry /* at this point, uppervp is locked */ 38165965Spendry 38265965Spendry /* 38365965Spendry * Now, if the file is being opened with truncation, 38465965Spendry * then the (new) upper vnode is ready to fly, 38565965Spendry * otherwise the data from the lower vnode must be 38665965Spendry * copied to the upper layer first. This only works 38765965Spendry * for regular files (check is made above). 38865965Spendry */ 38965965Spendry if ((mode & O_TRUNC) == 0) { 39065965Spendry /* 39165965Spendry * XXX - should not ignore errors 39265965Spendry * from VOP_CLOSE 39365965Spendry */ 39465994Spendry VOP_LOCK(tvp); 39565965Spendry error = VOP_OPEN(tvp, FREAD, cred, p); 39665965Spendry if (error == 0) { 39765965Spendry error = union_copyfile(p, cred, 39865965Spendry tvp, un->un_uppervp); 39965965Spendry VOP_UNLOCK(tvp); 40065965Spendry (void) VOP_CLOSE(tvp, FREAD); 40165965Spendry } else { 40265965Spendry VOP_UNLOCK(tvp); 40365965Spendry } 40465965Spendry VOP_UNLOCK(un->un_uppervp); 405*66027Spendry union_vn_close(un->un_uppervp, FWRITE); 40665965Spendry VOP_LOCK(un->un_uppervp); 40765997Spendry if (!error) 408*66027Spendry uprintf("union: copied up %s\n", 40965997Spendry un->un_path); 41065935Spendry } 41165997Spendry 41265997Spendry /* 41365997Spendry * Subsequent IOs will go to the top layer, so 41465997Spendry * call close on the lower vnode and open on the 41565997Spendry * upper vnode to ensure that the filesystem keeps 41665997Spendry * its references counts right. This doesn't do 41765997Spendry * the right thing with (cred) and (FREAD) though. 41865997Spendry * Ignoring error returns is not righ, either. 41965997Spendry */ 420*66027Spendry for (i = 0; i < un->un_openl; i++) { 42165997Spendry (void) VOP_CLOSE(tvp, FREAD); 42265997Spendry (void) VOP_OPEN(un->un_uppervp, FREAD, cred, p); 42365997Spendry } 424*66027Spendry un->un_openl = 0; 42565997Spendry 42665965Spendry if (error == 0) 42765965Spendry error = VOP_OPEN(un->un_uppervp, mode, cred, p); 42865963Spendry VOP_UNLOCK(un->un_uppervp); 42965965Spendry return (error); 43065935Spendry } 431*66027Spendry un->un_openl++; 43265935Spendry } 43365935Spendry 43465965Spendry VOP_LOCK(tvp); 43565965Spendry error = VOP_OPEN(tvp, mode, cred, p); 43665965Spendry VOP_UNLOCK(tvp); 43765965Spendry 43865965Spendry return (error); 43965935Spendry } 44065935Spendry 44165963Spendry int 44265963Spendry union_close(ap) 44365963Spendry struct vop_close_args /* { 44465963Spendry struct vnode *a_vp; 44565963Spendry int a_fflag; 44665963Spendry struct ucred *a_cred; 44765963Spendry struct proc *a_p; 44865963Spendry } */ *ap; 44965963Spendry { 45065997Spendry struct union_node *un = VTOUNION(ap->a_vp); 45165997Spendry struct vnode *vp; 45265963Spendry 45365997Spendry if (un->un_uppervp) { 45465997Spendry vp = un->un_uppervp; 45565997Spendry } else { 456*66027Spendry #ifdef UNION_DIAGNOSTIC 457*66027Spendry if (un->un_openl <= 0) 458*66027Spendry panic("union: un_openl cnt"); 45965997Spendry #endif 460*66027Spendry --un->un_openl; 46165997Spendry vp = un->un_lowervp; 46265997Spendry } 463*66027Spendry 46465997Spendry return (VOP_CLOSE(vp, ap->a_fflag, ap->a_cred, ap->a_p)); 46565963Spendry } 46665963Spendry 46765935Spendry /* 46865963Spendry * Check access permission on the union vnode. 46965963Spendry * The access check being enforced is to check 47065963Spendry * against both the underlying vnode, and any 47165963Spendry * copied vnode. This ensures that no additional 47265963Spendry * file permissions are given away simply because 47365963Spendry * the user caused an implicit file copy. 47465963Spendry */ 47565963Spendry int 47665963Spendry union_access(ap) 47765963Spendry struct vop_access_args /* { 47865963Spendry struct vnodeop_desc *a_desc; 47965963Spendry struct vnode *a_vp; 48065963Spendry int a_mode; 48165963Spendry struct ucred *a_cred; 48265963Spendry struct proc *a_p; 48365963Spendry } */ *ap; 48465963Spendry { 48565963Spendry struct union_node *un = VTOUNION(ap->a_vp); 48665965Spendry int error = 0; 48765963Spendry struct vnode *vp; 48865963Spendry 48965963Spendry if (vp = un->un_lowervp) { 49065965Spendry VOP_LOCK(vp); 49165963Spendry error = VOP_ACCESS(vp, ap->a_mode, ap->a_cred, ap->a_p); 49265965Spendry VOP_UNLOCK(vp); 49365963Spendry if (error) 49465963Spendry return (error); 49565963Spendry } 49665963Spendry 49765965Spendry if (vp = un->un_uppervp) { 49865965Spendry VOP_LOCK(vp); 49965965Spendry error = VOP_ACCESS(vp, ap->a_mode, ap->a_cred, ap->a_p); 50065965Spendry VOP_UNLOCK(vp); 50165965Spendry } 50265965Spendry 50365965Spendry return (error); 50465963Spendry } 50565963Spendry 50665963Spendry /* 50765935Spendry * We handle getattr only to change the fsid. 50865935Spendry */ 50965935Spendry int 51065935Spendry union_getattr(ap) 51165935Spendry struct vop_getattr_args /* { 51265935Spendry struct vnode *a_vp; 51365935Spendry struct vattr *a_vap; 51465935Spendry struct ucred *a_cred; 51565935Spendry struct proc *a_p; 51665935Spendry } */ *ap; 51765935Spendry { 51865935Spendry int error; 51965965Spendry struct vnode *vp = OTHERVP(ap->a_vp); 52065935Spendry 52165965Spendry VOP_LOCK(vp); 52265965Spendry error = VOP_GETATTR(vp, ap->a_vap, ap->a_cred, ap->a_p); 52365965Spendry VOP_UNLOCK(vp); 52465965Spendry 52565935Spendry /* Requires that arguments be restored. */ 52665935Spendry ap->a_vap->va_fsid = ap->a_vp->v_mount->mnt_stat.f_fsid.val[0]; 52765935Spendry return (0); 52865935Spendry } 52965935Spendry 53065963Spendry int 53165965Spendry union_setattr(ap) 53265963Spendry struct vop_setattr_args /* { 53365963Spendry struct vnode *a_vp; 53465963Spendry struct vattr *a_vap; 53565963Spendry struct ucred *a_cred; 53665963Spendry struct proc *a_p; 53765963Spendry } */ *ap; 53865963Spendry { 53965963Spendry struct union_node *un = VTOUNION(ap->a_vp); 54065963Spendry int error; 54165963Spendry 54265963Spendry if (un->un_uppervp) { 54365963Spendry VOP_LOCK(un->un_uppervp); 54465963Spendry error = VOP_SETATTR(un->un_uppervp, ap->a_vap, 54565963Spendry ap->a_cred, ap->a_p); 54665963Spendry VOP_UNLOCK(un->un_uppervp); 54765963Spendry } else { 54865963Spendry /* 54965963Spendry * XXX should do a copyfile (perhaps only if 55065963Spendry * the file permission change, which would not 55165963Spendry * track va_ctime correctly). 55265963Spendry */ 55365963Spendry error = EROFS; 55465963Spendry } 55565963Spendry 55665963Spendry return (error); 55765963Spendry } 55865963Spendry 55965963Spendry int 56065963Spendry union_read(ap) 56165963Spendry struct vop_read_args /* { 56265963Spendry struct vnode *a_vp; 56365963Spendry struct uio *a_uio; 56465963Spendry int a_ioflag; 56565963Spendry struct ucred *a_cred; 56665963Spendry } */ *ap; 56765963Spendry { 56865963Spendry int error; 56965963Spendry struct vnode *vp = OTHERVP(ap->a_vp); 57065963Spendry 57165965Spendry VOP_LOCK(vp); 57265963Spendry error = VOP_READ(vp, ap->a_uio, ap->a_ioflag, ap->a_cred); 57365965Spendry VOP_UNLOCK(vp); 57465963Spendry 57565963Spendry return (error); 57665963Spendry } 57765963Spendry 57865963Spendry int 57965963Spendry union_write(ap) 58065963Spendry struct vop_read_args /* { 58165963Spendry struct vnode *a_vp; 58265963Spendry struct uio *a_uio; 58365963Spendry int a_ioflag; 58465963Spendry struct ucred *a_cred; 58565963Spendry } */ *ap; 58665963Spendry { 58765963Spendry int error; 58865963Spendry struct vnode *vp = OTHERVP(ap->a_vp); 58965963Spendry 59065963Spendry VOP_LOCK(vp); 59165963Spendry error = VOP_WRITE(vp, ap->a_uio, ap->a_ioflag, ap->a_cred); 59265963Spendry VOP_UNLOCK(vp); 59365963Spendry 59465963Spendry return (error); 59565963Spendry } 59665963Spendry 59765963Spendry int 59865963Spendry union_ioctl(ap) 59965963Spendry struct vop_ioctl_args /* { 60065963Spendry struct vnode *a_vp; 60165963Spendry int a_command; 60265963Spendry caddr_t a_data; 60365963Spendry int a_fflag; 60465963Spendry struct ucred *a_cred; 60565963Spendry struct proc *a_p; 60665963Spendry } */ *ap; 60765963Spendry { 60865963Spendry 60965963Spendry return (VOP_IOCTL(OTHERVP(ap->a_vp), ap->a_command, ap->a_data, 61065963Spendry ap->a_fflag, ap->a_cred, ap->a_p)); 61165963Spendry } 61265963Spendry 61365963Spendry int 61465963Spendry union_select(ap) 61565963Spendry struct vop_select_args /* { 61665963Spendry struct vnode *a_vp; 61765963Spendry int a_which; 61865963Spendry int a_fflags; 61965963Spendry struct ucred *a_cred; 62065963Spendry struct proc *a_p; 62165963Spendry } */ *ap; 62265963Spendry { 62365963Spendry 62465963Spendry return (VOP_SELECT(OTHERVP(ap->a_vp), ap->a_which, ap->a_fflags, 62565963Spendry ap->a_cred, ap->a_p)); 62665963Spendry } 62765963Spendry 62865963Spendry int 62965963Spendry union_mmap(ap) 63065963Spendry struct vop_mmap_args /* { 63165963Spendry struct vnode *a_vp; 63265963Spendry int a_fflags; 63365963Spendry struct ucred *a_cred; 63465963Spendry struct proc *a_p; 63565963Spendry } */ *ap; 63665963Spendry { 63765963Spendry 63865963Spendry return (VOP_MMAP(OTHERVP(ap->a_vp), ap->a_fflags, 63965963Spendry ap->a_cred, ap->a_p)); 64065963Spendry } 64165963Spendry 64265963Spendry int 64365963Spendry union_fsync(ap) 64465963Spendry struct vop_fsync_args /* { 64565963Spendry struct vnode *a_vp; 64665963Spendry struct ucred *a_cred; 64765963Spendry int a_waitfor; 64865963Spendry struct proc *a_p; 64965963Spendry } */ *ap; 65065963Spendry { 65165963Spendry int error = 0; 65265963Spendry struct vnode *targetvp = OTHERVP(ap->a_vp); 65365963Spendry 65465963Spendry if (targetvp) { 65565963Spendry VOP_LOCK(targetvp); 65665963Spendry error = VOP_FSYNC(targetvp, ap->a_cred, 65765963Spendry ap->a_waitfor, ap->a_p); 65865963Spendry VOP_UNLOCK(targetvp); 65965963Spendry } 66065963Spendry 66165963Spendry return (error); 66265963Spendry } 66365963Spendry 66465963Spendry int 66565963Spendry union_seek(ap) 66665963Spendry struct vop_seek_args /* { 66765963Spendry struct vnode *a_vp; 66865963Spendry off_t a_oldoff; 66965963Spendry off_t a_newoff; 67065963Spendry struct ucred *a_cred; 67165963Spendry } */ *ap; 67265963Spendry { 67365963Spendry 67465963Spendry return (VOP_SEEK(OTHERVP(ap->a_vp), ap->a_oldoff, ap->a_newoff, ap->a_cred)); 67565963Spendry } 67665963Spendry 67765963Spendry int 67865963Spendry union_remove(ap) 67965963Spendry struct vop_remove_args /* { 68065963Spendry struct vnode *a_dvp; 68165963Spendry struct vnode *a_vp; 68265963Spendry struct componentname *a_cnp; 68365963Spendry } */ *ap; 68465963Spendry { 68565963Spendry int error; 68665963Spendry struct union_node *dun = VTOUNION(ap->a_dvp); 68765963Spendry struct union_node *un = VTOUNION(ap->a_vp); 68865963Spendry 68965963Spendry if (dun->un_uppervp && un->un_uppervp) { 69065963Spendry struct vnode *dvp = dun->un_uppervp; 69165963Spendry struct vnode *vp = un->un_uppervp; 69265963Spendry 69365963Spendry VREF(dvp); 69465963Spendry VOP_LOCK(dvp); 69565963Spendry vput(ap->a_dvp); 69665963Spendry VREF(vp); 69765963Spendry VOP_LOCK(vp); 69865963Spendry vput(ap->a_vp); 69965963Spendry 70065963Spendry error = VOP_REMOVE(dvp, vp, ap->a_cnp); 701*66027Spendry if (!error) 702*66027Spendry union_removed_upper(un); 703*66027Spendry 704*66027Spendry /* 705*66027Spendry * XXX: should create a whiteout here 706*66027Spendry */ 70765963Spendry } else { 70865963Spendry /* 70965963Spendry * XXX: should create a whiteout here 71065963Spendry */ 71165963Spendry vput(ap->a_dvp); 71265963Spendry vput(ap->a_vp); 71365963Spendry error = EROFS; 71465963Spendry } 71565963Spendry 71665963Spendry return (error); 71765963Spendry } 71865963Spendry 71965963Spendry int 72065963Spendry union_link(ap) 72165963Spendry struct vop_link_args /* { 72265963Spendry struct vnode *a_vp; 72365963Spendry struct vnode *a_tdvp; 72465963Spendry struct componentname *a_cnp; 72565963Spendry } */ *ap; 72665963Spendry { 72765963Spendry int error; 72865963Spendry struct union_node *dun = VTOUNION(ap->a_vp); 72965963Spendry struct union_node *un = VTOUNION(ap->a_tdvp); 73065963Spendry 73165963Spendry if (dun->un_uppervp && un->un_uppervp) { 73265963Spendry struct vnode *dvp = dun->un_uppervp; 73365963Spendry struct vnode *vp = un->un_uppervp; 73465963Spendry 73565963Spendry VREF(dvp); 73665963Spendry VOP_LOCK(dvp); 73765963Spendry vput(ap->a_vp); 73865963Spendry VREF(vp); 73965963Spendry vrele(ap->a_tdvp); 74065963Spendry 74165963Spendry error = VOP_LINK(dvp, vp, ap->a_cnp); 74265963Spendry } else { 74365963Spendry /* 74465963Spendry * XXX: need to copy to upper layer 74565963Spendry * and do the link there. 74665963Spendry */ 74765963Spendry vput(ap->a_vp); 74865963Spendry vrele(ap->a_tdvp); 74965963Spendry error = EROFS; 75065963Spendry } 75165963Spendry 75265963Spendry return (error); 75365963Spendry } 75465963Spendry 75565963Spendry int 75665963Spendry union_rename(ap) 75765963Spendry struct vop_rename_args /* { 75865963Spendry struct vnode *a_fdvp; 75965963Spendry struct vnode *a_fvp; 76065963Spendry struct componentname *a_fcnp; 76165963Spendry struct vnode *a_tdvp; 76265963Spendry struct vnode *a_tvp; 76365963Spendry struct componentname *a_tcnp; 76465963Spendry } */ *ap; 76565963Spendry { 76665963Spendry int error; 76765963Spendry 76865963Spendry struct vnode *fdvp = ap->a_fdvp; 76965963Spendry struct vnode *fvp = ap->a_fvp; 77065963Spendry struct vnode *tdvp = ap->a_tdvp; 77165963Spendry struct vnode *tvp = ap->a_tvp; 77265963Spendry 77365963Spendry if (fdvp->v_op == union_vnodeop_p) { /* always true */ 77465963Spendry struct union_node *un = VTOUNION(fdvp); 77565997Spendry if (un->un_uppervp == NULLVP) { 77665963Spendry error = EROFS; 77765963Spendry goto bad; 77865963Spendry } 77965963Spendry 78065963Spendry fdvp = un->un_uppervp; 78165963Spendry VREF(fdvp); 78265963Spendry vrele(ap->a_fdvp); 78365963Spendry } 78465963Spendry 78565963Spendry if (fvp->v_op == union_vnodeop_p) { /* always true */ 78665963Spendry struct union_node *un = VTOUNION(fvp); 78765997Spendry if (un->un_uppervp == NULLVP) { 78865963Spendry error = EROFS; 78965963Spendry goto bad; 79065963Spendry } 79165963Spendry 79265963Spendry fvp = un->un_uppervp; 79365963Spendry VREF(fvp); 79465963Spendry vrele(ap->a_fvp); 79565963Spendry } 79665963Spendry 79765963Spendry if (tdvp->v_op == union_vnodeop_p) { 79865963Spendry struct union_node *un = VTOUNION(tdvp); 79965997Spendry if (un->un_uppervp == NULLVP) { 80065963Spendry error = EROFS; 80165963Spendry goto bad; 80265963Spendry } 80365963Spendry 80465963Spendry tdvp = un->un_uppervp; 80565963Spendry VREF(tdvp); 80665963Spendry VOP_LOCK(tdvp); 80765997Spendry vput(ap->a_tdvp); 80865963Spendry } 80965963Spendry 81065963Spendry if (tvp && tvp->v_op == union_vnodeop_p) { 81165963Spendry struct union_node *un = VTOUNION(tvp); 81265997Spendry if (un->un_uppervp == NULLVP) { 81365963Spendry error = EROFS; 81465963Spendry goto bad; 81565963Spendry } 81665963Spendry 81765963Spendry tvp = un->un_uppervp; 81865963Spendry VREF(tvp); 81965963Spendry VOP_LOCK(tvp); 82065963Spendry vput(ap->a_tvp); 82165963Spendry } 82265963Spendry 82365963Spendry return (VOP_RENAME(fdvp, fvp, ap->a_fcnp, tdvp, tvp, ap->a_tcnp)); 82465963Spendry 82565963Spendry bad: 82665963Spendry vrele(fdvp); 82765963Spendry vrele(fvp); 82865963Spendry vput(tdvp); 82965963Spendry if (tvp) 83065963Spendry vput(tvp); 83165963Spendry 83265963Spendry return (error); 83365963Spendry } 83465963Spendry 83565963Spendry int 83665963Spendry union_mkdir(ap) 83765963Spendry struct vop_mkdir_args /* { 83865963Spendry struct vnode *a_dvp; 83965963Spendry struct vnode **a_vpp; 84065963Spendry struct componentname *a_cnp; 84165963Spendry struct vattr *a_vap; 84265963Spendry } */ *ap; 84365963Spendry { 84465963Spendry struct union_node *un = VTOUNION(ap->a_dvp); 84565963Spendry struct vnode *dvp = un->un_uppervp; 84665963Spendry 84765963Spendry if (dvp) { 84865963Spendry int error; 84965963Spendry struct vnode *vp; 85065963Spendry 85165963Spendry VREF(dvp); 85265963Spendry VOP_LOCK(dvp); 85365963Spendry vput(ap->a_dvp); 85465963Spendry error = VOP_MKDIR(dvp, &vp, ap->a_cnp, ap->a_vap); 85565963Spendry if (error) 85665963Spendry return (error); 85765963Spendry 85865997Spendry VOP_UNLOCK(vp); 85965963Spendry error = union_allocvp( 86065963Spendry ap->a_vpp, 86165989Spendry ap->a_dvp->v_mount, 86265989Spendry ap->a_dvp, 86365965Spendry NULLVP, 86465963Spendry ap->a_cnp, 86565963Spendry vp, 86665963Spendry NULLVP); 86765965Spendry if (error) 86865965Spendry vrele(vp); 86965963Spendry return (error); 87065963Spendry } 87165963Spendry 87265963Spendry vput(ap->a_dvp); 87365963Spendry return (EROFS); 87465963Spendry } 87565963Spendry 87665963Spendry int 87765963Spendry union_rmdir(ap) 87865963Spendry struct vop_rmdir_args /* { 87965963Spendry struct vnode *a_dvp; 88065963Spendry struct vnode *a_vp; 88165963Spendry struct componentname *a_cnp; 88265963Spendry } */ *ap; 88365963Spendry { 88465963Spendry int error; 88565963Spendry struct union_node *dun = VTOUNION(ap->a_dvp); 88665963Spendry struct union_node *un = VTOUNION(ap->a_vp); 88765963Spendry 88865963Spendry if (dun->un_uppervp && un->un_uppervp) { 88965963Spendry struct vnode *dvp = dun->un_uppervp; 89065963Spendry struct vnode *vp = un->un_uppervp; 89165963Spendry 89265963Spendry VREF(dvp); 89365963Spendry VOP_LOCK(dvp); 89465963Spendry vput(ap->a_dvp); 89565963Spendry VREF(vp); 89665963Spendry VOP_LOCK(vp); 89765963Spendry vput(ap->a_vp); 89865963Spendry 89965963Spendry error = VOP_REMOVE(dvp, vp, ap->a_cnp); 900*66027Spendry if (!error) 901*66027Spendry union_removed_upper(un); 902*66027Spendry 903*66027Spendry /* 904*66027Spendry * XXX: should create a whiteout here 905*66027Spendry */ 90665963Spendry } else { 90765963Spendry /* 90865963Spendry * XXX: should create a whiteout here 90965963Spendry */ 91065963Spendry vput(ap->a_dvp); 91165963Spendry vput(ap->a_vp); 91265963Spendry error = EROFS; 91365963Spendry } 91465963Spendry 91565963Spendry return (error); 91665963Spendry } 91765963Spendry 91865963Spendry int 91965963Spendry union_symlink(ap) 92065963Spendry struct vop_symlink_args /* { 92165963Spendry struct vnode *a_dvp; 92265963Spendry struct vnode **a_vpp; 92365963Spendry struct componentname *a_cnp; 92465963Spendry struct vattr *a_vap; 92565963Spendry char *a_target; 92665963Spendry } */ *ap; 92765963Spendry { 92865963Spendry struct union_node *un = VTOUNION(ap->a_dvp); 92965963Spendry struct vnode *dvp = un->un_uppervp; 93065963Spendry 93165963Spendry if (dvp) { 93265963Spendry int error; 93365963Spendry struct vnode *vp; 93465963Spendry struct mount *mp = ap->a_dvp->v_mount; 93565963Spendry 93665963Spendry VREF(dvp); 93765963Spendry VOP_LOCK(dvp); 93865963Spendry vput(ap->a_dvp); 93965963Spendry error = VOP_SYMLINK(dvp, &vp, ap->a_cnp, 94065963Spendry ap->a_vap, ap->a_target); 94165997Spendry *ap->a_vpp = NULLVP; 94265963Spendry return (error); 94365963Spendry } 94465963Spendry 94565963Spendry vput(ap->a_dvp); 94665963Spendry return (EROFS); 94765963Spendry } 94865963Spendry 94965935Spendry /* 95065935Spendry * union_readdir works in concert with getdirentries and 95165935Spendry * readdir(3) to provide a list of entries in the unioned 95265935Spendry * directories. getdirentries is responsible for walking 95365935Spendry * down the union stack. readdir(3) is responsible for 95465935Spendry * eliminating duplicate names from the returned data stream. 95565935Spendry */ 95665935Spendry int 95765935Spendry union_readdir(ap) 95865935Spendry struct vop_readdir_args /* { 95965935Spendry struct vnodeop_desc *a_desc; 96065935Spendry struct vnode *a_vp; 96165935Spendry struct uio *a_uio; 96265935Spendry struct ucred *a_cred; 96365935Spendry } */ *ap; 96465935Spendry { 96565963Spendry int error = 0; 96665935Spendry struct union_node *un = VTOUNION(ap->a_vp); 96765935Spendry 96865963Spendry if (un->un_uppervp) { 96965963Spendry struct vnode *vp = OTHERVP(ap->a_vp); 97065935Spendry 97165963Spendry VOP_LOCK(vp); 97265963Spendry error = VOP_READLINK(vp, ap->a_uio, ap->a_cred); 97365963Spendry VOP_UNLOCK(vp); 97465963Spendry } 97565963Spendry 97665963Spendry return (error); 97765935Spendry } 97865935Spendry 97965935Spendry int 98065963Spendry union_readlink(ap) 98165963Spendry struct vop_readlink_args /* { 98265963Spendry struct vnode *a_vp; 98365963Spendry struct uio *a_uio; 98465963Spendry struct ucred *a_cred; 98565963Spendry } */ *ap; 98665963Spendry { 98765963Spendry int error; 98865963Spendry struct vnode *vp = OTHERVP(ap->a_vp); 98965963Spendry 99065963Spendry VOP_LOCK(vp); 99165963Spendry error = VOP_READLINK(vp, ap->a_uio, ap->a_cred); 99265963Spendry VOP_UNLOCK(vp); 99365963Spendry 99465963Spendry return (error); 99565963Spendry } 99665963Spendry 99765963Spendry int 99865963Spendry union_abortop(ap) 99965963Spendry struct vop_abortop_args /* { 100065963Spendry struct vnode *a_dvp; 100165963Spendry struct componentname *a_cnp; 100265963Spendry } */ *ap; 100365963Spendry { 100465963Spendry int error; 100565965Spendry struct vnode *vp = OTHERVP(ap->a_dvp); 100665963Spendry struct union_node *un = VTOUNION(ap->a_dvp); 100765963Spendry int islocked = un->un_flags & UN_LOCKED; 100865963Spendry 100965963Spendry if (islocked) 101065963Spendry VOP_LOCK(vp); 101165963Spendry error = VOP_ABORTOP(vp, ap->a_cnp); 101265963Spendry if (islocked) 101365963Spendry VOP_UNLOCK(vp); 101465963Spendry 101565963Spendry return (error); 101665963Spendry } 101765963Spendry 101865963Spendry int 101965935Spendry union_inactive(ap) 102065935Spendry struct vop_inactive_args /* { 102165935Spendry struct vnode *a_vp; 102265935Spendry } */ *ap; 102365935Spendry { 102465935Spendry 102565935Spendry /* 102665935Spendry * Do nothing (and _don't_ bypass). 102765935Spendry * Wait to vrele lowervp until reclaim, 102865935Spendry * so that until then our union_node is in the 102965935Spendry * cache and reusable. 103065935Spendry * 103165935Spendry * NEEDSWORK: Someday, consider inactive'ing 103265935Spendry * the lowervp and then trying to reactivate it 103365935Spendry * with capabilities (v_id) 103465935Spendry * like they do in the name lookup cache code. 103565935Spendry * That's too much work for now. 103665935Spendry */ 103765989Spendry 1038*66027Spendry #ifdef UNION_DIAGNOSTIC 103965989Spendry struct union_node *un = VTOUNION(ap->a_vp); 104065989Spendry 104165989Spendry if (un->un_flags & UN_LOCKED) 104265989Spendry panic("union: inactivating locked node"); 104365989Spendry #endif 104465989Spendry 104565935Spendry return (0); 104665935Spendry } 104765935Spendry 104865935Spendry int 104965935Spendry union_reclaim(ap) 105065935Spendry struct vop_reclaim_args /* { 105165935Spendry struct vnode *a_vp; 105265935Spendry } */ *ap; 105365935Spendry { 105465935Spendry struct vnode *vp = ap->a_vp; 105565935Spendry struct union_node *un = VTOUNION(vp); 105665935Spendry struct vnode *uppervp = un->un_uppervp; 105765935Spendry struct vnode *lowervp = un->un_lowervp; 105865935Spendry struct vnode *dirvp = un->un_dirvp; 105965935Spendry char *path = un->un_path; 106065935Spendry 106165935Spendry /* 106265935Spendry * Note: in vop_reclaim, vp->v_op == dead_vnodeop_p, 106365935Spendry * so we can't call VOPs on ourself. 106465935Spendry */ 106565935Spendry /* After this assignment, this node will not be re-used. */ 106665997Spendry un->un_uppervp = NULLVP; 106765997Spendry un->un_lowervp = NULLVP; 106865997Spendry un->un_dirvp = NULLVP; 106965935Spendry un->un_path = NULL; 107065935Spendry union_freevp(vp); 107165935Spendry if (uppervp) 107265935Spendry vrele(uppervp); 107365935Spendry if (lowervp) 107465935Spendry vrele(lowervp); 107565935Spendry if (dirvp) 107665935Spendry vrele(dirvp); 107765935Spendry if (path) 107865935Spendry free(path, M_TEMP); 107965935Spendry return (0); 108065935Spendry } 108165935Spendry 108265963Spendry int 108365963Spendry union_lock(ap) 108465963Spendry struct vop_lock_args *ap; 108565963Spendry { 108665963Spendry struct union_node *un = VTOUNION(ap->a_vp); 108765935Spendry 108865965Spendry while (un->un_flags & UN_LOCKED) { 108965963Spendry #ifdef DIAGNOSTIC 109065989Spendry if (curproc && un->un_pid == curproc->p_pid && 109165989Spendry un->un_pid > -1 && curproc->p_pid > -1) 109265989Spendry panic("union: locking against myself"); 109365963Spendry #endif 109465963Spendry un->un_flags |= UN_WANT; 109565963Spendry sleep((caddr_t) &un->un_flags, PINOD); 109665963Spendry } 109765963Spendry un->un_flags |= UN_LOCKED; 109865989Spendry 109965963Spendry #ifdef DIAGNOSTIC 110065989Spendry if (curproc) 110165989Spendry un->un_pid = curproc->p_pid; 110265989Spendry else 110365989Spendry un->un_pid = -1; 110465963Spendry #endif 110565963Spendry } 110665963Spendry 110765935Spendry int 110865963Spendry union_unlock(ap) 110965963Spendry struct vop_lock_args *ap; 111065963Spendry { 111165963Spendry struct union_node *un = VTOUNION(ap->a_vp); 111265963Spendry 111365963Spendry #ifdef DIAGNOSTIC 111465965Spendry if ((un->un_flags & UN_LOCKED) == 0) 111565965Spendry panic("union: unlock unlocked node"); 111665989Spendry if (curproc && un->un_pid != curproc->p_pid && 111765989Spendry curproc->p_pid > -1 && un->un_pid > -1) 111865963Spendry panic("union: unlocking other process's union node"); 111965963Spendry #endif 112065963Spendry 112165963Spendry un->un_flags &= ~UN_LOCKED; 112265963Spendry if (un->un_flags & UN_WANT) { 112365963Spendry un->un_flags &= ~UN_WANT; 112465963Spendry wakeup((caddr_t) &un->un_flags); 112565963Spendry } 112665963Spendry 112765963Spendry #ifdef DIAGNOSTIC 112865963Spendry un->un_pid = 0; 112965963Spendry #endif 113065963Spendry } 113165963Spendry 113265963Spendry int 113365963Spendry union_bmap(ap) 113465963Spendry struct vop_bmap_args /* { 113565963Spendry struct vnode *a_vp; 113665963Spendry daddr_t a_bn; 113765963Spendry struct vnode **a_vpp; 113865963Spendry daddr_t *a_bnp; 113965963Spendry int *a_runp; 114065963Spendry } */ *ap; 114165963Spendry { 114265963Spendry int error; 114365963Spendry struct vnode *vp = OTHERVP(ap->a_vp); 114465963Spendry 114565963Spendry VOP_LOCK(vp); 114665963Spendry error = VOP_BMAP(vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp); 114765963Spendry VOP_UNLOCK(vp); 114865963Spendry 114965963Spendry return (error); 115065963Spendry } 115165963Spendry 115265963Spendry int 115365935Spendry union_print(ap) 115465935Spendry struct vop_print_args /* { 115565935Spendry struct vnode *a_vp; 115665935Spendry } */ *ap; 115765935Spendry { 115865935Spendry struct vnode *vp = ap->a_vp; 115965935Spendry 116065935Spendry printf("\ttag VT_UNION, vp=%x, uppervp=%x, lowervp=%x\n", 116165935Spendry vp, UPPERVP(vp), LOWERVP(vp)); 116265935Spendry return (0); 116365935Spendry } 116465935Spendry 116565963Spendry int 116665963Spendry union_islocked(ap) 116765963Spendry struct vop_islocked_args /* { 116865963Spendry struct vnode *a_vp; 116965963Spendry } */ *ap; 117065963Spendry { 117165935Spendry 117265963Spendry return ((VTOUNION(ap->a_vp)->un_flags & UN_LOCKED) ? 1 : 0); 117365963Spendry } 117465963Spendry 117565935Spendry int 117665963Spendry union_pathconf(ap) 117765963Spendry struct vop_pathconf_args /* { 117865963Spendry struct vnode *a_vp; 117965963Spendry int a_name; 118065963Spendry int *a_retval; 118165935Spendry } */ *ap; 118265935Spendry { 118365935Spendry int error; 118465963Spendry struct vnode *vp = OTHERVP(ap->a_vp); 118565935Spendry 118665963Spendry VOP_LOCK(vp); 118765963Spendry error = VOP_PATHCONF(vp, ap->a_name, ap->a_retval); 118865963Spendry VOP_UNLOCK(vp); 118965935Spendry 119065963Spendry return (error); 119165963Spendry } 119265935Spendry 119365963Spendry int 119465963Spendry union_advlock(ap) 119565963Spendry struct vop_advlock_args /* { 119665963Spendry struct vnode *a_vp; 119765963Spendry caddr_t a_id; 119865963Spendry int a_op; 119965963Spendry struct flock *a_fl; 120065963Spendry int a_flags; 120165963Spendry } */ *ap; 120265963Spendry { 120365935Spendry 120465963Spendry return (VOP_ADVLOCK(OTHERVP(ap->a_vp), ap->a_id, ap->a_op, 120565963Spendry ap->a_fl, ap->a_flags)); 120665935Spendry } 120765935Spendry 120865935Spendry 120965935Spendry /* 121065963Spendry * XXX - vop_strategy must be hand coded because it has no 121165935Spendry * vnode in its arguments. 121265935Spendry * This goes away with a merged VM/buffer cache. 121365935Spendry */ 121465935Spendry int 121565963Spendry union_strategy(ap) 121665963Spendry struct vop_strategy_args /* { 121765935Spendry struct buf *a_bp; 121865935Spendry } */ *ap; 121965935Spendry { 122065935Spendry struct buf *bp = ap->a_bp; 122165935Spendry int error; 122265935Spendry struct vnode *savedvp; 122365935Spendry 122465935Spendry savedvp = bp->b_vp; 122565963Spendry bp->b_vp = OTHERVP(bp->b_vp); 122665935Spendry 122765935Spendry #ifdef DIAGNOSTIC 122865997Spendry if (bp->b_vp == NULLVP) 122965963Spendry panic("union_strategy: nil vp"); 123065963Spendry if (((bp->b_flags & B_READ) == 0) && 123165963Spendry (bp->b_vp == LOWERVP(savedvp))) 123265963Spendry panic("union_strategy: writing to lowervp"); 123365935Spendry #endif 123465935Spendry 123565963Spendry error = VOP_STRATEGY(bp); 123665935Spendry bp->b_vp = savedvp; 123765935Spendry 123865935Spendry return (error); 123965935Spendry } 124065935Spendry 124165935Spendry /* 124265935Spendry * Global vfs data structures 124365935Spendry */ 124465935Spendry int (**union_vnodeop_p)(); 124565965Spendry struct vnodeopv_entry_desc union_vnodeop_entries[] = { 124665963Spendry { &vop_default_desc, vn_default_error }, 124765963Spendry { &vop_lookup_desc, union_lookup }, /* lookup */ 124865963Spendry { &vop_create_desc, union_create }, /* create */ 124965963Spendry { &vop_mknod_desc, union_mknod }, /* mknod */ 125065963Spendry { &vop_open_desc, union_open }, /* open */ 125165963Spendry { &vop_close_desc, union_close }, /* close */ 125265963Spendry { &vop_access_desc, union_access }, /* access */ 125365963Spendry { &vop_getattr_desc, union_getattr }, /* getattr */ 125465963Spendry { &vop_setattr_desc, union_setattr }, /* setattr */ 125565963Spendry { &vop_read_desc, union_read }, /* read */ 125665963Spendry { &vop_write_desc, union_write }, /* write */ 125765963Spendry { &vop_ioctl_desc, union_ioctl }, /* ioctl */ 125865963Spendry { &vop_select_desc, union_select }, /* select */ 125965963Spendry { &vop_mmap_desc, union_mmap }, /* mmap */ 126065963Spendry { &vop_fsync_desc, union_fsync }, /* fsync */ 126165963Spendry { &vop_seek_desc, union_seek }, /* seek */ 126265963Spendry { &vop_remove_desc, union_remove }, /* remove */ 126365963Spendry { &vop_link_desc, union_link }, /* link */ 126465963Spendry { &vop_rename_desc, union_rename }, /* rename */ 126565963Spendry { &vop_mkdir_desc, union_mkdir }, /* mkdir */ 126665963Spendry { &vop_rmdir_desc, union_rmdir }, /* rmdir */ 126765963Spendry { &vop_symlink_desc, union_symlink }, /* symlink */ 126865963Spendry { &vop_readdir_desc, union_readdir }, /* readdir */ 126965963Spendry { &vop_readlink_desc, union_readlink }, /* readlink */ 127065963Spendry { &vop_abortop_desc, union_abortop }, /* abortop */ 127165963Spendry { &vop_inactive_desc, union_inactive }, /* inactive */ 127265963Spendry { &vop_reclaim_desc, union_reclaim }, /* reclaim */ 127365963Spendry { &vop_lock_desc, union_lock }, /* lock */ 127465963Spendry { &vop_unlock_desc, union_unlock }, /* unlock */ 127565963Spendry { &vop_bmap_desc, union_bmap }, /* bmap */ 127665963Spendry { &vop_strategy_desc, union_strategy }, /* strategy */ 127765963Spendry { &vop_print_desc, union_print }, /* print */ 127865963Spendry { &vop_islocked_desc, union_islocked }, /* islocked */ 127965963Spendry { &vop_pathconf_desc, union_pathconf }, /* pathconf */ 128065963Spendry { &vop_advlock_desc, union_advlock }, /* advlock */ 128165963Spendry #ifdef notdef 128265963Spendry { &vop_blkatoff_desc, union_blkatoff }, /* blkatoff */ 128365963Spendry { &vop_valloc_desc, union_valloc }, /* valloc */ 128465963Spendry { &vop_vfree_desc, union_vfree }, /* vfree */ 128565963Spendry { &vop_truncate_desc, union_truncate }, /* truncate */ 128665963Spendry { &vop_update_desc, union_update }, /* update */ 128765963Spendry { &vop_bwrite_desc, union_bwrite }, /* bwrite */ 128865963Spendry #endif 128965935Spendry { (struct vnodeop_desc*)NULL, (int(*)())NULL } 129065935Spendry }; 129165935Spendry struct vnodeopv_desc union_vnodeop_opv_desc = 129265935Spendry { &union_vnodeop_p, union_vnodeop_entries }; 1293