10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51314Sowenr * Common Development and Distribution License (the "License"). 61314Sowenr * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 221224Srd117015 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/param.h> 290Sstevel@tonic-gate #include <sys/systm.h> 300Sstevel@tonic-gate #include <sys/errno.h> 310Sstevel@tonic-gate #include <sys/vnode.h> 320Sstevel@tonic-gate #include <sys/vfs.h> 330Sstevel@tonic-gate #include <sys/uio.h> 340Sstevel@tonic-gate #include <sys/cred.h> 350Sstevel@tonic-gate #include <sys/pathname.h> 360Sstevel@tonic-gate #include <sys/debug.h> 370Sstevel@tonic-gate #include <sys/fs/lofs_node.h> 380Sstevel@tonic-gate #include <sys/fs/lofs_info.h> 390Sstevel@tonic-gate #include <fs/fs_subr.h> 400Sstevel@tonic-gate #include <vm/as.h> 410Sstevel@tonic-gate #include <vm/seg.h> 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* 440Sstevel@tonic-gate * These are the vnode ops routines which implement the vnode interface to 450Sstevel@tonic-gate * the looped-back file system. These routines just take their parameters, 460Sstevel@tonic-gate * and then calling the appropriate real vnode routine(s) to do the work. 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate 490Sstevel@tonic-gate static int 500Sstevel@tonic-gate lo_open(vnode_t **vpp, int flag, struct cred *cr) 510Sstevel@tonic-gate { 520Sstevel@tonic-gate vnode_t *vp = *vpp; 530Sstevel@tonic-gate vnode_t *rvp; 540Sstevel@tonic-gate vnode_t *oldvp; 550Sstevel@tonic-gate int error; 560Sstevel@tonic-gate 570Sstevel@tonic-gate #ifdef LODEBUG 580Sstevel@tonic-gate lo_dprint(4, "lo_open vp %p cnt=%d realvp %p cnt=%d\n", 590Sstevel@tonic-gate vp, vp->v_count, realvp(vp), realvp(vp)->v_count); 600Sstevel@tonic-gate #endif 610Sstevel@tonic-gate 620Sstevel@tonic-gate oldvp = vp; 630Sstevel@tonic-gate vp = rvp = realvp(vp); 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * Need to hold new reference to vp since VOP_OPEN() may 660Sstevel@tonic-gate * decide to release it. 670Sstevel@tonic-gate */ 680Sstevel@tonic-gate VN_HOLD(vp); 690Sstevel@tonic-gate error = VOP_OPEN(&rvp, flag, cr); 700Sstevel@tonic-gate 710Sstevel@tonic-gate if (!error && rvp != vp) { 720Sstevel@tonic-gate /* 730Sstevel@tonic-gate * the FS which we called should have released the 740Sstevel@tonic-gate * new reference on vp 750Sstevel@tonic-gate */ 76324Sowenr *vpp = makelonode(rvp, vtoli(oldvp->v_vfsp), 0); 771314Sowenr if ((*vpp)->v_type == VDIR) { 781314Sowenr /* 791314Sowenr * Copy over any looping flags to the new lnode. 801314Sowenr */ 811314Sowenr (vtol(*vpp))->lo_looping |= (vtol(oldvp))->lo_looping; 821314Sowenr } 830Sstevel@tonic-gate if (IS_DEVVP(*vpp)) { 840Sstevel@tonic-gate vnode_t *svp; 850Sstevel@tonic-gate 860Sstevel@tonic-gate svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr); 870Sstevel@tonic-gate VN_RELE(*vpp); 880Sstevel@tonic-gate if (svp == NULL) 890Sstevel@tonic-gate error = ENOSYS; 900Sstevel@tonic-gate else 910Sstevel@tonic-gate *vpp = svp; 920Sstevel@tonic-gate } 930Sstevel@tonic-gate VN_RELE(oldvp); 940Sstevel@tonic-gate } else { 950Sstevel@tonic-gate ASSERT(rvp->v_count > 1); 960Sstevel@tonic-gate VN_RELE(rvp); 970Sstevel@tonic-gate } 980Sstevel@tonic-gate 990Sstevel@tonic-gate return (error); 1000Sstevel@tonic-gate } 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate static int 1030Sstevel@tonic-gate lo_close( 1040Sstevel@tonic-gate vnode_t *vp, 1050Sstevel@tonic-gate int flag, 1060Sstevel@tonic-gate int count, 1070Sstevel@tonic-gate offset_t offset, 1080Sstevel@tonic-gate struct cred *cr) 1090Sstevel@tonic-gate { 1100Sstevel@tonic-gate #ifdef LODEBUG 1110Sstevel@tonic-gate lo_dprint(4, "lo_close vp %p realvp %p\n", vp, realvp(vp)); 1120Sstevel@tonic-gate #endif 1130Sstevel@tonic-gate vp = realvp(vp); 1140Sstevel@tonic-gate return (VOP_CLOSE(vp, flag, count, offset, cr)); 1150Sstevel@tonic-gate } 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate static int 1180Sstevel@tonic-gate lo_read(vnode_t *vp, struct uio *uiop, int ioflag, struct cred *cr, 1190Sstevel@tonic-gate caller_context_t *ct) 1200Sstevel@tonic-gate { 1210Sstevel@tonic-gate #ifdef LODEBUG 1220Sstevel@tonic-gate lo_dprint(4, "lo_read vp %p realvp %p\n", vp, realvp(vp)); 1230Sstevel@tonic-gate #endif 1240Sstevel@tonic-gate vp = realvp(vp); 1250Sstevel@tonic-gate return (VOP_READ(vp, uiop, ioflag, cr, ct)); 1260Sstevel@tonic-gate } 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate static int 1290Sstevel@tonic-gate lo_write(vnode_t *vp, struct uio *uiop, int ioflag, struct cred *cr, 1300Sstevel@tonic-gate caller_context_t *ct) 1310Sstevel@tonic-gate { 1320Sstevel@tonic-gate #ifdef LODEBUG 1330Sstevel@tonic-gate lo_dprint(4, "lo_write vp %p realvp %p\n", vp, realvp(vp)); 1340Sstevel@tonic-gate #endif 1350Sstevel@tonic-gate vp = realvp(vp); 1360Sstevel@tonic-gate return (VOP_WRITE(vp, uiop, ioflag, cr, ct)); 1370Sstevel@tonic-gate } 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate static int 1400Sstevel@tonic-gate lo_ioctl( 1410Sstevel@tonic-gate vnode_t *vp, 1420Sstevel@tonic-gate int cmd, 1430Sstevel@tonic-gate intptr_t arg, 1440Sstevel@tonic-gate int flag, 1450Sstevel@tonic-gate struct cred *cr, 1460Sstevel@tonic-gate int *rvalp) 1470Sstevel@tonic-gate { 1480Sstevel@tonic-gate #ifdef LODEBUG 1490Sstevel@tonic-gate lo_dprint(4, "lo_ioctl vp %p realvp %p\n", vp, realvp(vp)); 1500Sstevel@tonic-gate #endif 1510Sstevel@tonic-gate vp = realvp(vp); 1520Sstevel@tonic-gate return (VOP_IOCTL(vp, cmd, arg, flag, cr, rvalp)); 1530Sstevel@tonic-gate } 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate static int 1560Sstevel@tonic-gate lo_setfl(vnode_t *vp, int oflags, int nflags, cred_t *cr) 1570Sstevel@tonic-gate { 1580Sstevel@tonic-gate vp = realvp(vp); 1590Sstevel@tonic-gate return (VOP_SETFL(vp, oflags, nflags, cr)); 1600Sstevel@tonic-gate } 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate static int 1630Sstevel@tonic-gate lo_getattr( 1640Sstevel@tonic-gate vnode_t *vp, 1650Sstevel@tonic-gate struct vattr *vap, 1660Sstevel@tonic-gate int flags, 1670Sstevel@tonic-gate struct cred *cr) 1680Sstevel@tonic-gate { 1690Sstevel@tonic-gate int error; 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate #ifdef LODEBUG 1720Sstevel@tonic-gate lo_dprint(4, "lo_getattr vp %p realvp %p\n", vp, realvp(vp)); 1730Sstevel@tonic-gate #endif 1740Sstevel@tonic-gate if (error = VOP_GETATTR(realvp(vp), vap, flags, cr)) 1750Sstevel@tonic-gate return (error); 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate return (0); 1780Sstevel@tonic-gate } 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate static int 1810Sstevel@tonic-gate lo_setattr( 1820Sstevel@tonic-gate vnode_t *vp, 1830Sstevel@tonic-gate struct vattr *vap, 1840Sstevel@tonic-gate int flags, 1850Sstevel@tonic-gate struct cred *cr, 1860Sstevel@tonic-gate caller_context_t *ct) 1870Sstevel@tonic-gate { 1880Sstevel@tonic-gate #ifdef LODEBUG 1890Sstevel@tonic-gate lo_dprint(4, "lo_setattr vp %p realvp %p\n", vp, realvp(vp)); 1900Sstevel@tonic-gate #endif 1910Sstevel@tonic-gate vp = realvp(vp); 1920Sstevel@tonic-gate return (VOP_SETATTR(vp, vap, flags, cr, ct)); 1930Sstevel@tonic-gate } 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate static int 1960Sstevel@tonic-gate lo_access(vnode_t *vp, int mode, int flags, struct cred *cr) 1970Sstevel@tonic-gate { 1980Sstevel@tonic-gate #ifdef LODEBUG 1990Sstevel@tonic-gate lo_dprint(4, "lo_access vp %p realvp %p\n", vp, realvp(vp)); 2000Sstevel@tonic-gate #endif 2010Sstevel@tonic-gate if (mode & VWRITE) { 2020Sstevel@tonic-gate if (vp->v_type == VREG && vn_is_readonly(vp)) 2030Sstevel@tonic-gate return (EROFS); 2040Sstevel@tonic-gate } 2050Sstevel@tonic-gate vp = realvp(vp); 2060Sstevel@tonic-gate return (VOP_ACCESS(vp, mode, flags, cr)); 2070Sstevel@tonic-gate } 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate static int 2100Sstevel@tonic-gate lo_fsync(vnode_t *vp, int syncflag, struct cred *cr) 2110Sstevel@tonic-gate { 2120Sstevel@tonic-gate #ifdef LODEBUG 2130Sstevel@tonic-gate lo_dprint(4, "lo_fsync vp %p realvp %p\n", vp, realvp(vp)); 2140Sstevel@tonic-gate #endif 2150Sstevel@tonic-gate vp = realvp(vp); 2160Sstevel@tonic-gate return (VOP_FSYNC(vp, syncflag, cr)); 2170Sstevel@tonic-gate } 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate /*ARGSUSED*/ 2200Sstevel@tonic-gate static void 2210Sstevel@tonic-gate lo_inactive(vnode_t *vp, struct cred *cr) 2220Sstevel@tonic-gate { 2230Sstevel@tonic-gate #ifdef LODEBUG 2240Sstevel@tonic-gate lo_dprint(4, "lo_inactive %p, realvp %p\n", vp, realvp(vp)); 2250Sstevel@tonic-gate #endif 2260Sstevel@tonic-gate freelonode(vtol(vp)); 2270Sstevel@tonic-gate } 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate /* ARGSUSED */ 2300Sstevel@tonic-gate static int 2310Sstevel@tonic-gate lo_fid(vnode_t *vp, struct fid *fidp) 2320Sstevel@tonic-gate { 2330Sstevel@tonic-gate #ifdef LODEBUG 2340Sstevel@tonic-gate lo_dprint(4, "lo_fid %p, realvp %p\n", vp, realvp(vp)); 2350Sstevel@tonic-gate #endif 2360Sstevel@tonic-gate vp = realvp(vp); 2370Sstevel@tonic-gate return (VOP_FID(vp, fidp)); 2380Sstevel@tonic-gate } 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate /* 2410Sstevel@tonic-gate * Given a vnode of lofs type, lookup nm name and 2420Sstevel@tonic-gate * return a shadow vnode (of lofs type) of the 2430Sstevel@tonic-gate * real vnode found. 2440Sstevel@tonic-gate * 2450Sstevel@tonic-gate * Due to the nature of lofs, there is a potential 2460Sstevel@tonic-gate * looping in path traversal. 2470Sstevel@tonic-gate * 2480Sstevel@tonic-gate * starting from the mount point of an lofs; 2490Sstevel@tonic-gate * a loop is defined to be a traversal path 2500Sstevel@tonic-gate * where the mount point or the real vnode of 2510Sstevel@tonic-gate * the root of this lofs is encountered twice. 2520Sstevel@tonic-gate * Once at the start of traversal and second 2530Sstevel@tonic-gate * when the looping is found. 2540Sstevel@tonic-gate * 2550Sstevel@tonic-gate * When a loop is encountered, a shadow of the 2560Sstevel@tonic-gate * covered vnode is returned to stop the looping. 2570Sstevel@tonic-gate * 2580Sstevel@tonic-gate * This normally works, but with the advent of 2590Sstevel@tonic-gate * the new automounter, returning the shadow of the 2600Sstevel@tonic-gate * covered vnode (autonode, in this case) does not 2610Sstevel@tonic-gate * stop the loop. Because further lookup on this 2620Sstevel@tonic-gate * lonode will cause the autonode to call lo_lookup() 2630Sstevel@tonic-gate * on the lonode covering it. 2640Sstevel@tonic-gate * 2650Sstevel@tonic-gate * example "/net/jurassic/net/jurassic" is a loop. 2660Sstevel@tonic-gate * returning the shadow of the autonode corresponding to 2670Sstevel@tonic-gate * "/net/jurassic/net/jurassic" will not terminate the 2680Sstevel@tonic-gate * loop. To solve this problem we allow the loop to go 269324Sowenr * through one more level component lookup. Whichever 270324Sowenr * directory is then looked up in "/net/jurassic/net/jurassic" 271324Sowenr * the vnode returned is the vnode covered by the autonode 272324Sowenr * "net" and this will terminate the loop. 2730Sstevel@tonic-gate * 2740Sstevel@tonic-gate * Lookup for dot dot has to be dealt with separately. 2750Sstevel@tonic-gate * It will be nice to have a "one size fits all" kind 2760Sstevel@tonic-gate * of solution, so that we don't have so many ifs statement 2770Sstevel@tonic-gate * in the lo_lookup() to handle dotdot. But, since 2780Sstevel@tonic-gate * there are so many special cases to handle different 2790Sstevel@tonic-gate * kinds looping above, we need special codes to handle 2800Sstevel@tonic-gate * dotdot lookup as well. 2810Sstevel@tonic-gate */ 2820Sstevel@tonic-gate static int 2830Sstevel@tonic-gate lo_lookup( 2840Sstevel@tonic-gate vnode_t *dvp, 2850Sstevel@tonic-gate char *nm, 2860Sstevel@tonic-gate vnode_t **vpp, 2870Sstevel@tonic-gate struct pathname *pnp, 2880Sstevel@tonic-gate int flags, 2890Sstevel@tonic-gate vnode_t *rdir, 2900Sstevel@tonic-gate struct cred *cr) 2910Sstevel@tonic-gate { 2920Sstevel@tonic-gate vnode_t *vp = NULL, *tvp = NULL, *nonlovp; 2930Sstevel@tonic-gate int error, is_indirectloop; 2940Sstevel@tonic-gate vnode_t *realdvp = realvp(dvp); 2950Sstevel@tonic-gate struct loinfo *li = vtoli(dvp->v_vfsp); 2960Sstevel@tonic-gate int looping = 0; 297324Sowenr int autoloop = 0; 2980Sstevel@tonic-gate int doingdotdot = 0; 2990Sstevel@tonic-gate int nosub = 0; 300324Sowenr int mkflag = 0; 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate /* 3030Sstevel@tonic-gate * If name is empty and no XATTR flags are set, then return 3040Sstevel@tonic-gate * dvp (empty name == lookup "."). If an XATTR flag is set 3050Sstevel@tonic-gate * then we need to call VOP_LOOKUP to get the xattr dir. 3060Sstevel@tonic-gate */ 3070Sstevel@tonic-gate if (nm[0] == '\0' && ! (flags & (CREATE_XATTR_DIR|LOOKUP_XATTR))) { 3080Sstevel@tonic-gate VN_HOLD(dvp); 3090Sstevel@tonic-gate *vpp = dvp; 3100Sstevel@tonic-gate return (0); 3110Sstevel@tonic-gate } 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate if (nm[0] == '.' && nm[1] == '.' && nm[2] == '\0') { 3140Sstevel@tonic-gate doingdotdot++; 3150Sstevel@tonic-gate /* 3160Sstevel@tonic-gate * Handle ".." out of mounted filesystem 3170Sstevel@tonic-gate */ 3180Sstevel@tonic-gate while ((realdvp->v_flag & VROOT) && realdvp != rootdir) { 3190Sstevel@tonic-gate realdvp = realdvp->v_vfsp->vfs_vnodecovered; 3200Sstevel@tonic-gate ASSERT(realdvp != NULL); 3210Sstevel@tonic-gate } 3220Sstevel@tonic-gate } 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate *vpp = NULL; /* default(error) case */ 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate /* 3270Sstevel@tonic-gate * Do the normal lookup 3280Sstevel@tonic-gate */ 3291085Smarks if (error = VOP_LOOKUP(realdvp, nm, &vp, pnp, flags, rdir, cr)) { 3301085Smarks vp = NULL; 3310Sstevel@tonic-gate goto out; 3321085Smarks } 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate /* 3350Sstevel@tonic-gate * We do this check here to avoid returning a stale file handle to the 3360Sstevel@tonic-gate * caller. 3370Sstevel@tonic-gate */ 3380Sstevel@tonic-gate if (nm[0] == '.' && nm[1] == '\0') { 3390Sstevel@tonic-gate ASSERT(vp == realdvp); 3400Sstevel@tonic-gate VN_HOLD(dvp); 3410Sstevel@tonic-gate VN_RELE(vp); 3420Sstevel@tonic-gate *vpp = dvp; 3430Sstevel@tonic-gate return (0); 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate if (doingdotdot) { 347324Sowenr if ((vtol(dvp))->lo_looping & LO_LOOPING) { 3480Sstevel@tonic-gate vfs_t *vfsp; 3490Sstevel@tonic-gate 3501153Snr123932 error = vn_vfsrlock_wait(realdvp); 3510Sstevel@tonic-gate if (error) 3520Sstevel@tonic-gate goto out; 3530Sstevel@tonic-gate vfsp = vn_mountedvfs(realdvp); 354324Sowenr /* 355324Sowenr * In the standard case if the looping flag is set and 356324Sowenr * performing dotdot we would be returning from a 357324Sowenr * covered vnode, implying vfsp could not be null. The 358324Sowenr * exceptions being if we have looping and overlay 359324Sowenr * mounts or looping and covered file systems. 360324Sowenr */ 361324Sowenr if (vfsp == NULL) { 3620Sstevel@tonic-gate /* 363324Sowenr * Overlay mount or covered file system, 364324Sowenr * so just make the shadow node. 3650Sstevel@tonic-gate */ 3660Sstevel@tonic-gate vn_vfsunlock(realdvp); 367324Sowenr *vpp = makelonode(vp, li, 0); 368324Sowenr (vtol(*vpp))->lo_looping |= LO_LOOPING; 369324Sowenr return (0); 370324Sowenr } 371324Sowenr /* 372324Sowenr * When looping get the actual found vnode 373324Sowenr * instead of the vnode covered. 374324Sowenr * Here we have to hold the lock for realdvp 375324Sowenr * since an unmount during the traversal to the 376324Sowenr * root vnode would turn *vfsp into garbage 377324Sowenr * which would be fatal. 378324Sowenr */ 3791153Snr123932 error = VFS_ROOT(vfsp, &tvp); 380324Sowenr vn_vfsunlock(realdvp); 3810Sstevel@tonic-gate 382324Sowenr if (error) 383324Sowenr goto out; 3841153Snr123932 385324Sowenr if ((tvp == li->li_rootvp) && (vp == realvp(tvp))) { 386324Sowenr /* 387324Sowenr * we're back at the real vnode 388324Sowenr * of the rootvp 389324Sowenr * 390324Sowenr * return the rootvp 391324Sowenr * Ex: /mnt/mnt/.. 392324Sowenr * where / has been lofs-mounted 393324Sowenr * onto /mnt. Return the lofs 394324Sowenr * node mounted at /mnt. 395324Sowenr */ 396324Sowenr *vpp = tvp; 397324Sowenr VN_RELE(vp); 398324Sowenr return (0); 3990Sstevel@tonic-gate } else { 4000Sstevel@tonic-gate /* 401324Sowenr * We are returning from a covered 402324Sowenr * node whose vfs_mountedhere is 403324Sowenr * not pointing to vfs of the current 404324Sowenr * root vnode. 405324Sowenr * This is a condn where in we 406324Sowenr * returned a covered node say Zc 407324Sowenr * but Zc is not the cover of current 408324Sowenr * root. 409324Sowenr * i.e.., if X is the root vnode 410324Sowenr * lookup(Zc,"..") is taking us to 411324Sowenr * X. 412324Sowenr * Ex: /net/X/net/X/Y 4130Sstevel@tonic-gate * 414324Sowenr * If LO_AUTOLOOP (autofs/lofs looping detected) 415324Sowenr * has been set then we are encountering the 416324Sowenr * cover of Y (Y being any directory vnode 417324Sowenr * under /net/X/net/X/). 418324Sowenr * When performing a dotdot set the 419324Sowenr * returned vp to the vnode covered 420324Sowenr * by the mounted lofs, ie /net/X/net/X 4210Sstevel@tonic-gate */ 422324Sowenr VN_RELE(tvp); 423324Sowenr if ((vtol(dvp))->lo_looping & LO_AUTOLOOP) { 424324Sowenr VN_RELE(vp); 425324Sowenr vp = li->li_rootvp; 426324Sowenr vp = vp->v_vfsp->vfs_vnodecovered; 4270Sstevel@tonic-gate VN_HOLD(vp); 428324Sowenr *vpp = makelonode(vp, li, 0); 429324Sowenr (vtol(*vpp))->lo_looping |= LO_LOOPING; 430324Sowenr return (0); 4310Sstevel@tonic-gate } 4320Sstevel@tonic-gate } 4330Sstevel@tonic-gate } else { 4340Sstevel@tonic-gate /* 4350Sstevel@tonic-gate * No frills just make the shadow node. 4360Sstevel@tonic-gate */ 437324Sowenr *vpp = makelonode(vp, li, 0); 4380Sstevel@tonic-gate return (0); 4390Sstevel@tonic-gate } 4400Sstevel@tonic-gate } 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate nosub = (vtoli(dvp->v_vfsp)->li_flag & LO_NOSUB); 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate /* 4450Sstevel@tonic-gate * If this vnode is mounted on, then we 4460Sstevel@tonic-gate * traverse to the vnode which is the root of 4470Sstevel@tonic-gate * the mounted file system. 4480Sstevel@tonic-gate */ 4490Sstevel@tonic-gate if (!nosub && (error = traverse(&vp))) 4500Sstevel@tonic-gate goto out; 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate /* 4530Sstevel@tonic-gate * Make a lnode for the real vnode. 4540Sstevel@tonic-gate */ 4550Sstevel@tonic-gate if (vp->v_type != VDIR || nosub) { 456324Sowenr *vpp = makelonode(vp, li, 0); 4570Sstevel@tonic-gate if (IS_DEVVP(*vpp)) { 4580Sstevel@tonic-gate vnode_t *svp; 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr); 4610Sstevel@tonic-gate VN_RELE(*vpp); 4620Sstevel@tonic-gate if (svp == NULL) 4630Sstevel@tonic-gate error = ENOSYS; 4640Sstevel@tonic-gate else 4650Sstevel@tonic-gate *vpp = svp; 4660Sstevel@tonic-gate } 4670Sstevel@tonic-gate return (error); 4680Sstevel@tonic-gate } 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate /* 4710Sstevel@tonic-gate * if the found vnode (vp) is not of type lofs 4720Sstevel@tonic-gate * then we're just going to make a shadow of that 4730Sstevel@tonic-gate * vp and get out. 4740Sstevel@tonic-gate * 4750Sstevel@tonic-gate * If the found vnode (vp) is of lofs type, and 4760Sstevel@tonic-gate * we're not doing dotdot, check if we are 4770Sstevel@tonic-gate * looping. 4780Sstevel@tonic-gate */ 4790Sstevel@tonic-gate if (!doingdotdot && vfs_matchops(vp->v_vfsp, lo_vfsops)) { 4800Sstevel@tonic-gate /* 4810Sstevel@tonic-gate * Check if we're looping, i.e. 4820Sstevel@tonic-gate * vp equals the root vp of the lofs, directly 4830Sstevel@tonic-gate * or indirectly, return the covered node. 4840Sstevel@tonic-gate */ 4850Sstevel@tonic-gate 486324Sowenr if (!((vtol(dvp))->lo_looping & LO_LOOPING)) { 4870Sstevel@tonic-gate if (vp == li->li_rootvp) { 4880Sstevel@tonic-gate /* 4890Sstevel@tonic-gate * Direct looping condn. 4900Sstevel@tonic-gate * Ex:- X is / mounted directory so lookup of 4910Sstevel@tonic-gate * /X/X is a direct looping condn. 4920Sstevel@tonic-gate */ 4930Sstevel@tonic-gate tvp = vp; 4940Sstevel@tonic-gate vp = vp->v_vfsp->vfs_vnodecovered; 4950Sstevel@tonic-gate VN_HOLD(vp); 4960Sstevel@tonic-gate VN_RELE(tvp); 4970Sstevel@tonic-gate looping++; 4980Sstevel@tonic-gate } else { 4990Sstevel@tonic-gate /* 5000Sstevel@tonic-gate * Indirect looping can be defined as 5010Sstevel@tonic-gate * real lookup returning rootvp of the current 5020Sstevel@tonic-gate * tree in any level of recursion. 5030Sstevel@tonic-gate * 5040Sstevel@tonic-gate * This check is useful if there are multiple 5050Sstevel@tonic-gate * levels of lofs indirections. Suppose vnode X 5060Sstevel@tonic-gate * in the current lookup has as its real vnode 5070Sstevel@tonic-gate * another lofs node. Y = realvp(X) Y should be 5080Sstevel@tonic-gate * a lofs node for the check to continue or Y 5090Sstevel@tonic-gate * is not the rootvp of X. 5100Sstevel@tonic-gate * Ex:- say X and Y are two vnodes 5110Sstevel@tonic-gate * say real(Y) is X and real(X) is Z 5120Sstevel@tonic-gate * parent vnode for X and Y is Z 5130Sstevel@tonic-gate * lookup(Y,"path") say we are looking for Y 5140Sstevel@tonic-gate * again under Y and we have to return Yc. 5150Sstevel@tonic-gate * but the lookup of Y under Y doesnot return 5160Sstevel@tonic-gate * Y the root vnode again here is why. 5170Sstevel@tonic-gate * 1. lookup(Y,"path of Y") will go to 5180Sstevel@tonic-gate * 2. lookup(real(Y),"path of Y") and then to 5190Sstevel@tonic-gate * 3. lookup(real(X),"path of Y"). 5200Sstevel@tonic-gate * and now what lookup level 1 sees is the 5210Sstevel@tonic-gate * outcome of 2 but the vnode Y is due to 5220Sstevel@tonic-gate * lookup(Z,"path of Y") so we have to skip 5230Sstevel@tonic-gate * intermediate levels to find if in any level 5240Sstevel@tonic-gate * there is a looping. 5250Sstevel@tonic-gate */ 5260Sstevel@tonic-gate is_indirectloop = 0; 5270Sstevel@tonic-gate nonlovp = vp; 5280Sstevel@tonic-gate while ( 5290Sstevel@tonic-gate vfs_matchops(nonlovp->v_vfsp, lo_vfsops) && 5300Sstevel@tonic-gate !(is_indirectloop)) { 5310Sstevel@tonic-gate if (li->li_rootvp == nonlovp) { 5320Sstevel@tonic-gate is_indirectloop++; 5330Sstevel@tonic-gate break; 5340Sstevel@tonic-gate } 5350Sstevel@tonic-gate nonlovp = realvp(nonlovp); 5360Sstevel@tonic-gate } 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate if (is_indirectloop) { 5390Sstevel@tonic-gate VN_RELE(vp); 5400Sstevel@tonic-gate vp = nonlovp; 5410Sstevel@tonic-gate vp = vp->v_vfsp->vfs_vnodecovered; 5420Sstevel@tonic-gate VN_HOLD(vp); 5430Sstevel@tonic-gate looping++; 5440Sstevel@tonic-gate } 5450Sstevel@tonic-gate } 5460Sstevel@tonic-gate } else { 5470Sstevel@tonic-gate /* 5480Sstevel@tonic-gate * come here only because of the interaction between 5490Sstevel@tonic-gate * the autofs and lofs. 5500Sstevel@tonic-gate * 5510Sstevel@tonic-gate * Lookup of "/net/X/net/X" will return a shadow of 5520Sstevel@tonic-gate * an autonode X_a which we call X_l. 5530Sstevel@tonic-gate * 5540Sstevel@tonic-gate * Lookup of anything under X_l, will trigger a call to 5550Sstevel@tonic-gate * auto_lookup(X_a,nm) which will eventually call 5560Sstevel@tonic-gate * lo_lookup(X_lr,nm) where X_lr is the root vnode of 5570Sstevel@tonic-gate * the current lofs. 5580Sstevel@tonic-gate * 5590Sstevel@tonic-gate * We come here only when we are called with X_l as dvp 5600Sstevel@tonic-gate * and look for something underneath. 5610Sstevel@tonic-gate * 562324Sowenr * Now that an autofs/lofs looping condition has been 563324Sowenr * identified any directory vnode contained within 564324Sowenr * dvp will be set to the vnode covered by the 565324Sowenr * mounted autofs. Thus all directories within dvp 566324Sowenr * will appear empty hence teminating the looping. 567324Sowenr * The LO_AUTOLOOP flag is set on the returned lonode 568324Sowenr * to indicate the termination of the autofs/lofs 569324Sowenr * looping. This is required for the correct behaviour 570324Sowenr * when performing a dotdot. 5710Sstevel@tonic-gate */ 5720Sstevel@tonic-gate realdvp = realvp(dvp); 5730Sstevel@tonic-gate while (vfs_matchops(realdvp->v_vfsp, lo_vfsops)) { 5740Sstevel@tonic-gate realdvp = realvp(realdvp); 5750Sstevel@tonic-gate } 5760Sstevel@tonic-gate 5770Sstevel@tonic-gate error = VFS_ROOT(realdvp->v_vfsp, &tvp); 5780Sstevel@tonic-gate if (error) 5790Sstevel@tonic-gate goto out; 5800Sstevel@tonic-gate /* 5810Sstevel@tonic-gate * tvp now contains the rootvp of the vfs of the 582324Sowenr * real vnode of dvp. The directory vnode vp is set 583324Sowenr * to the covered vnode to terminate looping. No 584324Sowenr * distinction is made between any vp as all directory 585324Sowenr * vnodes contained in dvp are returned as the covered 586324Sowenr * vnode. 5870Sstevel@tonic-gate */ 588324Sowenr VN_RELE(vp); 5891314Sowenr vp = tvp; /* possibly is an autonode */ 5900Sstevel@tonic-gate 591324Sowenr /* 592324Sowenr * Need to find the covered vnode 593324Sowenr */ 5941314Sowenr if (vp->v_vfsp->vfs_vnodecovered == NULL) { 5951314Sowenr /* 5961314Sowenr * We don't have a covered vnode so this isn't 5971314Sowenr * an autonode. To find the autonode simply 5981314Sowenr * find the vnode covered by the lofs rootvp. 5991314Sowenr */ 6001314Sowenr vp = li->li_rootvp; 6011314Sowenr vp = vp->v_vfsp->vfs_vnodecovered; 6021314Sowenr VN_RELE(tvp); 6031314Sowenr error = VFS_ROOT(vp->v_vfsp, &tvp); 6041314Sowenr if (error) 6051314Sowenr goto out; 6061314Sowenr vp = tvp; /* now this is an autonode */ 6071314Sowenr if (vp->v_vfsp->vfs_vnodecovered == NULL) { 6081314Sowenr /* 6091314Sowenr * Still can't find a covered vnode. 6101314Sowenr * Fail the lookup, or we'd loop. 6111314Sowenr */ 6121314Sowenr error = ENOENT; 6131314Sowenr goto out; 6141314Sowenr } 6151314Sowenr } 616324Sowenr vp = vp->v_vfsp->vfs_vnodecovered; 617324Sowenr VN_HOLD(vp); 618324Sowenr VN_RELE(tvp); 619324Sowenr /* 620324Sowenr * Force the creation of a new lnode even if the hash 621324Sowenr * table contains a lnode that references this vnode. 622324Sowenr */ 623324Sowenr mkflag = LOF_FORCE; 624324Sowenr autoloop++; 6250Sstevel@tonic-gate } 6260Sstevel@tonic-gate } 627324Sowenr *vpp = makelonode(vp, li, mkflag); 6280Sstevel@tonic-gate 629324Sowenr if ((looping) || 630324Sowenr (((vtol(dvp))->lo_looping & LO_LOOPING) && !doingdotdot)) { 631324Sowenr (vtol(*vpp))->lo_looping |= LO_LOOPING; 632324Sowenr } 633324Sowenr 634324Sowenr if (autoloop) { 635324Sowenr (vtol(*vpp))->lo_looping |= LO_AUTOLOOP; 6360Sstevel@tonic-gate } 6370Sstevel@tonic-gate 6380Sstevel@tonic-gate out: 6390Sstevel@tonic-gate if (error != 0 && vp != NULL) 6400Sstevel@tonic-gate VN_RELE(vp); 6410Sstevel@tonic-gate #ifdef LODEBUG 6420Sstevel@tonic-gate lo_dprint(4, 6430Sstevel@tonic-gate "lo_lookup dvp %x realdvp %x nm '%s' newvp %x real vp %x error %d\n", 6440Sstevel@tonic-gate dvp, realvp(dvp), nm, *vpp, vp, error); 6450Sstevel@tonic-gate #endif 6460Sstevel@tonic-gate return (error); 6470Sstevel@tonic-gate } 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate /*ARGSUSED*/ 6500Sstevel@tonic-gate static int 6510Sstevel@tonic-gate lo_create( 6520Sstevel@tonic-gate vnode_t *dvp, 6530Sstevel@tonic-gate char *nm, 6540Sstevel@tonic-gate struct vattr *va, 6550Sstevel@tonic-gate enum vcexcl exclusive, 6560Sstevel@tonic-gate int mode, 6570Sstevel@tonic-gate vnode_t **vpp, 6580Sstevel@tonic-gate struct cred *cr, 6590Sstevel@tonic-gate int flag) 6600Sstevel@tonic-gate { 6610Sstevel@tonic-gate int error; 6620Sstevel@tonic-gate vnode_t *vp = NULL; 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate #ifdef LODEBUG 6650Sstevel@tonic-gate lo_dprint(4, "lo_create vp %p realvp %p\n", dvp, realvp(dvp)); 6660Sstevel@tonic-gate #endif 6670Sstevel@tonic-gate if (*nm == '\0') { 6680Sstevel@tonic-gate ASSERT(vpp && dvp == *vpp); 6690Sstevel@tonic-gate vp = realvp(*vpp); 6700Sstevel@tonic-gate } 6710Sstevel@tonic-gate 6720Sstevel@tonic-gate error = VOP_CREATE(realvp(dvp), nm, va, exclusive, mode, &vp, cr, flag); 6730Sstevel@tonic-gate if (!error) { 674324Sowenr *vpp = makelonode(vp, vtoli(dvp->v_vfsp), 0); 6750Sstevel@tonic-gate if (IS_DEVVP(*vpp)) { 6760Sstevel@tonic-gate vnode_t *svp; 6770Sstevel@tonic-gate 6780Sstevel@tonic-gate svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr); 6790Sstevel@tonic-gate VN_RELE(*vpp); 6800Sstevel@tonic-gate if (svp == NULL) 6810Sstevel@tonic-gate error = ENOSYS; 6820Sstevel@tonic-gate else 6830Sstevel@tonic-gate *vpp = svp; 6840Sstevel@tonic-gate } 6850Sstevel@tonic-gate } 6860Sstevel@tonic-gate return (error); 6870Sstevel@tonic-gate } 6880Sstevel@tonic-gate 6890Sstevel@tonic-gate static int 6900Sstevel@tonic-gate lo_remove(vnode_t *dvp, char *nm, struct cred *cr) 6910Sstevel@tonic-gate { 6920Sstevel@tonic-gate #ifdef LODEBUG 6930Sstevel@tonic-gate lo_dprint(4, "lo_remove vp %p realvp %p\n", dvp, realvp(dvp)); 6940Sstevel@tonic-gate #endif 6950Sstevel@tonic-gate dvp = realvp(dvp); 6960Sstevel@tonic-gate return (VOP_REMOVE(dvp, nm, cr)); 6970Sstevel@tonic-gate } 6980Sstevel@tonic-gate 6990Sstevel@tonic-gate static int 7000Sstevel@tonic-gate lo_link(vnode_t *tdvp, vnode_t *vp, char *tnm, struct cred *cr) 7010Sstevel@tonic-gate { 7020Sstevel@tonic-gate #ifdef LODEBUG 7030Sstevel@tonic-gate lo_dprint(4, "lo_link vp %p realvp %p\n", vp, realvp(vp)); 7040Sstevel@tonic-gate #endif 7050Sstevel@tonic-gate while (vn_matchops(vp, lo_vnodeops)) { 7060Sstevel@tonic-gate vp = realvp(vp); 7070Sstevel@tonic-gate } 7080Sstevel@tonic-gate while (vn_matchops(tdvp, lo_vnodeops)) { 7090Sstevel@tonic-gate tdvp = realvp(tdvp); 7100Sstevel@tonic-gate } 7110Sstevel@tonic-gate if (vp->v_vfsp != tdvp->v_vfsp) 7120Sstevel@tonic-gate return (EXDEV); 7130Sstevel@tonic-gate return (VOP_LINK(tdvp, vp, tnm, cr)); 7140Sstevel@tonic-gate } 7150Sstevel@tonic-gate 7160Sstevel@tonic-gate static int 7170Sstevel@tonic-gate lo_rename( 7180Sstevel@tonic-gate vnode_t *odvp, 7190Sstevel@tonic-gate char *onm, 7200Sstevel@tonic-gate vnode_t *ndvp, 7210Sstevel@tonic-gate char *nnm, 7220Sstevel@tonic-gate struct cred *cr) 7230Sstevel@tonic-gate { 7240Sstevel@tonic-gate vnode_t *tnvp; 7250Sstevel@tonic-gate 7260Sstevel@tonic-gate #ifdef LODEBUG 7270Sstevel@tonic-gate lo_dprint(4, "lo_rename vp %p realvp %p\n", odvp, realvp(odvp)); 7280Sstevel@tonic-gate #endif 7290Sstevel@tonic-gate /* 7301800Ssjelinek * If we are coming from a loop back mounted fs, that has been 7311800Ssjelinek * mounted in the same filesystem as where we want to move to, 7321800Ssjelinek * and that filesystem is read/write, but the lofs filesystem is 7331800Ssjelinek * read only, we don't want to allow a rename of the file. The 7341800Ssjelinek * vn_rename code checks to be sure the target is read/write already 7351800Ssjelinek * so that is not necessary here. However, consider the following 7361800Ssjelinek * example: 7371800Ssjelinek * / - regular root fs 7381800Ssjelinek * /foo - directory in root 7391800Ssjelinek * /foo/bar - file in foo directory(in root fs) 7401800Ssjelinek * /baz - directory in root 7411800Ssjelinek * mount -F lofs -o ro /foo /baz - all still in root 7421800Ssjelinek * directory 7431800Ssjelinek * The fact that we mounted /foo on /baz read only should stop us 7441800Ssjelinek * from renaming the file /foo/bar /bar, but it doesn't since 7451800Ssjelinek * / is read/write. We are still renaming here since we are still 7461800Ssjelinek * in the same filesystem, it is just that we do not check to see 7471800Ssjelinek * if the filesystem we are coming from in this case is read only. 7481800Ssjelinek */ 7491800Ssjelinek if (odvp->v_vfsp->vfs_flag & VFS_RDONLY) 7501800Ssjelinek return (EROFS); 7511800Ssjelinek /* 7520Sstevel@tonic-gate * We need to make sure we're not trying to remove a mount point for a 7530Sstevel@tonic-gate * filesystem mounted on top of lofs, which only we know about. 7540Sstevel@tonic-gate */ 7550Sstevel@tonic-gate if (vn_matchops(ndvp, lo_vnodeops)) /* Not our problem. */ 7560Sstevel@tonic-gate goto rename; 7570Sstevel@tonic-gate if (VOP_LOOKUP(ndvp, nnm, &tnvp, NULL, 0, NULL, cr) != 0) 7580Sstevel@tonic-gate goto rename; 7590Sstevel@tonic-gate if (tnvp->v_type != VDIR) { 7600Sstevel@tonic-gate VN_RELE(tnvp); 7610Sstevel@tonic-gate goto rename; 7620Sstevel@tonic-gate } 7630Sstevel@tonic-gate if (vn_mountedvfs(tnvp)) { 7640Sstevel@tonic-gate VN_RELE(tnvp); 7650Sstevel@tonic-gate return (EBUSY); 7660Sstevel@tonic-gate } 7670Sstevel@tonic-gate VN_RELE(tnvp); 7680Sstevel@tonic-gate rename: 7690Sstevel@tonic-gate /* 7700Sstevel@tonic-gate * Since the case we're dealing with above can happen at any layer in 7710Sstevel@tonic-gate * the stack of lofs filesystems, we need to recurse down the stack, 7720Sstevel@tonic-gate * checking to see if there are any instances of a filesystem mounted on 7730Sstevel@tonic-gate * top of lofs. In order to keep on using the lofs version of 7740Sstevel@tonic-gate * VOP_RENAME(), we make sure that while the target directory is of type 7750Sstevel@tonic-gate * lofs, the source directory (the one used for getting the fs-specific 7760Sstevel@tonic-gate * version of VOP_RENAME()) is also of type lofs. 7770Sstevel@tonic-gate */ 7780Sstevel@tonic-gate if (vn_matchops(ndvp, lo_vnodeops)) { 7790Sstevel@tonic-gate ndvp = realvp(ndvp); /* Check the next layer */ 7800Sstevel@tonic-gate } else { 7810Sstevel@tonic-gate /* 7820Sstevel@tonic-gate * We can go fast here 7830Sstevel@tonic-gate */ 7840Sstevel@tonic-gate while (vn_matchops(odvp, lo_vnodeops)) { 7850Sstevel@tonic-gate odvp = realvp(odvp); 7860Sstevel@tonic-gate } 7870Sstevel@tonic-gate if (odvp->v_vfsp != ndvp->v_vfsp) 7880Sstevel@tonic-gate return (EXDEV); 7890Sstevel@tonic-gate } 7900Sstevel@tonic-gate return (VOP_RENAME(odvp, onm, ndvp, nnm, cr)); 7910Sstevel@tonic-gate } 7920Sstevel@tonic-gate 7930Sstevel@tonic-gate static int 7940Sstevel@tonic-gate lo_mkdir( 7950Sstevel@tonic-gate vnode_t *dvp, 7960Sstevel@tonic-gate char *nm, 7970Sstevel@tonic-gate struct vattr *va, 7980Sstevel@tonic-gate vnode_t **vpp, 7990Sstevel@tonic-gate struct cred *cr) 8000Sstevel@tonic-gate { 8010Sstevel@tonic-gate int error; 8020Sstevel@tonic-gate 8030Sstevel@tonic-gate #ifdef LODEBUG 8040Sstevel@tonic-gate lo_dprint(4, "lo_mkdir vp %p realvp %p\n", dvp, realvp(dvp)); 8050Sstevel@tonic-gate #endif 8060Sstevel@tonic-gate error = VOP_MKDIR(realvp(dvp), nm, va, vpp, cr); 8070Sstevel@tonic-gate if (!error) 808324Sowenr *vpp = makelonode(*vpp, vtoli(dvp->v_vfsp), 0); 8090Sstevel@tonic-gate return (error); 8100Sstevel@tonic-gate } 8110Sstevel@tonic-gate 8120Sstevel@tonic-gate static int 8130Sstevel@tonic-gate lo_realvp(vnode_t *vp, vnode_t **vpp) 8140Sstevel@tonic-gate { 8150Sstevel@tonic-gate #ifdef LODEBUG 8160Sstevel@tonic-gate lo_dprint(4, "lo_realvp %p\n", vp); 8170Sstevel@tonic-gate #endif 8180Sstevel@tonic-gate while (vn_matchops(vp, lo_vnodeops)) 8190Sstevel@tonic-gate vp = realvp(vp); 8200Sstevel@tonic-gate 8210Sstevel@tonic-gate if (VOP_REALVP(vp, vpp) != 0) 8220Sstevel@tonic-gate *vpp = vp; 8230Sstevel@tonic-gate return (0); 8240Sstevel@tonic-gate } 8250Sstevel@tonic-gate 8260Sstevel@tonic-gate static int 8270Sstevel@tonic-gate lo_rmdir( 8280Sstevel@tonic-gate vnode_t *dvp, 8290Sstevel@tonic-gate char *nm, 8300Sstevel@tonic-gate vnode_t *cdir, 8310Sstevel@tonic-gate struct cred *cr) 8320Sstevel@tonic-gate { 8330Sstevel@tonic-gate vnode_t *rvp = cdir; 8340Sstevel@tonic-gate 8350Sstevel@tonic-gate #ifdef LODEBUG 8360Sstevel@tonic-gate lo_dprint(4, "lo_rmdir vp %p realvp %p\n", dvp, realvp(dvp)); 8370Sstevel@tonic-gate #endif 8380Sstevel@tonic-gate /* if cdir is lofs vnode ptr get its real vnode ptr */ 8390Sstevel@tonic-gate if (vn_matchops(dvp, vn_getops(rvp))) 8400Sstevel@tonic-gate (void) lo_realvp(cdir, &rvp); 8410Sstevel@tonic-gate dvp = realvp(dvp); 8420Sstevel@tonic-gate return (VOP_RMDIR(dvp, nm, rvp, cr)); 8430Sstevel@tonic-gate } 8440Sstevel@tonic-gate 8450Sstevel@tonic-gate static int 8460Sstevel@tonic-gate lo_symlink( 8470Sstevel@tonic-gate vnode_t *dvp, 8480Sstevel@tonic-gate char *lnm, 8490Sstevel@tonic-gate struct vattr *tva, 8500Sstevel@tonic-gate char *tnm, 8510Sstevel@tonic-gate struct cred *cr) 8520Sstevel@tonic-gate { 8530Sstevel@tonic-gate #ifdef LODEBUG 8540Sstevel@tonic-gate lo_dprint(4, "lo_symlink vp %p realvp %p\n", dvp, realvp(dvp)); 8550Sstevel@tonic-gate #endif 8560Sstevel@tonic-gate dvp = realvp(dvp); 8570Sstevel@tonic-gate return (VOP_SYMLINK(dvp, lnm, tva, tnm, cr)); 8580Sstevel@tonic-gate } 8590Sstevel@tonic-gate 8600Sstevel@tonic-gate static int 8610Sstevel@tonic-gate lo_readlink(vnode_t *vp, struct uio *uiop, struct cred *cr) 8620Sstevel@tonic-gate { 8630Sstevel@tonic-gate vp = realvp(vp); 8640Sstevel@tonic-gate return (VOP_READLINK(vp, uiop, cr)); 8650Sstevel@tonic-gate } 8660Sstevel@tonic-gate 8670Sstevel@tonic-gate static int 8680Sstevel@tonic-gate lo_readdir(vnode_t *vp, struct uio *uiop, struct cred *cr, int *eofp) 8690Sstevel@tonic-gate { 8700Sstevel@tonic-gate #ifdef LODEBUG 8710Sstevel@tonic-gate lo_dprint(4, "lo_readdir vp %p realvp %p\n", vp, realvp(vp)); 8720Sstevel@tonic-gate #endif 8730Sstevel@tonic-gate vp = realvp(vp); 8740Sstevel@tonic-gate return (VOP_READDIR(vp, uiop, cr, eofp)); 8750Sstevel@tonic-gate } 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate static int 8780Sstevel@tonic-gate lo_rwlock(vnode_t *vp, int write_lock, caller_context_t *ct) 8790Sstevel@tonic-gate { 8800Sstevel@tonic-gate vp = realvp(vp); 8810Sstevel@tonic-gate return (VOP_RWLOCK(vp, write_lock, ct)); 8820Sstevel@tonic-gate } 8830Sstevel@tonic-gate 8840Sstevel@tonic-gate static void 8850Sstevel@tonic-gate lo_rwunlock(vnode_t *vp, int write_lock, caller_context_t *ct) 8860Sstevel@tonic-gate { 8870Sstevel@tonic-gate vp = realvp(vp); 8880Sstevel@tonic-gate VOP_RWUNLOCK(vp, write_lock, ct); 8890Sstevel@tonic-gate } 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate static int 8920Sstevel@tonic-gate lo_seek(vnode_t *vp, offset_t ooff, offset_t *noffp) 8930Sstevel@tonic-gate { 8940Sstevel@tonic-gate vp = realvp(vp); 8950Sstevel@tonic-gate return (VOP_SEEK(vp, ooff, noffp)); 8960Sstevel@tonic-gate } 8970Sstevel@tonic-gate 8980Sstevel@tonic-gate static int 8990Sstevel@tonic-gate lo_cmp(vnode_t *vp1, vnode_t *vp2) 9000Sstevel@tonic-gate { 9010Sstevel@tonic-gate while (vn_matchops(vp1, lo_vnodeops)) 9020Sstevel@tonic-gate vp1 = realvp(vp1); 9030Sstevel@tonic-gate while (vn_matchops(vp2, lo_vnodeops)) 9040Sstevel@tonic-gate vp2 = realvp(vp2); 9050Sstevel@tonic-gate return (VOP_CMP(vp1, vp2)); 9060Sstevel@tonic-gate } 9070Sstevel@tonic-gate 9080Sstevel@tonic-gate static int 9090Sstevel@tonic-gate lo_frlock( 9100Sstevel@tonic-gate vnode_t *vp, 9110Sstevel@tonic-gate int cmd, 9120Sstevel@tonic-gate struct flock64 *bfp, 9130Sstevel@tonic-gate int flag, 9140Sstevel@tonic-gate offset_t offset, 9150Sstevel@tonic-gate struct flk_callback *flk_cbp, 9160Sstevel@tonic-gate cred_t *cr) 9170Sstevel@tonic-gate { 9180Sstevel@tonic-gate vp = realvp(vp); 9190Sstevel@tonic-gate return (VOP_FRLOCK(vp, cmd, bfp, flag, offset, flk_cbp, cr)); 9200Sstevel@tonic-gate } 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate static int 9230Sstevel@tonic-gate lo_space( 9240Sstevel@tonic-gate vnode_t *vp, 9250Sstevel@tonic-gate int cmd, 9260Sstevel@tonic-gate struct flock64 *bfp, 9270Sstevel@tonic-gate int flag, 9280Sstevel@tonic-gate offset_t offset, 9290Sstevel@tonic-gate struct cred *cr, 9300Sstevel@tonic-gate caller_context_t *ct) 9310Sstevel@tonic-gate { 9320Sstevel@tonic-gate vp = realvp(vp); 9330Sstevel@tonic-gate return (VOP_SPACE(vp, cmd, bfp, flag, offset, cr, ct)); 9340Sstevel@tonic-gate } 9350Sstevel@tonic-gate 9360Sstevel@tonic-gate static int 9370Sstevel@tonic-gate lo_getpage( 9380Sstevel@tonic-gate vnode_t *vp, 9390Sstevel@tonic-gate offset_t off, 9400Sstevel@tonic-gate size_t len, 9410Sstevel@tonic-gate uint_t *prot, 9420Sstevel@tonic-gate struct page *parr[], 9430Sstevel@tonic-gate size_t psz, 9440Sstevel@tonic-gate struct seg *seg, 9450Sstevel@tonic-gate caddr_t addr, 9460Sstevel@tonic-gate enum seg_rw rw, 9470Sstevel@tonic-gate struct cred *cr) 9480Sstevel@tonic-gate { 9490Sstevel@tonic-gate vp = realvp(vp); 9500Sstevel@tonic-gate return (VOP_GETPAGE(vp, off, len, prot, parr, psz, seg, addr, rw, cr)); 9510Sstevel@tonic-gate } 9520Sstevel@tonic-gate 9530Sstevel@tonic-gate static int 9540Sstevel@tonic-gate lo_putpage(vnode_t *vp, offset_t off, size_t len, int flags, struct cred *cr) 9550Sstevel@tonic-gate { 9560Sstevel@tonic-gate vp = realvp(vp); 9570Sstevel@tonic-gate return (VOP_PUTPAGE(vp, off, len, flags, cr)); 9580Sstevel@tonic-gate } 9590Sstevel@tonic-gate 9600Sstevel@tonic-gate static int 9610Sstevel@tonic-gate lo_map( 9620Sstevel@tonic-gate vnode_t *vp, 9630Sstevel@tonic-gate offset_t off, 9640Sstevel@tonic-gate struct as *as, 9650Sstevel@tonic-gate caddr_t *addrp, 9660Sstevel@tonic-gate size_t len, 9670Sstevel@tonic-gate uchar_t prot, 9680Sstevel@tonic-gate uchar_t maxprot, 9690Sstevel@tonic-gate uint_t flags, 9700Sstevel@tonic-gate struct cred *cr) 9710Sstevel@tonic-gate { 9720Sstevel@tonic-gate vp = realvp(vp); 9730Sstevel@tonic-gate return (VOP_MAP(vp, off, as, addrp, len, prot, maxprot, flags, cr)); 9740Sstevel@tonic-gate } 9750Sstevel@tonic-gate 9760Sstevel@tonic-gate static int 9770Sstevel@tonic-gate lo_addmap( 9780Sstevel@tonic-gate vnode_t *vp, 9790Sstevel@tonic-gate offset_t off, 9800Sstevel@tonic-gate struct as *as, 9810Sstevel@tonic-gate caddr_t addr, 9820Sstevel@tonic-gate size_t len, 9830Sstevel@tonic-gate uchar_t prot, 9840Sstevel@tonic-gate uchar_t maxprot, 9850Sstevel@tonic-gate uint_t flags, 9860Sstevel@tonic-gate struct cred *cr) 9870Sstevel@tonic-gate { 9880Sstevel@tonic-gate vp = realvp(vp); 9890Sstevel@tonic-gate return (VOP_ADDMAP(vp, off, as, addr, len, prot, maxprot, flags, cr)); 9900Sstevel@tonic-gate } 9910Sstevel@tonic-gate 9920Sstevel@tonic-gate static int 9930Sstevel@tonic-gate lo_delmap( 9940Sstevel@tonic-gate vnode_t *vp, 9950Sstevel@tonic-gate offset_t off, 9960Sstevel@tonic-gate struct as *as, 9970Sstevel@tonic-gate caddr_t addr, 9980Sstevel@tonic-gate size_t len, 9990Sstevel@tonic-gate uint_t prot, 10000Sstevel@tonic-gate uint_t maxprot, 10010Sstevel@tonic-gate uint_t flags, 10020Sstevel@tonic-gate struct cred *cr) 10030Sstevel@tonic-gate { 10040Sstevel@tonic-gate vp = realvp(vp); 10050Sstevel@tonic-gate return (VOP_DELMAP(vp, off, as, addr, len, prot, maxprot, flags, cr)); 10060Sstevel@tonic-gate } 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate static int 10090Sstevel@tonic-gate lo_poll( 10100Sstevel@tonic-gate vnode_t *vp, 10110Sstevel@tonic-gate short events, 10120Sstevel@tonic-gate int anyyet, 10130Sstevel@tonic-gate short *reventsp, 10140Sstevel@tonic-gate struct pollhead **phpp) 10150Sstevel@tonic-gate { 10160Sstevel@tonic-gate vp = realvp(vp); 10170Sstevel@tonic-gate return (VOP_POLL(vp, events, anyyet, reventsp, phpp)); 10180Sstevel@tonic-gate } 10190Sstevel@tonic-gate 10200Sstevel@tonic-gate static int 10210Sstevel@tonic-gate lo_dump(vnode_t *vp, caddr_t addr, int bn, int count) 10220Sstevel@tonic-gate { 10230Sstevel@tonic-gate vp = realvp(vp); 10240Sstevel@tonic-gate return (VOP_DUMP(vp, addr, bn, count)); 10250Sstevel@tonic-gate } 10260Sstevel@tonic-gate 10270Sstevel@tonic-gate static int 10280Sstevel@tonic-gate lo_pathconf(vnode_t *vp, int cmd, ulong_t *valp, struct cred *cr) 10290Sstevel@tonic-gate { 10300Sstevel@tonic-gate vp = realvp(vp); 10310Sstevel@tonic-gate return (VOP_PATHCONF(vp, cmd, valp, cr)); 10320Sstevel@tonic-gate } 10330Sstevel@tonic-gate 10340Sstevel@tonic-gate static int 10350Sstevel@tonic-gate lo_pageio( 10360Sstevel@tonic-gate vnode_t *vp, 10370Sstevel@tonic-gate struct page *pp, 10380Sstevel@tonic-gate u_offset_t io_off, 10390Sstevel@tonic-gate size_t io_len, 10400Sstevel@tonic-gate int flags, 10410Sstevel@tonic-gate cred_t *cr) 10420Sstevel@tonic-gate { 10430Sstevel@tonic-gate vp = realvp(vp); 10440Sstevel@tonic-gate return (VOP_PAGEIO(vp, pp, io_off, io_len, flags, cr)); 10450Sstevel@tonic-gate } 10460Sstevel@tonic-gate 10470Sstevel@tonic-gate static void 10480Sstevel@tonic-gate lo_dispose(vnode_t *vp, page_t *pp, int fl, int dn, cred_t *cr) 10490Sstevel@tonic-gate { 10500Sstevel@tonic-gate vp = realvp(vp); 1051*3290Sjohansen if (vp != NULL && !VN_ISKAS(vp)) 10520Sstevel@tonic-gate VOP_DISPOSE(vp, pp, fl, dn, cr); 10530Sstevel@tonic-gate } 10540Sstevel@tonic-gate 10550Sstevel@tonic-gate static int 10560Sstevel@tonic-gate lo_setsecattr(vnode_t *vp, vsecattr_t *secattr, int flags, struct cred *cr) 10570Sstevel@tonic-gate { 10580Sstevel@tonic-gate if (vn_is_readonly(vp)) 10590Sstevel@tonic-gate return (EROFS); 10600Sstevel@tonic-gate vp = realvp(vp); 10610Sstevel@tonic-gate return (VOP_SETSECATTR(vp, secattr, flags, cr)); 10620Sstevel@tonic-gate } 10630Sstevel@tonic-gate 10640Sstevel@tonic-gate static int 10650Sstevel@tonic-gate lo_getsecattr(vnode_t *vp, vsecattr_t *secattr, int flags, struct cred *cr) 10660Sstevel@tonic-gate { 10670Sstevel@tonic-gate vp = realvp(vp); 10680Sstevel@tonic-gate return (VOP_GETSECATTR(vp, secattr, flags, cr)); 10690Sstevel@tonic-gate } 10700Sstevel@tonic-gate 10710Sstevel@tonic-gate static int 10720Sstevel@tonic-gate lo_shrlock(vnode_t *vp, int cmd, struct shrlock *shr, int flag, cred_t *cr) 10730Sstevel@tonic-gate { 10740Sstevel@tonic-gate vp = realvp(vp); 10750Sstevel@tonic-gate return (VOP_SHRLOCK(vp, cmd, shr, flag, cr)); 10760Sstevel@tonic-gate } 10770Sstevel@tonic-gate 10780Sstevel@tonic-gate /* 10790Sstevel@tonic-gate * Loopback vnode operations vector. 10800Sstevel@tonic-gate */ 10810Sstevel@tonic-gate 10820Sstevel@tonic-gate struct vnodeops *lo_vnodeops; 10830Sstevel@tonic-gate 10840Sstevel@tonic-gate const fs_operation_def_t lo_vnodeops_template[] = { 10850Sstevel@tonic-gate VOPNAME_OPEN, lo_open, 10860Sstevel@tonic-gate VOPNAME_CLOSE, lo_close, 10870Sstevel@tonic-gate VOPNAME_READ, lo_read, 10880Sstevel@tonic-gate VOPNAME_WRITE, lo_write, 10890Sstevel@tonic-gate VOPNAME_IOCTL, lo_ioctl, 10900Sstevel@tonic-gate VOPNAME_SETFL, lo_setfl, 10910Sstevel@tonic-gate VOPNAME_GETATTR, lo_getattr, 10920Sstevel@tonic-gate VOPNAME_SETATTR, lo_setattr, 10930Sstevel@tonic-gate VOPNAME_ACCESS, lo_access, 10940Sstevel@tonic-gate VOPNAME_LOOKUP, lo_lookup, 10950Sstevel@tonic-gate VOPNAME_CREATE, lo_create, 10960Sstevel@tonic-gate VOPNAME_REMOVE, lo_remove, 10970Sstevel@tonic-gate VOPNAME_LINK, lo_link, 10980Sstevel@tonic-gate VOPNAME_RENAME, lo_rename, 10990Sstevel@tonic-gate VOPNAME_MKDIR, lo_mkdir, 11000Sstevel@tonic-gate VOPNAME_RMDIR, lo_rmdir, 11010Sstevel@tonic-gate VOPNAME_READDIR, lo_readdir, 11020Sstevel@tonic-gate VOPNAME_SYMLINK, lo_symlink, 11030Sstevel@tonic-gate VOPNAME_READLINK, lo_readlink, 11040Sstevel@tonic-gate VOPNAME_FSYNC, lo_fsync, 11050Sstevel@tonic-gate VOPNAME_INACTIVE, (fs_generic_func_p) lo_inactive, 11060Sstevel@tonic-gate VOPNAME_FID, lo_fid, 11070Sstevel@tonic-gate VOPNAME_RWLOCK, lo_rwlock, 11080Sstevel@tonic-gate VOPNAME_RWUNLOCK, (fs_generic_func_p) lo_rwunlock, 11090Sstevel@tonic-gate VOPNAME_SEEK, lo_seek, 11100Sstevel@tonic-gate VOPNAME_CMP, lo_cmp, 11110Sstevel@tonic-gate VOPNAME_FRLOCK, lo_frlock, 11120Sstevel@tonic-gate VOPNAME_SPACE, lo_space, 11130Sstevel@tonic-gate VOPNAME_REALVP, lo_realvp, 11140Sstevel@tonic-gate VOPNAME_GETPAGE, lo_getpage, 11150Sstevel@tonic-gate VOPNAME_PUTPAGE, lo_putpage, 11160Sstevel@tonic-gate VOPNAME_MAP, (fs_generic_func_p) lo_map, 11170Sstevel@tonic-gate VOPNAME_ADDMAP, (fs_generic_func_p) lo_addmap, 11180Sstevel@tonic-gate VOPNAME_DELMAP, lo_delmap, 11190Sstevel@tonic-gate VOPNAME_POLL, (fs_generic_func_p) lo_poll, 11200Sstevel@tonic-gate VOPNAME_DUMP, lo_dump, 11210Sstevel@tonic-gate VOPNAME_DUMPCTL, fs_error, /* XXX - why? */ 11220Sstevel@tonic-gate VOPNAME_PATHCONF, lo_pathconf, 11230Sstevel@tonic-gate VOPNAME_PAGEIO, lo_pageio, 11240Sstevel@tonic-gate VOPNAME_DISPOSE, (fs_generic_func_p) lo_dispose, 11250Sstevel@tonic-gate VOPNAME_SETSECATTR, lo_setsecattr, 11260Sstevel@tonic-gate VOPNAME_GETSECATTR, lo_getsecattr, 11270Sstevel@tonic-gate VOPNAME_SHRLOCK, lo_shrlock, 11280Sstevel@tonic-gate NULL, NULL 11290Sstevel@tonic-gate }; 1130