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 5*1314Sowenr * Common Development and Distribution License (the "License"). 6*1314Sowenr * 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 #define IS_ZONEDEVFS(vp) \ 440Sstevel@tonic-gate (vtoli((vp)->v_vfsp)->li_flag & LO_ZONEDEVFS) 450Sstevel@tonic-gate 460Sstevel@tonic-gate /* 470Sstevel@tonic-gate * These are the vnode ops routines which implement the vnode interface to 480Sstevel@tonic-gate * the looped-back file system. These routines just take their parameters, 490Sstevel@tonic-gate * and then calling the appropriate real vnode routine(s) to do the work. 500Sstevel@tonic-gate */ 510Sstevel@tonic-gate 520Sstevel@tonic-gate static int 530Sstevel@tonic-gate lo_open(vnode_t **vpp, int flag, struct cred *cr) 540Sstevel@tonic-gate { 550Sstevel@tonic-gate vnode_t *vp = *vpp; 560Sstevel@tonic-gate vnode_t *rvp; 570Sstevel@tonic-gate vnode_t *oldvp; 580Sstevel@tonic-gate int error; 590Sstevel@tonic-gate 600Sstevel@tonic-gate #ifdef LODEBUG 610Sstevel@tonic-gate lo_dprint(4, "lo_open vp %p cnt=%d realvp %p cnt=%d\n", 620Sstevel@tonic-gate vp, vp->v_count, realvp(vp), realvp(vp)->v_count); 630Sstevel@tonic-gate #endif 640Sstevel@tonic-gate 650Sstevel@tonic-gate oldvp = vp; 660Sstevel@tonic-gate vp = rvp = realvp(vp); 670Sstevel@tonic-gate /* 680Sstevel@tonic-gate * Need to hold new reference to vp since VOP_OPEN() may 690Sstevel@tonic-gate * decide to release it. 700Sstevel@tonic-gate */ 710Sstevel@tonic-gate VN_HOLD(vp); 720Sstevel@tonic-gate error = VOP_OPEN(&rvp, flag, cr); 730Sstevel@tonic-gate 740Sstevel@tonic-gate if (!error && rvp != vp) { 750Sstevel@tonic-gate /* 760Sstevel@tonic-gate * the FS which we called should have released the 770Sstevel@tonic-gate * new reference on vp 780Sstevel@tonic-gate */ 79324Sowenr *vpp = makelonode(rvp, vtoli(oldvp->v_vfsp), 0); 80*1314Sowenr if ((*vpp)->v_type == VDIR) { 81*1314Sowenr /* 82*1314Sowenr * Copy over any looping flags to the new lnode. 83*1314Sowenr */ 84*1314Sowenr (vtol(*vpp))->lo_looping |= (vtol(oldvp))->lo_looping; 85*1314Sowenr } 860Sstevel@tonic-gate if (IS_DEVVP(*vpp)) { 870Sstevel@tonic-gate vnode_t *svp; 880Sstevel@tonic-gate 890Sstevel@tonic-gate svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr); 900Sstevel@tonic-gate VN_RELE(*vpp); 910Sstevel@tonic-gate if (svp == NULL) 920Sstevel@tonic-gate error = ENOSYS; 930Sstevel@tonic-gate else 940Sstevel@tonic-gate *vpp = svp; 950Sstevel@tonic-gate } 960Sstevel@tonic-gate VN_RELE(oldvp); 970Sstevel@tonic-gate } else { 980Sstevel@tonic-gate ASSERT(rvp->v_count > 1); 990Sstevel@tonic-gate VN_RELE(rvp); 1000Sstevel@tonic-gate } 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate return (error); 1030Sstevel@tonic-gate } 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate static int 1060Sstevel@tonic-gate lo_close( 1070Sstevel@tonic-gate vnode_t *vp, 1080Sstevel@tonic-gate int flag, 1090Sstevel@tonic-gate int count, 1100Sstevel@tonic-gate offset_t offset, 1110Sstevel@tonic-gate struct cred *cr) 1120Sstevel@tonic-gate { 1130Sstevel@tonic-gate #ifdef LODEBUG 1140Sstevel@tonic-gate lo_dprint(4, "lo_close vp %p realvp %p\n", vp, realvp(vp)); 1150Sstevel@tonic-gate #endif 1160Sstevel@tonic-gate vp = realvp(vp); 1170Sstevel@tonic-gate return (VOP_CLOSE(vp, flag, count, offset, cr)); 1180Sstevel@tonic-gate } 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate static int 1210Sstevel@tonic-gate lo_read(vnode_t *vp, struct uio *uiop, int ioflag, struct cred *cr, 1220Sstevel@tonic-gate caller_context_t *ct) 1230Sstevel@tonic-gate { 1240Sstevel@tonic-gate #ifdef LODEBUG 1250Sstevel@tonic-gate lo_dprint(4, "lo_read vp %p realvp %p\n", vp, realvp(vp)); 1260Sstevel@tonic-gate #endif 1270Sstevel@tonic-gate vp = realvp(vp); 1280Sstevel@tonic-gate return (VOP_READ(vp, uiop, ioflag, cr, ct)); 1290Sstevel@tonic-gate } 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate static int 1320Sstevel@tonic-gate lo_write(vnode_t *vp, struct uio *uiop, int ioflag, struct cred *cr, 1330Sstevel@tonic-gate caller_context_t *ct) 1340Sstevel@tonic-gate { 1350Sstevel@tonic-gate #ifdef LODEBUG 1360Sstevel@tonic-gate lo_dprint(4, "lo_write vp %p realvp %p\n", vp, realvp(vp)); 1370Sstevel@tonic-gate #endif 1380Sstevel@tonic-gate vp = realvp(vp); 1390Sstevel@tonic-gate return (VOP_WRITE(vp, uiop, ioflag, cr, ct)); 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate static int 1430Sstevel@tonic-gate lo_ioctl( 1440Sstevel@tonic-gate vnode_t *vp, 1450Sstevel@tonic-gate int cmd, 1460Sstevel@tonic-gate intptr_t arg, 1470Sstevel@tonic-gate int flag, 1480Sstevel@tonic-gate struct cred *cr, 1490Sstevel@tonic-gate int *rvalp) 1500Sstevel@tonic-gate { 1510Sstevel@tonic-gate #ifdef LODEBUG 1520Sstevel@tonic-gate lo_dprint(4, "lo_ioctl vp %p realvp %p\n", vp, realvp(vp)); 1530Sstevel@tonic-gate #endif 1540Sstevel@tonic-gate vp = realvp(vp); 1550Sstevel@tonic-gate return (VOP_IOCTL(vp, cmd, arg, flag, cr, rvalp)); 1560Sstevel@tonic-gate } 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate static int 1590Sstevel@tonic-gate lo_setfl(vnode_t *vp, int oflags, int nflags, cred_t *cr) 1600Sstevel@tonic-gate { 1610Sstevel@tonic-gate vp = realvp(vp); 1620Sstevel@tonic-gate return (VOP_SETFL(vp, oflags, nflags, cr)); 1630Sstevel@tonic-gate } 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate static int 1660Sstevel@tonic-gate lo_getattr( 1670Sstevel@tonic-gate vnode_t *vp, 1680Sstevel@tonic-gate struct vattr *vap, 1690Sstevel@tonic-gate int flags, 1700Sstevel@tonic-gate struct cred *cr) 1710Sstevel@tonic-gate { 1720Sstevel@tonic-gate int error; 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate #ifdef LODEBUG 1750Sstevel@tonic-gate lo_dprint(4, "lo_getattr vp %p realvp %p\n", vp, realvp(vp)); 1760Sstevel@tonic-gate #endif 1770Sstevel@tonic-gate if (error = VOP_GETATTR(realvp(vp), vap, flags, cr)) 1780Sstevel@tonic-gate return (error); 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate /* 1810Sstevel@tonic-gate * In zonedevfs mode, we pull a nasty trick; we make sure that 1820Sstevel@tonic-gate * the dev_t does *not* reflect the underlying device, so that 1830Sstevel@tonic-gate * no renames can occur to or from the /dev hierarchy. 1840Sstevel@tonic-gate */ 1850Sstevel@tonic-gate if (IS_ZONEDEVFS(vp)) { 1860Sstevel@tonic-gate vap->va_fsid = expldev(vp->v_vfsp->vfs_fsid.val[0]); 1870Sstevel@tonic-gate } 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate return (0); 1900Sstevel@tonic-gate } 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate static int 1930Sstevel@tonic-gate lo_setattr( 1940Sstevel@tonic-gate vnode_t *vp, 1950Sstevel@tonic-gate struct vattr *vap, 1960Sstevel@tonic-gate int flags, 1970Sstevel@tonic-gate struct cred *cr, 1980Sstevel@tonic-gate caller_context_t *ct) 1990Sstevel@tonic-gate { 2000Sstevel@tonic-gate #ifdef LODEBUG 2010Sstevel@tonic-gate lo_dprint(4, "lo_setattr vp %p realvp %p\n", vp, realvp(vp)); 2020Sstevel@tonic-gate #endif 2030Sstevel@tonic-gate if (IS_ZONEDEVFS(vp) && !IS_DEVVP(vp)) { 2040Sstevel@tonic-gate return (EACCES); 2050Sstevel@tonic-gate } 2060Sstevel@tonic-gate vp = realvp(vp); 2070Sstevel@tonic-gate return (VOP_SETATTR(vp, vap, flags, cr, ct)); 2080Sstevel@tonic-gate } 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate static int 2110Sstevel@tonic-gate lo_access(vnode_t *vp, int mode, int flags, struct cred *cr) 2120Sstevel@tonic-gate { 2130Sstevel@tonic-gate #ifdef LODEBUG 2140Sstevel@tonic-gate lo_dprint(4, "lo_access vp %p realvp %p\n", vp, realvp(vp)); 2150Sstevel@tonic-gate #endif 2160Sstevel@tonic-gate if (mode & VWRITE) { 2170Sstevel@tonic-gate if (vp->v_type == VREG && vn_is_readonly(vp)) 2180Sstevel@tonic-gate return (EROFS); 2190Sstevel@tonic-gate if (IS_ZONEDEVFS(vp) && !IS_DEVVP(vp)) 2200Sstevel@tonic-gate return (EACCES); 2210Sstevel@tonic-gate } 2220Sstevel@tonic-gate vp = realvp(vp); 2230Sstevel@tonic-gate return (VOP_ACCESS(vp, mode, flags, cr)); 2240Sstevel@tonic-gate } 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate static int 2270Sstevel@tonic-gate lo_fsync(vnode_t *vp, int syncflag, struct cred *cr) 2280Sstevel@tonic-gate { 2290Sstevel@tonic-gate #ifdef LODEBUG 2300Sstevel@tonic-gate lo_dprint(4, "lo_fsync vp %p realvp %p\n", vp, realvp(vp)); 2310Sstevel@tonic-gate #endif 2320Sstevel@tonic-gate vp = realvp(vp); 2330Sstevel@tonic-gate return (VOP_FSYNC(vp, syncflag, cr)); 2340Sstevel@tonic-gate } 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate /*ARGSUSED*/ 2370Sstevel@tonic-gate static void 2380Sstevel@tonic-gate lo_inactive(vnode_t *vp, struct cred *cr) 2390Sstevel@tonic-gate { 2400Sstevel@tonic-gate #ifdef LODEBUG 2410Sstevel@tonic-gate lo_dprint(4, "lo_inactive %p, realvp %p\n", vp, realvp(vp)); 2420Sstevel@tonic-gate #endif 2430Sstevel@tonic-gate freelonode(vtol(vp)); 2440Sstevel@tonic-gate } 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate /* ARGSUSED */ 2470Sstevel@tonic-gate static int 2480Sstevel@tonic-gate lo_fid(vnode_t *vp, struct fid *fidp) 2490Sstevel@tonic-gate { 2500Sstevel@tonic-gate #ifdef LODEBUG 2510Sstevel@tonic-gate lo_dprint(4, "lo_fid %p, realvp %p\n", vp, realvp(vp)); 2520Sstevel@tonic-gate #endif 2530Sstevel@tonic-gate vp = realvp(vp); 2540Sstevel@tonic-gate return (VOP_FID(vp, fidp)); 2550Sstevel@tonic-gate } 2560Sstevel@tonic-gate 2570Sstevel@tonic-gate /* 2580Sstevel@tonic-gate * Given a vnode of lofs type, lookup nm name and 2590Sstevel@tonic-gate * return a shadow vnode (of lofs type) of the 2600Sstevel@tonic-gate * real vnode found. 2610Sstevel@tonic-gate * 2620Sstevel@tonic-gate * Due to the nature of lofs, there is a potential 2630Sstevel@tonic-gate * looping in path traversal. 2640Sstevel@tonic-gate * 2650Sstevel@tonic-gate * starting from the mount point of an lofs; 2660Sstevel@tonic-gate * a loop is defined to be a traversal path 2670Sstevel@tonic-gate * where the mount point or the real vnode of 2680Sstevel@tonic-gate * the root of this lofs is encountered twice. 2690Sstevel@tonic-gate * Once at the start of traversal and second 2700Sstevel@tonic-gate * when the looping is found. 2710Sstevel@tonic-gate * 2720Sstevel@tonic-gate * When a loop is encountered, a shadow of the 2730Sstevel@tonic-gate * covered vnode is returned to stop the looping. 2740Sstevel@tonic-gate * 2750Sstevel@tonic-gate * This normally works, but with the advent of 2760Sstevel@tonic-gate * the new automounter, returning the shadow of the 2770Sstevel@tonic-gate * covered vnode (autonode, in this case) does not 2780Sstevel@tonic-gate * stop the loop. Because further lookup on this 2790Sstevel@tonic-gate * lonode will cause the autonode to call lo_lookup() 2800Sstevel@tonic-gate * on the lonode covering it. 2810Sstevel@tonic-gate * 2820Sstevel@tonic-gate * example "/net/jurassic/net/jurassic" is a loop. 2830Sstevel@tonic-gate * returning the shadow of the autonode corresponding to 2840Sstevel@tonic-gate * "/net/jurassic/net/jurassic" will not terminate the 2850Sstevel@tonic-gate * loop. To solve this problem we allow the loop to go 286324Sowenr * through one more level component lookup. Whichever 287324Sowenr * directory is then looked up in "/net/jurassic/net/jurassic" 288324Sowenr * the vnode returned is the vnode covered by the autonode 289324Sowenr * "net" and this will terminate the loop. 2900Sstevel@tonic-gate * 2910Sstevel@tonic-gate * Lookup for dot dot has to be dealt with separately. 2920Sstevel@tonic-gate * It will be nice to have a "one size fits all" kind 2930Sstevel@tonic-gate * of solution, so that we don't have so many ifs statement 2940Sstevel@tonic-gate * in the lo_lookup() to handle dotdot. But, since 2950Sstevel@tonic-gate * there are so many special cases to handle different 2960Sstevel@tonic-gate * kinds looping above, we need special codes to handle 2970Sstevel@tonic-gate * dotdot lookup as well. 2980Sstevel@tonic-gate */ 2990Sstevel@tonic-gate static int 3000Sstevel@tonic-gate lo_lookup( 3010Sstevel@tonic-gate vnode_t *dvp, 3020Sstevel@tonic-gate char *nm, 3030Sstevel@tonic-gate vnode_t **vpp, 3040Sstevel@tonic-gate struct pathname *pnp, 3050Sstevel@tonic-gate int flags, 3060Sstevel@tonic-gate vnode_t *rdir, 3070Sstevel@tonic-gate struct cred *cr) 3080Sstevel@tonic-gate { 3090Sstevel@tonic-gate vnode_t *vp = NULL, *tvp = NULL, *nonlovp; 3100Sstevel@tonic-gate int error, is_indirectloop; 3110Sstevel@tonic-gate vnode_t *realdvp = realvp(dvp); 3120Sstevel@tonic-gate struct loinfo *li = vtoli(dvp->v_vfsp); 3130Sstevel@tonic-gate int looping = 0; 314324Sowenr int autoloop = 0; 3150Sstevel@tonic-gate int doingdotdot = 0; 3160Sstevel@tonic-gate int nosub = 0; 317324Sowenr int mkflag = 0; 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate /* 3200Sstevel@tonic-gate * If name is empty and no XATTR flags are set, then return 3210Sstevel@tonic-gate * dvp (empty name == lookup "."). If an XATTR flag is set 3220Sstevel@tonic-gate * then we need to call VOP_LOOKUP to get the xattr dir. 3230Sstevel@tonic-gate */ 3240Sstevel@tonic-gate if (nm[0] == '\0' && ! (flags & (CREATE_XATTR_DIR|LOOKUP_XATTR))) { 3250Sstevel@tonic-gate VN_HOLD(dvp); 3260Sstevel@tonic-gate *vpp = dvp; 3270Sstevel@tonic-gate return (0); 3280Sstevel@tonic-gate } 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate if (nm[0] == '.' && nm[1] == '.' && nm[2] == '\0') { 3310Sstevel@tonic-gate doingdotdot++; 3320Sstevel@tonic-gate /* 3330Sstevel@tonic-gate * Handle ".." out of mounted filesystem 3340Sstevel@tonic-gate */ 3350Sstevel@tonic-gate while ((realdvp->v_flag & VROOT) && realdvp != rootdir) { 3360Sstevel@tonic-gate realdvp = realdvp->v_vfsp->vfs_vnodecovered; 3370Sstevel@tonic-gate ASSERT(realdvp != NULL); 3380Sstevel@tonic-gate } 3390Sstevel@tonic-gate } 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate *vpp = NULL; /* default(error) case */ 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate /* 3440Sstevel@tonic-gate * Do the normal lookup 3450Sstevel@tonic-gate */ 3461085Smarks if (error = VOP_LOOKUP(realdvp, nm, &vp, pnp, flags, rdir, cr)) { 3471085Smarks vp = NULL; 3480Sstevel@tonic-gate goto out; 3491085Smarks } 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate /* 3520Sstevel@tonic-gate * We do this check here to avoid returning a stale file handle to the 3530Sstevel@tonic-gate * caller. 3540Sstevel@tonic-gate */ 3550Sstevel@tonic-gate if (nm[0] == '.' && nm[1] == '\0') { 3560Sstevel@tonic-gate ASSERT(vp == realdvp); 3570Sstevel@tonic-gate VN_HOLD(dvp); 3580Sstevel@tonic-gate VN_RELE(vp); 3590Sstevel@tonic-gate *vpp = dvp; 3600Sstevel@tonic-gate return (0); 3610Sstevel@tonic-gate } 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate if (doingdotdot) { 364324Sowenr if ((vtol(dvp))->lo_looping & LO_LOOPING) { 3650Sstevel@tonic-gate vfs_t *vfsp; 3660Sstevel@tonic-gate 3671153Snr123932 error = vn_vfsrlock_wait(realdvp); 3680Sstevel@tonic-gate if (error) 3690Sstevel@tonic-gate goto out; 3700Sstevel@tonic-gate vfsp = vn_mountedvfs(realdvp); 371324Sowenr /* 372324Sowenr * In the standard case if the looping flag is set and 373324Sowenr * performing dotdot we would be returning from a 374324Sowenr * covered vnode, implying vfsp could not be null. The 375324Sowenr * exceptions being if we have looping and overlay 376324Sowenr * mounts or looping and covered file systems. 377324Sowenr */ 378324Sowenr if (vfsp == NULL) { 3790Sstevel@tonic-gate /* 380324Sowenr * Overlay mount or covered file system, 381324Sowenr * so just make the shadow node. 3820Sstevel@tonic-gate */ 3830Sstevel@tonic-gate vn_vfsunlock(realdvp); 384324Sowenr *vpp = makelonode(vp, li, 0); 385324Sowenr (vtol(*vpp))->lo_looping |= LO_LOOPING; 386324Sowenr return (0); 387324Sowenr } 388324Sowenr /* 389324Sowenr * When looping get the actual found vnode 390324Sowenr * instead of the vnode covered. 391324Sowenr * Here we have to hold the lock for realdvp 392324Sowenr * since an unmount during the traversal to the 393324Sowenr * root vnode would turn *vfsp into garbage 394324Sowenr * which would be fatal. 395324Sowenr */ 3961153Snr123932 error = VFS_ROOT(vfsp, &tvp); 397324Sowenr vn_vfsunlock(realdvp); 3980Sstevel@tonic-gate 399324Sowenr if (error) 400324Sowenr goto out; 4011153Snr123932 402324Sowenr if ((tvp == li->li_rootvp) && (vp == realvp(tvp))) { 403324Sowenr /* 404324Sowenr * we're back at the real vnode 405324Sowenr * of the rootvp 406324Sowenr * 407324Sowenr * return the rootvp 408324Sowenr * Ex: /mnt/mnt/.. 409324Sowenr * where / has been lofs-mounted 410324Sowenr * onto /mnt. Return the lofs 411324Sowenr * node mounted at /mnt. 412324Sowenr */ 413324Sowenr *vpp = tvp; 414324Sowenr VN_RELE(vp); 415324Sowenr return (0); 4160Sstevel@tonic-gate } else { 4170Sstevel@tonic-gate /* 418324Sowenr * We are returning from a covered 419324Sowenr * node whose vfs_mountedhere is 420324Sowenr * not pointing to vfs of the current 421324Sowenr * root vnode. 422324Sowenr * This is a condn where in we 423324Sowenr * returned a covered node say Zc 424324Sowenr * but Zc is not the cover of current 425324Sowenr * root. 426324Sowenr * i.e.., if X is the root vnode 427324Sowenr * lookup(Zc,"..") is taking us to 428324Sowenr * X. 429324Sowenr * Ex: /net/X/net/X/Y 4300Sstevel@tonic-gate * 431324Sowenr * If LO_AUTOLOOP (autofs/lofs looping detected) 432324Sowenr * has been set then we are encountering the 433324Sowenr * cover of Y (Y being any directory vnode 434324Sowenr * under /net/X/net/X/). 435324Sowenr * When performing a dotdot set the 436324Sowenr * returned vp to the vnode covered 437324Sowenr * by the mounted lofs, ie /net/X/net/X 4380Sstevel@tonic-gate */ 439324Sowenr VN_RELE(tvp); 440324Sowenr if ((vtol(dvp))->lo_looping & LO_AUTOLOOP) { 441324Sowenr VN_RELE(vp); 442324Sowenr vp = li->li_rootvp; 443324Sowenr vp = vp->v_vfsp->vfs_vnodecovered; 4440Sstevel@tonic-gate VN_HOLD(vp); 445324Sowenr *vpp = makelonode(vp, li, 0); 446324Sowenr (vtol(*vpp))->lo_looping |= LO_LOOPING; 447324Sowenr return (0); 4480Sstevel@tonic-gate } 4490Sstevel@tonic-gate } 4500Sstevel@tonic-gate } else { 4510Sstevel@tonic-gate /* 4520Sstevel@tonic-gate * No frills just make the shadow node. 4530Sstevel@tonic-gate */ 454324Sowenr *vpp = makelonode(vp, li, 0); 4550Sstevel@tonic-gate return (0); 4560Sstevel@tonic-gate } 4570Sstevel@tonic-gate } 4580Sstevel@tonic-gate 4590Sstevel@tonic-gate nosub = (vtoli(dvp->v_vfsp)->li_flag & LO_NOSUB); 4600Sstevel@tonic-gate 4610Sstevel@tonic-gate /* 4620Sstevel@tonic-gate * If this vnode is mounted on, then we 4630Sstevel@tonic-gate * traverse to the vnode which is the root of 4640Sstevel@tonic-gate * the mounted file system. 4650Sstevel@tonic-gate */ 4660Sstevel@tonic-gate if (!nosub && (error = traverse(&vp))) 4670Sstevel@tonic-gate goto out; 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate /* 4700Sstevel@tonic-gate * Make a lnode for the real vnode. 4710Sstevel@tonic-gate */ 4720Sstevel@tonic-gate if (vp->v_type != VDIR || nosub) { 473324Sowenr *vpp = makelonode(vp, li, 0); 4740Sstevel@tonic-gate if (IS_DEVVP(*vpp)) { 4750Sstevel@tonic-gate vnode_t *svp; 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr); 4780Sstevel@tonic-gate VN_RELE(*vpp); 4790Sstevel@tonic-gate if (svp == NULL) 4800Sstevel@tonic-gate error = ENOSYS; 4810Sstevel@tonic-gate else 4820Sstevel@tonic-gate *vpp = svp; 4830Sstevel@tonic-gate } 4840Sstevel@tonic-gate return (error); 4850Sstevel@tonic-gate } 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate /* 4880Sstevel@tonic-gate * if the found vnode (vp) is not of type lofs 4890Sstevel@tonic-gate * then we're just going to make a shadow of that 4900Sstevel@tonic-gate * vp and get out. 4910Sstevel@tonic-gate * 4920Sstevel@tonic-gate * If the found vnode (vp) is of lofs type, and 4930Sstevel@tonic-gate * we're not doing dotdot, check if we are 4940Sstevel@tonic-gate * looping. 4950Sstevel@tonic-gate */ 4960Sstevel@tonic-gate if (!doingdotdot && vfs_matchops(vp->v_vfsp, lo_vfsops)) { 4970Sstevel@tonic-gate /* 4980Sstevel@tonic-gate * Check if we're looping, i.e. 4990Sstevel@tonic-gate * vp equals the root vp of the lofs, directly 5000Sstevel@tonic-gate * or indirectly, return the covered node. 5010Sstevel@tonic-gate */ 5020Sstevel@tonic-gate 503324Sowenr if (!((vtol(dvp))->lo_looping & LO_LOOPING)) { 5040Sstevel@tonic-gate if (vp == li->li_rootvp) { 5050Sstevel@tonic-gate /* 5060Sstevel@tonic-gate * Direct looping condn. 5070Sstevel@tonic-gate * Ex:- X is / mounted directory so lookup of 5080Sstevel@tonic-gate * /X/X is a direct looping condn. 5090Sstevel@tonic-gate */ 5100Sstevel@tonic-gate tvp = vp; 5110Sstevel@tonic-gate vp = vp->v_vfsp->vfs_vnodecovered; 5120Sstevel@tonic-gate VN_HOLD(vp); 5130Sstevel@tonic-gate VN_RELE(tvp); 5140Sstevel@tonic-gate looping++; 5150Sstevel@tonic-gate } else { 5160Sstevel@tonic-gate /* 5170Sstevel@tonic-gate * Indirect looping can be defined as 5180Sstevel@tonic-gate * real lookup returning rootvp of the current 5190Sstevel@tonic-gate * tree in any level of recursion. 5200Sstevel@tonic-gate * 5210Sstevel@tonic-gate * This check is useful if there are multiple 5220Sstevel@tonic-gate * levels of lofs indirections. Suppose vnode X 5230Sstevel@tonic-gate * in the current lookup has as its real vnode 5240Sstevel@tonic-gate * another lofs node. Y = realvp(X) Y should be 5250Sstevel@tonic-gate * a lofs node for the check to continue or Y 5260Sstevel@tonic-gate * is not the rootvp of X. 5270Sstevel@tonic-gate * Ex:- say X and Y are two vnodes 5280Sstevel@tonic-gate * say real(Y) is X and real(X) is Z 5290Sstevel@tonic-gate * parent vnode for X and Y is Z 5300Sstevel@tonic-gate * lookup(Y,"path") say we are looking for Y 5310Sstevel@tonic-gate * again under Y and we have to return Yc. 5320Sstevel@tonic-gate * but the lookup of Y under Y doesnot return 5330Sstevel@tonic-gate * Y the root vnode again here is why. 5340Sstevel@tonic-gate * 1. lookup(Y,"path of Y") will go to 5350Sstevel@tonic-gate * 2. lookup(real(Y),"path of Y") and then to 5360Sstevel@tonic-gate * 3. lookup(real(X),"path of Y"). 5370Sstevel@tonic-gate * and now what lookup level 1 sees is the 5380Sstevel@tonic-gate * outcome of 2 but the vnode Y is due to 5390Sstevel@tonic-gate * lookup(Z,"path of Y") so we have to skip 5400Sstevel@tonic-gate * intermediate levels to find if in any level 5410Sstevel@tonic-gate * there is a looping. 5420Sstevel@tonic-gate */ 5430Sstevel@tonic-gate is_indirectloop = 0; 5440Sstevel@tonic-gate nonlovp = vp; 5450Sstevel@tonic-gate while ( 5460Sstevel@tonic-gate vfs_matchops(nonlovp->v_vfsp, lo_vfsops) && 5470Sstevel@tonic-gate !(is_indirectloop)) { 5480Sstevel@tonic-gate if (li->li_rootvp == nonlovp) { 5490Sstevel@tonic-gate is_indirectloop++; 5500Sstevel@tonic-gate break; 5510Sstevel@tonic-gate } 5520Sstevel@tonic-gate nonlovp = realvp(nonlovp); 5530Sstevel@tonic-gate } 5540Sstevel@tonic-gate 5550Sstevel@tonic-gate if (is_indirectloop) { 5560Sstevel@tonic-gate VN_RELE(vp); 5570Sstevel@tonic-gate vp = nonlovp; 5580Sstevel@tonic-gate vp = vp->v_vfsp->vfs_vnodecovered; 5590Sstevel@tonic-gate VN_HOLD(vp); 5600Sstevel@tonic-gate looping++; 5610Sstevel@tonic-gate } 5620Sstevel@tonic-gate } 5630Sstevel@tonic-gate } else { 5640Sstevel@tonic-gate /* 5650Sstevel@tonic-gate * come here only because of the interaction between 5660Sstevel@tonic-gate * the autofs and lofs. 5670Sstevel@tonic-gate * 5680Sstevel@tonic-gate * Lookup of "/net/X/net/X" will return a shadow of 5690Sstevel@tonic-gate * an autonode X_a which we call X_l. 5700Sstevel@tonic-gate * 5710Sstevel@tonic-gate * Lookup of anything under X_l, will trigger a call to 5720Sstevel@tonic-gate * auto_lookup(X_a,nm) which will eventually call 5730Sstevel@tonic-gate * lo_lookup(X_lr,nm) where X_lr is the root vnode of 5740Sstevel@tonic-gate * the current lofs. 5750Sstevel@tonic-gate * 5760Sstevel@tonic-gate * We come here only when we are called with X_l as dvp 5770Sstevel@tonic-gate * and look for something underneath. 5780Sstevel@tonic-gate * 579324Sowenr * Now that an autofs/lofs looping condition has been 580324Sowenr * identified any directory vnode contained within 581324Sowenr * dvp will be set to the vnode covered by the 582324Sowenr * mounted autofs. Thus all directories within dvp 583324Sowenr * will appear empty hence teminating the looping. 584324Sowenr * The LO_AUTOLOOP flag is set on the returned lonode 585324Sowenr * to indicate the termination of the autofs/lofs 586324Sowenr * looping. This is required for the correct behaviour 587324Sowenr * when performing a dotdot. 5880Sstevel@tonic-gate */ 5890Sstevel@tonic-gate realdvp = realvp(dvp); 5900Sstevel@tonic-gate while (vfs_matchops(realdvp->v_vfsp, lo_vfsops)) { 5910Sstevel@tonic-gate realdvp = realvp(realdvp); 5920Sstevel@tonic-gate } 5930Sstevel@tonic-gate 5940Sstevel@tonic-gate error = VFS_ROOT(realdvp->v_vfsp, &tvp); 5950Sstevel@tonic-gate if (error) 5960Sstevel@tonic-gate goto out; 5970Sstevel@tonic-gate /* 5980Sstevel@tonic-gate * tvp now contains the rootvp of the vfs of the 599324Sowenr * real vnode of dvp. The directory vnode vp is set 600324Sowenr * to the covered vnode to terminate looping. No 601324Sowenr * distinction is made between any vp as all directory 602324Sowenr * vnodes contained in dvp are returned as the covered 603324Sowenr * vnode. 6040Sstevel@tonic-gate */ 605324Sowenr VN_RELE(vp); 606*1314Sowenr vp = tvp; /* possibly is an autonode */ 6070Sstevel@tonic-gate 608324Sowenr /* 609324Sowenr * Need to find the covered vnode 610324Sowenr */ 611*1314Sowenr if (vp->v_vfsp->vfs_vnodecovered == NULL) { 612*1314Sowenr /* 613*1314Sowenr * We don't have a covered vnode so this isn't 614*1314Sowenr * an autonode. To find the autonode simply 615*1314Sowenr * find the vnode covered by the lofs rootvp. 616*1314Sowenr */ 617*1314Sowenr vp = li->li_rootvp; 618*1314Sowenr vp = vp->v_vfsp->vfs_vnodecovered; 619*1314Sowenr VN_RELE(tvp); 620*1314Sowenr error = VFS_ROOT(vp->v_vfsp, &tvp); 621*1314Sowenr if (error) 622*1314Sowenr goto out; 623*1314Sowenr vp = tvp; /* now this is an autonode */ 624*1314Sowenr if (vp->v_vfsp->vfs_vnodecovered == NULL) { 625*1314Sowenr /* 626*1314Sowenr * Still can't find a covered vnode. 627*1314Sowenr * Fail the lookup, or we'd loop. 628*1314Sowenr */ 629*1314Sowenr error = ENOENT; 630*1314Sowenr goto out; 631*1314Sowenr } 632*1314Sowenr } 633324Sowenr vp = vp->v_vfsp->vfs_vnodecovered; 634324Sowenr VN_HOLD(vp); 635324Sowenr VN_RELE(tvp); 636324Sowenr /* 637324Sowenr * Force the creation of a new lnode even if the hash 638324Sowenr * table contains a lnode that references this vnode. 639324Sowenr */ 640324Sowenr mkflag = LOF_FORCE; 641324Sowenr autoloop++; 6420Sstevel@tonic-gate } 6430Sstevel@tonic-gate } 644324Sowenr *vpp = makelonode(vp, li, mkflag); 6450Sstevel@tonic-gate 646324Sowenr if ((looping) || 647324Sowenr (((vtol(dvp))->lo_looping & LO_LOOPING) && !doingdotdot)) { 648324Sowenr (vtol(*vpp))->lo_looping |= LO_LOOPING; 649324Sowenr } 650324Sowenr 651324Sowenr if (autoloop) { 652324Sowenr (vtol(*vpp))->lo_looping |= LO_AUTOLOOP; 6530Sstevel@tonic-gate } 6540Sstevel@tonic-gate 6550Sstevel@tonic-gate out: 6560Sstevel@tonic-gate if (error != 0 && vp != NULL) 6570Sstevel@tonic-gate VN_RELE(vp); 6580Sstevel@tonic-gate #ifdef LODEBUG 6590Sstevel@tonic-gate lo_dprint(4, 6600Sstevel@tonic-gate "lo_lookup dvp %x realdvp %x nm '%s' newvp %x real vp %x error %d\n", 6610Sstevel@tonic-gate dvp, realvp(dvp), nm, *vpp, vp, error); 6620Sstevel@tonic-gate #endif 6630Sstevel@tonic-gate return (error); 6640Sstevel@tonic-gate } 6650Sstevel@tonic-gate 6660Sstevel@tonic-gate /*ARGSUSED*/ 6670Sstevel@tonic-gate static int 6680Sstevel@tonic-gate lo_create( 6690Sstevel@tonic-gate vnode_t *dvp, 6700Sstevel@tonic-gate char *nm, 6710Sstevel@tonic-gate struct vattr *va, 6720Sstevel@tonic-gate enum vcexcl exclusive, 6730Sstevel@tonic-gate int mode, 6740Sstevel@tonic-gate vnode_t **vpp, 6750Sstevel@tonic-gate struct cred *cr, 6760Sstevel@tonic-gate int flag) 6770Sstevel@tonic-gate { 6780Sstevel@tonic-gate int error; 6790Sstevel@tonic-gate vnode_t *vp = NULL; 6801224Srd117015 vnode_t *tvp = NULL; 6810Sstevel@tonic-gate 6820Sstevel@tonic-gate #ifdef LODEBUG 6830Sstevel@tonic-gate lo_dprint(4, "lo_create vp %p realvp %p\n", dvp, realvp(dvp)); 6840Sstevel@tonic-gate #endif 6850Sstevel@tonic-gate if (*nm == '\0') { 6860Sstevel@tonic-gate ASSERT(vpp && dvp == *vpp); 6870Sstevel@tonic-gate vp = realvp(*vpp); 6880Sstevel@tonic-gate } 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate if (IS_ZONEDEVFS(dvp)) { 6911224Srd117015 6921224Srd117015 /* 6931224Srd117015 * In the case of an exclusive create, *vpp will not 6941224Srd117015 * be populated. We must check to see if the file exists. 6951224Srd117015 */ 6961224Srd117015 if ((exclusive == EXCL) && (*nm != '\0')) { 6971224Srd117015 (void) VOP_LOOKUP(dvp, nm, &tvp, NULL, 0, NULL, cr); 6981224Srd117015 } 6991224Srd117015 7000Sstevel@tonic-gate /* Is this truly a create? If so, fail */ 7011224Srd117015 if ((*vpp == NULL) && (tvp == NULL)) 7020Sstevel@tonic-gate return (EACCES); 7030Sstevel@tonic-gate 7041224Srd117015 if (tvp != NULL) 7051224Srd117015 VN_RELE(tvp); 7061224Srd117015 7070Sstevel@tonic-gate /* Is this an open of a non-special for writing? If so, fail */ 7080Sstevel@tonic-gate if (*vpp != NULL && (mode & VWRITE) && !IS_DEVVP(*vpp)) 7090Sstevel@tonic-gate return (EACCES); 7100Sstevel@tonic-gate } 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate error = VOP_CREATE(realvp(dvp), nm, va, exclusive, mode, &vp, cr, flag); 7130Sstevel@tonic-gate if (!error) { 714324Sowenr *vpp = makelonode(vp, vtoli(dvp->v_vfsp), 0); 7150Sstevel@tonic-gate if (IS_DEVVP(*vpp)) { 7160Sstevel@tonic-gate vnode_t *svp; 7170Sstevel@tonic-gate 7180Sstevel@tonic-gate svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr); 7190Sstevel@tonic-gate VN_RELE(*vpp); 7200Sstevel@tonic-gate if (svp == NULL) 7210Sstevel@tonic-gate error = ENOSYS; 7220Sstevel@tonic-gate else 7230Sstevel@tonic-gate *vpp = svp; 7240Sstevel@tonic-gate } 7250Sstevel@tonic-gate } 7260Sstevel@tonic-gate return (error); 7270Sstevel@tonic-gate } 7280Sstevel@tonic-gate 7290Sstevel@tonic-gate static int 7300Sstevel@tonic-gate lo_remove(vnode_t *dvp, char *nm, struct cred *cr) 7310Sstevel@tonic-gate { 7320Sstevel@tonic-gate #ifdef LODEBUG 7330Sstevel@tonic-gate lo_dprint(4, "lo_remove vp %p realvp %p\n", dvp, realvp(dvp)); 7340Sstevel@tonic-gate #endif 7350Sstevel@tonic-gate if (IS_ZONEDEVFS(dvp)) 7360Sstevel@tonic-gate return (EACCES); 7370Sstevel@tonic-gate dvp = realvp(dvp); 7380Sstevel@tonic-gate return (VOP_REMOVE(dvp, nm, cr)); 7390Sstevel@tonic-gate } 7400Sstevel@tonic-gate 7410Sstevel@tonic-gate static int 7420Sstevel@tonic-gate lo_link(vnode_t *tdvp, vnode_t *vp, char *tnm, struct cred *cr) 7430Sstevel@tonic-gate { 7440Sstevel@tonic-gate #ifdef LODEBUG 7450Sstevel@tonic-gate lo_dprint(4, "lo_link vp %p realvp %p\n", vp, realvp(vp)); 7460Sstevel@tonic-gate #endif 7470Sstevel@tonic-gate while (vn_matchops(vp, lo_vnodeops)) { 7480Sstevel@tonic-gate if (IS_ZONEDEVFS(vp)) 7490Sstevel@tonic-gate return (EACCES); 7500Sstevel@tonic-gate vp = realvp(vp); 7510Sstevel@tonic-gate } 7520Sstevel@tonic-gate while (vn_matchops(tdvp, lo_vnodeops)) { 7530Sstevel@tonic-gate if (IS_ZONEDEVFS(tdvp)) 7540Sstevel@tonic-gate return (EACCES); 7550Sstevel@tonic-gate tdvp = realvp(tdvp); 7560Sstevel@tonic-gate } 7570Sstevel@tonic-gate if (vp->v_vfsp != tdvp->v_vfsp) 7580Sstevel@tonic-gate return (EXDEV); 7590Sstevel@tonic-gate return (VOP_LINK(tdvp, vp, tnm, cr)); 7600Sstevel@tonic-gate } 7610Sstevel@tonic-gate 7620Sstevel@tonic-gate static int 7630Sstevel@tonic-gate lo_rename( 7640Sstevel@tonic-gate vnode_t *odvp, 7650Sstevel@tonic-gate char *onm, 7660Sstevel@tonic-gate vnode_t *ndvp, 7670Sstevel@tonic-gate char *nnm, 7680Sstevel@tonic-gate struct cred *cr) 7690Sstevel@tonic-gate { 7700Sstevel@tonic-gate vnode_t *tnvp; 7710Sstevel@tonic-gate 7720Sstevel@tonic-gate #ifdef LODEBUG 7730Sstevel@tonic-gate lo_dprint(4, "lo_rename vp %p realvp %p\n", odvp, realvp(odvp)); 7740Sstevel@tonic-gate #endif 7750Sstevel@tonic-gate if (IS_ZONEDEVFS(odvp)) 7760Sstevel@tonic-gate return (EACCES); 7770Sstevel@tonic-gate /* 7780Sstevel@tonic-gate * We need to make sure we're not trying to remove a mount point for a 7790Sstevel@tonic-gate * filesystem mounted on top of lofs, which only we know about. 7800Sstevel@tonic-gate */ 7810Sstevel@tonic-gate if (vn_matchops(ndvp, lo_vnodeops)) /* Not our problem. */ 7820Sstevel@tonic-gate goto rename; 7830Sstevel@tonic-gate if (VOP_LOOKUP(ndvp, nnm, &tnvp, NULL, 0, NULL, cr) != 0) 7840Sstevel@tonic-gate goto rename; 7850Sstevel@tonic-gate if (tnvp->v_type != VDIR) { 7860Sstevel@tonic-gate VN_RELE(tnvp); 7870Sstevel@tonic-gate goto rename; 7880Sstevel@tonic-gate } 7890Sstevel@tonic-gate if (vn_mountedvfs(tnvp)) { 7900Sstevel@tonic-gate VN_RELE(tnvp); 7910Sstevel@tonic-gate return (EBUSY); 7920Sstevel@tonic-gate } 7930Sstevel@tonic-gate VN_RELE(tnvp); 7940Sstevel@tonic-gate rename: 7950Sstevel@tonic-gate /* 7960Sstevel@tonic-gate * Since the case we're dealing with above can happen at any layer in 7970Sstevel@tonic-gate * the stack of lofs filesystems, we need to recurse down the stack, 7980Sstevel@tonic-gate * checking to see if there are any instances of a filesystem mounted on 7990Sstevel@tonic-gate * top of lofs. In order to keep on using the lofs version of 8000Sstevel@tonic-gate * VOP_RENAME(), we make sure that while the target directory is of type 8010Sstevel@tonic-gate * lofs, the source directory (the one used for getting the fs-specific 8020Sstevel@tonic-gate * version of VOP_RENAME()) is also of type lofs. 8030Sstevel@tonic-gate */ 8040Sstevel@tonic-gate if (vn_matchops(ndvp, lo_vnodeops)) { 8050Sstevel@tonic-gate if (IS_ZONEDEVFS(ndvp)) 8060Sstevel@tonic-gate return (EACCES); 8070Sstevel@tonic-gate ndvp = realvp(ndvp); /* Check the next layer */ 8080Sstevel@tonic-gate } else { 8090Sstevel@tonic-gate /* 8100Sstevel@tonic-gate * We can go fast here 8110Sstevel@tonic-gate */ 8120Sstevel@tonic-gate while (vn_matchops(odvp, lo_vnodeops)) { 8130Sstevel@tonic-gate if (IS_ZONEDEVFS(odvp)) 8140Sstevel@tonic-gate return (EACCES); 8150Sstevel@tonic-gate odvp = realvp(odvp); 8160Sstevel@tonic-gate } 8170Sstevel@tonic-gate if (odvp->v_vfsp != ndvp->v_vfsp) 8180Sstevel@tonic-gate return (EXDEV); 8190Sstevel@tonic-gate } 8200Sstevel@tonic-gate return (VOP_RENAME(odvp, onm, ndvp, nnm, cr)); 8210Sstevel@tonic-gate } 8220Sstevel@tonic-gate 8230Sstevel@tonic-gate static int 8240Sstevel@tonic-gate lo_mkdir( 8250Sstevel@tonic-gate vnode_t *dvp, 8260Sstevel@tonic-gate char *nm, 8270Sstevel@tonic-gate struct vattr *va, 8280Sstevel@tonic-gate vnode_t **vpp, 8290Sstevel@tonic-gate struct cred *cr) 8300Sstevel@tonic-gate { 8310Sstevel@tonic-gate int error; 8320Sstevel@tonic-gate 8330Sstevel@tonic-gate #ifdef LODEBUG 8340Sstevel@tonic-gate lo_dprint(4, "lo_mkdir vp %p realvp %p\n", dvp, realvp(dvp)); 8350Sstevel@tonic-gate #endif 8360Sstevel@tonic-gate if (IS_ZONEDEVFS(dvp)) 8370Sstevel@tonic-gate return (EACCES); 8380Sstevel@tonic-gate error = VOP_MKDIR(realvp(dvp), nm, va, vpp, cr); 8390Sstevel@tonic-gate if (!error) 840324Sowenr *vpp = makelonode(*vpp, vtoli(dvp->v_vfsp), 0); 8410Sstevel@tonic-gate return (error); 8420Sstevel@tonic-gate } 8430Sstevel@tonic-gate 8440Sstevel@tonic-gate static int 8450Sstevel@tonic-gate lo_realvp(vnode_t *vp, vnode_t **vpp) 8460Sstevel@tonic-gate { 8470Sstevel@tonic-gate #ifdef LODEBUG 8480Sstevel@tonic-gate lo_dprint(4, "lo_realvp %p\n", vp); 8490Sstevel@tonic-gate #endif 8500Sstevel@tonic-gate while (vn_matchops(vp, lo_vnodeops)) 8510Sstevel@tonic-gate vp = realvp(vp); 8520Sstevel@tonic-gate 8530Sstevel@tonic-gate if (VOP_REALVP(vp, vpp) != 0) 8540Sstevel@tonic-gate *vpp = vp; 8550Sstevel@tonic-gate return (0); 8560Sstevel@tonic-gate } 8570Sstevel@tonic-gate 8580Sstevel@tonic-gate static int 8590Sstevel@tonic-gate lo_rmdir( 8600Sstevel@tonic-gate vnode_t *dvp, 8610Sstevel@tonic-gate char *nm, 8620Sstevel@tonic-gate vnode_t *cdir, 8630Sstevel@tonic-gate struct cred *cr) 8640Sstevel@tonic-gate { 8650Sstevel@tonic-gate vnode_t *rvp = cdir; 8660Sstevel@tonic-gate 8670Sstevel@tonic-gate #ifdef LODEBUG 8680Sstevel@tonic-gate lo_dprint(4, "lo_rmdir vp %p realvp %p\n", dvp, realvp(dvp)); 8690Sstevel@tonic-gate #endif 8700Sstevel@tonic-gate if (IS_ZONEDEVFS(dvp)) 8710Sstevel@tonic-gate return (EACCES); 8720Sstevel@tonic-gate /* if cdir is lofs vnode ptr get its real vnode ptr */ 8730Sstevel@tonic-gate if (vn_matchops(dvp, vn_getops(rvp))) 8740Sstevel@tonic-gate (void) lo_realvp(cdir, &rvp); 8750Sstevel@tonic-gate dvp = realvp(dvp); 8760Sstevel@tonic-gate return (VOP_RMDIR(dvp, nm, rvp, cr)); 8770Sstevel@tonic-gate } 8780Sstevel@tonic-gate 8790Sstevel@tonic-gate static int 8800Sstevel@tonic-gate lo_symlink( 8810Sstevel@tonic-gate vnode_t *dvp, 8820Sstevel@tonic-gate char *lnm, 8830Sstevel@tonic-gate struct vattr *tva, 8840Sstevel@tonic-gate char *tnm, 8850Sstevel@tonic-gate struct cred *cr) 8860Sstevel@tonic-gate { 8870Sstevel@tonic-gate #ifdef LODEBUG 8880Sstevel@tonic-gate lo_dprint(4, "lo_symlink vp %p realvp %p\n", dvp, realvp(dvp)); 8890Sstevel@tonic-gate #endif 8900Sstevel@tonic-gate if (IS_ZONEDEVFS(dvp)) 8910Sstevel@tonic-gate return (EACCES); 8920Sstevel@tonic-gate dvp = realvp(dvp); 8930Sstevel@tonic-gate return (VOP_SYMLINK(dvp, lnm, tva, tnm, cr)); 8940Sstevel@tonic-gate } 8950Sstevel@tonic-gate 8960Sstevel@tonic-gate static int 8970Sstevel@tonic-gate lo_readlink(vnode_t *vp, struct uio *uiop, struct cred *cr) 8980Sstevel@tonic-gate { 8990Sstevel@tonic-gate vp = realvp(vp); 9000Sstevel@tonic-gate return (VOP_READLINK(vp, uiop, cr)); 9010Sstevel@tonic-gate } 9020Sstevel@tonic-gate 9030Sstevel@tonic-gate static int 9040Sstevel@tonic-gate lo_readdir(vnode_t *vp, struct uio *uiop, struct cred *cr, int *eofp) 9050Sstevel@tonic-gate { 9060Sstevel@tonic-gate #ifdef LODEBUG 9070Sstevel@tonic-gate lo_dprint(4, "lo_readdir vp %p realvp %p\n", vp, realvp(vp)); 9080Sstevel@tonic-gate #endif 9090Sstevel@tonic-gate vp = realvp(vp); 9100Sstevel@tonic-gate return (VOP_READDIR(vp, uiop, cr, eofp)); 9110Sstevel@tonic-gate } 9120Sstevel@tonic-gate 9130Sstevel@tonic-gate static int 9140Sstevel@tonic-gate lo_rwlock(vnode_t *vp, int write_lock, caller_context_t *ct) 9150Sstevel@tonic-gate { 9160Sstevel@tonic-gate vp = realvp(vp); 9170Sstevel@tonic-gate return (VOP_RWLOCK(vp, write_lock, ct)); 9180Sstevel@tonic-gate } 9190Sstevel@tonic-gate 9200Sstevel@tonic-gate static void 9210Sstevel@tonic-gate lo_rwunlock(vnode_t *vp, int write_lock, caller_context_t *ct) 9220Sstevel@tonic-gate { 9230Sstevel@tonic-gate vp = realvp(vp); 9240Sstevel@tonic-gate VOP_RWUNLOCK(vp, write_lock, ct); 9250Sstevel@tonic-gate } 9260Sstevel@tonic-gate 9270Sstevel@tonic-gate static int 9280Sstevel@tonic-gate lo_seek(vnode_t *vp, offset_t ooff, offset_t *noffp) 9290Sstevel@tonic-gate { 9300Sstevel@tonic-gate vp = realvp(vp); 9310Sstevel@tonic-gate return (VOP_SEEK(vp, ooff, noffp)); 9320Sstevel@tonic-gate } 9330Sstevel@tonic-gate 9340Sstevel@tonic-gate static int 9350Sstevel@tonic-gate lo_cmp(vnode_t *vp1, vnode_t *vp2) 9360Sstevel@tonic-gate { 9370Sstevel@tonic-gate while (vn_matchops(vp1, lo_vnodeops)) 9380Sstevel@tonic-gate vp1 = realvp(vp1); 9390Sstevel@tonic-gate while (vn_matchops(vp2, lo_vnodeops)) 9400Sstevel@tonic-gate vp2 = realvp(vp2); 9410Sstevel@tonic-gate return (VOP_CMP(vp1, vp2)); 9420Sstevel@tonic-gate } 9430Sstevel@tonic-gate 9440Sstevel@tonic-gate static int 9450Sstevel@tonic-gate lo_frlock( 9460Sstevel@tonic-gate vnode_t *vp, 9470Sstevel@tonic-gate int cmd, 9480Sstevel@tonic-gate struct flock64 *bfp, 9490Sstevel@tonic-gate int flag, 9500Sstevel@tonic-gate offset_t offset, 9510Sstevel@tonic-gate struct flk_callback *flk_cbp, 9520Sstevel@tonic-gate cred_t *cr) 9530Sstevel@tonic-gate { 9540Sstevel@tonic-gate vp = realvp(vp); 9550Sstevel@tonic-gate return (VOP_FRLOCK(vp, cmd, bfp, flag, offset, flk_cbp, cr)); 9560Sstevel@tonic-gate } 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate static int 9590Sstevel@tonic-gate lo_space( 9600Sstevel@tonic-gate vnode_t *vp, 9610Sstevel@tonic-gate int cmd, 9620Sstevel@tonic-gate struct flock64 *bfp, 9630Sstevel@tonic-gate int flag, 9640Sstevel@tonic-gate offset_t offset, 9650Sstevel@tonic-gate struct cred *cr, 9660Sstevel@tonic-gate caller_context_t *ct) 9670Sstevel@tonic-gate { 9680Sstevel@tonic-gate vp = realvp(vp); 9690Sstevel@tonic-gate return (VOP_SPACE(vp, cmd, bfp, flag, offset, cr, ct)); 9700Sstevel@tonic-gate } 9710Sstevel@tonic-gate 9720Sstevel@tonic-gate static int 9730Sstevel@tonic-gate lo_getpage( 9740Sstevel@tonic-gate vnode_t *vp, 9750Sstevel@tonic-gate offset_t off, 9760Sstevel@tonic-gate size_t len, 9770Sstevel@tonic-gate uint_t *prot, 9780Sstevel@tonic-gate struct page *parr[], 9790Sstevel@tonic-gate size_t psz, 9800Sstevel@tonic-gate struct seg *seg, 9810Sstevel@tonic-gate caddr_t addr, 9820Sstevel@tonic-gate enum seg_rw rw, 9830Sstevel@tonic-gate struct cred *cr) 9840Sstevel@tonic-gate { 9850Sstevel@tonic-gate vp = realvp(vp); 9860Sstevel@tonic-gate return (VOP_GETPAGE(vp, off, len, prot, parr, psz, seg, addr, rw, cr)); 9870Sstevel@tonic-gate } 9880Sstevel@tonic-gate 9890Sstevel@tonic-gate static int 9900Sstevel@tonic-gate lo_putpage(vnode_t *vp, offset_t off, size_t len, int flags, struct cred *cr) 9910Sstevel@tonic-gate { 9920Sstevel@tonic-gate vp = realvp(vp); 9930Sstevel@tonic-gate return (VOP_PUTPAGE(vp, off, len, flags, cr)); 9940Sstevel@tonic-gate } 9950Sstevel@tonic-gate 9960Sstevel@tonic-gate static int 9970Sstevel@tonic-gate lo_map( 9980Sstevel@tonic-gate vnode_t *vp, 9990Sstevel@tonic-gate offset_t off, 10000Sstevel@tonic-gate struct as *as, 10010Sstevel@tonic-gate caddr_t *addrp, 10020Sstevel@tonic-gate size_t len, 10030Sstevel@tonic-gate uchar_t prot, 10040Sstevel@tonic-gate uchar_t maxprot, 10050Sstevel@tonic-gate uint_t flags, 10060Sstevel@tonic-gate struct cred *cr) 10070Sstevel@tonic-gate { 10080Sstevel@tonic-gate vp = realvp(vp); 10090Sstevel@tonic-gate return (VOP_MAP(vp, off, as, addrp, len, prot, maxprot, flags, cr)); 10100Sstevel@tonic-gate } 10110Sstevel@tonic-gate 10120Sstevel@tonic-gate static int 10130Sstevel@tonic-gate lo_addmap( 10140Sstevel@tonic-gate vnode_t *vp, 10150Sstevel@tonic-gate offset_t off, 10160Sstevel@tonic-gate struct as *as, 10170Sstevel@tonic-gate caddr_t addr, 10180Sstevel@tonic-gate size_t len, 10190Sstevel@tonic-gate uchar_t prot, 10200Sstevel@tonic-gate uchar_t maxprot, 10210Sstevel@tonic-gate uint_t flags, 10220Sstevel@tonic-gate struct cred *cr) 10230Sstevel@tonic-gate { 10240Sstevel@tonic-gate vp = realvp(vp); 10250Sstevel@tonic-gate return (VOP_ADDMAP(vp, off, as, addr, len, prot, maxprot, flags, cr)); 10260Sstevel@tonic-gate } 10270Sstevel@tonic-gate 10280Sstevel@tonic-gate static int 10290Sstevel@tonic-gate lo_delmap( 10300Sstevel@tonic-gate vnode_t *vp, 10310Sstevel@tonic-gate offset_t off, 10320Sstevel@tonic-gate struct as *as, 10330Sstevel@tonic-gate caddr_t addr, 10340Sstevel@tonic-gate size_t len, 10350Sstevel@tonic-gate uint_t prot, 10360Sstevel@tonic-gate uint_t maxprot, 10370Sstevel@tonic-gate uint_t flags, 10380Sstevel@tonic-gate struct cred *cr) 10390Sstevel@tonic-gate { 10400Sstevel@tonic-gate vp = realvp(vp); 10410Sstevel@tonic-gate return (VOP_DELMAP(vp, off, as, addr, len, prot, maxprot, flags, cr)); 10420Sstevel@tonic-gate } 10430Sstevel@tonic-gate 10440Sstevel@tonic-gate static int 10450Sstevel@tonic-gate lo_poll( 10460Sstevel@tonic-gate vnode_t *vp, 10470Sstevel@tonic-gate short events, 10480Sstevel@tonic-gate int anyyet, 10490Sstevel@tonic-gate short *reventsp, 10500Sstevel@tonic-gate struct pollhead **phpp) 10510Sstevel@tonic-gate { 10520Sstevel@tonic-gate vp = realvp(vp); 10530Sstevel@tonic-gate return (VOP_POLL(vp, events, anyyet, reventsp, phpp)); 10540Sstevel@tonic-gate } 10550Sstevel@tonic-gate 10560Sstevel@tonic-gate static int 10570Sstevel@tonic-gate lo_dump(vnode_t *vp, caddr_t addr, int bn, int count) 10580Sstevel@tonic-gate { 10590Sstevel@tonic-gate vp = realvp(vp); 10600Sstevel@tonic-gate return (VOP_DUMP(vp, addr, bn, count)); 10610Sstevel@tonic-gate } 10620Sstevel@tonic-gate 10630Sstevel@tonic-gate static int 10640Sstevel@tonic-gate lo_pathconf(vnode_t *vp, int cmd, ulong_t *valp, struct cred *cr) 10650Sstevel@tonic-gate { 10660Sstevel@tonic-gate vp = realvp(vp); 10670Sstevel@tonic-gate return (VOP_PATHCONF(vp, cmd, valp, cr)); 10680Sstevel@tonic-gate } 10690Sstevel@tonic-gate 10700Sstevel@tonic-gate static int 10710Sstevel@tonic-gate lo_pageio( 10720Sstevel@tonic-gate vnode_t *vp, 10730Sstevel@tonic-gate struct page *pp, 10740Sstevel@tonic-gate u_offset_t io_off, 10750Sstevel@tonic-gate size_t io_len, 10760Sstevel@tonic-gate int flags, 10770Sstevel@tonic-gate cred_t *cr) 10780Sstevel@tonic-gate { 10790Sstevel@tonic-gate vp = realvp(vp); 10800Sstevel@tonic-gate return (VOP_PAGEIO(vp, pp, io_off, io_len, flags, cr)); 10810Sstevel@tonic-gate } 10820Sstevel@tonic-gate 10830Sstevel@tonic-gate static void 10840Sstevel@tonic-gate lo_dispose(vnode_t *vp, page_t *pp, int fl, int dn, cred_t *cr) 10850Sstevel@tonic-gate { 10860Sstevel@tonic-gate vp = realvp(vp); 10870Sstevel@tonic-gate if (vp != NULL && vp != &kvp) 10880Sstevel@tonic-gate VOP_DISPOSE(vp, pp, fl, dn, cr); 10890Sstevel@tonic-gate } 10900Sstevel@tonic-gate 10910Sstevel@tonic-gate static int 10920Sstevel@tonic-gate lo_setsecattr(vnode_t *vp, vsecattr_t *secattr, int flags, struct cred *cr) 10930Sstevel@tonic-gate { 10940Sstevel@tonic-gate if (vn_is_readonly(vp)) 10950Sstevel@tonic-gate return (EROFS); 10960Sstevel@tonic-gate vp = realvp(vp); 10970Sstevel@tonic-gate return (VOP_SETSECATTR(vp, secattr, flags, cr)); 10980Sstevel@tonic-gate } 10990Sstevel@tonic-gate 11000Sstevel@tonic-gate static int 11010Sstevel@tonic-gate lo_getsecattr(vnode_t *vp, vsecattr_t *secattr, int flags, struct cred *cr) 11020Sstevel@tonic-gate { 11030Sstevel@tonic-gate vp = realvp(vp); 11040Sstevel@tonic-gate return (VOP_GETSECATTR(vp, secattr, flags, cr)); 11050Sstevel@tonic-gate } 11060Sstevel@tonic-gate 11070Sstevel@tonic-gate static int 11080Sstevel@tonic-gate lo_shrlock(vnode_t *vp, int cmd, struct shrlock *shr, int flag, cred_t *cr) 11090Sstevel@tonic-gate { 11100Sstevel@tonic-gate vp = realvp(vp); 11110Sstevel@tonic-gate return (VOP_SHRLOCK(vp, cmd, shr, flag, cr)); 11120Sstevel@tonic-gate } 11130Sstevel@tonic-gate 11140Sstevel@tonic-gate /* 11150Sstevel@tonic-gate * Loopback vnode operations vector. 11160Sstevel@tonic-gate */ 11170Sstevel@tonic-gate 11180Sstevel@tonic-gate struct vnodeops *lo_vnodeops; 11190Sstevel@tonic-gate 11200Sstevel@tonic-gate const fs_operation_def_t lo_vnodeops_template[] = { 11210Sstevel@tonic-gate VOPNAME_OPEN, lo_open, 11220Sstevel@tonic-gate VOPNAME_CLOSE, lo_close, 11230Sstevel@tonic-gate VOPNAME_READ, lo_read, 11240Sstevel@tonic-gate VOPNAME_WRITE, lo_write, 11250Sstevel@tonic-gate VOPNAME_IOCTL, lo_ioctl, 11260Sstevel@tonic-gate VOPNAME_SETFL, lo_setfl, 11270Sstevel@tonic-gate VOPNAME_GETATTR, lo_getattr, 11280Sstevel@tonic-gate VOPNAME_SETATTR, lo_setattr, 11290Sstevel@tonic-gate VOPNAME_ACCESS, lo_access, 11300Sstevel@tonic-gate VOPNAME_LOOKUP, lo_lookup, 11310Sstevel@tonic-gate VOPNAME_CREATE, lo_create, 11320Sstevel@tonic-gate VOPNAME_REMOVE, lo_remove, 11330Sstevel@tonic-gate VOPNAME_LINK, lo_link, 11340Sstevel@tonic-gate VOPNAME_RENAME, lo_rename, 11350Sstevel@tonic-gate VOPNAME_MKDIR, lo_mkdir, 11360Sstevel@tonic-gate VOPNAME_RMDIR, lo_rmdir, 11370Sstevel@tonic-gate VOPNAME_READDIR, lo_readdir, 11380Sstevel@tonic-gate VOPNAME_SYMLINK, lo_symlink, 11390Sstevel@tonic-gate VOPNAME_READLINK, lo_readlink, 11400Sstevel@tonic-gate VOPNAME_FSYNC, lo_fsync, 11410Sstevel@tonic-gate VOPNAME_INACTIVE, (fs_generic_func_p) lo_inactive, 11420Sstevel@tonic-gate VOPNAME_FID, lo_fid, 11430Sstevel@tonic-gate VOPNAME_RWLOCK, lo_rwlock, 11440Sstevel@tonic-gate VOPNAME_RWUNLOCK, (fs_generic_func_p) lo_rwunlock, 11450Sstevel@tonic-gate VOPNAME_SEEK, lo_seek, 11460Sstevel@tonic-gate VOPNAME_CMP, lo_cmp, 11470Sstevel@tonic-gate VOPNAME_FRLOCK, lo_frlock, 11480Sstevel@tonic-gate VOPNAME_SPACE, lo_space, 11490Sstevel@tonic-gate VOPNAME_REALVP, lo_realvp, 11500Sstevel@tonic-gate VOPNAME_GETPAGE, lo_getpage, 11510Sstevel@tonic-gate VOPNAME_PUTPAGE, lo_putpage, 11520Sstevel@tonic-gate VOPNAME_MAP, (fs_generic_func_p) lo_map, 11530Sstevel@tonic-gate VOPNAME_ADDMAP, (fs_generic_func_p) lo_addmap, 11540Sstevel@tonic-gate VOPNAME_DELMAP, lo_delmap, 11550Sstevel@tonic-gate VOPNAME_POLL, (fs_generic_func_p) lo_poll, 11560Sstevel@tonic-gate VOPNAME_DUMP, lo_dump, 11570Sstevel@tonic-gate VOPNAME_DUMPCTL, fs_error, /* XXX - why? */ 11580Sstevel@tonic-gate VOPNAME_PATHCONF, lo_pathconf, 11590Sstevel@tonic-gate VOPNAME_PAGEIO, lo_pageio, 11600Sstevel@tonic-gate VOPNAME_DISPOSE, (fs_generic_func_p) lo_dispose, 11610Sstevel@tonic-gate VOPNAME_SETSECATTR, lo_setsecattr, 11620Sstevel@tonic-gate VOPNAME_GETSECATTR, lo_getsecattr, 11630Sstevel@tonic-gate VOPNAME_SHRLOCK, lo_shrlock, 11640Sstevel@tonic-gate NULL, NULL 11650Sstevel@tonic-gate }; 1166