17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55a59a8b3Srsb * Common Development and Distribution License (the "License"). 65a59a8b3Srsb * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 220fbb751dSJohn Levon * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #include <sys/types.h> 267c478bd9Sstevel@tonic-gate #include <sys/param.h> 277c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 287c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 297c478bd9Sstevel@tonic-gate #include <sys/time.h> 307c478bd9Sstevel@tonic-gate #include <sys/pathname.h> 317c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 32aa59c4cbSrsb #include <sys/vfs_opreg.h> 337c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 347c478bd9Sstevel@tonic-gate #include <sys/stat.h> 357c478bd9Sstevel@tonic-gate #include <sys/uio.h> 367c478bd9Sstevel@tonic-gate #include <sys/stat.h> 377c478bd9Sstevel@tonic-gate #include <sys/errno.h> 387c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 397c478bd9Sstevel@tonic-gate #include <sys/cred.h> 407c478bd9Sstevel@tonic-gate #include <sys/statvfs.h> 417c478bd9Sstevel@tonic-gate #include <sys/mount.h> 427c478bd9Sstevel@tonic-gate #include <sys/debug.h> 437c478bd9Sstevel@tonic-gate #include <sys/systm.h> 447c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 457c478bd9Sstevel@tonic-gate #include <fs/fs_subr.h> 467c478bd9Sstevel@tonic-gate #include <vm/page.h> 477c478bd9Sstevel@tonic-gate #include <vm/anon.h> 487c478bd9Sstevel@tonic-gate #include <sys/model.h> 497c478bd9Sstevel@tonic-gate #include <sys/policy.h> 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #include <sys/fs/swapnode.h> 527c478bd9Sstevel@tonic-gate #include <sys/fs/tmp.h> 537c478bd9Sstevel@tonic-gate #include <sys/fs/tmpnode.h> 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate static int tmpfsfstype; 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate /* 587c478bd9Sstevel@tonic-gate * tmpfs vfs operations. 597c478bd9Sstevel@tonic-gate */ 607c478bd9Sstevel@tonic-gate static int tmpfsinit(int, char *); 617c478bd9Sstevel@tonic-gate static int tmp_mount(struct vfs *, struct vnode *, 627c478bd9Sstevel@tonic-gate struct mounta *, struct cred *); 637c478bd9Sstevel@tonic-gate static int tmp_unmount(struct vfs *, int, struct cred *); 647c478bd9Sstevel@tonic-gate static int tmp_root(struct vfs *, struct vnode **); 657c478bd9Sstevel@tonic-gate static int tmp_statvfs(struct vfs *, struct statvfs64 *); 667c478bd9Sstevel@tonic-gate static int tmp_vget(struct vfs *, struct vnode **, struct fid *); 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * Loadable module wrapper 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate static mntopts_t tmpfs_proto_opttbl; 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate static vfsdef_t vfw = { 767c478bd9Sstevel@tonic-gate VFSDEF_VERSION, 777c478bd9Sstevel@tonic-gate "tmpfs", 787c478bd9Sstevel@tonic-gate tmpfsinit, 790fbb751dSJohn Levon VSW_HASPROTO|VSW_STATS|VSW_ZMOUNT, 807c478bd9Sstevel@tonic-gate &tmpfs_proto_opttbl 817c478bd9Sstevel@tonic-gate }; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate /* 847c478bd9Sstevel@tonic-gate * in-kernel mnttab options 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate static char *xattr_cancel[] = { MNTOPT_NOXATTR, NULL }; 877c478bd9Sstevel@tonic-gate static char *noxattr_cancel[] = { MNTOPT_XATTR, NULL }; 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate static mntopt_t tmpfs_options[] = { 907c478bd9Sstevel@tonic-gate /* Option name Cancel Opt Arg Flags Data */ 917c478bd9Sstevel@tonic-gate { MNTOPT_XATTR, xattr_cancel, NULL, MO_DEFAULT, NULL}, 927c478bd9Sstevel@tonic-gate { MNTOPT_NOXATTR, noxattr_cancel, NULL, NULL, NULL}, 937c478bd9Sstevel@tonic-gate { "size", NULL, "0", MO_HASVALUE, NULL} 947c478bd9Sstevel@tonic-gate }; 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate static mntopts_t tmpfs_proto_opttbl = { 987c478bd9Sstevel@tonic-gate sizeof (tmpfs_options) / sizeof (mntopt_t), 997c478bd9Sstevel@tonic-gate tmpfs_options 1007c478bd9Sstevel@tonic-gate }; 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate /* 1037c478bd9Sstevel@tonic-gate * Module linkage information 1047c478bd9Sstevel@tonic-gate */ 1057c478bd9Sstevel@tonic-gate static struct modlfs modlfs = { 1067c478bd9Sstevel@tonic-gate &mod_fsops, "filesystem for tmpfs", &vfw 1077c478bd9Sstevel@tonic-gate }; 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 1107c478bd9Sstevel@tonic-gate MODREV_1, &modlfs, NULL 1117c478bd9Sstevel@tonic-gate }; 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate int 1147c478bd9Sstevel@tonic-gate _init() 1157c478bd9Sstevel@tonic-gate { 1167c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 1177c478bd9Sstevel@tonic-gate } 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate int 1207c478bd9Sstevel@tonic-gate _fini() 1217c478bd9Sstevel@tonic-gate { 1227c478bd9Sstevel@tonic-gate int error; 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate error = mod_remove(&modlinkage); 1257c478bd9Sstevel@tonic-gate if (error) 1267c478bd9Sstevel@tonic-gate return (error); 1277c478bd9Sstevel@tonic-gate /* 1287c478bd9Sstevel@tonic-gate * Tear down the operations vectors 1297c478bd9Sstevel@tonic-gate */ 1307c478bd9Sstevel@tonic-gate (void) vfs_freevfsops_by_type(tmpfsfstype); 1317c478bd9Sstevel@tonic-gate vn_freevnodeops(tmp_vnodeops); 1327c478bd9Sstevel@tonic-gate return (0); 1337c478bd9Sstevel@tonic-gate } 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate int 1367c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 1377c478bd9Sstevel@tonic-gate { 1387c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate /* 1427c478bd9Sstevel@tonic-gate * The following are patchable variables limiting the amount of system 1437c478bd9Sstevel@tonic-gate * resources tmpfs can use. 1447c478bd9Sstevel@tonic-gate * 1457c478bd9Sstevel@tonic-gate * tmpfs_maxkmem limits the amount of kernel kmem_alloc memory 1467c478bd9Sstevel@tonic-gate * tmpfs can use for it's data structures (e.g. tmpnodes, directory entries) 1477c478bd9Sstevel@tonic-gate * It is not determined by setting a hard limit but rather as a percentage of 1487c478bd9Sstevel@tonic-gate * physical memory which is determined when tmpfs is first used in the system. 1497c478bd9Sstevel@tonic-gate * 1507c478bd9Sstevel@tonic-gate * tmpfs_minfree is the minimum amount of swap space that tmpfs leaves for 1517c478bd9Sstevel@tonic-gate * the rest of the system. In other words, if the amount of free swap space 1527c478bd9Sstevel@tonic-gate * in the system (i.e. anoninfo.ani_free) drops below tmpfs_minfree, tmpfs 1537c478bd9Sstevel@tonic-gate * anon allocations will fail. 1547c478bd9Sstevel@tonic-gate * 1557c478bd9Sstevel@tonic-gate * There is also a per mount limit on the amount of swap space 1567c478bd9Sstevel@tonic-gate * (tmount.tm_anonmax) settable via a mount option. 1577c478bd9Sstevel@tonic-gate */ 1587c478bd9Sstevel@tonic-gate size_t tmpfs_maxkmem = 0; 1597c478bd9Sstevel@tonic-gate size_t tmpfs_minfree = 0; 1607c478bd9Sstevel@tonic-gate size_t tmp_kmemspace; /* bytes of kernel heap used by all tmpfs */ 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate static major_t tmpfs_major; 1637c478bd9Sstevel@tonic-gate static minor_t tmpfs_minor; 1647c478bd9Sstevel@tonic-gate static kmutex_t tmpfs_minor_lock; 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate /* 1677c478bd9Sstevel@tonic-gate * initialize global tmpfs locks and such 1687c478bd9Sstevel@tonic-gate * called when loading tmpfs module 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate static int 1717c478bd9Sstevel@tonic-gate tmpfsinit(int fstype, char *name) 1727c478bd9Sstevel@tonic-gate { 1737c478bd9Sstevel@tonic-gate static const fs_operation_def_t tmp_vfsops_template[] = { 174aa59c4cbSrsb VFSNAME_MOUNT, { .vfs_mount = tmp_mount }, 175aa59c4cbSrsb VFSNAME_UNMOUNT, { .vfs_unmount = tmp_unmount }, 176aa59c4cbSrsb VFSNAME_ROOT, { .vfs_root = tmp_root }, 177aa59c4cbSrsb VFSNAME_STATVFS, { .vfs_statvfs = tmp_statvfs }, 178aa59c4cbSrsb VFSNAME_VGET, { .vfs_vget = tmp_vget }, 1797c478bd9Sstevel@tonic-gate NULL, NULL 1807c478bd9Sstevel@tonic-gate }; 1817c478bd9Sstevel@tonic-gate int error; 1827c478bd9Sstevel@tonic-gate extern void tmpfs_hash_init(); 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate tmpfs_hash_init(); 1857c478bd9Sstevel@tonic-gate tmpfsfstype = fstype; 1867c478bd9Sstevel@tonic-gate ASSERT(tmpfsfstype != 0); 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate error = vfs_setfsops(fstype, tmp_vfsops_template, NULL); 1897c478bd9Sstevel@tonic-gate if (error != 0) { 1907c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "tmpfsinit: bad vfs ops template"); 1917c478bd9Sstevel@tonic-gate return (error); 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate error = vn_make_ops(name, tmp_vnodeops_template, &tmp_vnodeops); 1957c478bd9Sstevel@tonic-gate if (error != 0) { 1967c478bd9Sstevel@tonic-gate (void) vfs_freevfsops_by_type(fstype); 1977c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "tmpfsinit: bad vnode ops template"); 1987c478bd9Sstevel@tonic-gate return (error); 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate /* 2027c478bd9Sstevel@tonic-gate * tmpfs_minfree doesn't need to be some function of configured 2037c478bd9Sstevel@tonic-gate * swap space since it really is an absolute limit of swap space 2047c478bd9Sstevel@tonic-gate * which still allows other processes to execute. 2057c478bd9Sstevel@tonic-gate */ 2067c478bd9Sstevel@tonic-gate if (tmpfs_minfree == 0) { 2077c478bd9Sstevel@tonic-gate /* 2087c478bd9Sstevel@tonic-gate * Set if not patched 2097c478bd9Sstevel@tonic-gate */ 2107c478bd9Sstevel@tonic-gate tmpfs_minfree = btopr(TMPMINFREE); 2117c478bd9Sstevel@tonic-gate } 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate /* 2147c478bd9Sstevel@tonic-gate * The maximum amount of space tmpfs can allocate is 2157c478bd9Sstevel@tonic-gate * TMPMAXPROCKMEM percent of kernel memory 2167c478bd9Sstevel@tonic-gate */ 2177c478bd9Sstevel@tonic-gate if (tmpfs_maxkmem == 0) 2187c478bd9Sstevel@tonic-gate tmpfs_maxkmem = MAX(PAGESIZE, kmem_maxavail() / TMPMAXFRACKMEM); 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate if ((tmpfs_major = getudev()) == (major_t)-1) { 2217c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "tmpfsinit: Can't get unique device number."); 2227c478bd9Sstevel@tonic-gate tmpfs_major = 0; 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate mutex_init(&tmpfs_minor_lock, NULL, MUTEX_DEFAULT, NULL); 2257c478bd9Sstevel@tonic-gate return (0); 2267c478bd9Sstevel@tonic-gate } 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate static int 2297c478bd9Sstevel@tonic-gate tmp_mount( 2307c478bd9Sstevel@tonic-gate struct vfs *vfsp, 2317c478bd9Sstevel@tonic-gate struct vnode *mvp, 2327c478bd9Sstevel@tonic-gate struct mounta *uap, 2337c478bd9Sstevel@tonic-gate struct cred *cr) 2347c478bd9Sstevel@tonic-gate { 2357c478bd9Sstevel@tonic-gate struct tmount *tm = NULL; 2367c478bd9Sstevel@tonic-gate struct tmpnode *tp; 2377c478bd9Sstevel@tonic-gate struct pathname dpn; 2387c478bd9Sstevel@tonic-gate int error; 2397c478bd9Sstevel@tonic-gate pgcnt_t anonmax; 2407c478bd9Sstevel@tonic-gate struct vattr rattr; 2417c478bd9Sstevel@tonic-gate int got_attrs; 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate char *sizestr; 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0) 2467c478bd9Sstevel@tonic-gate return (error); 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate if (mvp->v_type != VDIR) 2497c478bd9Sstevel@tonic-gate return (ENOTDIR); 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate mutex_enter(&mvp->v_lock); 2527c478bd9Sstevel@tonic-gate if ((uap->flags & MS_OVERLAY) == 0 && 2537c478bd9Sstevel@tonic-gate (mvp->v_count != 1 || (mvp->v_flag & VROOT))) { 2547c478bd9Sstevel@tonic-gate mutex_exit(&mvp->v_lock); 2557c478bd9Sstevel@tonic-gate return (EBUSY); 2567c478bd9Sstevel@tonic-gate } 2577c478bd9Sstevel@tonic-gate mutex_exit(&mvp->v_lock); 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate /* 2607c478bd9Sstevel@tonic-gate * Having the resource be anything but "swap" doesn't make sense. 2617c478bd9Sstevel@tonic-gate */ 262*d7de0ceaSRobert Harris vfs_setresource(vfsp, "swap", 0); 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate /* 2657c478bd9Sstevel@tonic-gate * now look for options we understand... 2667c478bd9Sstevel@tonic-gate */ 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate /* tmpfs doesn't support read-only mounts */ 2697c478bd9Sstevel@tonic-gate if (vfs_optionisset(vfsp, MNTOPT_RO, NULL)) { 2707c478bd9Sstevel@tonic-gate error = EINVAL; 2717c478bd9Sstevel@tonic-gate goto out; 2727c478bd9Sstevel@tonic-gate } 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate /* 2757c478bd9Sstevel@tonic-gate * tm_anonmax is set according to the mount arguments 2767c478bd9Sstevel@tonic-gate * if any. Otherwise, it is set to a maximum value. 2777c478bd9Sstevel@tonic-gate */ 2787c478bd9Sstevel@tonic-gate if (vfs_optionisset(vfsp, "size", &sizestr)) { 2797c478bd9Sstevel@tonic-gate if ((error = tmp_convnum(sizestr, &anonmax)) != 0) 2807c478bd9Sstevel@tonic-gate goto out; 2817c478bd9Sstevel@tonic-gate } else { 2827c478bd9Sstevel@tonic-gate anonmax = ULONG_MAX; 2837c478bd9Sstevel@tonic-gate } 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate if (error = pn_get(uap->dir, 2867c478bd9Sstevel@tonic-gate (uap->flags & MS_SYSSPACE) ? UIO_SYSSPACE : UIO_USERSPACE, &dpn)) 2877c478bd9Sstevel@tonic-gate goto out; 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate if ((tm = tmp_memalloc(sizeof (struct tmount), 0)) == NULL) { 2907c478bd9Sstevel@tonic-gate pn_free(&dpn); 2917c478bd9Sstevel@tonic-gate error = ENOMEM; 2927c478bd9Sstevel@tonic-gate goto out; 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate /* 2967c478bd9Sstevel@tonic-gate * find an available minor device number for this mount 2977c478bd9Sstevel@tonic-gate */ 2987c478bd9Sstevel@tonic-gate mutex_enter(&tmpfs_minor_lock); 2997c478bd9Sstevel@tonic-gate do { 3007c478bd9Sstevel@tonic-gate tmpfs_minor = (tmpfs_minor + 1) & L_MAXMIN32; 3017c478bd9Sstevel@tonic-gate tm->tm_dev = makedevice(tmpfs_major, tmpfs_minor); 3027c478bd9Sstevel@tonic-gate } while (vfs_devismounted(tm->tm_dev)); 3037c478bd9Sstevel@tonic-gate mutex_exit(&tmpfs_minor_lock); 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate /* 3067c478bd9Sstevel@tonic-gate * Set but don't bother entering the mutex 3077c478bd9Sstevel@tonic-gate * (tmount not on mount list yet) 3087c478bd9Sstevel@tonic-gate */ 3097c478bd9Sstevel@tonic-gate mutex_init(&tm->tm_contents, NULL, MUTEX_DEFAULT, NULL); 3107c478bd9Sstevel@tonic-gate mutex_init(&tm->tm_renamelck, NULL, MUTEX_DEFAULT, NULL); 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate tm->tm_vfsp = vfsp; 3137c478bd9Sstevel@tonic-gate tm->tm_anonmax = anonmax; 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate vfsp->vfs_data = (caddr_t)tm; 3167c478bd9Sstevel@tonic-gate vfsp->vfs_fstype = tmpfsfstype; 3177c478bd9Sstevel@tonic-gate vfsp->vfs_dev = tm->tm_dev; 3187c478bd9Sstevel@tonic-gate vfsp->vfs_bsize = PAGESIZE; 3197c478bd9Sstevel@tonic-gate vfsp->vfs_flag |= VFS_NOTRUNC; 3207c478bd9Sstevel@tonic-gate vfs_make_fsid(&vfsp->vfs_fsid, tm->tm_dev, tmpfsfstype); 3217c478bd9Sstevel@tonic-gate tm->tm_mntpath = tmp_memalloc(dpn.pn_pathlen + 1, TMP_MUSTHAVE); 3227c478bd9Sstevel@tonic-gate (void) strcpy(tm->tm_mntpath, dpn.pn_path); 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate /* 3257c478bd9Sstevel@tonic-gate * allocate and initialize root tmpnode structure 3267c478bd9Sstevel@tonic-gate */ 3277c478bd9Sstevel@tonic-gate bzero(&rattr, sizeof (struct vattr)); 3287c478bd9Sstevel@tonic-gate rattr.va_mode = (mode_t)(S_IFDIR | 0777); /* XXX modes */ 3297c478bd9Sstevel@tonic-gate rattr.va_type = VDIR; 3307c478bd9Sstevel@tonic-gate rattr.va_rdev = 0; 3317c478bd9Sstevel@tonic-gate tp = tmp_memalloc(sizeof (struct tmpnode), TMP_MUSTHAVE); 3327c478bd9Sstevel@tonic-gate tmpnode_init(tm, tp, &rattr, cr); 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate /* 3357c478bd9Sstevel@tonic-gate * Get the mode, uid, and gid from the underlying mount point. 3367c478bd9Sstevel@tonic-gate */ 3377c478bd9Sstevel@tonic-gate rattr.va_mask = AT_MODE|AT_UID|AT_GID; /* Hint to getattr */ 338da6c28aaSamw got_attrs = VOP_GETATTR(mvp, &rattr, 0, cr, NULL); 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate rw_enter(&tp->tn_rwlock, RW_WRITER); 3417c478bd9Sstevel@tonic-gate TNTOV(tp)->v_flag |= VROOT; 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate /* 3447c478bd9Sstevel@tonic-gate * If the getattr succeeded, use its results. Otherwise allow 3457c478bd9Sstevel@tonic-gate * the previously set hardwired defaults to prevail. 3467c478bd9Sstevel@tonic-gate */ 3477c478bd9Sstevel@tonic-gate if (got_attrs == 0) { 3487c478bd9Sstevel@tonic-gate tp->tn_mode = rattr.va_mode; 3497c478bd9Sstevel@tonic-gate tp->tn_uid = rattr.va_uid; 3507c478bd9Sstevel@tonic-gate tp->tn_gid = rattr.va_gid; 3517c478bd9Sstevel@tonic-gate } 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate /* 3547c478bd9Sstevel@tonic-gate * initialize linked list of tmpnodes so that the back pointer of 3557c478bd9Sstevel@tonic-gate * the root tmpnode always points to the last one on the list 3567c478bd9Sstevel@tonic-gate * and the forward pointer of the last node is null 3577c478bd9Sstevel@tonic-gate */ 3587c478bd9Sstevel@tonic-gate tp->tn_back = tp; 3597c478bd9Sstevel@tonic-gate tp->tn_forw = NULL; 3607c478bd9Sstevel@tonic-gate tp->tn_nlink = 0; 3617c478bd9Sstevel@tonic-gate tm->tm_rootnode = tp; 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate tdirinit(tp, tp); 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate rw_exit(&tp->tn_rwlock); 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate pn_free(&dpn); 3687c478bd9Sstevel@tonic-gate error = 0; 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate out: 371da6c28aaSamw if (error == 0) 3729660e5cbSJanice Chang vfs_set_feature(vfsp, VFSFT_SYSATTR_VIEWS); 373da6c28aaSamw 3747c478bd9Sstevel@tonic-gate return (error); 3757c478bd9Sstevel@tonic-gate } 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate static int 3787c478bd9Sstevel@tonic-gate tmp_unmount(struct vfs *vfsp, int flag, struct cred *cr) 3797c478bd9Sstevel@tonic-gate { 3807c478bd9Sstevel@tonic-gate struct tmount *tm = (struct tmount *)VFSTOTM(vfsp); 3817c478bd9Sstevel@tonic-gate struct tmpnode *tnp, *cancel; 3827c478bd9Sstevel@tonic-gate struct vnode *vp; 3837c478bd9Sstevel@tonic-gate int error; 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate if ((error = secpolicy_fs_unmount(cr, vfsp)) != 0) 3867c478bd9Sstevel@tonic-gate return (error); 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate /* 3897c478bd9Sstevel@tonic-gate * forced unmount is not supported by this file system 3907c478bd9Sstevel@tonic-gate * and thus, ENOTSUP, is being returned. 3917c478bd9Sstevel@tonic-gate */ 3927c478bd9Sstevel@tonic-gate if (flag & MS_FORCE) 3937c478bd9Sstevel@tonic-gate return (ENOTSUP); 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate mutex_enter(&tm->tm_contents); 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate /* 3987c478bd9Sstevel@tonic-gate * If there are no open files, only the root node should have 3997c478bd9Sstevel@tonic-gate * a reference count. 4007c478bd9Sstevel@tonic-gate * With tm_contents held, nothing can be added or removed. 4017c478bd9Sstevel@tonic-gate * There may be some dirty pages. To prevent fsflush from 4027c478bd9Sstevel@tonic-gate * disrupting the unmount, put a hold on each node while scanning. 4037c478bd9Sstevel@tonic-gate * If we find a previously referenced node, undo the holds we have 4047c478bd9Sstevel@tonic-gate * placed and fail EBUSY. 4057c478bd9Sstevel@tonic-gate */ 4067c478bd9Sstevel@tonic-gate tnp = tm->tm_rootnode; 4077c478bd9Sstevel@tonic-gate if (TNTOV(tnp)->v_count > 1) { 4087c478bd9Sstevel@tonic-gate mutex_exit(&tm->tm_contents); 4097c478bd9Sstevel@tonic-gate return (EBUSY); 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate for (tnp = tnp->tn_forw; tnp; tnp = tnp->tn_forw) { 4137c478bd9Sstevel@tonic-gate if ((vp = TNTOV(tnp))->v_count > 0) { 4147c478bd9Sstevel@tonic-gate cancel = tm->tm_rootnode->tn_forw; 4157c478bd9Sstevel@tonic-gate while (cancel != tnp) { 4167c478bd9Sstevel@tonic-gate vp = TNTOV(cancel); 4177c478bd9Sstevel@tonic-gate ASSERT(vp->v_count > 0); 4187c478bd9Sstevel@tonic-gate VN_RELE(vp); 4197c478bd9Sstevel@tonic-gate cancel = cancel->tn_forw; 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate mutex_exit(&tm->tm_contents); 4227c478bd9Sstevel@tonic-gate return (EBUSY); 4237c478bd9Sstevel@tonic-gate } 4247c478bd9Sstevel@tonic-gate VN_HOLD(vp); 4257c478bd9Sstevel@tonic-gate } 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate /* 4287c478bd9Sstevel@tonic-gate * We can drop the mutex now because no one can find this mount 4297c478bd9Sstevel@tonic-gate */ 4307c478bd9Sstevel@tonic-gate mutex_exit(&tm->tm_contents); 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate /* 4337c478bd9Sstevel@tonic-gate * Free all kmemalloc'd and anonalloc'd memory associated with 4347c478bd9Sstevel@tonic-gate * this filesystem. To do this, we go through the file list twice, 4357c478bd9Sstevel@tonic-gate * once to remove all the directory entries, and then to remove 4367c478bd9Sstevel@tonic-gate * all the files. We do this because there is useful code in 4377c478bd9Sstevel@tonic-gate * tmpnode_free which assumes that the directory entry has been 4387c478bd9Sstevel@tonic-gate * removed before the file. 4397c478bd9Sstevel@tonic-gate */ 4407c478bd9Sstevel@tonic-gate /* 4417c478bd9Sstevel@tonic-gate * Remove all directory entries 4427c478bd9Sstevel@tonic-gate */ 4437c478bd9Sstevel@tonic-gate for (tnp = tm->tm_rootnode; tnp; tnp = tnp->tn_forw) { 4447c478bd9Sstevel@tonic-gate rw_enter(&tnp->tn_rwlock, RW_WRITER); 4457c478bd9Sstevel@tonic-gate if (tnp->tn_type == VDIR) 4467c478bd9Sstevel@tonic-gate tdirtrunc(tnp); 4477c478bd9Sstevel@tonic-gate if (tnp->tn_vnode->v_flag & V_XATTRDIR) { 4487c478bd9Sstevel@tonic-gate /* 4497c478bd9Sstevel@tonic-gate * Account for implicit attrdir reference. 4507c478bd9Sstevel@tonic-gate */ 4517c478bd9Sstevel@tonic-gate ASSERT(tnp->tn_nlink > 0); 4527c478bd9Sstevel@tonic-gate DECR_COUNT(&tnp->tn_nlink, &tnp->tn_tlock); 4537c478bd9Sstevel@tonic-gate } 4547c478bd9Sstevel@tonic-gate rw_exit(&tnp->tn_rwlock); 4557c478bd9Sstevel@tonic-gate } 4567c478bd9Sstevel@tonic-gate 4577c478bd9Sstevel@tonic-gate ASSERT(tm->tm_rootnode); 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate /* 4607c478bd9Sstevel@tonic-gate * All links are gone, v_count is keeping nodes in place. 4617c478bd9Sstevel@tonic-gate * VN_RELE should make the node disappear, unless somebody 4627c478bd9Sstevel@tonic-gate * is holding pages against it. Nap and retry until it disappears. 4637c478bd9Sstevel@tonic-gate * 4647c478bd9Sstevel@tonic-gate * We re-acquire the lock to prevent others who have a HOLD on 4657c478bd9Sstevel@tonic-gate * a tmpnode via its pages or anon slots from blowing it away 4667c478bd9Sstevel@tonic-gate * (in tmp_inactive) while we're trying to get to it here. Once 4677c478bd9Sstevel@tonic-gate * we have a HOLD on it we know it'll stick around. 4687c478bd9Sstevel@tonic-gate * 4697c478bd9Sstevel@tonic-gate */ 4707c478bd9Sstevel@tonic-gate mutex_enter(&tm->tm_contents); 4717c478bd9Sstevel@tonic-gate /* 4727c478bd9Sstevel@tonic-gate * Remove all the files (except the rootnode) backwards. 4737c478bd9Sstevel@tonic-gate */ 4747c478bd9Sstevel@tonic-gate while ((tnp = tm->tm_rootnode->tn_back) != tm->tm_rootnode) { 4757c478bd9Sstevel@tonic-gate mutex_exit(&tm->tm_contents); 4767c478bd9Sstevel@tonic-gate /* 4777c478bd9Sstevel@tonic-gate * Inhibit tmp_inactive from touching attribute directory 4787c478bd9Sstevel@tonic-gate * as all nodes will be released here. 4797c478bd9Sstevel@tonic-gate * Note we handled the link count in pass 2 above. 4807c478bd9Sstevel@tonic-gate */ 4817c478bd9Sstevel@tonic-gate rw_enter(&tnp->tn_rwlock, RW_WRITER); 4827c478bd9Sstevel@tonic-gate tnp->tn_xattrdp = NULL; 4837c478bd9Sstevel@tonic-gate rw_exit(&tnp->tn_rwlock); 4847c478bd9Sstevel@tonic-gate vp = TNTOV(tnp); 4857c478bd9Sstevel@tonic-gate VN_RELE(vp); 4867c478bd9Sstevel@tonic-gate mutex_enter(&tm->tm_contents); 4877c478bd9Sstevel@tonic-gate /* 4887c478bd9Sstevel@tonic-gate * It's still there after the RELE. Someone else like pageout 4897c478bd9Sstevel@tonic-gate * has a hold on it so wait a bit and then try again - we know 4907c478bd9Sstevel@tonic-gate * they'll give it up soon. 4917c478bd9Sstevel@tonic-gate */ 4927c478bd9Sstevel@tonic-gate if (tnp == tm->tm_rootnode->tn_back) { 4937c478bd9Sstevel@tonic-gate VN_HOLD(vp); 4947c478bd9Sstevel@tonic-gate mutex_exit(&tm->tm_contents); 4957c478bd9Sstevel@tonic-gate delay(hz / 4); 4967c478bd9Sstevel@tonic-gate mutex_enter(&tm->tm_contents); 4977c478bd9Sstevel@tonic-gate } 4987c478bd9Sstevel@tonic-gate } 4997c478bd9Sstevel@tonic-gate mutex_exit(&tm->tm_contents); 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate tm->tm_rootnode->tn_xattrdp = NULL; 5027c478bd9Sstevel@tonic-gate VN_RELE(TNTOV(tm->tm_rootnode)); 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate ASSERT(tm->tm_mntpath); 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate tmp_memfree(tm->tm_mntpath, strlen(tm->tm_mntpath) + 1); 5077c478bd9Sstevel@tonic-gate 5087c478bd9Sstevel@tonic-gate ASSERT(tm->tm_anonmem == 0); 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate mutex_destroy(&tm->tm_contents); 5117c478bd9Sstevel@tonic-gate mutex_destroy(&tm->tm_renamelck); 5127c478bd9Sstevel@tonic-gate tmp_memfree(tm, sizeof (struct tmount)); 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate return (0); 5157c478bd9Sstevel@tonic-gate } 5167c478bd9Sstevel@tonic-gate 5177c478bd9Sstevel@tonic-gate /* 5187c478bd9Sstevel@tonic-gate * return root tmpnode for given vnode 5197c478bd9Sstevel@tonic-gate */ 5207c478bd9Sstevel@tonic-gate static int 5217c478bd9Sstevel@tonic-gate tmp_root(struct vfs *vfsp, struct vnode **vpp) 5227c478bd9Sstevel@tonic-gate { 5237c478bd9Sstevel@tonic-gate struct tmount *tm = (struct tmount *)VFSTOTM(vfsp); 5247c478bd9Sstevel@tonic-gate struct tmpnode *tp = tm->tm_rootnode; 5257c478bd9Sstevel@tonic-gate struct vnode *vp; 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate ASSERT(tp); 5287c478bd9Sstevel@tonic-gate 5297c478bd9Sstevel@tonic-gate vp = TNTOV(tp); 5307c478bd9Sstevel@tonic-gate VN_HOLD(vp); 5317c478bd9Sstevel@tonic-gate *vpp = vp; 5327c478bd9Sstevel@tonic-gate return (0); 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate static int 5367c478bd9Sstevel@tonic-gate tmp_statvfs(struct vfs *vfsp, struct statvfs64 *sbp) 5377c478bd9Sstevel@tonic-gate { 5387c478bd9Sstevel@tonic-gate struct tmount *tm = (struct tmount *)VFSTOTM(vfsp); 5397c478bd9Sstevel@tonic-gate ulong_t blocks; 5407c478bd9Sstevel@tonic-gate dev32_t d32; 5413d2ef5a6S zoneid_t eff_zid; 5423d2ef5a6S struct zone *zp; 5433d2ef5a6S 5443d2ef5a6S /* 5453d2ef5a6S * The file system may have been mounted by the global zone on 5463d2ef5a6S * behalf of the non-global zone. In that case, the tmount zone_id 5473d2ef5a6S * will be the global zone. We still want to show the swap cap inside 5483d2ef5a6S * the zone in this case, even though the file system was mounted by 5493d2ef5a6S * the global zone. 5503d2ef5a6S */ 5513d2ef5a6S if (curproc->p_zone->zone_id != GLOBAL_ZONEUNIQID) 5523d2ef5a6S zp = curproc->p_zone; 5533d2ef5a6S else 5543d2ef5a6S zp = tm->tm_vfsp->vfs_zone; 5553d2ef5a6S 5563d2ef5a6S if (zp == NULL) 5573d2ef5a6S eff_zid = GLOBAL_ZONEUNIQID; 5583d2ef5a6S else 5593d2ef5a6S eff_zid = zp->zone_id; 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate sbp->f_bsize = PAGESIZE; 5627c478bd9Sstevel@tonic-gate sbp->f_frsize = PAGESIZE; 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate /* 5657c478bd9Sstevel@tonic-gate * Find the amount of available physical and memory swap 5667c478bd9Sstevel@tonic-gate */ 5677c478bd9Sstevel@tonic-gate mutex_enter(&anoninfo_lock); 5687c478bd9Sstevel@tonic-gate ASSERT(k_anoninfo.ani_max >= k_anoninfo.ani_phys_resv); 5697c478bd9Sstevel@tonic-gate blocks = (ulong_t)CURRENT_TOTAL_AVAILABLE_SWAP; 5707c478bd9Sstevel@tonic-gate mutex_exit(&anoninfo_lock); 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate /* 5737c478bd9Sstevel@tonic-gate * If tm_anonmax for this mount is less than the available swap space 5747c478bd9Sstevel@tonic-gate * (minus the amount tmpfs can't use), use that instead 5757c478bd9Sstevel@tonic-gate */ 5767c478bd9Sstevel@tonic-gate if (blocks > tmpfs_minfree) 5777c478bd9Sstevel@tonic-gate sbp->f_bfree = MIN(blocks - tmpfs_minfree, 5787c478bd9Sstevel@tonic-gate tm->tm_anonmax - tm->tm_anonmem); 5797c478bd9Sstevel@tonic-gate else 5807c478bd9Sstevel@tonic-gate sbp->f_bfree = 0; 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate sbp->f_bavail = sbp->f_bfree; 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate /* 5857c478bd9Sstevel@tonic-gate * Total number of blocks is what's available plus what's been used 5867c478bd9Sstevel@tonic-gate */ 5877c478bd9Sstevel@tonic-gate sbp->f_blocks = (fsblkcnt64_t)(sbp->f_bfree + tm->tm_anonmem); 5887c478bd9Sstevel@tonic-gate 5893d2ef5a6S if (eff_zid != GLOBAL_ZONEUNIQID && 5903d2ef5a6S zp->zone_max_swap_ctl != UINT64_MAX) { 5913d2ef5a6S /* 5923d2ef5a6S * If the fs is used by a non-global zone with a swap cap, 5933d2ef5a6S * then report the capped size. 5943d2ef5a6S */ 5953d2ef5a6S rctl_qty_t cap, used; 5963d2ef5a6S pgcnt_t pgcap, pgused; 5973d2ef5a6S 5983d2ef5a6S mutex_enter(&zp->zone_mem_lock); 5993d2ef5a6S cap = zp->zone_max_swap_ctl; 6003d2ef5a6S used = zp->zone_max_swap; 6013d2ef5a6S mutex_exit(&zp->zone_mem_lock); 6023d2ef5a6S 6033d2ef5a6S pgcap = btop(cap); 6043d2ef5a6S pgused = btop(used); 6053d2ef5a6S 6063d2ef5a6S sbp->f_bfree = MIN(pgcap - pgused, sbp->f_bfree); 6073d2ef5a6S sbp->f_bavail = sbp->f_bfree; 6083d2ef5a6S sbp->f_blocks = MIN(pgcap, sbp->f_blocks); 6093d2ef5a6S } 6103d2ef5a6S 6117c478bd9Sstevel@tonic-gate /* 6127c478bd9Sstevel@tonic-gate * The maximum number of files available is approximately the number 6137c478bd9Sstevel@tonic-gate * of tmpnodes we can allocate from the remaining kernel memory 6147c478bd9Sstevel@tonic-gate * available to tmpfs. This is fairly inaccurate since it doesn't 6157c478bd9Sstevel@tonic-gate * take into account the names stored in the directory entries. 6167c478bd9Sstevel@tonic-gate */ 6177c478bd9Sstevel@tonic-gate if (tmpfs_maxkmem > tmp_kmemspace) 6187c478bd9Sstevel@tonic-gate sbp->f_ffree = (tmpfs_maxkmem - tmp_kmemspace) / 6197c478bd9Sstevel@tonic-gate (sizeof (struct tmpnode) + sizeof (struct tdirent)); 6207c478bd9Sstevel@tonic-gate else 6217c478bd9Sstevel@tonic-gate sbp->f_ffree = 0; 6227c478bd9Sstevel@tonic-gate 6237c478bd9Sstevel@tonic-gate sbp->f_files = tmpfs_maxkmem / 6247c478bd9Sstevel@tonic-gate (sizeof (struct tmpnode) + sizeof (struct tdirent)); 6257c478bd9Sstevel@tonic-gate sbp->f_favail = (fsfilcnt64_t)(sbp->f_ffree); 6267c478bd9Sstevel@tonic-gate (void) cmpldev(&d32, vfsp->vfs_dev); 6277c478bd9Sstevel@tonic-gate sbp->f_fsid = d32; 6287c478bd9Sstevel@tonic-gate (void) strcpy(sbp->f_basetype, vfssw[tmpfsfstype].vsw_name); 6297c478bd9Sstevel@tonic-gate (void) strncpy(sbp->f_fstr, tm->tm_mntpath, sizeof (sbp->f_fstr)); 6307c478bd9Sstevel@tonic-gate /* 6317c478bd9Sstevel@tonic-gate * ensure null termination 6327c478bd9Sstevel@tonic-gate */ 6337c478bd9Sstevel@tonic-gate sbp->f_fstr[sizeof (sbp->f_fstr) - 1] = '\0'; 6347c478bd9Sstevel@tonic-gate sbp->f_flag = vf_to_stf(vfsp->vfs_flag); 6357c478bd9Sstevel@tonic-gate sbp->f_namemax = MAXNAMELEN - 1; 6367c478bd9Sstevel@tonic-gate return (0); 6377c478bd9Sstevel@tonic-gate } 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate static int 6407c478bd9Sstevel@tonic-gate tmp_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp) 6417c478bd9Sstevel@tonic-gate { 6427c478bd9Sstevel@tonic-gate struct tfid *tfid; 6437c478bd9Sstevel@tonic-gate struct tmount *tm = (struct tmount *)VFSTOTM(vfsp); 6447c478bd9Sstevel@tonic-gate struct tmpnode *tp = NULL; 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate tfid = (struct tfid *)fidp; 6477c478bd9Sstevel@tonic-gate *vpp = NULL; 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate mutex_enter(&tm->tm_contents); 6507c478bd9Sstevel@tonic-gate for (tp = tm->tm_rootnode; tp; tp = tp->tn_forw) { 6517c478bd9Sstevel@tonic-gate mutex_enter(&tp->tn_tlock); 6527c478bd9Sstevel@tonic-gate if (tp->tn_nodeid == tfid->tfid_ino) { 6537c478bd9Sstevel@tonic-gate /* 6547c478bd9Sstevel@tonic-gate * If the gen numbers don't match we know the 6557c478bd9Sstevel@tonic-gate * file won't be found since only one tmpnode 6567c478bd9Sstevel@tonic-gate * can have this number at a time. 6577c478bd9Sstevel@tonic-gate */ 6587c478bd9Sstevel@tonic-gate if (tp->tn_gen != tfid->tfid_gen || tp->tn_nlink == 0) { 6597c478bd9Sstevel@tonic-gate mutex_exit(&tp->tn_tlock); 6607c478bd9Sstevel@tonic-gate mutex_exit(&tm->tm_contents); 6617c478bd9Sstevel@tonic-gate return (0); 6627c478bd9Sstevel@tonic-gate } 6637c478bd9Sstevel@tonic-gate *vpp = (struct vnode *)TNTOV(tp); 6647c478bd9Sstevel@tonic-gate 6657c478bd9Sstevel@tonic-gate VN_HOLD(*vpp); 6667c478bd9Sstevel@tonic-gate 6677c478bd9Sstevel@tonic-gate if ((tp->tn_mode & S_ISVTX) && 6687c478bd9Sstevel@tonic-gate !(tp->tn_mode & (S_IXUSR | S_IFDIR))) { 6697c478bd9Sstevel@tonic-gate mutex_enter(&(*vpp)->v_lock); 6707c478bd9Sstevel@tonic-gate (*vpp)->v_flag |= VISSWAP; 6717c478bd9Sstevel@tonic-gate mutex_exit(&(*vpp)->v_lock); 6727c478bd9Sstevel@tonic-gate } 6737c478bd9Sstevel@tonic-gate mutex_exit(&tp->tn_tlock); 6747c478bd9Sstevel@tonic-gate mutex_exit(&tm->tm_contents); 6757c478bd9Sstevel@tonic-gate return (0); 6767c478bd9Sstevel@tonic-gate } 6777c478bd9Sstevel@tonic-gate mutex_exit(&tp->tn_tlock); 6787c478bd9Sstevel@tonic-gate } 6797c478bd9Sstevel@tonic-gate mutex_exit(&tm->tm_contents); 6807c478bd9Sstevel@tonic-gate return (0); 6817c478bd9Sstevel@tonic-gate } 682