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 /* 2248011479Ssn199410 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 317c478bd9Sstevel@tonic-gate * The Regents of the University of California 327c478bd9Sstevel@tonic-gate * All Rights Reserved 337c478bd9Sstevel@tonic-gate * 347c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 357c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 367c478bd9Sstevel@tonic-gate * contributors. 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #include <sys/types.h> 437c478bd9Sstevel@tonic-gate #include <sys/param.h> 447c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 457c478bd9Sstevel@tonic-gate #include <sys/errno.h> 467c478bd9Sstevel@tonic-gate #include <sys/cred.h> 477c478bd9Sstevel@tonic-gate #include <sys/user.h> 487c478bd9Sstevel@tonic-gate #include <sys/uio.h> 497c478bd9Sstevel@tonic-gate #include <sys/file.h> 507c478bd9Sstevel@tonic-gate #include <sys/pathname.h> 517c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 52aa59c4cbSrsb #include <sys/vfs_opreg.h> 537c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 547c478bd9Sstevel@tonic-gate #include <sys/rwstlock.h> 557c478bd9Sstevel@tonic-gate #include <sys/fem.h> 567c478bd9Sstevel@tonic-gate #include <sys/stat.h> 577c478bd9Sstevel@tonic-gate #include <sys/mode.h> 587c478bd9Sstevel@tonic-gate #include <sys/conf.h> 597c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 607c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 617c478bd9Sstevel@tonic-gate #include <sys/systm.h> 627c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 637c478bd9Sstevel@tonic-gate #include <sys/debug.h> 647c478bd9Sstevel@tonic-gate #include <c2/audit.h> 657c478bd9Sstevel@tonic-gate #include <sys/acl.h> 667c478bd9Sstevel@tonic-gate #include <sys/nbmlock.h> 677c478bd9Sstevel@tonic-gate #include <sys/fcntl.h> 687c478bd9Sstevel@tonic-gate #include <fs/fs_subr.h> 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate /* Determine if this vnode is a file that is read-only */ 717c478bd9Sstevel@tonic-gate #define ISROFILE(vp) \ 727c478bd9Sstevel@tonic-gate ((vp)->v_type != VCHR && (vp)->v_type != VBLK && \ 737c478bd9Sstevel@tonic-gate (vp)->v_type != VFIFO && vn_is_readonly(vp)) 747c478bd9Sstevel@tonic-gate 75108322fbScarlsonj /* Tunable via /etc/system; used only by admin/install */ 76108322fbScarlsonj int nfs_global_client_only; 77108322fbScarlsonj 787c478bd9Sstevel@tonic-gate /* 795a59a8b3Srsb * Array of vopstats_t for per-FS-type vopstats. This array has the same 805a59a8b3Srsb * number of entries as and parallel to the vfssw table. (Arguably, it could 815a59a8b3Srsb * be part of the vfssw table.) Once it's initialized, it's accessed using 825a59a8b3Srsb * the same fstype index that is used to index into the vfssw table. 835a59a8b3Srsb */ 845a59a8b3Srsb vopstats_t **vopstats_fstype; 855a59a8b3Srsb 865a59a8b3Srsb /* vopstats initialization template used for fast initialization via bcopy() */ 875a59a8b3Srsb static vopstats_t *vs_templatep; 885a59a8b3Srsb 895a59a8b3Srsb /* Kmem cache handle for vsk_anchor_t allocations */ 905a59a8b3Srsb kmem_cache_t *vsk_anchor_cache; 915a59a8b3Srsb 92*df2381bfSpraks /* file events cleanup routine */ 93*df2381bfSpraks extern void free_fopdata(vnode_t *); 94*df2381bfSpraks 955a59a8b3Srsb /* 965a59a8b3Srsb * Root of AVL tree for the kstats associated with vopstats. Lock protects 975a59a8b3Srsb * updates to vsktat_tree. 985a59a8b3Srsb */ 995a59a8b3Srsb avl_tree_t vskstat_tree; 1005a59a8b3Srsb kmutex_t vskstat_tree_lock; 1015a59a8b3Srsb 1025a59a8b3Srsb /* Global variable which enables/disables the vopstats collection */ 1035a59a8b3Srsb int vopstats_enabled = 1; 1045a59a8b3Srsb 1055a59a8b3Srsb /* 1065a59a8b3Srsb * The following is the common set of actions needed to update the 1075a59a8b3Srsb * vopstats structure from a vnode op. Both VOPSTATS_UPDATE() and 1085a59a8b3Srsb * VOPSTATS_UPDATE_IO() do almost the same thing, except for the 1095a59a8b3Srsb * recording of the bytes transferred. Since the code is similar 1105a59a8b3Srsb * but small, it is nearly a duplicate. Consequently any changes 1115a59a8b3Srsb * to one may need to be reflected in the other. 1125a59a8b3Srsb * Rundown of the variables: 1135a59a8b3Srsb * vp - Pointer to the vnode 1145a59a8b3Srsb * counter - Partial name structure member to update in vopstats for counts 1155a59a8b3Srsb * bytecounter - Partial name structure member to update in vopstats for bytes 1165a59a8b3Srsb * bytesval - Value to update in vopstats for bytes 1175a59a8b3Srsb * fstype - Index into vsanchor_fstype[], same as index into vfssw[] 1185a59a8b3Srsb * vsp - Pointer to vopstats structure (either in vfs or vsanchor_fstype[i]) 1195a59a8b3Srsb */ 1205a59a8b3Srsb 1215a59a8b3Srsb #define VOPSTATS_UPDATE(vp, counter) { \ 1225a59a8b3Srsb vfs_t *vfsp = (vp)->v_vfsp; \ 123ddfcde86Srsb if (vfsp && vfsp->vfs_implp && \ 124ddfcde86Srsb (vfsp->vfs_flag & VFS_STATS) && (vp)->v_type != VBAD) { \ 1255a59a8b3Srsb vopstats_t *vsp = &vfsp->vfs_vopstats; \ 1262bb1cb30Sbmc uint64_t *stataddr = &(vsp->n##counter.value.ui64); \ 1272bb1cb30Sbmc extern void __dtrace_probe___fsinfo_##counter(vnode_t *, \ 1282bb1cb30Sbmc size_t, uint64_t *); \ 1292bb1cb30Sbmc __dtrace_probe___fsinfo_##counter(vp, 0, stataddr); \ 1302bb1cb30Sbmc (*stataddr)++; \ 1315a59a8b3Srsb if ((vsp = vfsp->vfs_fstypevsp) != NULL) { \ 1322bb1cb30Sbmc vsp->n##counter.value.ui64++; \ 1335a59a8b3Srsb } \ 1345a59a8b3Srsb } \ 1355a59a8b3Srsb } 1365a59a8b3Srsb 1375a59a8b3Srsb #define VOPSTATS_UPDATE_IO(vp, counter, bytecounter, bytesval) { \ 1385a59a8b3Srsb vfs_t *vfsp = (vp)->v_vfsp; \ 139ddfcde86Srsb if (vfsp && vfsp->vfs_implp && \ 140ddfcde86Srsb (vfsp->vfs_flag & VFS_STATS) && (vp)->v_type != VBAD) { \ 1415a59a8b3Srsb vopstats_t *vsp = &vfsp->vfs_vopstats; \ 1422bb1cb30Sbmc uint64_t *stataddr = &(vsp->n##counter.value.ui64); \ 1432bb1cb30Sbmc extern void __dtrace_probe___fsinfo_##counter(vnode_t *, \ 1442bb1cb30Sbmc size_t, uint64_t *); \ 1452bb1cb30Sbmc __dtrace_probe___fsinfo_##counter(vp, bytesval, stataddr); \ 1462bb1cb30Sbmc (*stataddr)++; \ 1475a59a8b3Srsb vsp->bytecounter.value.ui64 += bytesval; \ 1485a59a8b3Srsb if ((vsp = vfsp->vfs_fstypevsp) != NULL) { \ 1492bb1cb30Sbmc vsp->n##counter.value.ui64++; \ 1505a59a8b3Srsb vsp->bytecounter.value.ui64 += bytesval; \ 1515a59a8b3Srsb } \ 1525a59a8b3Srsb } \ 1535a59a8b3Srsb } 1545a59a8b3Srsb 1555a59a8b3Srsb /* 156f48205beScasper * If the filesystem does not support XIDs map credential 157f48205beScasper * If the vfsp is NULL, perhaps we should also map? 158f48205beScasper */ 159f48205beScasper #define VOPXID_MAP_CR(vp, cr) { \ 160f48205beScasper vfs_t *vfsp = (vp)->v_vfsp; \ 161f48205beScasper if (vfsp != NULL && (vfsp->vfs_flag & VFS_XID) == 0) \ 162f48205beScasper cr = crgetmapped(cr); \ 163f48205beScasper } 164f48205beScasper 165f48205beScasper /* 1667c478bd9Sstevel@tonic-gate * Convert stat(2) formats to vnode types and vice versa. (Knows about 1677c478bd9Sstevel@tonic-gate * numerical order of S_IFMT and vnode types.) 1687c478bd9Sstevel@tonic-gate */ 1697c478bd9Sstevel@tonic-gate enum vtype iftovt_tab[] = { 1707c478bd9Sstevel@tonic-gate VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON, 1717c478bd9Sstevel@tonic-gate VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VNON 1727c478bd9Sstevel@tonic-gate }; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate ushort_t vttoif_tab[] = { 1757c478bd9Sstevel@tonic-gate 0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, S_IFIFO, 1767c478bd9Sstevel@tonic-gate S_IFDOOR, 0, S_IFSOCK, S_IFPORT, 0 1777c478bd9Sstevel@tonic-gate }; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate /* 1807c478bd9Sstevel@tonic-gate * The system vnode cache. 1817c478bd9Sstevel@tonic-gate */ 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate kmem_cache_t *vn_cache; 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate /* 1877c478bd9Sstevel@tonic-gate * Vnode operations vector. 1887c478bd9Sstevel@tonic-gate */ 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate static const fs_operation_trans_def_t vn_ops_table[] = { 1917c478bd9Sstevel@tonic-gate VOPNAME_OPEN, offsetof(struct vnodeops, vop_open), 1927c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate VOPNAME_CLOSE, offsetof(struct vnodeops, vop_close), 1957c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate VOPNAME_READ, offsetof(struct vnodeops, vop_read), 1987c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate VOPNAME_WRITE, offsetof(struct vnodeops, vop_write), 2017c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate VOPNAME_IOCTL, offsetof(struct vnodeops, vop_ioctl), 2047c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate VOPNAME_SETFL, offsetof(struct vnodeops, vop_setfl), 2077c478bd9Sstevel@tonic-gate fs_setfl, fs_nosys, 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate VOPNAME_GETATTR, offsetof(struct vnodeops, vop_getattr), 2107c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate VOPNAME_SETATTR, offsetof(struct vnodeops, vop_setattr), 2137c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate VOPNAME_ACCESS, offsetof(struct vnodeops, vop_access), 2167c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate VOPNAME_LOOKUP, offsetof(struct vnodeops, vop_lookup), 2197c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate VOPNAME_CREATE, offsetof(struct vnodeops, vop_create), 2227c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate VOPNAME_REMOVE, offsetof(struct vnodeops, vop_remove), 2257c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate VOPNAME_LINK, offsetof(struct vnodeops, vop_link), 2287c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate VOPNAME_RENAME, offsetof(struct vnodeops, vop_rename), 2317c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate VOPNAME_MKDIR, offsetof(struct vnodeops, vop_mkdir), 2347c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate VOPNAME_RMDIR, offsetof(struct vnodeops, vop_rmdir), 2377c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate VOPNAME_READDIR, offsetof(struct vnodeops, vop_readdir), 2407c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate VOPNAME_SYMLINK, offsetof(struct vnodeops, vop_symlink), 2437c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate VOPNAME_READLINK, offsetof(struct vnodeops, vop_readlink), 2467c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate VOPNAME_FSYNC, offsetof(struct vnodeops, vop_fsync), 2497c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate VOPNAME_INACTIVE, offsetof(struct vnodeops, vop_inactive), 2527c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate VOPNAME_FID, offsetof(struct vnodeops, vop_fid), 2557c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate VOPNAME_RWLOCK, offsetof(struct vnodeops, vop_rwlock), 2587c478bd9Sstevel@tonic-gate fs_rwlock, fs_rwlock, 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate VOPNAME_RWUNLOCK, offsetof(struct vnodeops, vop_rwunlock), 2617c478bd9Sstevel@tonic-gate (fs_generic_func_p) fs_rwunlock, 2627c478bd9Sstevel@tonic-gate (fs_generic_func_p) fs_rwunlock, /* no errors allowed */ 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate VOPNAME_SEEK, offsetof(struct vnodeops, vop_seek), 2657c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate VOPNAME_CMP, offsetof(struct vnodeops, vop_cmp), 2687c478bd9Sstevel@tonic-gate fs_cmp, fs_cmp, /* no errors allowed */ 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate VOPNAME_FRLOCK, offsetof(struct vnodeops, vop_frlock), 2717c478bd9Sstevel@tonic-gate fs_frlock, fs_nosys, 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate VOPNAME_SPACE, offsetof(struct vnodeops, vop_space), 2747c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate VOPNAME_REALVP, offsetof(struct vnodeops, vop_realvp), 2777c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate VOPNAME_GETPAGE, offsetof(struct vnodeops, vop_getpage), 2807c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate VOPNAME_PUTPAGE, offsetof(struct vnodeops, vop_putpage), 2837c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate VOPNAME_MAP, offsetof(struct vnodeops, vop_map), 2867c478bd9Sstevel@tonic-gate (fs_generic_func_p) fs_nosys_map, 2877c478bd9Sstevel@tonic-gate (fs_generic_func_p) fs_nosys_map, 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate VOPNAME_ADDMAP, offsetof(struct vnodeops, vop_addmap), 2907c478bd9Sstevel@tonic-gate (fs_generic_func_p) fs_nosys_addmap, 2917c478bd9Sstevel@tonic-gate (fs_generic_func_p) fs_nosys_addmap, 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate VOPNAME_DELMAP, offsetof(struct vnodeops, vop_delmap), 2947c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate VOPNAME_POLL, offsetof(struct vnodeops, vop_poll), 2977c478bd9Sstevel@tonic-gate (fs_generic_func_p) fs_poll, (fs_generic_func_p) fs_nosys_poll, 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate VOPNAME_DUMP, offsetof(struct vnodeops, vop_dump), 3007c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate VOPNAME_PATHCONF, offsetof(struct vnodeops, vop_pathconf), 3037c478bd9Sstevel@tonic-gate fs_pathconf, fs_nosys, 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate VOPNAME_PAGEIO, offsetof(struct vnodeops, vop_pageio), 3067c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate VOPNAME_DUMPCTL, offsetof(struct vnodeops, vop_dumpctl), 3097c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate VOPNAME_DISPOSE, offsetof(struct vnodeops, vop_dispose), 3127c478bd9Sstevel@tonic-gate (fs_generic_func_p) fs_dispose, 3137c478bd9Sstevel@tonic-gate (fs_generic_func_p) fs_nodispose, 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate VOPNAME_SETSECATTR, offsetof(struct vnodeops, vop_setsecattr), 3167c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate VOPNAME_GETSECATTR, offsetof(struct vnodeops, vop_getsecattr), 3197c478bd9Sstevel@tonic-gate fs_fab_acl, fs_nosys, 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate VOPNAME_SHRLOCK, offsetof(struct vnodeops, vop_shrlock), 3227c478bd9Sstevel@tonic-gate fs_shrlock, fs_nosys, 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate VOPNAME_VNEVENT, offsetof(struct vnodeops, vop_vnevent), 3257c478bd9Sstevel@tonic-gate (fs_generic_func_p) fs_vnevent_nosupport, 3267c478bd9Sstevel@tonic-gate (fs_generic_func_p) fs_vnevent_nosupport, 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate NULL, 0, NULL, NULL 3297c478bd9Sstevel@tonic-gate }; 3307c478bd9Sstevel@tonic-gate 3315a59a8b3Srsb /* 3325a59a8b3Srsb * Used by the AVL routines to compare two vsk_anchor_t structures in the tree. 3335a59a8b3Srsb * We use the f_fsid reported by VFS_STATVFS() since we use that for the 3345a59a8b3Srsb * kstat name. 3355a59a8b3Srsb */ 3365a59a8b3Srsb static int 3375a59a8b3Srsb vska_compar(const void *n1, const void *n2) 3385a59a8b3Srsb { 3395a59a8b3Srsb int ret; 3405a59a8b3Srsb ulong_t p1 = ((vsk_anchor_t *)n1)->vsk_fsid; 3415a59a8b3Srsb ulong_t p2 = ((vsk_anchor_t *)n2)->vsk_fsid; 3425a59a8b3Srsb 3435a59a8b3Srsb if (p1 < p2) { 3445a59a8b3Srsb ret = -1; 3455a59a8b3Srsb } else if (p1 > p2) { 3465a59a8b3Srsb ret = 1; 3475a59a8b3Srsb } else { 3485a59a8b3Srsb ret = 0; 3495a59a8b3Srsb } 3505a59a8b3Srsb 3515a59a8b3Srsb return (ret); 3525a59a8b3Srsb } 3535a59a8b3Srsb 3545a59a8b3Srsb /* 3555a59a8b3Srsb * Used to create a single template which will be bcopy()ed to a newly 3565a59a8b3Srsb * allocated vsanchor_combo_t structure in new_vsanchor(), below. 3575a59a8b3Srsb */ 3585a59a8b3Srsb static vopstats_t * 3595a59a8b3Srsb create_vopstats_template() 3605a59a8b3Srsb { 3615a59a8b3Srsb vopstats_t *vsp; 3625a59a8b3Srsb 3635a59a8b3Srsb vsp = kmem_alloc(sizeof (vopstats_t), KM_SLEEP); 3645a59a8b3Srsb bzero(vsp, sizeof (*vsp)); /* Start fresh */ 3655a59a8b3Srsb 3665a59a8b3Srsb /* VOP_OPEN */ 3675a59a8b3Srsb kstat_named_init(&vsp->nopen, "nopen", KSTAT_DATA_UINT64); 3685a59a8b3Srsb /* VOP_CLOSE */ 3695a59a8b3Srsb kstat_named_init(&vsp->nclose, "nclose", KSTAT_DATA_UINT64); 3705a59a8b3Srsb /* VOP_READ I/O */ 3715a59a8b3Srsb kstat_named_init(&vsp->nread, "nread", KSTAT_DATA_UINT64); 3725a59a8b3Srsb kstat_named_init(&vsp->read_bytes, "read_bytes", KSTAT_DATA_UINT64); 3735a59a8b3Srsb /* VOP_WRITE I/O */ 3745a59a8b3Srsb kstat_named_init(&vsp->nwrite, "nwrite", KSTAT_DATA_UINT64); 3755a59a8b3Srsb kstat_named_init(&vsp->write_bytes, "write_bytes", KSTAT_DATA_UINT64); 3765a59a8b3Srsb /* VOP_IOCTL */ 3775a59a8b3Srsb kstat_named_init(&vsp->nioctl, "nioctl", KSTAT_DATA_UINT64); 3785a59a8b3Srsb /* VOP_SETFL */ 3795a59a8b3Srsb kstat_named_init(&vsp->nsetfl, "nsetfl", KSTAT_DATA_UINT64); 3805a59a8b3Srsb /* VOP_GETATTR */ 3815a59a8b3Srsb kstat_named_init(&vsp->ngetattr, "ngetattr", KSTAT_DATA_UINT64); 3825a59a8b3Srsb /* VOP_SETATTR */ 3835a59a8b3Srsb kstat_named_init(&vsp->nsetattr, "nsetattr", KSTAT_DATA_UINT64); 3845a59a8b3Srsb /* VOP_ACCESS */ 3855a59a8b3Srsb kstat_named_init(&vsp->naccess, "naccess", KSTAT_DATA_UINT64); 3865a59a8b3Srsb /* VOP_LOOKUP */ 3875a59a8b3Srsb kstat_named_init(&vsp->nlookup, "nlookup", KSTAT_DATA_UINT64); 3885a59a8b3Srsb /* VOP_CREATE */ 3895a59a8b3Srsb kstat_named_init(&vsp->ncreate, "ncreate", KSTAT_DATA_UINT64); 3905a59a8b3Srsb /* VOP_REMOVE */ 3915a59a8b3Srsb kstat_named_init(&vsp->nremove, "nremove", KSTAT_DATA_UINT64); 3925a59a8b3Srsb /* VOP_LINK */ 3935a59a8b3Srsb kstat_named_init(&vsp->nlink, "nlink", KSTAT_DATA_UINT64); 3945a59a8b3Srsb /* VOP_RENAME */ 3955a59a8b3Srsb kstat_named_init(&vsp->nrename, "nrename", KSTAT_DATA_UINT64); 3965a59a8b3Srsb /* VOP_MKDIR */ 3975a59a8b3Srsb kstat_named_init(&vsp->nmkdir, "nmkdir", KSTAT_DATA_UINT64); 3985a59a8b3Srsb /* VOP_RMDIR */ 3995a59a8b3Srsb kstat_named_init(&vsp->nrmdir, "nrmdir", KSTAT_DATA_UINT64); 4005a59a8b3Srsb /* VOP_READDIR I/O */ 4015a59a8b3Srsb kstat_named_init(&vsp->nreaddir, "nreaddir", KSTAT_DATA_UINT64); 4025a59a8b3Srsb kstat_named_init(&vsp->readdir_bytes, "readdir_bytes", 4035a59a8b3Srsb KSTAT_DATA_UINT64); 4045a59a8b3Srsb /* VOP_SYMLINK */ 4055a59a8b3Srsb kstat_named_init(&vsp->nsymlink, "nsymlink", KSTAT_DATA_UINT64); 4065a59a8b3Srsb /* VOP_READLINK */ 4075a59a8b3Srsb kstat_named_init(&vsp->nreadlink, "nreadlink", KSTAT_DATA_UINT64); 4085a59a8b3Srsb /* VOP_FSYNC */ 4095a59a8b3Srsb kstat_named_init(&vsp->nfsync, "nfsync", KSTAT_DATA_UINT64); 4105a59a8b3Srsb /* VOP_INACTIVE */ 4115a59a8b3Srsb kstat_named_init(&vsp->ninactive, "ninactive", KSTAT_DATA_UINT64); 4125a59a8b3Srsb /* VOP_FID */ 4135a59a8b3Srsb kstat_named_init(&vsp->nfid, "nfid", KSTAT_DATA_UINT64); 4145a59a8b3Srsb /* VOP_RWLOCK */ 4155a59a8b3Srsb kstat_named_init(&vsp->nrwlock, "nrwlock", KSTAT_DATA_UINT64); 4165a59a8b3Srsb /* VOP_RWUNLOCK */ 4175a59a8b3Srsb kstat_named_init(&vsp->nrwunlock, "nrwunlock", KSTAT_DATA_UINT64); 4185a59a8b3Srsb /* VOP_SEEK */ 4195a59a8b3Srsb kstat_named_init(&vsp->nseek, "nseek", KSTAT_DATA_UINT64); 4205a59a8b3Srsb /* VOP_CMP */ 4215a59a8b3Srsb kstat_named_init(&vsp->ncmp, "ncmp", KSTAT_DATA_UINT64); 4225a59a8b3Srsb /* VOP_FRLOCK */ 4235a59a8b3Srsb kstat_named_init(&vsp->nfrlock, "nfrlock", KSTAT_DATA_UINT64); 4245a59a8b3Srsb /* VOP_SPACE */ 4255a59a8b3Srsb kstat_named_init(&vsp->nspace, "nspace", KSTAT_DATA_UINT64); 4265a59a8b3Srsb /* VOP_REALVP */ 4275a59a8b3Srsb kstat_named_init(&vsp->nrealvp, "nrealvp", KSTAT_DATA_UINT64); 4285a59a8b3Srsb /* VOP_GETPAGE */ 4295a59a8b3Srsb kstat_named_init(&vsp->ngetpage, "ngetpage", KSTAT_DATA_UINT64); 4305a59a8b3Srsb /* VOP_PUTPAGE */ 4315a59a8b3Srsb kstat_named_init(&vsp->nputpage, "nputpage", KSTAT_DATA_UINT64); 4325a59a8b3Srsb /* VOP_MAP */ 4335a59a8b3Srsb kstat_named_init(&vsp->nmap, "nmap", KSTAT_DATA_UINT64); 4345a59a8b3Srsb /* VOP_ADDMAP */ 4355a59a8b3Srsb kstat_named_init(&vsp->naddmap, "naddmap", KSTAT_DATA_UINT64); 4365a59a8b3Srsb /* VOP_DELMAP */ 4375a59a8b3Srsb kstat_named_init(&vsp->ndelmap, "ndelmap", KSTAT_DATA_UINT64); 4385a59a8b3Srsb /* VOP_POLL */ 4395a59a8b3Srsb kstat_named_init(&vsp->npoll, "npoll", KSTAT_DATA_UINT64); 4405a59a8b3Srsb /* VOP_DUMP */ 4415a59a8b3Srsb kstat_named_init(&vsp->ndump, "ndump", KSTAT_DATA_UINT64); 4425a59a8b3Srsb /* VOP_PATHCONF */ 4435a59a8b3Srsb kstat_named_init(&vsp->npathconf, "npathconf", KSTAT_DATA_UINT64); 4445a59a8b3Srsb /* VOP_PAGEIO */ 4455a59a8b3Srsb kstat_named_init(&vsp->npageio, "npageio", KSTAT_DATA_UINT64); 4465a59a8b3Srsb /* VOP_DUMPCTL */ 4475a59a8b3Srsb kstat_named_init(&vsp->ndumpctl, "ndumpctl", KSTAT_DATA_UINT64); 4485a59a8b3Srsb /* VOP_DISPOSE */ 4495a59a8b3Srsb kstat_named_init(&vsp->ndispose, "ndispose", KSTAT_DATA_UINT64); 4505a59a8b3Srsb /* VOP_SETSECATTR */ 4515a59a8b3Srsb kstat_named_init(&vsp->nsetsecattr, "nsetsecattr", KSTAT_DATA_UINT64); 4525a59a8b3Srsb /* VOP_GETSECATTR */ 4535a59a8b3Srsb kstat_named_init(&vsp->ngetsecattr, "ngetsecattr", KSTAT_DATA_UINT64); 4545a59a8b3Srsb /* VOP_SHRLOCK */ 4555a59a8b3Srsb kstat_named_init(&vsp->nshrlock, "nshrlock", KSTAT_DATA_UINT64); 4565a59a8b3Srsb /* VOP_VNEVENT */ 4575a59a8b3Srsb kstat_named_init(&vsp->nvnevent, "nvnevent", KSTAT_DATA_UINT64); 4585a59a8b3Srsb 4595a59a8b3Srsb return (vsp); 4605a59a8b3Srsb } 4615a59a8b3Srsb 4625a59a8b3Srsb /* 4635a59a8b3Srsb * Creates a kstat structure associated with a vopstats structure. 4645a59a8b3Srsb */ 4655a59a8b3Srsb kstat_t * 4665a59a8b3Srsb new_vskstat(char *ksname, vopstats_t *vsp) 4675a59a8b3Srsb { 4685a59a8b3Srsb kstat_t *ksp; 4695a59a8b3Srsb 4705a59a8b3Srsb if (!vopstats_enabled) { 4715a59a8b3Srsb return (NULL); 4725a59a8b3Srsb } 4735a59a8b3Srsb 4745a59a8b3Srsb ksp = kstat_create("unix", 0, ksname, "misc", KSTAT_TYPE_NAMED, 4755a59a8b3Srsb sizeof (vopstats_t)/sizeof (kstat_named_t), 4765a59a8b3Srsb KSTAT_FLAG_VIRTUAL|KSTAT_FLAG_WRITABLE); 4775a59a8b3Srsb if (ksp) { 4785a59a8b3Srsb ksp->ks_data = vsp; 4795a59a8b3Srsb kstat_install(ksp); 4805a59a8b3Srsb } 4815a59a8b3Srsb 4825a59a8b3Srsb return (ksp); 4835a59a8b3Srsb } 4845a59a8b3Srsb 4855a59a8b3Srsb /* 4865a59a8b3Srsb * Called from vfsinit() to initialize the support mechanisms for vopstats 4875a59a8b3Srsb */ 4885a59a8b3Srsb void 4895a59a8b3Srsb vopstats_startup() 4905a59a8b3Srsb { 4915a59a8b3Srsb if (!vopstats_enabled) 4925a59a8b3Srsb return; 4935a59a8b3Srsb 4945a59a8b3Srsb /* 4955a59a8b3Srsb * Creates the AVL tree which holds per-vfs vopstat anchors. This 4965a59a8b3Srsb * is necessary since we need to check if a kstat exists before we 4975a59a8b3Srsb * attempt to create it. Also, initialize its lock. 4985a59a8b3Srsb */ 4995a59a8b3Srsb avl_create(&vskstat_tree, vska_compar, sizeof (vsk_anchor_t), 5005a59a8b3Srsb offsetof(vsk_anchor_t, vsk_node)); 5015a59a8b3Srsb mutex_init(&vskstat_tree_lock, NULL, MUTEX_DEFAULT, NULL); 5025a59a8b3Srsb 5035a59a8b3Srsb vsk_anchor_cache = kmem_cache_create("vsk_anchor_cache", 5045a59a8b3Srsb sizeof (vsk_anchor_t), sizeof (uintptr_t), NULL, NULL, NULL, 5055a59a8b3Srsb NULL, NULL, 0); 5065a59a8b3Srsb 5075a59a8b3Srsb /* 5085a59a8b3Srsb * Set up the array of pointers for the vopstats-by-FS-type. 5095a59a8b3Srsb * The entries will be allocated/initialized as each file system 5105a59a8b3Srsb * goes through modload/mod_installfs. 5115a59a8b3Srsb */ 5125a59a8b3Srsb vopstats_fstype = (vopstats_t **)kmem_zalloc( 5135a59a8b3Srsb (sizeof (vopstats_t *) * nfstype), KM_SLEEP); 5145a59a8b3Srsb 5155a59a8b3Srsb /* Set up the global vopstats initialization template */ 5165a59a8b3Srsb vs_templatep = create_vopstats_template(); 5175a59a8b3Srsb } 5185a59a8b3Srsb 5195a59a8b3Srsb /* 5205a59a8b3Srsb * We need to have the all of the counters zeroed. 5215a59a8b3Srsb * The initialization of the vopstats_t includes on the order of 5225a59a8b3Srsb * 50 calls to kstat_named_init(). Rather that do that on every call, 5235a59a8b3Srsb * we do it once in a template (vs_templatep) then bcopy it over. 5245a59a8b3Srsb */ 5255a59a8b3Srsb void 5265a59a8b3Srsb initialize_vopstats(vopstats_t *vsp) 5275a59a8b3Srsb { 5285a59a8b3Srsb if (vsp == NULL) 5295a59a8b3Srsb return; 5305a59a8b3Srsb 5315a59a8b3Srsb bcopy(vs_templatep, vsp, sizeof (vopstats_t)); 5325a59a8b3Srsb } 5335a59a8b3Srsb 5345a59a8b3Srsb /* 53582c7f3c4Srsb * If possible, determine which vopstats by fstype to use and 53682c7f3c4Srsb * return a pointer to the caller. 5375a59a8b3Srsb */ 53882c7f3c4Srsb vopstats_t * 53982c7f3c4Srsb get_fstype_vopstats(vfs_t *vfsp, struct vfssw *vswp) 5405a59a8b3Srsb { 5415a59a8b3Srsb int fstype = 0; /* Index into vfssw[] */ 54282c7f3c4Srsb vopstats_t *vsp = NULL; 5435a59a8b3Srsb 5445a59a8b3Srsb if (vfsp == NULL || (vfsp->vfs_flag & VFS_STATS) == 0 || 5455a59a8b3Srsb !vopstats_enabled) 54682c7f3c4Srsb return (NULL); 5475a59a8b3Srsb /* 5485a59a8b3Srsb * Set up the fstype. We go to so much trouble because all versions 5495a59a8b3Srsb * of NFS use the same fstype in their vfs even though they have 5505a59a8b3Srsb * distinct entries in the vfssw[] table. 55182c7f3c4Srsb * NOTE: A special vfs (e.g., EIO_vfs) may not have an entry. 5525a59a8b3Srsb */ 5535a59a8b3Srsb if (vswp) { 5545a59a8b3Srsb fstype = vswp - vfssw; /* Gets us the index */ 5555a59a8b3Srsb } else { 5565a59a8b3Srsb fstype = vfsp->vfs_fstype; 5575a59a8b3Srsb } 5585a59a8b3Srsb 5595a59a8b3Srsb /* 5605a59a8b3Srsb * Point to the per-fstype vopstats. The only valid values are 5615a59a8b3Srsb * non-zero positive values less than the number of vfssw[] table 5625a59a8b3Srsb * entries. 5635a59a8b3Srsb */ 5645a59a8b3Srsb if (fstype > 0 && fstype < nfstype) { 56582c7f3c4Srsb vsp = vopstats_fstype[fstype]; 5665a59a8b3Srsb } 5675a59a8b3Srsb 56882c7f3c4Srsb return (vsp); 56982c7f3c4Srsb } 57082c7f3c4Srsb 57182c7f3c4Srsb /* 57282c7f3c4Srsb * Generate a kstat name, create the kstat structure, and allocate a 57382c7f3c4Srsb * vsk_anchor_t to hold it together. Return the pointer to the vsk_anchor_t 57482c7f3c4Srsb * to the caller. This must only be called from a mount. 57582c7f3c4Srsb */ 57682c7f3c4Srsb vsk_anchor_t * 57782c7f3c4Srsb get_vskstat_anchor(vfs_t *vfsp) 57882c7f3c4Srsb { 57982c7f3c4Srsb char kstatstr[KSTAT_STRLEN]; /* kstat name for vopstats */ 58082c7f3c4Srsb statvfs64_t statvfsbuf; /* Needed to find f_fsid */ 58182c7f3c4Srsb vsk_anchor_t *vskp = NULL; /* vfs <--> kstat anchor */ 58282c7f3c4Srsb kstat_t *ksp; /* Ptr to new kstat */ 58382c7f3c4Srsb avl_index_t where; /* Location in the AVL tree */ 58482c7f3c4Srsb 585ddfcde86Srsb if (vfsp == NULL || vfsp->vfs_implp == NULL || 586ddfcde86Srsb (vfsp->vfs_flag & VFS_STATS) == 0 || !vopstats_enabled) 58782c7f3c4Srsb return (NULL); 58882c7f3c4Srsb 5895a59a8b3Srsb /* Need to get the fsid to build a kstat name */ 5905a59a8b3Srsb if (VFS_STATVFS(vfsp, &statvfsbuf) == 0) { 5915a59a8b3Srsb /* Create a name for our kstats based on fsid */ 5925a59a8b3Srsb (void) snprintf(kstatstr, KSTAT_STRLEN, "%s%lx", 5935a59a8b3Srsb VOPSTATS_STR, statvfsbuf.f_fsid); 5945a59a8b3Srsb 5955a59a8b3Srsb /* Allocate and initialize the vsk_anchor_t */ 5965a59a8b3Srsb vskp = kmem_cache_alloc(vsk_anchor_cache, KM_SLEEP); 5975a59a8b3Srsb bzero(vskp, sizeof (*vskp)); 5985a59a8b3Srsb vskp->vsk_fsid = statvfsbuf.f_fsid; 5995a59a8b3Srsb 6005a59a8b3Srsb mutex_enter(&vskstat_tree_lock); 6015a59a8b3Srsb if (avl_find(&vskstat_tree, vskp, &where) == NULL) { 6025a59a8b3Srsb avl_insert(&vskstat_tree, vskp, where); 6035a59a8b3Srsb mutex_exit(&vskstat_tree_lock); 6045a59a8b3Srsb 6055a59a8b3Srsb /* 6065a59a8b3Srsb * Now that we've got the anchor in the AVL 6075a59a8b3Srsb * tree, we can create the kstat. 6085a59a8b3Srsb */ 6095a59a8b3Srsb ksp = new_vskstat(kstatstr, &vfsp->vfs_vopstats); 6105a59a8b3Srsb if (ksp) { 6115a59a8b3Srsb vskp->vsk_ksp = ksp; 6125a59a8b3Srsb } 6135a59a8b3Srsb } else { 6145a59a8b3Srsb /* Oops, found one! Release memory and lock. */ 6155a59a8b3Srsb mutex_exit(&vskstat_tree_lock); 6165a59a8b3Srsb kmem_cache_free(vsk_anchor_cache, vskp); 61782c7f3c4Srsb vskp = NULL; 6185a59a8b3Srsb } 6195a59a8b3Srsb } 62082c7f3c4Srsb return (vskp); 6215a59a8b3Srsb } 6225a59a8b3Srsb 6235a59a8b3Srsb /* 6245a59a8b3Srsb * We're in the process of tearing down the vfs and need to cleanup 6255a59a8b3Srsb * the data structures associated with the vopstats. Must only be called 6265a59a8b3Srsb * from dounmount(). 6275a59a8b3Srsb */ 6285a59a8b3Srsb void 6295a59a8b3Srsb teardown_vopstats(vfs_t *vfsp) 6305a59a8b3Srsb { 6315a59a8b3Srsb vsk_anchor_t *vskap; 6325a59a8b3Srsb avl_index_t where; 6335a59a8b3Srsb 634ddfcde86Srsb if (vfsp == NULL || vfsp->vfs_implp == NULL || 635ddfcde86Srsb (vfsp->vfs_flag & VFS_STATS) == 0 || !vopstats_enabled) 6365a59a8b3Srsb return; 6375a59a8b3Srsb 6385a59a8b3Srsb /* This is a safe check since VFS_STATS must be set (see above) */ 6395a59a8b3Srsb if ((vskap = vfsp->vfs_vskap) == NULL) 6405a59a8b3Srsb return; 6415a59a8b3Srsb 6425a59a8b3Srsb /* Whack the pointer right away */ 6435a59a8b3Srsb vfsp->vfs_vskap = NULL; 6445a59a8b3Srsb 6455a59a8b3Srsb /* Lock the tree, remove the node, and delete the kstat */ 6465a59a8b3Srsb mutex_enter(&vskstat_tree_lock); 6475a59a8b3Srsb if (avl_find(&vskstat_tree, vskap, &where)) { 6485a59a8b3Srsb avl_remove(&vskstat_tree, vskap); 6495a59a8b3Srsb } 6505a59a8b3Srsb 6515a59a8b3Srsb if (vskap->vsk_ksp) { 6525a59a8b3Srsb kstat_delete(vskap->vsk_ksp); 6535a59a8b3Srsb } 6545a59a8b3Srsb mutex_exit(&vskstat_tree_lock); 6555a59a8b3Srsb 6565a59a8b3Srsb kmem_cache_free(vsk_anchor_cache, vskap); 6575a59a8b3Srsb } 6587c478bd9Sstevel@tonic-gate 6597c478bd9Sstevel@tonic-gate /* 6607c478bd9Sstevel@tonic-gate * Read or write a vnode. Called from kernel code. 6617c478bd9Sstevel@tonic-gate */ 6627c478bd9Sstevel@tonic-gate int 6637c478bd9Sstevel@tonic-gate vn_rdwr( 6647c478bd9Sstevel@tonic-gate enum uio_rw rw, 6657c478bd9Sstevel@tonic-gate struct vnode *vp, 6667c478bd9Sstevel@tonic-gate caddr_t base, 6677c478bd9Sstevel@tonic-gate ssize_t len, 6687c478bd9Sstevel@tonic-gate offset_t offset, 6697c478bd9Sstevel@tonic-gate enum uio_seg seg, 6707c478bd9Sstevel@tonic-gate int ioflag, 6717c478bd9Sstevel@tonic-gate rlim64_t ulimit, /* meaningful only if rw is UIO_WRITE */ 6727c478bd9Sstevel@tonic-gate cred_t *cr, 6737c478bd9Sstevel@tonic-gate ssize_t *residp) 6747c478bd9Sstevel@tonic-gate { 6757c478bd9Sstevel@tonic-gate struct uio uio; 6767c478bd9Sstevel@tonic-gate struct iovec iov; 6777c478bd9Sstevel@tonic-gate int error; 6787c478bd9Sstevel@tonic-gate int in_crit = 0; 6797c478bd9Sstevel@tonic-gate 6807c478bd9Sstevel@tonic-gate if (rw == UIO_WRITE && ISROFILE(vp)) 6817c478bd9Sstevel@tonic-gate return (EROFS); 6827c478bd9Sstevel@tonic-gate 6837c478bd9Sstevel@tonic-gate if (len < 0) 6847c478bd9Sstevel@tonic-gate return (EIO); 6857c478bd9Sstevel@tonic-gate 686f48205beScasper VOPXID_MAP_CR(vp, cr); 687f48205beScasper 6887c478bd9Sstevel@tonic-gate iov.iov_base = base; 6897c478bd9Sstevel@tonic-gate iov.iov_len = len; 6907c478bd9Sstevel@tonic-gate uio.uio_iov = &iov; 6917c478bd9Sstevel@tonic-gate uio.uio_iovcnt = 1; 6927c478bd9Sstevel@tonic-gate uio.uio_loffset = offset; 6937c478bd9Sstevel@tonic-gate uio.uio_segflg = (short)seg; 6947c478bd9Sstevel@tonic-gate uio.uio_resid = len; 6957c478bd9Sstevel@tonic-gate uio.uio_llimit = ulimit; 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate /* 6987c478bd9Sstevel@tonic-gate * We have to enter the critical region before calling VOP_RWLOCK 6997c478bd9Sstevel@tonic-gate * to avoid a deadlock with ufs. 7007c478bd9Sstevel@tonic-gate */ 7017c478bd9Sstevel@tonic-gate if (nbl_need_check(vp)) { 7027c478bd9Sstevel@tonic-gate int svmand; 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate nbl_start_crit(vp, RW_READER); 7057c478bd9Sstevel@tonic-gate in_crit = 1; 7067c478bd9Sstevel@tonic-gate error = nbl_svmand(vp, cr, &svmand); 7077c478bd9Sstevel@tonic-gate if (error != 0) 7087c478bd9Sstevel@tonic-gate goto done; 7097c478bd9Sstevel@tonic-gate if (nbl_conflict(vp, rw == UIO_WRITE ? NBL_WRITE : NBL_READ, 7107c478bd9Sstevel@tonic-gate uio.uio_offset, uio.uio_resid, svmand)) { 7117c478bd9Sstevel@tonic-gate error = EACCES; 7127c478bd9Sstevel@tonic-gate goto done; 7137c478bd9Sstevel@tonic-gate } 7147c478bd9Sstevel@tonic-gate } 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate (void) VOP_RWLOCK(vp, 7177c478bd9Sstevel@tonic-gate rw == UIO_WRITE ? V_WRITELOCK_TRUE : V_WRITELOCK_FALSE, NULL); 7187c478bd9Sstevel@tonic-gate if (rw == UIO_WRITE) { 7197c478bd9Sstevel@tonic-gate uio.uio_fmode = FWRITE; 7207c478bd9Sstevel@tonic-gate uio.uio_extflg = UIO_COPY_DEFAULT; 7217c478bd9Sstevel@tonic-gate error = VOP_WRITE(vp, &uio, ioflag, cr, NULL); 7227c478bd9Sstevel@tonic-gate } else { 7237c478bd9Sstevel@tonic-gate uio.uio_fmode = FREAD; 7247c478bd9Sstevel@tonic-gate uio.uio_extflg = UIO_COPY_CACHED; 7257c478bd9Sstevel@tonic-gate error = VOP_READ(vp, &uio, ioflag, cr, NULL); 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate VOP_RWUNLOCK(vp, rw == UIO_WRITE ? V_WRITELOCK_TRUE : V_WRITELOCK_FALSE, 7287c478bd9Sstevel@tonic-gate NULL); 7297c478bd9Sstevel@tonic-gate if (residp) 7307c478bd9Sstevel@tonic-gate *residp = uio.uio_resid; 7317c478bd9Sstevel@tonic-gate else if (uio.uio_resid) 7327c478bd9Sstevel@tonic-gate error = EIO; 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate done: 7357c478bd9Sstevel@tonic-gate if (in_crit) 7367c478bd9Sstevel@tonic-gate nbl_end_crit(vp); 7377c478bd9Sstevel@tonic-gate return (error); 7387c478bd9Sstevel@tonic-gate } 7397c478bd9Sstevel@tonic-gate 7407c478bd9Sstevel@tonic-gate /* 7417c478bd9Sstevel@tonic-gate * Release a vnode. Call VOP_INACTIVE on last reference or 7427c478bd9Sstevel@tonic-gate * decrement reference count. 7437c478bd9Sstevel@tonic-gate * 7447c478bd9Sstevel@tonic-gate * To avoid race conditions, the v_count is left at 1 for 7457c478bd9Sstevel@tonic-gate * the call to VOP_INACTIVE. This prevents another thread 7467c478bd9Sstevel@tonic-gate * from reclaiming and releasing the vnode *before* the 7477c478bd9Sstevel@tonic-gate * VOP_INACTIVE routine has a chance to destroy the vnode. 7487c478bd9Sstevel@tonic-gate * We can't have more than 1 thread calling VOP_INACTIVE 7497c478bd9Sstevel@tonic-gate * on a vnode. 7507c478bd9Sstevel@tonic-gate */ 7517c478bd9Sstevel@tonic-gate void 7527c478bd9Sstevel@tonic-gate vn_rele(vnode_t *vp) 7537c478bd9Sstevel@tonic-gate { 7547c478bd9Sstevel@tonic-gate if (vp->v_count == 0) 7557c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "vn_rele: vnode ref count 0"); 7567c478bd9Sstevel@tonic-gate mutex_enter(&vp->v_lock); 7577c478bd9Sstevel@tonic-gate if (vp->v_count == 1) { 7587c478bd9Sstevel@tonic-gate mutex_exit(&vp->v_lock); 7597c478bd9Sstevel@tonic-gate VOP_INACTIVE(vp, CRED()); 7607c478bd9Sstevel@tonic-gate } else { 7617c478bd9Sstevel@tonic-gate vp->v_count--; 7627c478bd9Sstevel@tonic-gate mutex_exit(&vp->v_lock); 7637c478bd9Sstevel@tonic-gate } 7647c478bd9Sstevel@tonic-gate } 7657c478bd9Sstevel@tonic-gate 7667c478bd9Sstevel@tonic-gate /* 7677c478bd9Sstevel@tonic-gate * Like vn_rele() except that it clears v_stream under v_lock. 7687c478bd9Sstevel@tonic-gate * This is used by sockfs when it dismantels the association between 7697c478bd9Sstevel@tonic-gate * the sockfs node and the vnode in the underlaying file system. 7707c478bd9Sstevel@tonic-gate * v_lock has to be held to prevent a thread coming through the lookupname 7717c478bd9Sstevel@tonic-gate * path from accessing a stream head that is going away. 7727c478bd9Sstevel@tonic-gate */ 7737c478bd9Sstevel@tonic-gate void 7747c478bd9Sstevel@tonic-gate vn_rele_stream(vnode_t *vp) 7757c478bd9Sstevel@tonic-gate { 7767c478bd9Sstevel@tonic-gate if (vp->v_count == 0) 7777c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "vn_rele: vnode ref count 0"); 7787c478bd9Sstevel@tonic-gate mutex_enter(&vp->v_lock); 7797c478bd9Sstevel@tonic-gate vp->v_stream = NULL; 7807c478bd9Sstevel@tonic-gate if (vp->v_count == 1) { 7817c478bd9Sstevel@tonic-gate mutex_exit(&vp->v_lock); 7827c478bd9Sstevel@tonic-gate VOP_INACTIVE(vp, CRED()); 7837c478bd9Sstevel@tonic-gate } else { 7847c478bd9Sstevel@tonic-gate vp->v_count--; 7857c478bd9Sstevel@tonic-gate mutex_exit(&vp->v_lock); 7867c478bd9Sstevel@tonic-gate } 7877c478bd9Sstevel@tonic-gate } 7887c478bd9Sstevel@tonic-gate 7897c478bd9Sstevel@tonic-gate int 7907c478bd9Sstevel@tonic-gate vn_open( 7917c478bd9Sstevel@tonic-gate char *pnamep, 7927c478bd9Sstevel@tonic-gate enum uio_seg seg, 7937c478bd9Sstevel@tonic-gate int filemode, 7947c478bd9Sstevel@tonic-gate int createmode, 7957c478bd9Sstevel@tonic-gate struct vnode **vpp, 7967c478bd9Sstevel@tonic-gate enum create crwhy, 7977c478bd9Sstevel@tonic-gate mode_t umask) 7987c478bd9Sstevel@tonic-gate { 7997c478bd9Sstevel@tonic-gate return (vn_openat(pnamep, seg, filemode, 8007c478bd9Sstevel@tonic-gate createmode, vpp, crwhy, umask, NULL)); 8017c478bd9Sstevel@tonic-gate } 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate 8047c478bd9Sstevel@tonic-gate /* 8057c478bd9Sstevel@tonic-gate * Open/create a vnode. 8067c478bd9Sstevel@tonic-gate * This may be callable by the kernel, the only known use 8077c478bd9Sstevel@tonic-gate * of user context being that the current user credentials 8087c478bd9Sstevel@tonic-gate * are used for permissions. crwhy is defined iff filemode & FCREAT. 8097c478bd9Sstevel@tonic-gate */ 8107c478bd9Sstevel@tonic-gate int 8117c478bd9Sstevel@tonic-gate vn_openat( 8127c478bd9Sstevel@tonic-gate char *pnamep, 8137c478bd9Sstevel@tonic-gate enum uio_seg seg, 8147c478bd9Sstevel@tonic-gate int filemode, 8157c478bd9Sstevel@tonic-gate int createmode, 8167c478bd9Sstevel@tonic-gate struct vnode **vpp, 8177c478bd9Sstevel@tonic-gate enum create crwhy, 8187c478bd9Sstevel@tonic-gate mode_t umask, 8197c478bd9Sstevel@tonic-gate struct vnode *startvp) 8207c478bd9Sstevel@tonic-gate { 8217c478bd9Sstevel@tonic-gate struct vnode *vp; 8227c478bd9Sstevel@tonic-gate int mode; 8237c478bd9Sstevel@tonic-gate int error; 8247c478bd9Sstevel@tonic-gate int in_crit = 0; 8257c478bd9Sstevel@tonic-gate struct vattr vattr; 8267c478bd9Sstevel@tonic-gate enum symfollow follow; 827dd29fa4aSprabahar int estale_retry = 0; 8287c478bd9Sstevel@tonic-gate 8297c478bd9Sstevel@tonic-gate mode = 0; 8307c478bd9Sstevel@tonic-gate if (filemode & FREAD) 8317c478bd9Sstevel@tonic-gate mode |= VREAD; 8327c478bd9Sstevel@tonic-gate if (filemode & (FWRITE|FTRUNC)) 8337c478bd9Sstevel@tonic-gate mode |= VWRITE; 8347c478bd9Sstevel@tonic-gate 8357c478bd9Sstevel@tonic-gate /* symlink interpretation */ 8367c478bd9Sstevel@tonic-gate if (filemode & FNOFOLLOW) 8377c478bd9Sstevel@tonic-gate follow = NO_FOLLOW; 8387c478bd9Sstevel@tonic-gate else 8397c478bd9Sstevel@tonic-gate follow = FOLLOW; 8407c478bd9Sstevel@tonic-gate 8417c478bd9Sstevel@tonic-gate top: 8427c478bd9Sstevel@tonic-gate if (filemode & FCREAT) { 8437c478bd9Sstevel@tonic-gate enum vcexcl excl; 8447c478bd9Sstevel@tonic-gate 8457c478bd9Sstevel@tonic-gate /* 8467c478bd9Sstevel@tonic-gate * Wish to create a file. 8477c478bd9Sstevel@tonic-gate */ 8487c478bd9Sstevel@tonic-gate vattr.va_type = VREG; 8497c478bd9Sstevel@tonic-gate vattr.va_mode = createmode; 8507c478bd9Sstevel@tonic-gate vattr.va_mask = AT_TYPE|AT_MODE; 8517c478bd9Sstevel@tonic-gate if (filemode & FTRUNC) { 8527c478bd9Sstevel@tonic-gate vattr.va_size = 0; 8537c478bd9Sstevel@tonic-gate vattr.va_mask |= AT_SIZE; 8547c478bd9Sstevel@tonic-gate } 8557c478bd9Sstevel@tonic-gate if (filemode & FEXCL) 8567c478bd9Sstevel@tonic-gate excl = EXCL; 8577c478bd9Sstevel@tonic-gate else 8587c478bd9Sstevel@tonic-gate excl = NONEXCL; 8597c478bd9Sstevel@tonic-gate 8607c478bd9Sstevel@tonic-gate if (error = 8617c478bd9Sstevel@tonic-gate vn_createat(pnamep, seg, &vattr, excl, mode, &vp, crwhy, 8627c478bd9Sstevel@tonic-gate (filemode & ~(FTRUNC|FEXCL)), 8637c478bd9Sstevel@tonic-gate umask, startvp)) 8647c478bd9Sstevel@tonic-gate return (error); 8657c478bd9Sstevel@tonic-gate } else { 8667c478bd9Sstevel@tonic-gate /* 8677c478bd9Sstevel@tonic-gate * Wish to open a file. Just look it up. 8687c478bd9Sstevel@tonic-gate */ 8697c478bd9Sstevel@tonic-gate if (error = lookupnameat(pnamep, seg, follow, 8707c478bd9Sstevel@tonic-gate NULLVPP, &vp, startvp)) { 871dd29fa4aSprabahar if ((error == ESTALE) && 872dd29fa4aSprabahar fs_need_estale_retry(estale_retry++)) 8737c478bd9Sstevel@tonic-gate goto top; 8747c478bd9Sstevel@tonic-gate return (error); 8757c478bd9Sstevel@tonic-gate } 8767c478bd9Sstevel@tonic-gate 8777c478bd9Sstevel@tonic-gate /* 8787c478bd9Sstevel@tonic-gate * Get the attributes to check whether file is large. 8797c478bd9Sstevel@tonic-gate * We do this only if the FOFFMAX flag is not set and 8807c478bd9Sstevel@tonic-gate * only for regular files. 8817c478bd9Sstevel@tonic-gate */ 8827c478bd9Sstevel@tonic-gate 8837c478bd9Sstevel@tonic-gate if (!(filemode & FOFFMAX) && (vp->v_type == VREG)) { 8847c478bd9Sstevel@tonic-gate vattr.va_mask = AT_SIZE; 8857c478bd9Sstevel@tonic-gate if ((error = VOP_GETATTR(vp, &vattr, 0, CRED()))) { 8867c478bd9Sstevel@tonic-gate goto out; 8877c478bd9Sstevel@tonic-gate } 8887c478bd9Sstevel@tonic-gate if (vattr.va_size > (u_offset_t)MAXOFF32_T) { 8897c478bd9Sstevel@tonic-gate /* 8907c478bd9Sstevel@tonic-gate * Large File API - regular open fails 8917c478bd9Sstevel@tonic-gate * if FOFFMAX flag is set in file mode 8927c478bd9Sstevel@tonic-gate */ 8937c478bd9Sstevel@tonic-gate error = EOVERFLOW; 8947c478bd9Sstevel@tonic-gate goto out; 8957c478bd9Sstevel@tonic-gate } 8967c478bd9Sstevel@tonic-gate } 8977c478bd9Sstevel@tonic-gate /* 8987c478bd9Sstevel@tonic-gate * Can't write directories, active texts, or 8997c478bd9Sstevel@tonic-gate * read-only filesystems. Can't truncate files 9007c478bd9Sstevel@tonic-gate * on which mandatory locking is in effect. 9017c478bd9Sstevel@tonic-gate */ 9027c478bd9Sstevel@tonic-gate if (filemode & (FWRITE|FTRUNC)) { 9037c478bd9Sstevel@tonic-gate /* 9047c478bd9Sstevel@tonic-gate * Allow writable directory if VDIROPEN flag is set. 9057c478bd9Sstevel@tonic-gate */ 9067c478bd9Sstevel@tonic-gate if (vp->v_type == VDIR && !(vp->v_flag & VDIROPEN)) { 9077c478bd9Sstevel@tonic-gate error = EISDIR; 9087c478bd9Sstevel@tonic-gate goto out; 9097c478bd9Sstevel@tonic-gate } 9107c478bd9Sstevel@tonic-gate if (ISROFILE(vp)) { 9117c478bd9Sstevel@tonic-gate error = EROFS; 9127c478bd9Sstevel@tonic-gate goto out; 9137c478bd9Sstevel@tonic-gate } 9147c478bd9Sstevel@tonic-gate /* 9157c478bd9Sstevel@tonic-gate * Can't truncate files on which mandatory locking 9167c478bd9Sstevel@tonic-gate * or non-blocking mandatory locking is in effect. 9177c478bd9Sstevel@tonic-gate */ 9187c478bd9Sstevel@tonic-gate if (filemode & FTRUNC) { 9197c478bd9Sstevel@tonic-gate vnode_t *rvp; 9207c478bd9Sstevel@tonic-gate 9217c478bd9Sstevel@tonic-gate if (VOP_REALVP(vp, &rvp) != 0) 9227c478bd9Sstevel@tonic-gate rvp = vp; 9237c478bd9Sstevel@tonic-gate if (nbl_need_check(vp)) { 9247c478bd9Sstevel@tonic-gate nbl_start_crit(vp, RW_READER); 9257c478bd9Sstevel@tonic-gate in_crit = 1; 9267c478bd9Sstevel@tonic-gate vattr.va_mask = AT_MODE|AT_SIZE; 9277c478bd9Sstevel@tonic-gate if ((error = VOP_GETATTR(vp, &vattr, 0, 9287c478bd9Sstevel@tonic-gate CRED())) == 0) { 9297c478bd9Sstevel@tonic-gate if (rvp->v_filocks != NULL) 9307c478bd9Sstevel@tonic-gate if (MANDLOCK(vp, 9317c478bd9Sstevel@tonic-gate vattr.va_mode)) 9327c478bd9Sstevel@tonic-gate error = EAGAIN; 9337c478bd9Sstevel@tonic-gate if (!error) { 9347c478bd9Sstevel@tonic-gate if (nbl_conflict(vp, 9357c478bd9Sstevel@tonic-gate NBL_WRITE, 0, 9367c478bd9Sstevel@tonic-gate vattr.va_size, 0)) 9377c478bd9Sstevel@tonic-gate error = EACCES; 9387c478bd9Sstevel@tonic-gate } 9397c478bd9Sstevel@tonic-gate } 9407c478bd9Sstevel@tonic-gate } else if (rvp->v_filocks != NULL) { 9417c478bd9Sstevel@tonic-gate vattr.va_mask = AT_MODE; 9427c478bd9Sstevel@tonic-gate if ((error = VOP_GETATTR(vp, &vattr, 9437c478bd9Sstevel@tonic-gate 0, CRED())) == 0 && MANDLOCK(vp, 9447c478bd9Sstevel@tonic-gate vattr.va_mode)) 9457c478bd9Sstevel@tonic-gate error = EAGAIN; 9467c478bd9Sstevel@tonic-gate } 9477c478bd9Sstevel@tonic-gate } 9487c478bd9Sstevel@tonic-gate if (error) 9497c478bd9Sstevel@tonic-gate goto out; 9507c478bd9Sstevel@tonic-gate } 9517c478bd9Sstevel@tonic-gate /* 9527c478bd9Sstevel@tonic-gate * Check permissions. 9537c478bd9Sstevel@tonic-gate */ 9547c478bd9Sstevel@tonic-gate if (error = VOP_ACCESS(vp, mode, 0, CRED())) 9557c478bd9Sstevel@tonic-gate goto out; 9567c478bd9Sstevel@tonic-gate } 9577c478bd9Sstevel@tonic-gate 9587c478bd9Sstevel@tonic-gate /* 9597c478bd9Sstevel@tonic-gate * Do remaining checks for FNOFOLLOW and FNOLINKS. 9607c478bd9Sstevel@tonic-gate */ 9617c478bd9Sstevel@tonic-gate if ((filemode & FNOFOLLOW) && vp->v_type == VLNK) { 9629acbbeafSnn35248 error = ELOOP; 9637c478bd9Sstevel@tonic-gate goto out; 9647c478bd9Sstevel@tonic-gate } 9657c478bd9Sstevel@tonic-gate if (filemode & FNOLINKS) { 9667c478bd9Sstevel@tonic-gate vattr.va_mask = AT_NLINK; 9677c478bd9Sstevel@tonic-gate if ((error = VOP_GETATTR(vp, &vattr, 0, CRED()))) { 9687c478bd9Sstevel@tonic-gate goto out; 9697c478bd9Sstevel@tonic-gate } 9707c478bd9Sstevel@tonic-gate if (vattr.va_nlink != 1) { 9717c478bd9Sstevel@tonic-gate error = EMLINK; 9727c478bd9Sstevel@tonic-gate goto out; 9737c478bd9Sstevel@tonic-gate } 9747c478bd9Sstevel@tonic-gate } 9757c478bd9Sstevel@tonic-gate 9767c478bd9Sstevel@tonic-gate /* 9777c478bd9Sstevel@tonic-gate * Opening a socket corresponding to the AF_UNIX pathname 9787c478bd9Sstevel@tonic-gate * in the filesystem name space is not supported. 9797c478bd9Sstevel@tonic-gate * However, VSOCK nodes in namefs are supported in order 9807c478bd9Sstevel@tonic-gate * to make fattach work for sockets. 9817c478bd9Sstevel@tonic-gate * 9827c478bd9Sstevel@tonic-gate * XXX This uses VOP_REALVP to distinguish between 9837c478bd9Sstevel@tonic-gate * an unopened namefs node (where VOP_REALVP returns a 9847c478bd9Sstevel@tonic-gate * different VSOCK vnode) and a VSOCK created by vn_create 9857c478bd9Sstevel@tonic-gate * in some file system (where VOP_REALVP would never return 9867c478bd9Sstevel@tonic-gate * a different vnode). 9877c478bd9Sstevel@tonic-gate */ 9887c478bd9Sstevel@tonic-gate if (vp->v_type == VSOCK) { 9897c478bd9Sstevel@tonic-gate struct vnode *nvp; 9907c478bd9Sstevel@tonic-gate 9917c478bd9Sstevel@tonic-gate error = VOP_REALVP(vp, &nvp); 9927c478bd9Sstevel@tonic-gate if (error != 0 || nvp == NULL || nvp == vp || 9937c478bd9Sstevel@tonic-gate nvp->v_type != VSOCK) { 9947c478bd9Sstevel@tonic-gate error = EOPNOTSUPP; 9957c478bd9Sstevel@tonic-gate goto out; 9967c478bd9Sstevel@tonic-gate } 9977c478bd9Sstevel@tonic-gate } 9987c478bd9Sstevel@tonic-gate /* 9997c478bd9Sstevel@tonic-gate * Do opening protocol. 10007c478bd9Sstevel@tonic-gate */ 10017c478bd9Sstevel@tonic-gate error = VOP_OPEN(&vp, filemode, CRED()); 10027c478bd9Sstevel@tonic-gate /* 10037c478bd9Sstevel@tonic-gate * Truncate if required. 10047c478bd9Sstevel@tonic-gate */ 10057c478bd9Sstevel@tonic-gate if (error == 0 && (filemode & FTRUNC) && !(filemode & FCREAT)) { 10067c478bd9Sstevel@tonic-gate vattr.va_size = 0; 10077c478bd9Sstevel@tonic-gate vattr.va_mask = AT_SIZE; 10087c478bd9Sstevel@tonic-gate if ((error = VOP_SETATTR(vp, &vattr, 0, CRED(), NULL)) != 0) 10097c478bd9Sstevel@tonic-gate (void) VOP_CLOSE(vp, filemode, 1, (offset_t)0, CRED()); 10107c478bd9Sstevel@tonic-gate } 10117c478bd9Sstevel@tonic-gate out: 10127c478bd9Sstevel@tonic-gate ASSERT(vp->v_count > 0); 10137c478bd9Sstevel@tonic-gate 10147c478bd9Sstevel@tonic-gate if (in_crit) { 10157c478bd9Sstevel@tonic-gate nbl_end_crit(vp); 10167c478bd9Sstevel@tonic-gate in_crit = 0; 10177c478bd9Sstevel@tonic-gate } 10187c478bd9Sstevel@tonic-gate if (error) { 10197c478bd9Sstevel@tonic-gate /* 10207c478bd9Sstevel@tonic-gate * The following clause was added to handle a problem 10217c478bd9Sstevel@tonic-gate * with NFS consistency. It is possible that a lookup 10227c478bd9Sstevel@tonic-gate * of the file to be opened succeeded, but the file 10237c478bd9Sstevel@tonic-gate * itself doesn't actually exist on the server. This 10247c478bd9Sstevel@tonic-gate * is chiefly due to the DNLC containing an entry for 10257c478bd9Sstevel@tonic-gate * the file which has been removed on the server. In 10267c478bd9Sstevel@tonic-gate * this case, we just start over. If there was some 10277c478bd9Sstevel@tonic-gate * other cause for the ESTALE error, then the lookup 10287c478bd9Sstevel@tonic-gate * of the file will fail and the error will be returned 10297c478bd9Sstevel@tonic-gate * above instead of looping around from here. 10307c478bd9Sstevel@tonic-gate */ 10317c478bd9Sstevel@tonic-gate VN_RELE(vp); 1032dd29fa4aSprabahar if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) 10337c478bd9Sstevel@tonic-gate goto top; 10347c478bd9Sstevel@tonic-gate } else 10357c478bd9Sstevel@tonic-gate *vpp = vp; 10367c478bd9Sstevel@tonic-gate return (error); 10377c478bd9Sstevel@tonic-gate } 10387c478bd9Sstevel@tonic-gate 10397c478bd9Sstevel@tonic-gate int 10407c478bd9Sstevel@tonic-gate vn_create( 10417c478bd9Sstevel@tonic-gate char *pnamep, 10427c478bd9Sstevel@tonic-gate enum uio_seg seg, 10437c478bd9Sstevel@tonic-gate struct vattr *vap, 10447c478bd9Sstevel@tonic-gate enum vcexcl excl, 10457c478bd9Sstevel@tonic-gate int mode, 10467c478bd9Sstevel@tonic-gate struct vnode **vpp, 10477c478bd9Sstevel@tonic-gate enum create why, 10487c478bd9Sstevel@tonic-gate int flag, 10497c478bd9Sstevel@tonic-gate mode_t umask) 10507c478bd9Sstevel@tonic-gate { 10517c478bd9Sstevel@tonic-gate return (vn_createat(pnamep, seg, vap, excl, mode, vpp, 10527c478bd9Sstevel@tonic-gate why, flag, umask, NULL)); 10537c478bd9Sstevel@tonic-gate } 10547c478bd9Sstevel@tonic-gate 10557c478bd9Sstevel@tonic-gate /* 10567c478bd9Sstevel@tonic-gate * Create a vnode (makenode). 10577c478bd9Sstevel@tonic-gate */ 10587c478bd9Sstevel@tonic-gate int 10597c478bd9Sstevel@tonic-gate vn_createat( 10607c478bd9Sstevel@tonic-gate char *pnamep, 10617c478bd9Sstevel@tonic-gate enum uio_seg seg, 10627c478bd9Sstevel@tonic-gate struct vattr *vap, 10637c478bd9Sstevel@tonic-gate enum vcexcl excl, 10647c478bd9Sstevel@tonic-gate int mode, 10657c478bd9Sstevel@tonic-gate struct vnode **vpp, 10667c478bd9Sstevel@tonic-gate enum create why, 10677c478bd9Sstevel@tonic-gate int flag, 10687c478bd9Sstevel@tonic-gate mode_t umask, 10697c478bd9Sstevel@tonic-gate struct vnode *startvp) 10707c478bd9Sstevel@tonic-gate { 10717c478bd9Sstevel@tonic-gate struct vnode *dvp; /* ptr to parent dir vnode */ 10727c478bd9Sstevel@tonic-gate struct vnode *vp = NULL; 10737c478bd9Sstevel@tonic-gate struct pathname pn; 10747c478bd9Sstevel@tonic-gate int error; 10757c478bd9Sstevel@tonic-gate int in_crit = 0; 10767c478bd9Sstevel@tonic-gate struct vattr vattr; 10777c478bd9Sstevel@tonic-gate enum symfollow follow; 1078dd29fa4aSprabahar int estale_retry = 0; 10797c478bd9Sstevel@tonic-gate 10807c478bd9Sstevel@tonic-gate ASSERT((vap->va_mask & (AT_TYPE|AT_MODE)) == (AT_TYPE|AT_MODE)); 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate /* symlink interpretation */ 10837c478bd9Sstevel@tonic-gate if ((flag & FNOFOLLOW) || excl == EXCL) 10847c478bd9Sstevel@tonic-gate follow = NO_FOLLOW; 10857c478bd9Sstevel@tonic-gate else 10867c478bd9Sstevel@tonic-gate follow = FOLLOW; 10877c478bd9Sstevel@tonic-gate flag &= ~(FNOFOLLOW|FNOLINKS); 10887c478bd9Sstevel@tonic-gate 10897c478bd9Sstevel@tonic-gate top: 10907c478bd9Sstevel@tonic-gate /* 10917c478bd9Sstevel@tonic-gate * Lookup directory. 10927c478bd9Sstevel@tonic-gate * If new object is a file, call lower level to create it. 10937c478bd9Sstevel@tonic-gate * Note that it is up to the lower level to enforce exclusive 10947c478bd9Sstevel@tonic-gate * creation, if the file is already there. 10957c478bd9Sstevel@tonic-gate * This allows the lower level to do whatever 10967c478bd9Sstevel@tonic-gate * locking or protocol that is needed to prevent races. 10977c478bd9Sstevel@tonic-gate * If the new object is directory call lower level to make 10987c478bd9Sstevel@tonic-gate * the new directory, with "." and "..". 10997c478bd9Sstevel@tonic-gate */ 11007c478bd9Sstevel@tonic-gate if (error = pn_get(pnamep, seg, &pn)) 11017c478bd9Sstevel@tonic-gate return (error); 11027c478bd9Sstevel@tonic-gate #ifdef C2_AUDIT 11037c478bd9Sstevel@tonic-gate if (audit_active) 11047c478bd9Sstevel@tonic-gate audit_vncreate_start(); 11057c478bd9Sstevel@tonic-gate #endif /* C2_AUDIT */ 11067c478bd9Sstevel@tonic-gate dvp = NULL; 11077c478bd9Sstevel@tonic-gate *vpp = NULL; 11087c478bd9Sstevel@tonic-gate /* 11097c478bd9Sstevel@tonic-gate * lookup will find the parent directory for the vnode. 11107c478bd9Sstevel@tonic-gate * When it is done the pn holds the name of the entry 11117c478bd9Sstevel@tonic-gate * in the directory. 11127c478bd9Sstevel@tonic-gate * If this is a non-exclusive create we also find the node itself. 11137c478bd9Sstevel@tonic-gate */ 11147c478bd9Sstevel@tonic-gate error = lookuppnat(&pn, NULL, follow, &dvp, 11157c478bd9Sstevel@tonic-gate (excl == EXCL) ? NULLVPP : vpp, startvp); 11167c478bd9Sstevel@tonic-gate if (error) { 11177c478bd9Sstevel@tonic-gate pn_free(&pn); 1118dd29fa4aSprabahar if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) 11197c478bd9Sstevel@tonic-gate goto top; 11207c478bd9Sstevel@tonic-gate if (why == CRMKDIR && error == EINVAL) 11217c478bd9Sstevel@tonic-gate error = EEXIST; /* SVID */ 11227c478bd9Sstevel@tonic-gate return (error); 11237c478bd9Sstevel@tonic-gate } 11247c478bd9Sstevel@tonic-gate 11257c478bd9Sstevel@tonic-gate if (why != CRMKNOD) 11267c478bd9Sstevel@tonic-gate vap->va_mode &= ~VSVTX; 11277c478bd9Sstevel@tonic-gate 11287c478bd9Sstevel@tonic-gate /* 11297c478bd9Sstevel@tonic-gate * If default ACLs are defined for the directory don't apply the 11307c478bd9Sstevel@tonic-gate * umask if umask is passed. 11317c478bd9Sstevel@tonic-gate */ 11327c478bd9Sstevel@tonic-gate 11337c478bd9Sstevel@tonic-gate if (umask) { 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate vsecattr_t vsec; 11367c478bd9Sstevel@tonic-gate 11377c478bd9Sstevel@tonic-gate vsec.vsa_aclcnt = 0; 11387c478bd9Sstevel@tonic-gate vsec.vsa_aclentp = NULL; 11397c478bd9Sstevel@tonic-gate vsec.vsa_dfaclcnt = 0; 11407c478bd9Sstevel@tonic-gate vsec.vsa_dfaclentp = NULL; 11417c478bd9Sstevel@tonic-gate vsec.vsa_mask = VSA_DFACLCNT; 1142fa9e4066Sahrens error = VOP_GETSECATTR(dvp, &vsec, 0, CRED()); 1143fa9e4066Sahrens /* 1144fa9e4066Sahrens * If error is ENOSYS then treat it as no error 1145fa9e4066Sahrens * Don't want to force all file systems to support 1146fa9e4066Sahrens * aclent_t style of ACL's. 1147fa9e4066Sahrens */ 1148fa9e4066Sahrens if (error == ENOSYS) 1149fa9e4066Sahrens error = 0; 1150fa9e4066Sahrens if (error) { 11517c478bd9Sstevel@tonic-gate if (*vpp != NULL) 11527c478bd9Sstevel@tonic-gate VN_RELE(*vpp); 11537c478bd9Sstevel@tonic-gate goto out; 1154fa9e4066Sahrens } else { 11557c478bd9Sstevel@tonic-gate /* 11567c478bd9Sstevel@tonic-gate * Apply the umask if no default ACLs. 11577c478bd9Sstevel@tonic-gate */ 11587c478bd9Sstevel@tonic-gate if (vsec.vsa_dfaclcnt == 0) 11597c478bd9Sstevel@tonic-gate vap->va_mode &= ~umask; 11607c478bd9Sstevel@tonic-gate 11617c478bd9Sstevel@tonic-gate /* 1162fa9e4066Sahrens * VOP_GETSECATTR() may have allocated memory for 1163fa9e4066Sahrens * ACLs we didn't request, so double-check and 1164fa9e4066Sahrens * free it if necessary. 11657c478bd9Sstevel@tonic-gate */ 11667c478bd9Sstevel@tonic-gate if (vsec.vsa_aclcnt && vsec.vsa_aclentp != NULL) 11677c478bd9Sstevel@tonic-gate kmem_free((caddr_t)vsec.vsa_aclentp, 11687c478bd9Sstevel@tonic-gate vsec.vsa_aclcnt * sizeof (aclent_t)); 11697c478bd9Sstevel@tonic-gate if (vsec.vsa_dfaclcnt && vsec.vsa_dfaclentp != NULL) 11707c478bd9Sstevel@tonic-gate kmem_free((caddr_t)vsec.vsa_dfaclentp, 11717c478bd9Sstevel@tonic-gate vsec.vsa_dfaclcnt * sizeof (aclent_t)); 11727c478bd9Sstevel@tonic-gate } 1173fa9e4066Sahrens } 11747c478bd9Sstevel@tonic-gate 11757c478bd9Sstevel@tonic-gate /* 11767c478bd9Sstevel@tonic-gate * In general we want to generate EROFS if the file system is 11777c478bd9Sstevel@tonic-gate * readonly. However, POSIX (IEEE Std. 1003.1) section 5.3.1 11787c478bd9Sstevel@tonic-gate * documents the open system call, and it says that O_CREAT has no 11797c478bd9Sstevel@tonic-gate * effect if the file already exists. Bug 1119649 states 11807c478bd9Sstevel@tonic-gate * that open(path, O_CREAT, ...) fails when attempting to open an 11817c478bd9Sstevel@tonic-gate * existing file on a read only file system. Thus, the first part 11827c478bd9Sstevel@tonic-gate * of the following if statement has 3 checks: 11837c478bd9Sstevel@tonic-gate * if the file exists && 11847c478bd9Sstevel@tonic-gate * it is being open with write access && 11857c478bd9Sstevel@tonic-gate * the file system is read only 11867c478bd9Sstevel@tonic-gate * then generate EROFS 11877c478bd9Sstevel@tonic-gate */ 11887c478bd9Sstevel@tonic-gate if ((*vpp != NULL && (mode & VWRITE) && ISROFILE(*vpp)) || 11897c478bd9Sstevel@tonic-gate (*vpp == NULL && dvp->v_vfsp->vfs_flag & VFS_RDONLY)) { 11907c478bd9Sstevel@tonic-gate if (*vpp) 11917c478bd9Sstevel@tonic-gate VN_RELE(*vpp); 11927c478bd9Sstevel@tonic-gate error = EROFS; 11937c478bd9Sstevel@tonic-gate } else if (excl == NONEXCL && *vpp != NULL) { 11947c478bd9Sstevel@tonic-gate vnode_t *rvp; 11957c478bd9Sstevel@tonic-gate 11967c478bd9Sstevel@tonic-gate /* 11977c478bd9Sstevel@tonic-gate * File already exists. If a mandatory lock has been 11987c478bd9Sstevel@tonic-gate * applied, return error. 11997c478bd9Sstevel@tonic-gate */ 12007c478bd9Sstevel@tonic-gate vp = *vpp; 12017c478bd9Sstevel@tonic-gate if (VOP_REALVP(vp, &rvp) != 0) 12027c478bd9Sstevel@tonic-gate rvp = vp; 12037c478bd9Sstevel@tonic-gate if ((vap->va_mask & AT_SIZE) && nbl_need_check(vp)) { 12047c478bd9Sstevel@tonic-gate nbl_start_crit(vp, RW_READER); 12057c478bd9Sstevel@tonic-gate in_crit = 1; 12067c478bd9Sstevel@tonic-gate } 12077c478bd9Sstevel@tonic-gate if (rvp->v_filocks != NULL || rvp->v_shrlocks != NULL) { 12087c478bd9Sstevel@tonic-gate vattr.va_mask = AT_MODE|AT_SIZE; 12097c478bd9Sstevel@tonic-gate if (error = VOP_GETATTR(vp, &vattr, 0, CRED())) { 12107c478bd9Sstevel@tonic-gate goto out; 12117c478bd9Sstevel@tonic-gate } 12127c478bd9Sstevel@tonic-gate if (MANDLOCK(vp, vattr.va_mode)) { 12137c478bd9Sstevel@tonic-gate error = EAGAIN; 12147c478bd9Sstevel@tonic-gate goto out; 12157c478bd9Sstevel@tonic-gate } 12167c478bd9Sstevel@tonic-gate /* 12177c478bd9Sstevel@tonic-gate * File cannot be truncated if non-blocking mandatory 12187c478bd9Sstevel@tonic-gate * locks are currently on the file. 12197c478bd9Sstevel@tonic-gate */ 12207c478bd9Sstevel@tonic-gate if ((vap->va_mask & AT_SIZE) && in_crit) { 12217c478bd9Sstevel@tonic-gate u_offset_t offset; 12227c478bd9Sstevel@tonic-gate ssize_t length; 12237c478bd9Sstevel@tonic-gate 12247c478bd9Sstevel@tonic-gate offset = vap->va_size > vattr.va_size ? 12257c478bd9Sstevel@tonic-gate vattr.va_size : vap->va_size; 12267c478bd9Sstevel@tonic-gate length = vap->va_size > vattr.va_size ? 12277c478bd9Sstevel@tonic-gate vap->va_size - vattr.va_size : 12287c478bd9Sstevel@tonic-gate vattr.va_size - vap->va_size; 12297c478bd9Sstevel@tonic-gate if (nbl_conflict(vp, NBL_WRITE, offset, 12307c478bd9Sstevel@tonic-gate length, 0)) { 12317c478bd9Sstevel@tonic-gate error = EACCES; 12327c478bd9Sstevel@tonic-gate goto out; 12337c478bd9Sstevel@tonic-gate } 12347c478bd9Sstevel@tonic-gate } 12357c478bd9Sstevel@tonic-gate } 12367c478bd9Sstevel@tonic-gate 12377c478bd9Sstevel@tonic-gate /* 12387c478bd9Sstevel@tonic-gate * If the file is the root of a VFS, we've crossed a 12397c478bd9Sstevel@tonic-gate * mount point and the "containing" directory that we 12407c478bd9Sstevel@tonic-gate * acquired above (dvp) is irrelevant because it's in 12417c478bd9Sstevel@tonic-gate * a different file system. We apply VOP_CREATE to the 12427c478bd9Sstevel@tonic-gate * target itself instead of to the containing directory 12437c478bd9Sstevel@tonic-gate * and supply a null path name to indicate (conventionally) 12447c478bd9Sstevel@tonic-gate * the node itself as the "component" of interest. 12457c478bd9Sstevel@tonic-gate * 12467c478bd9Sstevel@tonic-gate * The intercession of the file system is necessary to 12477c478bd9Sstevel@tonic-gate * ensure that the appropriate permission checks are 12487c478bd9Sstevel@tonic-gate * done. 12497c478bd9Sstevel@tonic-gate */ 12507c478bd9Sstevel@tonic-gate if (vp->v_flag & VROOT) { 12517c478bd9Sstevel@tonic-gate ASSERT(why != CRMKDIR); 12527c478bd9Sstevel@tonic-gate error = 12537c478bd9Sstevel@tonic-gate VOP_CREATE(vp, "", vap, excl, mode, vpp, CRED(), 12547c478bd9Sstevel@tonic-gate flag); 12557c478bd9Sstevel@tonic-gate /* 12567c478bd9Sstevel@tonic-gate * If the create succeeded, it will have created 12577c478bd9Sstevel@tonic-gate * a new reference to the vnode. Give up the 12587c478bd9Sstevel@tonic-gate * original reference. The assertion should not 12597c478bd9Sstevel@tonic-gate * get triggered because NBMAND locks only apply to 12607c478bd9Sstevel@tonic-gate * VREG files. And if in_crit is non-zero for some 12617c478bd9Sstevel@tonic-gate * reason, detect that here, rather than when we 12627c478bd9Sstevel@tonic-gate * deference a null vp. 12637c478bd9Sstevel@tonic-gate */ 12647c478bd9Sstevel@tonic-gate ASSERT(in_crit == 0); 12657c478bd9Sstevel@tonic-gate VN_RELE(vp); 12667c478bd9Sstevel@tonic-gate vp = NULL; 12677c478bd9Sstevel@tonic-gate goto out; 12687c478bd9Sstevel@tonic-gate } 12697c478bd9Sstevel@tonic-gate 12707c478bd9Sstevel@tonic-gate /* 12717c478bd9Sstevel@tonic-gate * Large File API - non-large open (FOFFMAX flag not set) 12727c478bd9Sstevel@tonic-gate * of regular file fails if the file size exceeds MAXOFF32_T. 12737c478bd9Sstevel@tonic-gate */ 12747c478bd9Sstevel@tonic-gate if (why != CRMKDIR && 12757c478bd9Sstevel@tonic-gate !(flag & FOFFMAX) && 12767c478bd9Sstevel@tonic-gate (vp->v_type == VREG)) { 12777c478bd9Sstevel@tonic-gate vattr.va_mask = AT_SIZE; 12787c478bd9Sstevel@tonic-gate if ((error = VOP_GETATTR(vp, &vattr, 0, CRED()))) { 12797c478bd9Sstevel@tonic-gate goto out; 12807c478bd9Sstevel@tonic-gate } 12817c478bd9Sstevel@tonic-gate if ((vattr.va_size > (u_offset_t)MAXOFF32_T)) { 12827c478bd9Sstevel@tonic-gate error = EOVERFLOW; 12837c478bd9Sstevel@tonic-gate goto out; 12847c478bd9Sstevel@tonic-gate } 12857c478bd9Sstevel@tonic-gate } 12867c478bd9Sstevel@tonic-gate } 12877c478bd9Sstevel@tonic-gate 12887c478bd9Sstevel@tonic-gate if (error == 0) { 12897c478bd9Sstevel@tonic-gate /* 12907c478bd9Sstevel@tonic-gate * Call mkdir() if specified, otherwise create(). 12917c478bd9Sstevel@tonic-gate */ 12927c478bd9Sstevel@tonic-gate int must_be_dir = pn_fixslash(&pn); /* trailing '/'? */ 12937c478bd9Sstevel@tonic-gate 12947c478bd9Sstevel@tonic-gate if (why == CRMKDIR) 12957c478bd9Sstevel@tonic-gate error = VOP_MKDIR(dvp, pn.pn_path, vap, vpp, CRED()); 12967c478bd9Sstevel@tonic-gate else if (!must_be_dir) 12977c478bd9Sstevel@tonic-gate error = VOP_CREATE(dvp, pn.pn_path, vap, 12987c478bd9Sstevel@tonic-gate excl, mode, vpp, CRED(), flag); 12997c478bd9Sstevel@tonic-gate else 13007c478bd9Sstevel@tonic-gate error = ENOTDIR; 13017c478bd9Sstevel@tonic-gate } 13027c478bd9Sstevel@tonic-gate 13037c478bd9Sstevel@tonic-gate out: 13047c478bd9Sstevel@tonic-gate 13057c478bd9Sstevel@tonic-gate #ifdef C2_AUDIT 13067c478bd9Sstevel@tonic-gate if (audit_active) 13077c478bd9Sstevel@tonic-gate audit_vncreate_finish(*vpp, error); 13087c478bd9Sstevel@tonic-gate #endif /* C2_AUDIT */ 13097c478bd9Sstevel@tonic-gate if (in_crit) { 13107c478bd9Sstevel@tonic-gate nbl_end_crit(vp); 13117c478bd9Sstevel@tonic-gate in_crit = 0; 13127c478bd9Sstevel@tonic-gate } 13137c478bd9Sstevel@tonic-gate if (vp != NULL) { 13147c478bd9Sstevel@tonic-gate VN_RELE(vp); 13157c478bd9Sstevel@tonic-gate vp = NULL; 13167c478bd9Sstevel@tonic-gate } 13177c478bd9Sstevel@tonic-gate pn_free(&pn); 13187c478bd9Sstevel@tonic-gate VN_RELE(dvp); 13197c478bd9Sstevel@tonic-gate /* 13207c478bd9Sstevel@tonic-gate * The following clause was added to handle a problem 13217c478bd9Sstevel@tonic-gate * with NFS consistency. It is possible that a lookup 13227c478bd9Sstevel@tonic-gate * of the file to be created succeeded, but the file 13237c478bd9Sstevel@tonic-gate * itself doesn't actually exist on the server. This 13247c478bd9Sstevel@tonic-gate * is chiefly due to the DNLC containing an entry for 13257c478bd9Sstevel@tonic-gate * the file which has been removed on the server. In 13267c478bd9Sstevel@tonic-gate * this case, we just start over. If there was some 13277c478bd9Sstevel@tonic-gate * other cause for the ESTALE error, then the lookup 13287c478bd9Sstevel@tonic-gate * of the file will fail and the error will be returned 13297c478bd9Sstevel@tonic-gate * above instead of looping around from here. 13307c478bd9Sstevel@tonic-gate */ 1331dd29fa4aSprabahar if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) 13327c478bd9Sstevel@tonic-gate goto top; 13337c478bd9Sstevel@tonic-gate return (error); 13347c478bd9Sstevel@tonic-gate } 13357c478bd9Sstevel@tonic-gate 13367c478bd9Sstevel@tonic-gate int 13377c478bd9Sstevel@tonic-gate vn_link(char *from, char *to, enum uio_seg seg) 13387c478bd9Sstevel@tonic-gate { 13397c478bd9Sstevel@tonic-gate struct vnode *fvp; /* from vnode ptr */ 13407c478bd9Sstevel@tonic-gate struct vnode *tdvp; /* to directory vnode ptr */ 13417c478bd9Sstevel@tonic-gate struct pathname pn; 13427c478bd9Sstevel@tonic-gate int error; 13437c478bd9Sstevel@tonic-gate struct vattr vattr; 13447c478bd9Sstevel@tonic-gate dev_t fsid; 1345dd29fa4aSprabahar int estale_retry = 0; 13467c478bd9Sstevel@tonic-gate 13477c478bd9Sstevel@tonic-gate top: 13487c478bd9Sstevel@tonic-gate fvp = tdvp = NULL; 13497c478bd9Sstevel@tonic-gate if (error = pn_get(to, seg, &pn)) 13507c478bd9Sstevel@tonic-gate return (error); 13517c478bd9Sstevel@tonic-gate if (error = lookupname(from, seg, NO_FOLLOW, NULLVPP, &fvp)) 13527c478bd9Sstevel@tonic-gate goto out; 13537c478bd9Sstevel@tonic-gate if (error = lookuppn(&pn, NULL, NO_FOLLOW, &tdvp, NULLVPP)) 13547c478bd9Sstevel@tonic-gate goto out; 13557c478bd9Sstevel@tonic-gate /* 13567c478bd9Sstevel@tonic-gate * Make sure both source vnode and target directory vnode are 13577c478bd9Sstevel@tonic-gate * in the same vfs and that it is writeable. 13587c478bd9Sstevel@tonic-gate */ 13597c478bd9Sstevel@tonic-gate vattr.va_mask = AT_FSID; 13607c478bd9Sstevel@tonic-gate if (error = VOP_GETATTR(fvp, &vattr, 0, CRED())) 13617c478bd9Sstevel@tonic-gate goto out; 13627c478bd9Sstevel@tonic-gate fsid = vattr.va_fsid; 13637c478bd9Sstevel@tonic-gate vattr.va_mask = AT_FSID; 13647c478bd9Sstevel@tonic-gate if (error = VOP_GETATTR(tdvp, &vattr, 0, CRED())) 13657c478bd9Sstevel@tonic-gate goto out; 13667c478bd9Sstevel@tonic-gate if (fsid != vattr.va_fsid) { 13677c478bd9Sstevel@tonic-gate error = EXDEV; 13687c478bd9Sstevel@tonic-gate goto out; 13697c478bd9Sstevel@tonic-gate } 13707c478bd9Sstevel@tonic-gate if (tdvp->v_vfsp->vfs_flag & VFS_RDONLY) { 13717c478bd9Sstevel@tonic-gate error = EROFS; 13727c478bd9Sstevel@tonic-gate goto out; 13737c478bd9Sstevel@tonic-gate } 13747c478bd9Sstevel@tonic-gate /* 13757c478bd9Sstevel@tonic-gate * Do the link. 13767c478bd9Sstevel@tonic-gate */ 13777c478bd9Sstevel@tonic-gate (void) pn_fixslash(&pn); 13787c478bd9Sstevel@tonic-gate error = VOP_LINK(tdvp, fvp, pn.pn_path, CRED()); 13797c478bd9Sstevel@tonic-gate out: 13807c478bd9Sstevel@tonic-gate pn_free(&pn); 13817c478bd9Sstevel@tonic-gate if (fvp) 13827c478bd9Sstevel@tonic-gate VN_RELE(fvp); 13837c478bd9Sstevel@tonic-gate if (tdvp) 13847c478bd9Sstevel@tonic-gate VN_RELE(tdvp); 1385dd29fa4aSprabahar if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) 13867c478bd9Sstevel@tonic-gate goto top; 13877c478bd9Sstevel@tonic-gate return (error); 13887c478bd9Sstevel@tonic-gate } 13897c478bd9Sstevel@tonic-gate 13907c478bd9Sstevel@tonic-gate int 13917c478bd9Sstevel@tonic-gate vn_rename(char *from, char *to, enum uio_seg seg) 13927c478bd9Sstevel@tonic-gate { 13937c478bd9Sstevel@tonic-gate return (vn_renameat(NULL, from, NULL, to, seg)); 13947c478bd9Sstevel@tonic-gate } 13957c478bd9Sstevel@tonic-gate 13967c478bd9Sstevel@tonic-gate int 13977c478bd9Sstevel@tonic-gate vn_renameat(vnode_t *fdvp, char *fname, vnode_t *tdvp, 13987c478bd9Sstevel@tonic-gate char *tname, enum uio_seg seg) 13997c478bd9Sstevel@tonic-gate { 14007c478bd9Sstevel@tonic-gate int error; 14017c478bd9Sstevel@tonic-gate struct vattr vattr; 14027c478bd9Sstevel@tonic-gate struct pathname fpn; /* from pathname */ 14037c478bd9Sstevel@tonic-gate struct pathname tpn; /* to pathname */ 14047c478bd9Sstevel@tonic-gate dev_t fsid; 14057c478bd9Sstevel@tonic-gate int in_crit = 0; 14067c478bd9Sstevel@tonic-gate vnode_t *fromvp, *fvp; 14077c478bd9Sstevel@tonic-gate vnode_t *tovp; 1408dd29fa4aSprabahar int estale_retry = 0; 14097c478bd9Sstevel@tonic-gate 14107c478bd9Sstevel@tonic-gate top: 14117c478bd9Sstevel@tonic-gate fvp = fromvp = tovp = NULL; 14127c478bd9Sstevel@tonic-gate /* 14137c478bd9Sstevel@tonic-gate * Get to and from pathnames. 14147c478bd9Sstevel@tonic-gate */ 14157c478bd9Sstevel@tonic-gate if (error = pn_get(fname, seg, &fpn)) 14167c478bd9Sstevel@tonic-gate return (error); 14177c478bd9Sstevel@tonic-gate if (error = pn_get(tname, seg, &tpn)) { 14187c478bd9Sstevel@tonic-gate pn_free(&fpn); 14197c478bd9Sstevel@tonic-gate return (error); 14207c478bd9Sstevel@tonic-gate } 14217c478bd9Sstevel@tonic-gate 14227c478bd9Sstevel@tonic-gate /* 14237c478bd9Sstevel@tonic-gate * First we need to resolve the correct directories 14247c478bd9Sstevel@tonic-gate * The passed in directories may only be a starting point, 14257c478bd9Sstevel@tonic-gate * but we need the real directories the file(s) live in. 14267c478bd9Sstevel@tonic-gate * For example the fname may be something like usr/lib/sparc 14277c478bd9Sstevel@tonic-gate * and we were passed in the / directory, but we need to 14287c478bd9Sstevel@tonic-gate * use the lib directory for the rename. 14297c478bd9Sstevel@tonic-gate */ 14307c478bd9Sstevel@tonic-gate 14317c478bd9Sstevel@tonic-gate #ifdef C2_AUDIT 14327c478bd9Sstevel@tonic-gate if (audit_active) 14337c478bd9Sstevel@tonic-gate audit_setfsat_path(1); 14347c478bd9Sstevel@tonic-gate #endif /* C2_AUDIT */ 14357c478bd9Sstevel@tonic-gate /* 14367c478bd9Sstevel@tonic-gate * Lookup to and from directories. 14377c478bd9Sstevel@tonic-gate */ 14387c478bd9Sstevel@tonic-gate if (error = lookuppnat(&fpn, NULL, NO_FOLLOW, &fromvp, &fvp, fdvp)) { 14397c478bd9Sstevel@tonic-gate goto out; 14407c478bd9Sstevel@tonic-gate } 14417c478bd9Sstevel@tonic-gate 14427c478bd9Sstevel@tonic-gate /* 14437c478bd9Sstevel@tonic-gate * Make sure there is an entry. 14447c478bd9Sstevel@tonic-gate */ 14457c478bd9Sstevel@tonic-gate if (fvp == NULL) { 14467c478bd9Sstevel@tonic-gate error = ENOENT; 14477c478bd9Sstevel@tonic-gate goto out; 14487c478bd9Sstevel@tonic-gate } 14497c478bd9Sstevel@tonic-gate 14507c478bd9Sstevel@tonic-gate #ifdef C2_AUDIT 14517c478bd9Sstevel@tonic-gate if (audit_active) 14527c478bd9Sstevel@tonic-gate audit_setfsat_path(3); 14537c478bd9Sstevel@tonic-gate #endif /* C2_AUDIT */ 14547c478bd9Sstevel@tonic-gate if (error = lookuppnat(&tpn, NULL, NO_FOLLOW, &tovp, NULLVPP, tdvp)) { 14557c478bd9Sstevel@tonic-gate goto out; 14567c478bd9Sstevel@tonic-gate } 14577c478bd9Sstevel@tonic-gate 14587c478bd9Sstevel@tonic-gate /* 14597c478bd9Sstevel@tonic-gate * Make sure both the from vnode directory and the to directory 14607c478bd9Sstevel@tonic-gate * are in the same vfs and the to directory is writable. 14617c478bd9Sstevel@tonic-gate * We check fsid's, not vfs pointers, so loopback fs works. 14627c478bd9Sstevel@tonic-gate */ 14637c478bd9Sstevel@tonic-gate if (fromvp != tovp) { 14647c478bd9Sstevel@tonic-gate vattr.va_mask = AT_FSID; 14657c478bd9Sstevel@tonic-gate if (error = VOP_GETATTR(fromvp, &vattr, 0, CRED())) 14667c478bd9Sstevel@tonic-gate goto out; 14677c478bd9Sstevel@tonic-gate fsid = vattr.va_fsid; 14687c478bd9Sstevel@tonic-gate vattr.va_mask = AT_FSID; 14697c478bd9Sstevel@tonic-gate if (error = VOP_GETATTR(tovp, &vattr, 0, CRED())) 14707c478bd9Sstevel@tonic-gate goto out; 14717c478bd9Sstevel@tonic-gate if (fsid != vattr.va_fsid) { 14727c478bd9Sstevel@tonic-gate error = EXDEV; 14737c478bd9Sstevel@tonic-gate goto out; 14747c478bd9Sstevel@tonic-gate } 14757c478bd9Sstevel@tonic-gate } 14767c478bd9Sstevel@tonic-gate 14777c478bd9Sstevel@tonic-gate if (tovp->v_vfsp->vfs_flag & VFS_RDONLY) { 14787c478bd9Sstevel@tonic-gate error = EROFS; 14797c478bd9Sstevel@tonic-gate goto out; 14807c478bd9Sstevel@tonic-gate } 14817c478bd9Sstevel@tonic-gate 14827c478bd9Sstevel@tonic-gate if (nbl_need_check(fvp)) { 14837c478bd9Sstevel@tonic-gate nbl_start_crit(fvp, RW_READER); 14847c478bd9Sstevel@tonic-gate in_crit = 1; 14857c478bd9Sstevel@tonic-gate if (nbl_conflict(fvp, NBL_RENAME, 0, 0, 0)) { 14867c478bd9Sstevel@tonic-gate error = EACCES; 14877c478bd9Sstevel@tonic-gate goto out; 14887c478bd9Sstevel@tonic-gate } 14897c478bd9Sstevel@tonic-gate } 14907c478bd9Sstevel@tonic-gate 14917c478bd9Sstevel@tonic-gate /* 14927c478bd9Sstevel@tonic-gate * Do the rename. 14937c478bd9Sstevel@tonic-gate */ 14947c478bd9Sstevel@tonic-gate (void) pn_fixslash(&tpn); 14957c478bd9Sstevel@tonic-gate error = VOP_RENAME(fromvp, fpn.pn_path, tovp, tpn.pn_path, CRED()); 14967c478bd9Sstevel@tonic-gate 14977c478bd9Sstevel@tonic-gate out: 14987c478bd9Sstevel@tonic-gate pn_free(&fpn); 14997c478bd9Sstevel@tonic-gate pn_free(&tpn); 15007c478bd9Sstevel@tonic-gate if (in_crit) { 15017c478bd9Sstevel@tonic-gate nbl_end_crit(fvp); 15027c478bd9Sstevel@tonic-gate in_crit = 0; 15037c478bd9Sstevel@tonic-gate } 15047c478bd9Sstevel@tonic-gate if (fromvp) 15057c478bd9Sstevel@tonic-gate VN_RELE(fromvp); 15067c478bd9Sstevel@tonic-gate if (tovp) 15077c478bd9Sstevel@tonic-gate VN_RELE(tovp); 15087c478bd9Sstevel@tonic-gate if (fvp) 15097c478bd9Sstevel@tonic-gate VN_RELE(fvp); 1510dd29fa4aSprabahar if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) 15117c478bd9Sstevel@tonic-gate goto top; 15127c478bd9Sstevel@tonic-gate return (error); 15137c478bd9Sstevel@tonic-gate } 15147c478bd9Sstevel@tonic-gate 15157c478bd9Sstevel@tonic-gate /* 15167c478bd9Sstevel@tonic-gate * Remove a file or directory. 15177c478bd9Sstevel@tonic-gate */ 15187c478bd9Sstevel@tonic-gate int 15197c478bd9Sstevel@tonic-gate vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag) 15207c478bd9Sstevel@tonic-gate { 15217c478bd9Sstevel@tonic-gate return (vn_removeat(NULL, fnamep, seg, dirflag)); 15227c478bd9Sstevel@tonic-gate } 15237c478bd9Sstevel@tonic-gate 15247c478bd9Sstevel@tonic-gate int 15257c478bd9Sstevel@tonic-gate vn_removeat(vnode_t *startvp, char *fnamep, enum uio_seg seg, enum rm dirflag) 15267c478bd9Sstevel@tonic-gate { 15277c478bd9Sstevel@tonic-gate struct vnode *vp; /* entry vnode */ 15287c478bd9Sstevel@tonic-gate struct vnode *dvp; /* ptr to parent dir vnode */ 15297c478bd9Sstevel@tonic-gate struct vnode *coveredvp; 15307c478bd9Sstevel@tonic-gate struct pathname pn; /* name of entry */ 15317c478bd9Sstevel@tonic-gate enum vtype vtype; 15327c478bd9Sstevel@tonic-gate int error; 15337c478bd9Sstevel@tonic-gate struct vfs *vfsp; 15347c478bd9Sstevel@tonic-gate struct vfs *dvfsp; /* ptr to parent dir vfs */ 15357c478bd9Sstevel@tonic-gate int in_crit = 0; 1536dd29fa4aSprabahar int estale_retry = 0; 15377c478bd9Sstevel@tonic-gate 15387c478bd9Sstevel@tonic-gate top: 15397c478bd9Sstevel@tonic-gate if (error = pn_get(fnamep, seg, &pn)) 15407c478bd9Sstevel@tonic-gate return (error); 15417c478bd9Sstevel@tonic-gate dvp = vp = NULL; 15427c478bd9Sstevel@tonic-gate if (error = lookuppnat(&pn, NULL, NO_FOLLOW, &dvp, &vp, startvp)) { 15437c478bd9Sstevel@tonic-gate pn_free(&pn); 1544dd29fa4aSprabahar if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) 15457c478bd9Sstevel@tonic-gate goto top; 15467c478bd9Sstevel@tonic-gate return (error); 15477c478bd9Sstevel@tonic-gate } 15487c478bd9Sstevel@tonic-gate 15497c478bd9Sstevel@tonic-gate /* 15507c478bd9Sstevel@tonic-gate * Make sure there is an entry. 15517c478bd9Sstevel@tonic-gate */ 15527c478bd9Sstevel@tonic-gate if (vp == NULL) { 15537c478bd9Sstevel@tonic-gate error = ENOENT; 15547c478bd9Sstevel@tonic-gate goto out; 15557c478bd9Sstevel@tonic-gate } 15567c478bd9Sstevel@tonic-gate 15577c478bd9Sstevel@tonic-gate vfsp = vp->v_vfsp; 15587c478bd9Sstevel@tonic-gate dvfsp = dvp->v_vfsp; 15597c478bd9Sstevel@tonic-gate 15607c478bd9Sstevel@tonic-gate /* 15617c478bd9Sstevel@tonic-gate * If the named file is the root of a mounted filesystem, fail, 15627c478bd9Sstevel@tonic-gate * unless it's marked unlinkable. In that case, unmount the 15637c478bd9Sstevel@tonic-gate * filesystem and proceed to unlink the covered vnode. (If the 15647c478bd9Sstevel@tonic-gate * covered vnode is a directory, use rmdir instead of unlink, 15657c478bd9Sstevel@tonic-gate * to avoid file system corruption.) 15667c478bd9Sstevel@tonic-gate */ 15677c478bd9Sstevel@tonic-gate if (vp->v_flag & VROOT) { 15687c478bd9Sstevel@tonic-gate if (vfsp->vfs_flag & VFS_UNLINKABLE) { 15697c478bd9Sstevel@tonic-gate if (dirflag == RMDIRECTORY) { 15707c478bd9Sstevel@tonic-gate /* 15717c478bd9Sstevel@tonic-gate * User called rmdir(2) on a file that has 15727c478bd9Sstevel@tonic-gate * been namefs mounted on top of. Since 15737c478bd9Sstevel@tonic-gate * namefs doesn't allow directories to 15747c478bd9Sstevel@tonic-gate * be mounted on other files we know 15757c478bd9Sstevel@tonic-gate * vp is not of type VDIR so fail to operation. 15767c478bd9Sstevel@tonic-gate */ 15777c478bd9Sstevel@tonic-gate error = ENOTDIR; 15787c478bd9Sstevel@tonic-gate goto out; 15797c478bd9Sstevel@tonic-gate } 15807c478bd9Sstevel@tonic-gate coveredvp = vfsp->vfs_vnodecovered; 15817c478bd9Sstevel@tonic-gate VN_HOLD(coveredvp); 15827c478bd9Sstevel@tonic-gate VN_RELE(vp); 15837c478bd9Sstevel@tonic-gate vp = NULL; 15847c478bd9Sstevel@tonic-gate if ((error = vn_vfswlock(coveredvp)) == 0) 15857c478bd9Sstevel@tonic-gate error = dounmount(vfsp, 0, CRED()); 15867c478bd9Sstevel@tonic-gate /* 15877c478bd9Sstevel@tonic-gate * Unmounted the namefs file system; now get 15887c478bd9Sstevel@tonic-gate * the object it was mounted over. 15897c478bd9Sstevel@tonic-gate */ 15907c478bd9Sstevel@tonic-gate vp = coveredvp; 15917c478bd9Sstevel@tonic-gate /* 15927c478bd9Sstevel@tonic-gate * If namefs was mounted over a directory, then 15937c478bd9Sstevel@tonic-gate * we want to use rmdir() instead of unlink(). 15947c478bd9Sstevel@tonic-gate */ 15957c478bd9Sstevel@tonic-gate if (vp->v_type == VDIR) 15967c478bd9Sstevel@tonic-gate dirflag = RMDIRECTORY; 15977c478bd9Sstevel@tonic-gate } else 15987c478bd9Sstevel@tonic-gate error = EBUSY; 15997c478bd9Sstevel@tonic-gate 16007c478bd9Sstevel@tonic-gate if (error) 16017c478bd9Sstevel@tonic-gate goto out; 16027c478bd9Sstevel@tonic-gate } 16037c478bd9Sstevel@tonic-gate 16047c478bd9Sstevel@tonic-gate /* 16057c478bd9Sstevel@tonic-gate * Make sure filesystem is writeable. 16067c478bd9Sstevel@tonic-gate * We check the parent directory's vfs in case this is an lofs vnode. 16077c478bd9Sstevel@tonic-gate */ 16087c478bd9Sstevel@tonic-gate if (dvfsp && dvfsp->vfs_flag & VFS_RDONLY) { 16097c478bd9Sstevel@tonic-gate error = EROFS; 16107c478bd9Sstevel@tonic-gate goto out; 16117c478bd9Sstevel@tonic-gate } 16127c478bd9Sstevel@tonic-gate 16137c478bd9Sstevel@tonic-gate vtype = vp->v_type; 16147c478bd9Sstevel@tonic-gate 16157c478bd9Sstevel@tonic-gate /* 16167c478bd9Sstevel@tonic-gate * If there is the possibility of an nbmand share reservation, make 16177c478bd9Sstevel@tonic-gate * sure it's okay to remove the file. Keep a reference to the 16187c478bd9Sstevel@tonic-gate * vnode, so that we can exit the nbl critical region after 16197c478bd9Sstevel@tonic-gate * calling VOP_REMOVE. 16207c478bd9Sstevel@tonic-gate * If there is no possibility of an nbmand share reservation, 16217c478bd9Sstevel@tonic-gate * release the vnode reference now. Filesystems like NFS may 16227c478bd9Sstevel@tonic-gate * behave differently if there is an extra reference, so get rid of 16237c478bd9Sstevel@tonic-gate * this one. Fortunately, we can't have nbmand mounts on NFS 16247c478bd9Sstevel@tonic-gate * filesystems. 16257c478bd9Sstevel@tonic-gate */ 16267c478bd9Sstevel@tonic-gate if (nbl_need_check(vp)) { 16277c478bd9Sstevel@tonic-gate nbl_start_crit(vp, RW_READER); 16287c478bd9Sstevel@tonic-gate in_crit = 1; 16297c478bd9Sstevel@tonic-gate if (nbl_conflict(vp, NBL_REMOVE, 0, 0, 0)) { 16307c478bd9Sstevel@tonic-gate error = EACCES; 16317c478bd9Sstevel@tonic-gate goto out; 16327c478bd9Sstevel@tonic-gate } 16337c478bd9Sstevel@tonic-gate } else { 16347c478bd9Sstevel@tonic-gate VN_RELE(vp); 16357c478bd9Sstevel@tonic-gate vp = NULL; 16367c478bd9Sstevel@tonic-gate } 16377c478bd9Sstevel@tonic-gate 16387c478bd9Sstevel@tonic-gate if (dirflag == RMDIRECTORY) { 16397c478bd9Sstevel@tonic-gate /* 16407c478bd9Sstevel@tonic-gate * Caller is using rmdir(2), which can only be applied to 16417c478bd9Sstevel@tonic-gate * directories. 16427c478bd9Sstevel@tonic-gate */ 16437c478bd9Sstevel@tonic-gate if (vtype != VDIR) { 16447c478bd9Sstevel@tonic-gate error = ENOTDIR; 16457c478bd9Sstevel@tonic-gate } else { 16467c478bd9Sstevel@tonic-gate vnode_t *cwd; 16477c478bd9Sstevel@tonic-gate proc_t *pp = curproc; 16487c478bd9Sstevel@tonic-gate 16497c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_lock); 16507c478bd9Sstevel@tonic-gate cwd = PTOU(pp)->u_cdir; 16517c478bd9Sstevel@tonic-gate VN_HOLD(cwd); 16527c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_lock); 16537c478bd9Sstevel@tonic-gate error = VOP_RMDIR(dvp, pn.pn_path, cwd, CRED()); 16547c478bd9Sstevel@tonic-gate VN_RELE(cwd); 16557c478bd9Sstevel@tonic-gate } 16567c478bd9Sstevel@tonic-gate } else { 16577c478bd9Sstevel@tonic-gate /* 16587c478bd9Sstevel@tonic-gate * Unlink(2) can be applied to anything. 16597c478bd9Sstevel@tonic-gate */ 16607c478bd9Sstevel@tonic-gate error = VOP_REMOVE(dvp, pn.pn_path, CRED()); 16617c478bd9Sstevel@tonic-gate } 16627c478bd9Sstevel@tonic-gate 16637c478bd9Sstevel@tonic-gate out: 16647c478bd9Sstevel@tonic-gate pn_free(&pn); 16657c478bd9Sstevel@tonic-gate if (in_crit) { 16667c478bd9Sstevel@tonic-gate nbl_end_crit(vp); 16677c478bd9Sstevel@tonic-gate in_crit = 0; 16687c478bd9Sstevel@tonic-gate } 16697c478bd9Sstevel@tonic-gate if (vp != NULL) 16707c478bd9Sstevel@tonic-gate VN_RELE(vp); 16717c478bd9Sstevel@tonic-gate if (dvp != NULL) 16727c478bd9Sstevel@tonic-gate VN_RELE(dvp); 1673dd29fa4aSprabahar if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) 16747c478bd9Sstevel@tonic-gate goto top; 16757c478bd9Sstevel@tonic-gate return (error); 16767c478bd9Sstevel@tonic-gate } 16777c478bd9Sstevel@tonic-gate 16787c478bd9Sstevel@tonic-gate /* 16797c478bd9Sstevel@tonic-gate * Utility function to compare equality of vnodes. 16807c478bd9Sstevel@tonic-gate * Compare the underlying real vnodes, if there are underlying vnodes. 16817c478bd9Sstevel@tonic-gate * This is a more thorough comparison than the VN_CMP() macro provides. 16827c478bd9Sstevel@tonic-gate */ 16837c478bd9Sstevel@tonic-gate int 16847c478bd9Sstevel@tonic-gate vn_compare(vnode_t *vp1, vnode_t *vp2) 16857c478bd9Sstevel@tonic-gate { 16867c478bd9Sstevel@tonic-gate vnode_t *realvp; 16877c478bd9Sstevel@tonic-gate 16887c478bd9Sstevel@tonic-gate if (vp1 != NULL && VOP_REALVP(vp1, &realvp) == 0) 16897c478bd9Sstevel@tonic-gate vp1 = realvp; 16907c478bd9Sstevel@tonic-gate if (vp2 != NULL && VOP_REALVP(vp2, &realvp) == 0) 16917c478bd9Sstevel@tonic-gate vp2 = realvp; 16927c478bd9Sstevel@tonic-gate return (VN_CMP(vp1, vp2)); 16937c478bd9Sstevel@tonic-gate } 16947c478bd9Sstevel@tonic-gate 16957c478bd9Sstevel@tonic-gate /* 16967c478bd9Sstevel@tonic-gate * The number of locks to hash into. This value must be a power 16977c478bd9Sstevel@tonic-gate * of 2 minus 1 and should probably also be prime. 16987c478bd9Sstevel@tonic-gate */ 16997c478bd9Sstevel@tonic-gate #define NUM_BUCKETS 1023 17007c478bd9Sstevel@tonic-gate 17017c478bd9Sstevel@tonic-gate struct vn_vfslocks_bucket { 17027c478bd9Sstevel@tonic-gate kmutex_t vb_lock; 17037c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vb_list; 17047c478bd9Sstevel@tonic-gate char pad[64 - sizeof (kmutex_t) - sizeof (void *)]; 17057c478bd9Sstevel@tonic-gate }; 17067c478bd9Sstevel@tonic-gate 17077c478bd9Sstevel@tonic-gate /* 17087c478bd9Sstevel@tonic-gate * Total number of buckets will be NUM_BUCKETS + 1 . 17097c478bd9Sstevel@tonic-gate */ 17107c478bd9Sstevel@tonic-gate 17117c478bd9Sstevel@tonic-gate #pragma align 64(vn_vfslocks_buckets) 17127c478bd9Sstevel@tonic-gate static struct vn_vfslocks_bucket vn_vfslocks_buckets[NUM_BUCKETS + 1]; 17137c478bd9Sstevel@tonic-gate 17147c478bd9Sstevel@tonic-gate #define VN_VFSLOCKS_SHIFT 9 17157c478bd9Sstevel@tonic-gate 17167c478bd9Sstevel@tonic-gate #define VN_VFSLOCKS_HASH(vfsvpptr) \ 17177c478bd9Sstevel@tonic-gate ((((intptr_t)(vfsvpptr)) >> VN_VFSLOCKS_SHIFT) & NUM_BUCKETS) 17187c478bd9Sstevel@tonic-gate 17197c478bd9Sstevel@tonic-gate /* 17207c478bd9Sstevel@tonic-gate * vn_vfslocks_getlock() uses an HASH scheme to generate 17217c478bd9Sstevel@tonic-gate * rwstlock using vfs/vnode pointer passed to it. 17227c478bd9Sstevel@tonic-gate * 17237c478bd9Sstevel@tonic-gate * vn_vfslocks_rele() releases a reference in the 17247c478bd9Sstevel@tonic-gate * HASH table which allows the entry allocated by 17257c478bd9Sstevel@tonic-gate * vn_vfslocks_getlock() to be freed at a later 17267c478bd9Sstevel@tonic-gate * stage when the refcount drops to zero. 17277c478bd9Sstevel@tonic-gate */ 17287c478bd9Sstevel@tonic-gate 17297c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t * 17307c478bd9Sstevel@tonic-gate vn_vfslocks_getlock(void *vfsvpptr) 17317c478bd9Sstevel@tonic-gate { 17327c478bd9Sstevel@tonic-gate struct vn_vfslocks_bucket *bp; 17337c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vep; 17347c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *tvep; 17357c478bd9Sstevel@tonic-gate 17367c478bd9Sstevel@tonic-gate ASSERT(vfsvpptr != NULL); 17377c478bd9Sstevel@tonic-gate bp = &vn_vfslocks_buckets[VN_VFSLOCKS_HASH(vfsvpptr)]; 17387c478bd9Sstevel@tonic-gate 17397c478bd9Sstevel@tonic-gate mutex_enter(&bp->vb_lock); 17407c478bd9Sstevel@tonic-gate for (vep = bp->vb_list; vep != NULL; vep = vep->ve_next) { 17417c478bd9Sstevel@tonic-gate if (vep->ve_vpvfs == vfsvpptr) { 17427c478bd9Sstevel@tonic-gate vep->ve_refcnt++; 17437c478bd9Sstevel@tonic-gate mutex_exit(&bp->vb_lock); 17447c478bd9Sstevel@tonic-gate return (vep); 17457c478bd9Sstevel@tonic-gate } 17467c478bd9Sstevel@tonic-gate } 17477c478bd9Sstevel@tonic-gate mutex_exit(&bp->vb_lock); 17487c478bd9Sstevel@tonic-gate vep = kmem_alloc(sizeof (*vep), KM_SLEEP); 17497c478bd9Sstevel@tonic-gate rwst_init(&vep->ve_lock, NULL, RW_DEFAULT, NULL); 17507c478bd9Sstevel@tonic-gate vep->ve_vpvfs = (char *)vfsvpptr; 17517c478bd9Sstevel@tonic-gate vep->ve_refcnt = 1; 17527c478bd9Sstevel@tonic-gate mutex_enter(&bp->vb_lock); 17537c478bd9Sstevel@tonic-gate for (tvep = bp->vb_list; tvep != NULL; tvep = tvep->ve_next) { 17547c478bd9Sstevel@tonic-gate if (tvep->ve_vpvfs == vfsvpptr) { 17557c478bd9Sstevel@tonic-gate tvep->ve_refcnt++; 17567c478bd9Sstevel@tonic-gate mutex_exit(&bp->vb_lock); 17577c478bd9Sstevel@tonic-gate 17587c478bd9Sstevel@tonic-gate /* 17597c478bd9Sstevel@tonic-gate * There is already an entry in the hash 17607c478bd9Sstevel@tonic-gate * destroy what we just allocated. 17617c478bd9Sstevel@tonic-gate */ 17627c478bd9Sstevel@tonic-gate rwst_destroy(&vep->ve_lock); 17637c478bd9Sstevel@tonic-gate kmem_free(vep, sizeof (*vep)); 17647c478bd9Sstevel@tonic-gate return (tvep); 17657c478bd9Sstevel@tonic-gate } 17667c478bd9Sstevel@tonic-gate } 17677c478bd9Sstevel@tonic-gate vep->ve_next = bp->vb_list; 17687c478bd9Sstevel@tonic-gate bp->vb_list = vep; 17697c478bd9Sstevel@tonic-gate mutex_exit(&bp->vb_lock); 17707c478bd9Sstevel@tonic-gate return (vep); 17717c478bd9Sstevel@tonic-gate } 17727c478bd9Sstevel@tonic-gate 17737c478bd9Sstevel@tonic-gate void 17747c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vn_vfslocks_entry_t *vepent) 17757c478bd9Sstevel@tonic-gate { 17767c478bd9Sstevel@tonic-gate struct vn_vfslocks_bucket *bp; 17777c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vep; 17787c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *pvep; 17797c478bd9Sstevel@tonic-gate 17807c478bd9Sstevel@tonic-gate ASSERT(vepent != NULL); 17817c478bd9Sstevel@tonic-gate ASSERT(vepent->ve_vpvfs != NULL); 17827c478bd9Sstevel@tonic-gate 17837c478bd9Sstevel@tonic-gate bp = &vn_vfslocks_buckets[VN_VFSLOCKS_HASH(vepent->ve_vpvfs)]; 17847c478bd9Sstevel@tonic-gate 17857c478bd9Sstevel@tonic-gate mutex_enter(&bp->vb_lock); 17867c478bd9Sstevel@tonic-gate vepent->ve_refcnt--; 17877c478bd9Sstevel@tonic-gate 17887c478bd9Sstevel@tonic-gate if ((int32_t)vepent->ve_refcnt < 0) 17897c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "vn_vfslocks_rele: refcount negative"); 17907c478bd9Sstevel@tonic-gate 17917c478bd9Sstevel@tonic-gate if (vepent->ve_refcnt == 0) { 17927c478bd9Sstevel@tonic-gate for (vep = bp->vb_list; vep != NULL; vep = vep->ve_next) { 17937c478bd9Sstevel@tonic-gate if (vep->ve_vpvfs == vepent->ve_vpvfs) { 17947c478bd9Sstevel@tonic-gate if (bp->vb_list == vep) 17957c478bd9Sstevel@tonic-gate bp->vb_list = vep->ve_next; 17967c478bd9Sstevel@tonic-gate else { 17977c478bd9Sstevel@tonic-gate /* LINTED */ 17987c478bd9Sstevel@tonic-gate pvep->ve_next = vep->ve_next; 17997c478bd9Sstevel@tonic-gate } 18007c478bd9Sstevel@tonic-gate mutex_exit(&bp->vb_lock); 18017c478bd9Sstevel@tonic-gate rwst_destroy(&vep->ve_lock); 18027c478bd9Sstevel@tonic-gate kmem_free(vep, sizeof (*vep)); 18037c478bd9Sstevel@tonic-gate return; 18047c478bd9Sstevel@tonic-gate } 18057c478bd9Sstevel@tonic-gate pvep = vep; 18067c478bd9Sstevel@tonic-gate } 18077c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "vn_vfslocks_rele: vp/vfs not found"); 18087c478bd9Sstevel@tonic-gate } 18097c478bd9Sstevel@tonic-gate mutex_exit(&bp->vb_lock); 18107c478bd9Sstevel@tonic-gate } 18117c478bd9Sstevel@tonic-gate 18127c478bd9Sstevel@tonic-gate /* 18137c478bd9Sstevel@tonic-gate * vn_vfswlock_wait is used to implement a lock which is logically a writers 18147c478bd9Sstevel@tonic-gate * lock protecting the v_vfsmountedhere field. 18157c478bd9Sstevel@tonic-gate * vn_vfswlock_wait has been modified to be similar to vn_vfswlock, 18167c478bd9Sstevel@tonic-gate * except that it blocks to acquire the lock VVFSLOCK. 18177c478bd9Sstevel@tonic-gate * 18187c478bd9Sstevel@tonic-gate * traverse() and routines re-implementing part of traverse (e.g. autofs) 18197c478bd9Sstevel@tonic-gate * need to hold this lock. mount(), vn_rename(), vn_remove() and so on 18207c478bd9Sstevel@tonic-gate * need the non-blocking version of the writers lock i.e. vn_vfswlock 18217c478bd9Sstevel@tonic-gate */ 18227c478bd9Sstevel@tonic-gate int 18237c478bd9Sstevel@tonic-gate vn_vfswlock_wait(vnode_t *vp) 18247c478bd9Sstevel@tonic-gate { 18257c478bd9Sstevel@tonic-gate int retval; 18267c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vpvfsentry; 18277c478bd9Sstevel@tonic-gate ASSERT(vp != NULL); 18287c478bd9Sstevel@tonic-gate 18297c478bd9Sstevel@tonic-gate vpvfsentry = vn_vfslocks_getlock(vp); 18307c478bd9Sstevel@tonic-gate retval = rwst_enter_sig(&vpvfsentry->ve_lock, RW_WRITER); 18317c478bd9Sstevel@tonic-gate 18327c478bd9Sstevel@tonic-gate if (retval == EINTR) { 18337c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vpvfsentry); 18347c478bd9Sstevel@tonic-gate return (EINTR); 18357c478bd9Sstevel@tonic-gate } 18367c478bd9Sstevel@tonic-gate return (retval); 18377c478bd9Sstevel@tonic-gate } 18387c478bd9Sstevel@tonic-gate 18397c478bd9Sstevel@tonic-gate int 18407c478bd9Sstevel@tonic-gate vn_vfsrlock_wait(vnode_t *vp) 18417c478bd9Sstevel@tonic-gate { 18427c478bd9Sstevel@tonic-gate int retval; 18437c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vpvfsentry; 18447c478bd9Sstevel@tonic-gate ASSERT(vp != NULL); 18457c478bd9Sstevel@tonic-gate 18467c478bd9Sstevel@tonic-gate vpvfsentry = vn_vfslocks_getlock(vp); 18477c478bd9Sstevel@tonic-gate retval = rwst_enter_sig(&vpvfsentry->ve_lock, RW_READER); 18487c478bd9Sstevel@tonic-gate 18497c478bd9Sstevel@tonic-gate if (retval == EINTR) { 18507c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vpvfsentry); 18517c478bd9Sstevel@tonic-gate return (EINTR); 18527c478bd9Sstevel@tonic-gate } 18537c478bd9Sstevel@tonic-gate 18547c478bd9Sstevel@tonic-gate return (retval); 18557c478bd9Sstevel@tonic-gate } 18567c478bd9Sstevel@tonic-gate 18577c478bd9Sstevel@tonic-gate 18587c478bd9Sstevel@tonic-gate /* 18597c478bd9Sstevel@tonic-gate * vn_vfswlock is used to implement a lock which is logically a writers lock 18607c478bd9Sstevel@tonic-gate * protecting the v_vfsmountedhere field. 18617c478bd9Sstevel@tonic-gate */ 18627c478bd9Sstevel@tonic-gate int 18637c478bd9Sstevel@tonic-gate vn_vfswlock(vnode_t *vp) 18647c478bd9Sstevel@tonic-gate { 18657c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vpvfsentry; 18667c478bd9Sstevel@tonic-gate 18677c478bd9Sstevel@tonic-gate /* 18687c478bd9Sstevel@tonic-gate * If vp is NULL then somebody is trying to lock the covered vnode 18697c478bd9Sstevel@tonic-gate * of /. (vfs_vnodecovered is NULL for /). This situation will 18707c478bd9Sstevel@tonic-gate * only happen when unmounting /. Since that operation will fail 18717c478bd9Sstevel@tonic-gate * anyway, return EBUSY here instead of in VFS_UNMOUNT. 18727c478bd9Sstevel@tonic-gate */ 18737c478bd9Sstevel@tonic-gate if (vp == NULL) 18747c478bd9Sstevel@tonic-gate return (EBUSY); 18757c478bd9Sstevel@tonic-gate 18767c478bd9Sstevel@tonic-gate vpvfsentry = vn_vfslocks_getlock(vp); 18777c478bd9Sstevel@tonic-gate 18787c478bd9Sstevel@tonic-gate if (rwst_tryenter(&vpvfsentry->ve_lock, RW_WRITER)) 18797c478bd9Sstevel@tonic-gate return (0); 18807c478bd9Sstevel@tonic-gate 18817c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vpvfsentry); 18827c478bd9Sstevel@tonic-gate return (EBUSY); 18837c478bd9Sstevel@tonic-gate } 18847c478bd9Sstevel@tonic-gate 18857c478bd9Sstevel@tonic-gate int 18867c478bd9Sstevel@tonic-gate vn_vfsrlock(vnode_t *vp) 18877c478bd9Sstevel@tonic-gate { 18887c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vpvfsentry; 18897c478bd9Sstevel@tonic-gate 18907c478bd9Sstevel@tonic-gate /* 18917c478bd9Sstevel@tonic-gate * If vp is NULL then somebody is trying to lock the covered vnode 18927c478bd9Sstevel@tonic-gate * of /. (vfs_vnodecovered is NULL for /). This situation will 18937c478bd9Sstevel@tonic-gate * only happen when unmounting /. Since that operation will fail 18947c478bd9Sstevel@tonic-gate * anyway, return EBUSY here instead of in VFS_UNMOUNT. 18957c478bd9Sstevel@tonic-gate */ 18967c478bd9Sstevel@tonic-gate if (vp == NULL) 18977c478bd9Sstevel@tonic-gate return (EBUSY); 18987c478bd9Sstevel@tonic-gate 18997c478bd9Sstevel@tonic-gate vpvfsentry = vn_vfslocks_getlock(vp); 19007c478bd9Sstevel@tonic-gate 19017c478bd9Sstevel@tonic-gate if (rwst_tryenter(&vpvfsentry->ve_lock, RW_READER)) 19027c478bd9Sstevel@tonic-gate return (0); 19037c478bd9Sstevel@tonic-gate 19047c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vpvfsentry); 19057c478bd9Sstevel@tonic-gate return (EBUSY); 19067c478bd9Sstevel@tonic-gate } 19077c478bd9Sstevel@tonic-gate 19087c478bd9Sstevel@tonic-gate void 19097c478bd9Sstevel@tonic-gate vn_vfsunlock(vnode_t *vp) 19107c478bd9Sstevel@tonic-gate { 19117c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vpvfsentry; 19127c478bd9Sstevel@tonic-gate 19137c478bd9Sstevel@tonic-gate /* 19147c478bd9Sstevel@tonic-gate * ve_refcnt needs to be decremented twice. 19157c478bd9Sstevel@tonic-gate * 1. To release refernce after a call to vn_vfslocks_getlock() 19167c478bd9Sstevel@tonic-gate * 2. To release the reference from the locking routines like 19177c478bd9Sstevel@tonic-gate * vn_vfsrlock/vn_vfswlock etc,. 19187c478bd9Sstevel@tonic-gate */ 19197c478bd9Sstevel@tonic-gate vpvfsentry = vn_vfslocks_getlock(vp); 19207c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vpvfsentry); 19217c478bd9Sstevel@tonic-gate 19227c478bd9Sstevel@tonic-gate rwst_exit(&vpvfsentry->ve_lock); 19237c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vpvfsentry); 19247c478bd9Sstevel@tonic-gate } 19257c478bd9Sstevel@tonic-gate 19267c478bd9Sstevel@tonic-gate int 19277c478bd9Sstevel@tonic-gate vn_vfswlock_held(vnode_t *vp) 19287c478bd9Sstevel@tonic-gate { 19297c478bd9Sstevel@tonic-gate int held; 19307c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vpvfsentry; 19317c478bd9Sstevel@tonic-gate 19327c478bd9Sstevel@tonic-gate ASSERT(vp != NULL); 19337c478bd9Sstevel@tonic-gate 19347c478bd9Sstevel@tonic-gate vpvfsentry = vn_vfslocks_getlock(vp); 19357c478bd9Sstevel@tonic-gate held = rwst_lock_held(&vpvfsentry->ve_lock, RW_WRITER); 19367c478bd9Sstevel@tonic-gate 19377c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vpvfsentry); 19387c478bd9Sstevel@tonic-gate return (held); 19397c478bd9Sstevel@tonic-gate } 19407c478bd9Sstevel@tonic-gate 19417c478bd9Sstevel@tonic-gate 19427c478bd9Sstevel@tonic-gate int 19437c478bd9Sstevel@tonic-gate vn_make_ops( 19447c478bd9Sstevel@tonic-gate const char *name, /* Name of file system */ 19457c478bd9Sstevel@tonic-gate const fs_operation_def_t *templ, /* Operation specification */ 19467c478bd9Sstevel@tonic-gate vnodeops_t **actual) /* Return the vnodeops */ 19477c478bd9Sstevel@tonic-gate { 19487c478bd9Sstevel@tonic-gate int unused_ops; 19497c478bd9Sstevel@tonic-gate int error; 19507c478bd9Sstevel@tonic-gate 19517c478bd9Sstevel@tonic-gate *actual = (vnodeops_t *)kmem_alloc(sizeof (vnodeops_t), KM_SLEEP); 19527c478bd9Sstevel@tonic-gate 19537c478bd9Sstevel@tonic-gate (*actual)->vnop_name = name; 19547c478bd9Sstevel@tonic-gate 19557c478bd9Sstevel@tonic-gate error = fs_build_vector(*actual, &unused_ops, vn_ops_table, templ); 19567c478bd9Sstevel@tonic-gate if (error) { 19577c478bd9Sstevel@tonic-gate kmem_free(*actual, sizeof (vnodeops_t)); 19587c478bd9Sstevel@tonic-gate } 19597c478bd9Sstevel@tonic-gate 19607c478bd9Sstevel@tonic-gate #if DEBUG 19617c478bd9Sstevel@tonic-gate if (unused_ops != 0) 19627c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "vn_make_ops: %s: %d operations supplied " 19637c478bd9Sstevel@tonic-gate "but not used", name, unused_ops); 19647c478bd9Sstevel@tonic-gate #endif 19657c478bd9Sstevel@tonic-gate 19667c478bd9Sstevel@tonic-gate return (error); 19677c478bd9Sstevel@tonic-gate } 19687c478bd9Sstevel@tonic-gate 19697c478bd9Sstevel@tonic-gate /* 19707c478bd9Sstevel@tonic-gate * Free the vnodeops created as a result of vn_make_ops() 19717c478bd9Sstevel@tonic-gate */ 19727c478bd9Sstevel@tonic-gate void 19737c478bd9Sstevel@tonic-gate vn_freevnodeops(vnodeops_t *vnops) 19747c478bd9Sstevel@tonic-gate { 19757c478bd9Sstevel@tonic-gate kmem_free(vnops, sizeof (vnodeops_t)); 19767c478bd9Sstevel@tonic-gate } 19777c478bd9Sstevel@tonic-gate 19787c478bd9Sstevel@tonic-gate /* 19797c478bd9Sstevel@tonic-gate * Vnode cache. 19807c478bd9Sstevel@tonic-gate */ 19817c478bd9Sstevel@tonic-gate 19827c478bd9Sstevel@tonic-gate /* ARGSUSED */ 19837c478bd9Sstevel@tonic-gate static int 19847c478bd9Sstevel@tonic-gate vn_cache_constructor(void *buf, void *cdrarg, int kmflags) 19857c478bd9Sstevel@tonic-gate { 19867c478bd9Sstevel@tonic-gate struct vnode *vp; 19877c478bd9Sstevel@tonic-gate 19887c478bd9Sstevel@tonic-gate vp = buf; 19897c478bd9Sstevel@tonic-gate 19907c478bd9Sstevel@tonic-gate mutex_init(&vp->v_lock, NULL, MUTEX_DEFAULT, NULL); 19917c478bd9Sstevel@tonic-gate cv_init(&vp->v_cv, NULL, CV_DEFAULT, NULL); 19927c478bd9Sstevel@tonic-gate rw_init(&vp->v_nbllock, NULL, RW_DEFAULT, NULL); 19937c478bd9Sstevel@tonic-gate rw_init(&vp->v_mslock, NULL, RW_DEFAULT, NULL); 19947c478bd9Sstevel@tonic-gate vp->v_femhead = NULL; /* Must be done before vn_reinit() */ 19957c478bd9Sstevel@tonic-gate vp->v_path = NULL; 19967c478bd9Sstevel@tonic-gate vp->v_mpssdata = NULL; 1997*df2381bfSpraks vp->v_fopdata = NULL; 19987c478bd9Sstevel@tonic-gate 19997c478bd9Sstevel@tonic-gate return (0); 20007c478bd9Sstevel@tonic-gate } 20017c478bd9Sstevel@tonic-gate 20027c478bd9Sstevel@tonic-gate /* ARGSUSED */ 20037c478bd9Sstevel@tonic-gate static void 20047c478bd9Sstevel@tonic-gate vn_cache_destructor(void *buf, void *cdrarg) 20057c478bd9Sstevel@tonic-gate { 20067c478bd9Sstevel@tonic-gate struct vnode *vp; 20077c478bd9Sstevel@tonic-gate 20087c478bd9Sstevel@tonic-gate vp = buf; 20097c478bd9Sstevel@tonic-gate 20107c478bd9Sstevel@tonic-gate rw_destroy(&vp->v_mslock); 20117c478bd9Sstevel@tonic-gate rw_destroy(&vp->v_nbllock); 20127c478bd9Sstevel@tonic-gate cv_destroy(&vp->v_cv); 20137c478bd9Sstevel@tonic-gate mutex_destroy(&vp->v_lock); 20147c478bd9Sstevel@tonic-gate } 20157c478bd9Sstevel@tonic-gate 20167c478bd9Sstevel@tonic-gate void 20177c478bd9Sstevel@tonic-gate vn_create_cache(void) 20187c478bd9Sstevel@tonic-gate { 20197c478bd9Sstevel@tonic-gate vn_cache = kmem_cache_create("vn_cache", sizeof (struct vnode), 64, 20207c478bd9Sstevel@tonic-gate vn_cache_constructor, vn_cache_destructor, NULL, NULL, 20217c478bd9Sstevel@tonic-gate NULL, 0); 20227c478bd9Sstevel@tonic-gate } 20237c478bd9Sstevel@tonic-gate 20247c478bd9Sstevel@tonic-gate void 20257c478bd9Sstevel@tonic-gate vn_destroy_cache(void) 20267c478bd9Sstevel@tonic-gate { 20277c478bd9Sstevel@tonic-gate kmem_cache_destroy(vn_cache); 20287c478bd9Sstevel@tonic-gate } 20297c478bd9Sstevel@tonic-gate 20307c478bd9Sstevel@tonic-gate /* 20317c478bd9Sstevel@tonic-gate * Used by file systems when fs-specific nodes (e.g., ufs inodes) are 20327c478bd9Sstevel@tonic-gate * cached by the file system and vnodes remain associated. 20337c478bd9Sstevel@tonic-gate */ 20347c478bd9Sstevel@tonic-gate void 20357c478bd9Sstevel@tonic-gate vn_recycle(vnode_t *vp) 20367c478bd9Sstevel@tonic-gate { 20377c478bd9Sstevel@tonic-gate ASSERT(vp->v_pages == NULL); 20387c478bd9Sstevel@tonic-gate 20397c478bd9Sstevel@tonic-gate /* 20407c478bd9Sstevel@tonic-gate * XXX - This really belongs in vn_reinit(), but we have some issues 20417c478bd9Sstevel@tonic-gate * with the counts. Best to have it here for clean initialization. 20427c478bd9Sstevel@tonic-gate */ 20437c478bd9Sstevel@tonic-gate vp->v_rdcnt = 0; 20447c478bd9Sstevel@tonic-gate vp->v_wrcnt = 0; 20457c478bd9Sstevel@tonic-gate vp->v_mmap_read = 0; 20467c478bd9Sstevel@tonic-gate vp->v_mmap_write = 0; 20477c478bd9Sstevel@tonic-gate 20487c478bd9Sstevel@tonic-gate /* 20497c478bd9Sstevel@tonic-gate * If FEM was in use, make sure everything gets cleaned up 20507c478bd9Sstevel@tonic-gate * NOTE: vp->v_femhead is initialized to NULL in the vnode 20517c478bd9Sstevel@tonic-gate * constructor. 20527c478bd9Sstevel@tonic-gate */ 20537c478bd9Sstevel@tonic-gate if (vp->v_femhead) { 20547c478bd9Sstevel@tonic-gate /* XXX - There should be a free_femhead() that does all this */ 20557c478bd9Sstevel@tonic-gate ASSERT(vp->v_femhead->femh_list == NULL); 20567c478bd9Sstevel@tonic-gate mutex_destroy(&vp->v_femhead->femh_lock); 20577c478bd9Sstevel@tonic-gate kmem_free(vp->v_femhead, sizeof (*(vp->v_femhead))); 20587c478bd9Sstevel@tonic-gate vp->v_femhead = NULL; 20597c478bd9Sstevel@tonic-gate } 20607c478bd9Sstevel@tonic-gate if (vp->v_path) { 20617c478bd9Sstevel@tonic-gate kmem_free(vp->v_path, strlen(vp->v_path) + 1); 20627c478bd9Sstevel@tonic-gate vp->v_path = NULL; 20637c478bd9Sstevel@tonic-gate } 2064*df2381bfSpraks 2065*df2381bfSpraks if (vp->v_fopdata != NULL) { 2066*df2381bfSpraks free_fopdata(vp); 2067*df2381bfSpraks } 20687c478bd9Sstevel@tonic-gate vp->v_mpssdata = NULL; 20697c478bd9Sstevel@tonic-gate } 20707c478bd9Sstevel@tonic-gate 20717c478bd9Sstevel@tonic-gate /* 20727c478bd9Sstevel@tonic-gate * Used to reset the vnode fields including those that are directly accessible 20737c478bd9Sstevel@tonic-gate * as well as those which require an accessor function. 20747c478bd9Sstevel@tonic-gate * 20757c478bd9Sstevel@tonic-gate * Does not initialize: 20767c478bd9Sstevel@tonic-gate * synchronization objects: v_lock, v_nbllock, v_cv 20777c478bd9Sstevel@tonic-gate * v_data (since FS-nodes and vnodes point to each other and should 20787c478bd9Sstevel@tonic-gate * be updated simultaneously) 20797c478bd9Sstevel@tonic-gate * v_op (in case someone needs to make a VOP call on this object) 20807c478bd9Sstevel@tonic-gate */ 20817c478bd9Sstevel@tonic-gate void 20827c478bd9Sstevel@tonic-gate vn_reinit(vnode_t *vp) 20837c478bd9Sstevel@tonic-gate { 20847c478bd9Sstevel@tonic-gate vp->v_count = 1; 20857c478bd9Sstevel@tonic-gate vp->v_vfsp = NULL; 20867c478bd9Sstevel@tonic-gate vp->v_stream = NULL; 20877c478bd9Sstevel@tonic-gate vp->v_vfsmountedhere = NULL; 20887c478bd9Sstevel@tonic-gate vp->v_flag = 0; 20897c478bd9Sstevel@tonic-gate vp->v_type = VNON; 20907c478bd9Sstevel@tonic-gate vp->v_rdev = NODEV; 20917c478bd9Sstevel@tonic-gate 20927c478bd9Sstevel@tonic-gate vp->v_filocks = NULL; 20937c478bd9Sstevel@tonic-gate vp->v_shrlocks = NULL; 20947c478bd9Sstevel@tonic-gate vp->v_pages = NULL; 20957c478bd9Sstevel@tonic-gate vp->v_npages = 0; 20967c478bd9Sstevel@tonic-gate vp->v_msnpages = 0; 20977c478bd9Sstevel@tonic-gate vp->v_scanfront = NULL; 20987c478bd9Sstevel@tonic-gate vp->v_scanback = NULL; 20997c478bd9Sstevel@tonic-gate 21007c478bd9Sstevel@tonic-gate vp->v_locality = NULL; 21017c478bd9Sstevel@tonic-gate vp->v_scantime = 0; 21027c478bd9Sstevel@tonic-gate vp->v_mset = 0; 21037c478bd9Sstevel@tonic-gate vp->v_msflags = 0; 21047c478bd9Sstevel@tonic-gate vp->v_msnext = NULL; 21057c478bd9Sstevel@tonic-gate vp->v_msprev = NULL; 21067c478bd9Sstevel@tonic-gate 21077c478bd9Sstevel@tonic-gate /* Handles v_femhead, v_path, and the r/w/map counts */ 21087c478bd9Sstevel@tonic-gate vn_recycle(vp); 21097c478bd9Sstevel@tonic-gate } 21107c478bd9Sstevel@tonic-gate 21117c478bd9Sstevel@tonic-gate vnode_t * 21127c478bd9Sstevel@tonic-gate vn_alloc(int kmflag) 21137c478bd9Sstevel@tonic-gate { 21147c478bd9Sstevel@tonic-gate vnode_t *vp; 21157c478bd9Sstevel@tonic-gate 21167c478bd9Sstevel@tonic-gate vp = kmem_cache_alloc(vn_cache, kmflag); 21177c478bd9Sstevel@tonic-gate 21187c478bd9Sstevel@tonic-gate if (vp != NULL) { 21197c478bd9Sstevel@tonic-gate vp->v_femhead = NULL; /* Must be done before vn_reinit() */ 2120*df2381bfSpraks vp->v_fopdata = NULL; 21217c478bd9Sstevel@tonic-gate vn_reinit(vp); 21227c478bd9Sstevel@tonic-gate } 21237c478bd9Sstevel@tonic-gate 21247c478bd9Sstevel@tonic-gate return (vp); 21257c478bd9Sstevel@tonic-gate } 21267c478bd9Sstevel@tonic-gate 21277c478bd9Sstevel@tonic-gate void 21287c478bd9Sstevel@tonic-gate vn_free(vnode_t *vp) 21297c478bd9Sstevel@tonic-gate { 21307c478bd9Sstevel@tonic-gate /* 21317c478bd9Sstevel@tonic-gate * Some file systems call vn_free() with v_count of zero, 21327c478bd9Sstevel@tonic-gate * some with v_count of 1. In any case, the value should 21337c478bd9Sstevel@tonic-gate * never be anything else. 21347c478bd9Sstevel@tonic-gate */ 21357c478bd9Sstevel@tonic-gate ASSERT((vp->v_count == 0) || (vp->v_count == 1)); 21367c478bd9Sstevel@tonic-gate if (vp->v_path != NULL) { 21377c478bd9Sstevel@tonic-gate kmem_free(vp->v_path, strlen(vp->v_path) + 1); 21387c478bd9Sstevel@tonic-gate vp->v_path = NULL; 21397c478bd9Sstevel@tonic-gate } 21407c478bd9Sstevel@tonic-gate 21417c478bd9Sstevel@tonic-gate /* If FEM was in use, make sure everything gets cleaned up */ 21427c478bd9Sstevel@tonic-gate if (vp->v_femhead) { 21437c478bd9Sstevel@tonic-gate /* XXX - There should be a free_femhead() that does all this */ 21447c478bd9Sstevel@tonic-gate ASSERT(vp->v_femhead->femh_list == NULL); 21457c478bd9Sstevel@tonic-gate mutex_destroy(&vp->v_femhead->femh_lock); 21467c478bd9Sstevel@tonic-gate kmem_free(vp->v_femhead, sizeof (*(vp->v_femhead))); 21477c478bd9Sstevel@tonic-gate vp->v_femhead = NULL; 21487c478bd9Sstevel@tonic-gate } 2149*df2381bfSpraks 2150*df2381bfSpraks if (vp->v_fopdata != NULL) { 2151*df2381bfSpraks free_fopdata(vp); 2152*df2381bfSpraks } 21537c478bd9Sstevel@tonic-gate vp->v_mpssdata = NULL; 21547c478bd9Sstevel@tonic-gate kmem_cache_free(vn_cache, vp); 21557c478bd9Sstevel@tonic-gate } 21567c478bd9Sstevel@tonic-gate 21577c478bd9Sstevel@tonic-gate /* 21587c478bd9Sstevel@tonic-gate * vnode status changes, should define better states than 1, 0. 21597c478bd9Sstevel@tonic-gate */ 21607c478bd9Sstevel@tonic-gate void 21617c478bd9Sstevel@tonic-gate vn_reclaim(vnode_t *vp) 21627c478bd9Sstevel@tonic-gate { 21637c478bd9Sstevel@tonic-gate vfs_t *vfsp = vp->v_vfsp; 21647c478bd9Sstevel@tonic-gate 2165ddfcde86Srsb if (vfsp == NULL || 2166ddfcde86Srsb vfsp->vfs_implp == NULL || vfsp->vfs_femhead == NULL) { 21677c478bd9Sstevel@tonic-gate return; 21687c478bd9Sstevel@tonic-gate } 21697c478bd9Sstevel@tonic-gate (void) VFS_VNSTATE(vfsp, vp, VNTRANS_RECLAIMED); 21707c478bd9Sstevel@tonic-gate } 21717c478bd9Sstevel@tonic-gate 21727c478bd9Sstevel@tonic-gate void 21737c478bd9Sstevel@tonic-gate vn_idle(vnode_t *vp) 21747c478bd9Sstevel@tonic-gate { 21757c478bd9Sstevel@tonic-gate vfs_t *vfsp = vp->v_vfsp; 21767c478bd9Sstevel@tonic-gate 2177ddfcde86Srsb if (vfsp == NULL || 2178ddfcde86Srsb vfsp->vfs_implp == NULL || vfsp->vfs_femhead == NULL) { 21797c478bd9Sstevel@tonic-gate return; 21807c478bd9Sstevel@tonic-gate } 21817c478bd9Sstevel@tonic-gate (void) VFS_VNSTATE(vfsp, vp, VNTRANS_IDLED); 21827c478bd9Sstevel@tonic-gate } 21837c478bd9Sstevel@tonic-gate void 21847c478bd9Sstevel@tonic-gate vn_exists(vnode_t *vp) 21857c478bd9Sstevel@tonic-gate { 21867c478bd9Sstevel@tonic-gate vfs_t *vfsp = vp->v_vfsp; 21877c478bd9Sstevel@tonic-gate 2188ddfcde86Srsb if (vfsp == NULL || 2189ddfcde86Srsb vfsp->vfs_implp == NULL || vfsp->vfs_femhead == NULL) { 21907c478bd9Sstevel@tonic-gate return; 21917c478bd9Sstevel@tonic-gate } 21927c478bd9Sstevel@tonic-gate (void) VFS_VNSTATE(vfsp, vp, VNTRANS_EXISTS); 21937c478bd9Sstevel@tonic-gate } 21947c478bd9Sstevel@tonic-gate 21957c478bd9Sstevel@tonic-gate void 21967c478bd9Sstevel@tonic-gate vn_invalid(vnode_t *vp) 21977c478bd9Sstevel@tonic-gate { 21987c478bd9Sstevel@tonic-gate vfs_t *vfsp = vp->v_vfsp; 21997c478bd9Sstevel@tonic-gate 2200ddfcde86Srsb if (vfsp == NULL || 2201ddfcde86Srsb vfsp->vfs_implp == NULL || vfsp->vfs_femhead == NULL) { 22027c478bd9Sstevel@tonic-gate return; 22037c478bd9Sstevel@tonic-gate } 22047c478bd9Sstevel@tonic-gate (void) VFS_VNSTATE(vfsp, vp, VNTRANS_DESTROYED); 22057c478bd9Sstevel@tonic-gate } 22067c478bd9Sstevel@tonic-gate 22077c478bd9Sstevel@tonic-gate /* Vnode event notification */ 22087c478bd9Sstevel@tonic-gate 22097c478bd9Sstevel@tonic-gate int 22107c478bd9Sstevel@tonic-gate vnevent_support(vnode_t *vp) 22117c478bd9Sstevel@tonic-gate { 22127c478bd9Sstevel@tonic-gate if (vp == NULL) 22137c478bd9Sstevel@tonic-gate return (EINVAL); 22147c478bd9Sstevel@tonic-gate 2215*df2381bfSpraks return (VOP_VNEVENT(vp, VE_SUPPORT, NULL, NULL)); 22167c478bd9Sstevel@tonic-gate } 22177c478bd9Sstevel@tonic-gate 22187c478bd9Sstevel@tonic-gate void 2219*df2381bfSpraks vnevent_rename_src(vnode_t *vp, vnode_t *dvp, char *name) 22207c478bd9Sstevel@tonic-gate { 22217c478bd9Sstevel@tonic-gate if (vp == NULL || vp->v_femhead == NULL) { 22227c478bd9Sstevel@tonic-gate return; 22237c478bd9Sstevel@tonic-gate } 2224*df2381bfSpraks (void) VOP_VNEVENT(vp, VE_RENAME_SRC, dvp, name); 22257c478bd9Sstevel@tonic-gate } 22267c478bd9Sstevel@tonic-gate 22277c478bd9Sstevel@tonic-gate void 2228*df2381bfSpraks vnevent_rename_dest(vnode_t *vp, vnode_t *dvp, char *name) 22297c478bd9Sstevel@tonic-gate { 22307c478bd9Sstevel@tonic-gate if (vp == NULL || vp->v_femhead == NULL) { 22317c478bd9Sstevel@tonic-gate return; 22327c478bd9Sstevel@tonic-gate } 2233*df2381bfSpraks (void) VOP_VNEVENT(vp, VE_RENAME_DEST, dvp, name); 22347c478bd9Sstevel@tonic-gate } 22357c478bd9Sstevel@tonic-gate 22367c478bd9Sstevel@tonic-gate void 2237*df2381bfSpraks vnevent_rename_dest_dir(vnode_t *vp) 22387c478bd9Sstevel@tonic-gate { 22397c478bd9Sstevel@tonic-gate if (vp == NULL || vp->v_femhead == NULL) { 22407c478bd9Sstevel@tonic-gate return; 22417c478bd9Sstevel@tonic-gate } 2242*df2381bfSpraks (void) VOP_VNEVENT(vp, VE_RENAME_DEST_DIR, NULL, NULL); 22437c478bd9Sstevel@tonic-gate } 22447c478bd9Sstevel@tonic-gate 22457c478bd9Sstevel@tonic-gate void 2246*df2381bfSpraks vnevent_remove(vnode_t *vp, vnode_t *dvp, char *name) 22477c478bd9Sstevel@tonic-gate { 22487c478bd9Sstevel@tonic-gate if (vp == NULL || vp->v_femhead == NULL) { 22497c478bd9Sstevel@tonic-gate return; 22507c478bd9Sstevel@tonic-gate } 2251*df2381bfSpraks (void) VOP_VNEVENT(vp, VE_REMOVE, dvp, name); 2252*df2381bfSpraks } 2253*df2381bfSpraks 2254*df2381bfSpraks void 2255*df2381bfSpraks vnevent_rmdir(vnode_t *vp, vnode_t *dvp, char *name) 2256*df2381bfSpraks { 2257*df2381bfSpraks if (vp == NULL || vp->v_femhead == NULL) { 2258*df2381bfSpraks return; 2259*df2381bfSpraks } 2260*df2381bfSpraks (void) VOP_VNEVENT(vp, VE_RMDIR, dvp, name); 2261*df2381bfSpraks } 2262*df2381bfSpraks 2263*df2381bfSpraks void 2264*df2381bfSpraks vnevent_create(vnode_t *vp) 2265*df2381bfSpraks { 2266*df2381bfSpraks if (vp == NULL || vp->v_femhead == NULL) { 2267*df2381bfSpraks return; 2268*df2381bfSpraks } 2269*df2381bfSpraks (void) VOP_VNEVENT(vp, VE_CREATE, NULL, NULL); 2270*df2381bfSpraks } 2271*df2381bfSpraks 2272*df2381bfSpraks void 2273*df2381bfSpraks vnevent_link(vnode_t *vp) 2274*df2381bfSpraks { 2275*df2381bfSpraks if (vp == NULL || vp->v_femhead == NULL) { 2276*df2381bfSpraks return; 2277*df2381bfSpraks } 2278*df2381bfSpraks (void) VOP_VNEVENT(vp, VE_LINK, NULL, NULL); 2279*df2381bfSpraks } 2280*df2381bfSpraks 2281*df2381bfSpraks void 2282*df2381bfSpraks vnevent_mountedover(vnode_t *vp) 2283*df2381bfSpraks { 2284*df2381bfSpraks if (vp == NULL || vp->v_femhead == NULL) { 2285*df2381bfSpraks return; 2286*df2381bfSpraks } 2287*df2381bfSpraks (void) VOP_VNEVENT(vp, VE_MOUNTEDOVER, NULL, NULL); 22887c478bd9Sstevel@tonic-gate } 22897c478bd9Sstevel@tonic-gate 22907c478bd9Sstevel@tonic-gate /* 22917c478bd9Sstevel@tonic-gate * Vnode accessors. 22927c478bd9Sstevel@tonic-gate */ 22937c478bd9Sstevel@tonic-gate 22947c478bd9Sstevel@tonic-gate int 22957c478bd9Sstevel@tonic-gate vn_is_readonly(vnode_t *vp) 22967c478bd9Sstevel@tonic-gate { 22977c478bd9Sstevel@tonic-gate return (vp->v_vfsp->vfs_flag & VFS_RDONLY); 22987c478bd9Sstevel@tonic-gate } 22997c478bd9Sstevel@tonic-gate 23007c478bd9Sstevel@tonic-gate int 23017c478bd9Sstevel@tonic-gate vn_has_flocks(vnode_t *vp) 23027c478bd9Sstevel@tonic-gate { 23037c478bd9Sstevel@tonic-gate return (vp->v_filocks != NULL); 23047c478bd9Sstevel@tonic-gate } 23057c478bd9Sstevel@tonic-gate 23067c478bd9Sstevel@tonic-gate int 23077c478bd9Sstevel@tonic-gate vn_has_mandatory_locks(vnode_t *vp, int mode) 23087c478bd9Sstevel@tonic-gate { 23097c478bd9Sstevel@tonic-gate return ((vp->v_filocks != NULL) && (MANDLOCK(vp, mode))); 23107c478bd9Sstevel@tonic-gate } 23117c478bd9Sstevel@tonic-gate 23127c478bd9Sstevel@tonic-gate int 23137c478bd9Sstevel@tonic-gate vn_has_cached_data(vnode_t *vp) 23147c478bd9Sstevel@tonic-gate { 23157c478bd9Sstevel@tonic-gate return (vp->v_pages != NULL); 23167c478bd9Sstevel@tonic-gate } 23177c478bd9Sstevel@tonic-gate 23187c478bd9Sstevel@tonic-gate /* 23197c478bd9Sstevel@tonic-gate * Return 0 if the vnode in question shouldn't be permitted into a zone via 23207c478bd9Sstevel@tonic-gate * zone_enter(2). 23217c478bd9Sstevel@tonic-gate */ 23227c478bd9Sstevel@tonic-gate int 23237c478bd9Sstevel@tonic-gate vn_can_change_zones(vnode_t *vp) 23247c478bd9Sstevel@tonic-gate { 23257c478bd9Sstevel@tonic-gate struct vfssw *vswp; 23267c478bd9Sstevel@tonic-gate int allow = 1; 23277c478bd9Sstevel@tonic-gate vnode_t *rvp; 23287c478bd9Sstevel@tonic-gate 2329108322fbScarlsonj if (nfs_global_client_only != 0) 2330108322fbScarlsonj return (1); 2331108322fbScarlsonj 23327c478bd9Sstevel@tonic-gate /* 23337c478bd9Sstevel@tonic-gate * We always want to look at the underlying vnode if there is one. 23347c478bd9Sstevel@tonic-gate */ 23357c478bd9Sstevel@tonic-gate if (VOP_REALVP(vp, &rvp) != 0) 23367c478bd9Sstevel@tonic-gate rvp = vp; 23377c478bd9Sstevel@tonic-gate /* 23387c478bd9Sstevel@tonic-gate * Some pseudo filesystems (including doorfs) don't actually register 23397c478bd9Sstevel@tonic-gate * their vfsops_t, so the following may return NULL; we happily let 23407c478bd9Sstevel@tonic-gate * such vnodes switch zones. 23417c478bd9Sstevel@tonic-gate */ 23427c478bd9Sstevel@tonic-gate vswp = vfs_getvfsswbyvfsops(vfs_getops(rvp->v_vfsp)); 23437c478bd9Sstevel@tonic-gate if (vswp != NULL) { 23447c478bd9Sstevel@tonic-gate if (vswp->vsw_flag & VSW_NOTZONESAFE) 23457c478bd9Sstevel@tonic-gate allow = 0; 23467c478bd9Sstevel@tonic-gate vfs_unrefvfssw(vswp); 23477c478bd9Sstevel@tonic-gate } 23487c478bd9Sstevel@tonic-gate return (allow); 23497c478bd9Sstevel@tonic-gate } 23507c478bd9Sstevel@tonic-gate 23517c478bd9Sstevel@tonic-gate /* 23527c478bd9Sstevel@tonic-gate * Return nonzero if the vnode is a mount point, zero if not. 23537c478bd9Sstevel@tonic-gate */ 23547c478bd9Sstevel@tonic-gate int 23557c478bd9Sstevel@tonic-gate vn_ismntpt(vnode_t *vp) 23567c478bd9Sstevel@tonic-gate { 23577c478bd9Sstevel@tonic-gate return (vp->v_vfsmountedhere != NULL); 23587c478bd9Sstevel@tonic-gate } 23597c478bd9Sstevel@tonic-gate 23607c478bd9Sstevel@tonic-gate /* Retrieve the vfs (if any) mounted on this vnode */ 23617c478bd9Sstevel@tonic-gate vfs_t * 23627c478bd9Sstevel@tonic-gate vn_mountedvfs(vnode_t *vp) 23637c478bd9Sstevel@tonic-gate { 23647c478bd9Sstevel@tonic-gate return (vp->v_vfsmountedhere); 23657c478bd9Sstevel@tonic-gate } 23667c478bd9Sstevel@tonic-gate 23677c478bd9Sstevel@tonic-gate /* 23687c478bd9Sstevel@tonic-gate * vn_is_opened() checks whether a particular file is opened and 23697c478bd9Sstevel@tonic-gate * whether the open is for read and/or write. 23707c478bd9Sstevel@tonic-gate * 23717c478bd9Sstevel@tonic-gate * Vnode counts are only kept on regular files (v_type=VREG). 23727c478bd9Sstevel@tonic-gate */ 23737c478bd9Sstevel@tonic-gate int 23747c478bd9Sstevel@tonic-gate vn_is_opened( 23757c478bd9Sstevel@tonic-gate vnode_t *vp, 23767c478bd9Sstevel@tonic-gate v_mode_t mode) 23777c478bd9Sstevel@tonic-gate { 23787c478bd9Sstevel@tonic-gate 23797c478bd9Sstevel@tonic-gate ASSERT(vp != NULL); 23807c478bd9Sstevel@tonic-gate 23817c478bd9Sstevel@tonic-gate switch (mode) { 23827c478bd9Sstevel@tonic-gate case V_WRITE: 23837c478bd9Sstevel@tonic-gate if (vp->v_wrcnt) 23847c478bd9Sstevel@tonic-gate return (V_TRUE); 23857c478bd9Sstevel@tonic-gate break; 23867c478bd9Sstevel@tonic-gate case V_RDANDWR: 23877c478bd9Sstevel@tonic-gate if (vp->v_rdcnt && vp->v_wrcnt) 23887c478bd9Sstevel@tonic-gate return (V_TRUE); 23897c478bd9Sstevel@tonic-gate break; 23907c478bd9Sstevel@tonic-gate case V_RDORWR: 23917c478bd9Sstevel@tonic-gate if (vp->v_rdcnt || vp->v_wrcnt) 23927c478bd9Sstevel@tonic-gate return (V_TRUE); 23937c478bd9Sstevel@tonic-gate break; 23947c478bd9Sstevel@tonic-gate case V_READ: 23957c478bd9Sstevel@tonic-gate if (vp->v_rdcnt) 23967c478bd9Sstevel@tonic-gate return (V_TRUE); 23977c478bd9Sstevel@tonic-gate break; 23987c478bd9Sstevel@tonic-gate } 23997c478bd9Sstevel@tonic-gate 24007c478bd9Sstevel@tonic-gate return (V_FALSE); 24017c478bd9Sstevel@tonic-gate } 24027c478bd9Sstevel@tonic-gate 24037c478bd9Sstevel@tonic-gate /* 24047c478bd9Sstevel@tonic-gate * vn_is_mapped() checks whether a particular file is mapped and whether 24057c478bd9Sstevel@tonic-gate * the file is mapped read and/or write. 24067c478bd9Sstevel@tonic-gate */ 24077c478bd9Sstevel@tonic-gate int 24087c478bd9Sstevel@tonic-gate vn_is_mapped( 24097c478bd9Sstevel@tonic-gate vnode_t *vp, 24107c478bd9Sstevel@tonic-gate v_mode_t mode) 24117c478bd9Sstevel@tonic-gate { 24127c478bd9Sstevel@tonic-gate 24137c478bd9Sstevel@tonic-gate ASSERT(vp != NULL); 24147c478bd9Sstevel@tonic-gate 24157c478bd9Sstevel@tonic-gate #if !defined(_LP64) 24167c478bd9Sstevel@tonic-gate switch (mode) { 24177c478bd9Sstevel@tonic-gate /* 24187c478bd9Sstevel@tonic-gate * The atomic_add_64_nv functions force atomicity in the 24197c478bd9Sstevel@tonic-gate * case of 32 bit architectures. Otherwise the 64 bit values 24207c478bd9Sstevel@tonic-gate * require two fetches. The value of the fields may be 24217c478bd9Sstevel@tonic-gate * (potentially) changed between the first fetch and the 24227c478bd9Sstevel@tonic-gate * second 24237c478bd9Sstevel@tonic-gate */ 24247c478bd9Sstevel@tonic-gate case V_WRITE: 24257c478bd9Sstevel@tonic-gate if (atomic_add_64_nv((&(vp->v_mmap_write)), 0)) 24267c478bd9Sstevel@tonic-gate return (V_TRUE); 24277c478bd9Sstevel@tonic-gate break; 24287c478bd9Sstevel@tonic-gate case V_RDANDWR: 24297c478bd9Sstevel@tonic-gate if ((atomic_add_64_nv((&(vp->v_mmap_read)), 0)) && 24307c478bd9Sstevel@tonic-gate (atomic_add_64_nv((&(vp->v_mmap_write)), 0))) 24317c478bd9Sstevel@tonic-gate return (V_TRUE); 24327c478bd9Sstevel@tonic-gate break; 24337c478bd9Sstevel@tonic-gate case V_RDORWR: 24347c478bd9Sstevel@tonic-gate if ((atomic_add_64_nv((&(vp->v_mmap_read)), 0)) || 24357c478bd9Sstevel@tonic-gate (atomic_add_64_nv((&(vp->v_mmap_write)), 0))) 24367c478bd9Sstevel@tonic-gate return (V_TRUE); 24377c478bd9Sstevel@tonic-gate break; 24387c478bd9Sstevel@tonic-gate case V_READ: 24397c478bd9Sstevel@tonic-gate if (atomic_add_64_nv((&(vp->v_mmap_read)), 0)) 24407c478bd9Sstevel@tonic-gate return (V_TRUE); 24417c478bd9Sstevel@tonic-gate break; 24427c478bd9Sstevel@tonic-gate } 24437c478bd9Sstevel@tonic-gate #else 24447c478bd9Sstevel@tonic-gate switch (mode) { 24457c478bd9Sstevel@tonic-gate case V_WRITE: 24467c478bd9Sstevel@tonic-gate if (vp->v_mmap_write) 24477c478bd9Sstevel@tonic-gate return (V_TRUE); 24487c478bd9Sstevel@tonic-gate break; 24497c478bd9Sstevel@tonic-gate case V_RDANDWR: 24507c478bd9Sstevel@tonic-gate if (vp->v_mmap_read && vp->v_mmap_write) 24517c478bd9Sstevel@tonic-gate return (V_TRUE); 24527c478bd9Sstevel@tonic-gate break; 24537c478bd9Sstevel@tonic-gate case V_RDORWR: 24547c478bd9Sstevel@tonic-gate if (vp->v_mmap_read || vp->v_mmap_write) 24557c478bd9Sstevel@tonic-gate return (V_TRUE); 24567c478bd9Sstevel@tonic-gate break; 24577c478bd9Sstevel@tonic-gate case V_READ: 24587c478bd9Sstevel@tonic-gate if (vp->v_mmap_read) 24597c478bd9Sstevel@tonic-gate return (V_TRUE); 24607c478bd9Sstevel@tonic-gate break; 24617c478bd9Sstevel@tonic-gate } 24627c478bd9Sstevel@tonic-gate #endif 24637c478bd9Sstevel@tonic-gate 24647c478bd9Sstevel@tonic-gate return (V_FALSE); 24657c478bd9Sstevel@tonic-gate } 24667c478bd9Sstevel@tonic-gate 24677c478bd9Sstevel@tonic-gate /* 24687c478bd9Sstevel@tonic-gate * Set the operations vector for a vnode. 24697c478bd9Sstevel@tonic-gate * 24707c478bd9Sstevel@tonic-gate * FEM ensures that the v_femhead pointer is filled in before the 24717c478bd9Sstevel@tonic-gate * v_op pointer is changed. This means that if the v_femhead pointer 24727c478bd9Sstevel@tonic-gate * is NULL, and the v_op field hasn't changed since before which checked 24737c478bd9Sstevel@tonic-gate * the v_femhead pointer; then our update is ok - we are not racing with 24747c478bd9Sstevel@tonic-gate * FEM. 24757c478bd9Sstevel@tonic-gate */ 24767c478bd9Sstevel@tonic-gate void 24777c478bd9Sstevel@tonic-gate vn_setops(vnode_t *vp, vnodeops_t *vnodeops) 24787c478bd9Sstevel@tonic-gate { 24797c478bd9Sstevel@tonic-gate vnodeops_t *op; 24807c478bd9Sstevel@tonic-gate 24817c478bd9Sstevel@tonic-gate ASSERT(vp != NULL); 24827c478bd9Sstevel@tonic-gate ASSERT(vnodeops != NULL); 24837c478bd9Sstevel@tonic-gate 24847c478bd9Sstevel@tonic-gate op = vp->v_op; 24857c478bd9Sstevel@tonic-gate membar_consumer(); 24867c478bd9Sstevel@tonic-gate /* 24877c478bd9Sstevel@tonic-gate * If vp->v_femhead == NULL, then we'll call casptr() to do the 24887c478bd9Sstevel@tonic-gate * compare-and-swap on vp->v_op. If either fails, then FEM is 24897c478bd9Sstevel@tonic-gate * in effect on the vnode and we need to have FEM deal with it. 24907c478bd9Sstevel@tonic-gate */ 24917c478bd9Sstevel@tonic-gate if (vp->v_femhead != NULL || casptr(&vp->v_op, op, vnodeops) != op) { 24927c478bd9Sstevel@tonic-gate fem_setvnops(vp, vnodeops); 24937c478bd9Sstevel@tonic-gate } 24947c478bd9Sstevel@tonic-gate } 24957c478bd9Sstevel@tonic-gate 24967c478bd9Sstevel@tonic-gate /* 24977c478bd9Sstevel@tonic-gate * Retrieve the operations vector for a vnode 24987c478bd9Sstevel@tonic-gate * As with vn_setops(above); make sure we aren't racing with FEM. 24997c478bd9Sstevel@tonic-gate * FEM sets the v_op to a special, internal, vnodeops that wouldn't 25007c478bd9Sstevel@tonic-gate * make sense to the callers of this routine. 25017c478bd9Sstevel@tonic-gate */ 25027c478bd9Sstevel@tonic-gate vnodeops_t * 25037c478bd9Sstevel@tonic-gate vn_getops(vnode_t *vp) 25047c478bd9Sstevel@tonic-gate { 25057c478bd9Sstevel@tonic-gate vnodeops_t *op; 25067c478bd9Sstevel@tonic-gate 25077c478bd9Sstevel@tonic-gate ASSERT(vp != NULL); 25087c478bd9Sstevel@tonic-gate 25097c478bd9Sstevel@tonic-gate op = vp->v_op; 25107c478bd9Sstevel@tonic-gate membar_consumer(); 25117c478bd9Sstevel@tonic-gate if (vp->v_femhead == NULL && op == vp->v_op) { 25127c478bd9Sstevel@tonic-gate return (op); 25137c478bd9Sstevel@tonic-gate } else { 25147c478bd9Sstevel@tonic-gate return (fem_getvnops(vp)); 25157c478bd9Sstevel@tonic-gate } 25167c478bd9Sstevel@tonic-gate } 25177c478bd9Sstevel@tonic-gate 25187c478bd9Sstevel@tonic-gate /* 25197c478bd9Sstevel@tonic-gate * Returns non-zero (1) if the vnodeops matches that of the vnode. 25207c478bd9Sstevel@tonic-gate * Returns zero (0) if not. 25217c478bd9Sstevel@tonic-gate */ 25227c478bd9Sstevel@tonic-gate int 25237c478bd9Sstevel@tonic-gate vn_matchops(vnode_t *vp, vnodeops_t *vnodeops) 25247c478bd9Sstevel@tonic-gate { 25257c478bd9Sstevel@tonic-gate return (vn_getops(vp) == vnodeops); 25267c478bd9Sstevel@tonic-gate } 25277c478bd9Sstevel@tonic-gate 25287c478bd9Sstevel@tonic-gate /* 25297c478bd9Sstevel@tonic-gate * Returns non-zero (1) if the specified operation matches the 25307c478bd9Sstevel@tonic-gate * corresponding operation for that the vnode. 25317c478bd9Sstevel@tonic-gate * Returns zero (0) if not. 25327c478bd9Sstevel@tonic-gate */ 25337c478bd9Sstevel@tonic-gate 25347c478bd9Sstevel@tonic-gate #define MATCHNAME(n1, n2) (((n1)[0] == (n2)[0]) && (strcmp((n1), (n2)) == 0)) 25357c478bd9Sstevel@tonic-gate 25367c478bd9Sstevel@tonic-gate int 25377c478bd9Sstevel@tonic-gate vn_matchopval(vnode_t *vp, char *vopname, fs_generic_func_p funcp) 25387c478bd9Sstevel@tonic-gate { 25397c478bd9Sstevel@tonic-gate const fs_operation_trans_def_t *otdp; 25407c478bd9Sstevel@tonic-gate fs_generic_func_p *loc = NULL; 25417c478bd9Sstevel@tonic-gate vnodeops_t *vop = vn_getops(vp); 25427c478bd9Sstevel@tonic-gate 25437c478bd9Sstevel@tonic-gate ASSERT(vopname != NULL); 25447c478bd9Sstevel@tonic-gate 25457c478bd9Sstevel@tonic-gate for (otdp = vn_ops_table; otdp->name != NULL; otdp++) { 25467c478bd9Sstevel@tonic-gate if (MATCHNAME(otdp->name, vopname)) { 25477c478bd9Sstevel@tonic-gate loc = (fs_generic_func_p *)((char *)(vop) 25487c478bd9Sstevel@tonic-gate + otdp->offset); 25497c478bd9Sstevel@tonic-gate break; 25507c478bd9Sstevel@tonic-gate } 25517c478bd9Sstevel@tonic-gate } 25527c478bd9Sstevel@tonic-gate 25537c478bd9Sstevel@tonic-gate return ((loc != NULL) && (*loc == funcp)); 25547c478bd9Sstevel@tonic-gate } 25557c478bd9Sstevel@tonic-gate 25567c478bd9Sstevel@tonic-gate /* 25577c478bd9Sstevel@tonic-gate * fs_new_caller_id() needs to return a unique ID on a given local system. 25587c478bd9Sstevel@tonic-gate * The IDs do not need to survive across reboots. These are primarily 25597c478bd9Sstevel@tonic-gate * used so that (FEM) monitors can detect particular callers (such as 25607c478bd9Sstevel@tonic-gate * the NFS server) to a given vnode/vfs operation. 25617c478bd9Sstevel@tonic-gate */ 25627c478bd9Sstevel@tonic-gate u_longlong_t 25637c478bd9Sstevel@tonic-gate fs_new_caller_id() 25647c478bd9Sstevel@tonic-gate { 25657c478bd9Sstevel@tonic-gate static uint64_t next_caller_id = 0LL; /* First call returns 1 */ 25667c478bd9Sstevel@tonic-gate 25677c478bd9Sstevel@tonic-gate return ((u_longlong_t)atomic_add_64_nv(&next_caller_id, 1)); 25687c478bd9Sstevel@tonic-gate } 25697c478bd9Sstevel@tonic-gate 25707c478bd9Sstevel@tonic-gate /* 25717c478bd9Sstevel@tonic-gate * Given a starting vnode and a path, updates the path in the target vnode in 25727c478bd9Sstevel@tonic-gate * a safe manner. If the vnode already has path information embedded, then the 2573ca2c3138Seschrock * cached path is left untouched. 25747c478bd9Sstevel@tonic-gate */ 257548011479Ssn199410 257648011479Ssn199410 size_t max_vnode_path = 4 * MAXPATHLEN; 257748011479Ssn199410 25787c478bd9Sstevel@tonic-gate void 25797c478bd9Sstevel@tonic-gate vn_setpath(vnode_t *rootvp, struct vnode *startvp, struct vnode *vp, 25807c478bd9Sstevel@tonic-gate const char *path, size_t plen) 25817c478bd9Sstevel@tonic-gate { 25827c478bd9Sstevel@tonic-gate char *rpath; 25837c478bd9Sstevel@tonic-gate vnode_t *base; 25847c478bd9Sstevel@tonic-gate size_t rpathlen, rpathalloc; 25857c478bd9Sstevel@tonic-gate int doslash = 1; 25867c478bd9Sstevel@tonic-gate 25877c478bd9Sstevel@tonic-gate if (*path == '/') { 25887c478bd9Sstevel@tonic-gate base = rootvp; 25897c478bd9Sstevel@tonic-gate path++; 25907c478bd9Sstevel@tonic-gate plen--; 25917c478bd9Sstevel@tonic-gate } else { 25927c478bd9Sstevel@tonic-gate base = startvp; 25937c478bd9Sstevel@tonic-gate } 25947c478bd9Sstevel@tonic-gate 25957c478bd9Sstevel@tonic-gate /* 25967c478bd9Sstevel@tonic-gate * We cannot grab base->v_lock while we hold vp->v_lock because of 25977c478bd9Sstevel@tonic-gate * the potential for deadlock. 25987c478bd9Sstevel@tonic-gate */ 25997c478bd9Sstevel@tonic-gate mutex_enter(&base->v_lock); 26007c478bd9Sstevel@tonic-gate if (base->v_path == NULL) { 26017c478bd9Sstevel@tonic-gate mutex_exit(&base->v_lock); 26027c478bd9Sstevel@tonic-gate return; 26037c478bd9Sstevel@tonic-gate } 26047c478bd9Sstevel@tonic-gate 26057c478bd9Sstevel@tonic-gate rpathlen = strlen(base->v_path); 26067c478bd9Sstevel@tonic-gate rpathalloc = rpathlen + plen + 1; 26077c478bd9Sstevel@tonic-gate /* Avoid adding a slash if there's already one there */ 26087c478bd9Sstevel@tonic-gate if (base->v_path[rpathlen-1] == '/') 26097c478bd9Sstevel@tonic-gate doslash = 0; 26107c478bd9Sstevel@tonic-gate else 26117c478bd9Sstevel@tonic-gate rpathalloc++; 26127c478bd9Sstevel@tonic-gate 26137c478bd9Sstevel@tonic-gate /* 26147c478bd9Sstevel@tonic-gate * We don't want to call kmem_alloc(KM_SLEEP) with kernel locks held, 26157c478bd9Sstevel@tonic-gate * so we must do this dance. If, by chance, something changes the path, 26167c478bd9Sstevel@tonic-gate * just give up since there is no real harm. 26177c478bd9Sstevel@tonic-gate */ 26187c478bd9Sstevel@tonic-gate mutex_exit(&base->v_lock); 26197c478bd9Sstevel@tonic-gate 262048011479Ssn199410 /* Paths should stay within reason */ 262148011479Ssn199410 if (rpathalloc > max_vnode_path) 262248011479Ssn199410 return; 262348011479Ssn199410 26247c478bd9Sstevel@tonic-gate rpath = kmem_alloc(rpathalloc, KM_SLEEP); 26257c478bd9Sstevel@tonic-gate 26267c478bd9Sstevel@tonic-gate mutex_enter(&base->v_lock); 26277c478bd9Sstevel@tonic-gate if (base->v_path == NULL || strlen(base->v_path) != rpathlen) { 26287c478bd9Sstevel@tonic-gate mutex_exit(&base->v_lock); 26297c478bd9Sstevel@tonic-gate kmem_free(rpath, rpathalloc); 26307c478bd9Sstevel@tonic-gate return; 26317c478bd9Sstevel@tonic-gate } 26327c478bd9Sstevel@tonic-gate bcopy(base->v_path, rpath, rpathlen); 26337c478bd9Sstevel@tonic-gate mutex_exit(&base->v_lock); 26347c478bd9Sstevel@tonic-gate 26357c478bd9Sstevel@tonic-gate if (doslash) 26367c478bd9Sstevel@tonic-gate rpath[rpathlen++] = '/'; 26377c478bd9Sstevel@tonic-gate bcopy(path, rpath + rpathlen, plen); 26387c478bd9Sstevel@tonic-gate rpath[rpathlen + plen] = '\0'; 26397c478bd9Sstevel@tonic-gate 26407c478bd9Sstevel@tonic-gate mutex_enter(&vp->v_lock); 26417c478bd9Sstevel@tonic-gate if (vp->v_path != NULL) { 26427c478bd9Sstevel@tonic-gate mutex_exit(&vp->v_lock); 26437c478bd9Sstevel@tonic-gate kmem_free(rpath, rpathalloc); 26447c478bd9Sstevel@tonic-gate } else { 26457c478bd9Sstevel@tonic-gate vp->v_path = rpath; 26467c478bd9Sstevel@tonic-gate mutex_exit(&vp->v_lock); 26477c478bd9Sstevel@tonic-gate } 26487c478bd9Sstevel@tonic-gate } 26497c478bd9Sstevel@tonic-gate 26507c478bd9Sstevel@tonic-gate /* 26517c478bd9Sstevel@tonic-gate * Sets the path to the vnode to be the given string, regardless of current 26527c478bd9Sstevel@tonic-gate * context. The string must be a complete path from rootdir. This is only used 26537c478bd9Sstevel@tonic-gate * by fsop_root() for setting the path based on the mountpoint. 26547c478bd9Sstevel@tonic-gate */ 26557c478bd9Sstevel@tonic-gate void 26567c478bd9Sstevel@tonic-gate vn_setpath_str(struct vnode *vp, const char *str, size_t len) 26577c478bd9Sstevel@tonic-gate { 26587c478bd9Sstevel@tonic-gate char *buf = kmem_alloc(len + 1, KM_SLEEP); 26597c478bd9Sstevel@tonic-gate 26607c478bd9Sstevel@tonic-gate mutex_enter(&vp->v_lock); 26617c478bd9Sstevel@tonic-gate if (vp->v_path != NULL) { 26627c478bd9Sstevel@tonic-gate mutex_exit(&vp->v_lock); 26637c478bd9Sstevel@tonic-gate kmem_free(buf, len + 1); 26647c478bd9Sstevel@tonic-gate return; 26657c478bd9Sstevel@tonic-gate } 26667c478bd9Sstevel@tonic-gate 26677c478bd9Sstevel@tonic-gate vp->v_path = buf; 26687c478bd9Sstevel@tonic-gate bcopy(str, vp->v_path, len); 26697c478bd9Sstevel@tonic-gate vp->v_path[len] = '\0'; 26707c478bd9Sstevel@tonic-gate 26717c478bd9Sstevel@tonic-gate mutex_exit(&vp->v_lock); 26727c478bd9Sstevel@tonic-gate } 26737c478bd9Sstevel@tonic-gate 26747c478bd9Sstevel@tonic-gate /* 26757c478bd9Sstevel@tonic-gate * Similar to vn_setpath_str(), this function sets the path of the destination 26767c478bd9Sstevel@tonic-gate * vnode to the be the same as the source vnode. 26777c478bd9Sstevel@tonic-gate */ 26787c478bd9Sstevel@tonic-gate void 26797c478bd9Sstevel@tonic-gate vn_copypath(struct vnode *src, struct vnode *dst) 26807c478bd9Sstevel@tonic-gate { 26817c478bd9Sstevel@tonic-gate char *buf; 26827c478bd9Sstevel@tonic-gate int alloc; 26837c478bd9Sstevel@tonic-gate 26847c478bd9Sstevel@tonic-gate mutex_enter(&src->v_lock); 26857c478bd9Sstevel@tonic-gate if (src->v_path == NULL) { 26867c478bd9Sstevel@tonic-gate mutex_exit(&src->v_lock); 26877c478bd9Sstevel@tonic-gate return; 26887c478bd9Sstevel@tonic-gate } 26897c478bd9Sstevel@tonic-gate alloc = strlen(src->v_path) + 1; 26907c478bd9Sstevel@tonic-gate 26917c478bd9Sstevel@tonic-gate /* avoid kmem_alloc() with lock held */ 26927c478bd9Sstevel@tonic-gate mutex_exit(&src->v_lock); 26937c478bd9Sstevel@tonic-gate buf = kmem_alloc(alloc, KM_SLEEP); 26947c478bd9Sstevel@tonic-gate mutex_enter(&src->v_lock); 26957c478bd9Sstevel@tonic-gate if (src->v_path == NULL || strlen(src->v_path) + 1 != alloc) { 26967c478bd9Sstevel@tonic-gate mutex_exit(&src->v_lock); 26977c478bd9Sstevel@tonic-gate kmem_free(buf, alloc); 26987c478bd9Sstevel@tonic-gate return; 26997c478bd9Sstevel@tonic-gate } 27007c478bd9Sstevel@tonic-gate bcopy(src->v_path, buf, alloc); 27017c478bd9Sstevel@tonic-gate mutex_exit(&src->v_lock); 27027c478bd9Sstevel@tonic-gate 27037c478bd9Sstevel@tonic-gate mutex_enter(&dst->v_lock); 27047c478bd9Sstevel@tonic-gate if (dst->v_path != NULL) { 27057c478bd9Sstevel@tonic-gate mutex_exit(&dst->v_lock); 27067c478bd9Sstevel@tonic-gate kmem_free(buf, alloc); 27077c478bd9Sstevel@tonic-gate return; 27087c478bd9Sstevel@tonic-gate } 27097c478bd9Sstevel@tonic-gate dst->v_path = buf; 27107c478bd9Sstevel@tonic-gate mutex_exit(&dst->v_lock); 27117c478bd9Sstevel@tonic-gate } 27127c478bd9Sstevel@tonic-gate 27137c478bd9Sstevel@tonic-gate /* 27147c478bd9Sstevel@tonic-gate * XXX Private interface for segvn routines that handle vnode 27157c478bd9Sstevel@tonic-gate * large page segments. 27167c478bd9Sstevel@tonic-gate * 27177c478bd9Sstevel@tonic-gate * return 1 if vp's file system VOP_PAGEIO() implementation 27187c478bd9Sstevel@tonic-gate * can be safely used instead of VOP_GETPAGE() for handling 27197c478bd9Sstevel@tonic-gate * pagefaults against regular non swap files. VOP_PAGEIO() 27207c478bd9Sstevel@tonic-gate * interface is considered safe here if its implementation 27217c478bd9Sstevel@tonic-gate * is very close to VOP_GETPAGE() implementation. 27227c478bd9Sstevel@tonic-gate * e.g. It zero's out the part of the page beyond EOF. Doesn't 27237c478bd9Sstevel@tonic-gate * panic if there're file holes but instead returns an error. 27247c478bd9Sstevel@tonic-gate * Doesn't assume file won't be changed by user writes, etc. 27257c478bd9Sstevel@tonic-gate * 27267c478bd9Sstevel@tonic-gate * return 0 otherwise. 27277c478bd9Sstevel@tonic-gate * 27287c478bd9Sstevel@tonic-gate * For now allow segvn to only use VOP_PAGEIO() with ufs and nfs. 27297c478bd9Sstevel@tonic-gate */ 27307c478bd9Sstevel@tonic-gate int 27317c478bd9Sstevel@tonic-gate vn_vmpss_usepageio(vnode_t *vp) 27327c478bd9Sstevel@tonic-gate { 27337c478bd9Sstevel@tonic-gate vfs_t *vfsp = vp->v_vfsp; 27347c478bd9Sstevel@tonic-gate char *fsname = vfssw[vfsp->vfs_fstype].vsw_name; 27357c478bd9Sstevel@tonic-gate char *pageio_ok_fss[] = {"ufs", "nfs", NULL}; 27367c478bd9Sstevel@tonic-gate char **fsok = pageio_ok_fss; 27377c478bd9Sstevel@tonic-gate 27387c478bd9Sstevel@tonic-gate if (fsname == NULL) { 27397c478bd9Sstevel@tonic-gate return (0); 27407c478bd9Sstevel@tonic-gate } 27417c478bd9Sstevel@tonic-gate 27427c478bd9Sstevel@tonic-gate for (; *fsok; fsok++) { 27437c478bd9Sstevel@tonic-gate if (strcmp(*fsok, fsname) == 0) { 27447c478bd9Sstevel@tonic-gate return (1); 27457c478bd9Sstevel@tonic-gate } 27467c478bd9Sstevel@tonic-gate } 27477c478bd9Sstevel@tonic-gate return (0); 27487c478bd9Sstevel@tonic-gate } 27497c478bd9Sstevel@tonic-gate 27507c478bd9Sstevel@tonic-gate /* VOP_XXX() macros call the corresponding fop_xxx() function */ 27517c478bd9Sstevel@tonic-gate 27527c478bd9Sstevel@tonic-gate int 27537c478bd9Sstevel@tonic-gate fop_open( 27547c478bd9Sstevel@tonic-gate vnode_t **vpp, 27557c478bd9Sstevel@tonic-gate int mode, 27567c478bd9Sstevel@tonic-gate cred_t *cr) 27577c478bd9Sstevel@tonic-gate { 27587c478bd9Sstevel@tonic-gate int ret; 27597c478bd9Sstevel@tonic-gate vnode_t *vp = *vpp; 27607c478bd9Sstevel@tonic-gate 27617c478bd9Sstevel@tonic-gate VN_HOLD(vp); 27627c478bd9Sstevel@tonic-gate /* 27637c478bd9Sstevel@tonic-gate * Adding to the vnode counts before calling open 27647c478bd9Sstevel@tonic-gate * avoids the need for a mutex. It circumvents a race 27657c478bd9Sstevel@tonic-gate * condition where a query made on the vnode counts results in a 27667c478bd9Sstevel@tonic-gate * false negative. The inquirer goes away believing the file is 27677c478bd9Sstevel@tonic-gate * not open when there is an open on the file already under way. 27687c478bd9Sstevel@tonic-gate * 27697c478bd9Sstevel@tonic-gate * The counts are meant to prevent NFS from granting a delegation 27707c478bd9Sstevel@tonic-gate * when it would be dangerous to do so. 27717c478bd9Sstevel@tonic-gate * 27727c478bd9Sstevel@tonic-gate * The vnode counts are only kept on regular files 27737c478bd9Sstevel@tonic-gate */ 27747c478bd9Sstevel@tonic-gate if ((*vpp)->v_type == VREG) { 27757c478bd9Sstevel@tonic-gate if (mode & FREAD) 27767c478bd9Sstevel@tonic-gate atomic_add_32(&((*vpp)->v_rdcnt), 1); 27777c478bd9Sstevel@tonic-gate if (mode & FWRITE) 27787c478bd9Sstevel@tonic-gate atomic_add_32(&((*vpp)->v_wrcnt), 1); 27797c478bd9Sstevel@tonic-gate } 27807c478bd9Sstevel@tonic-gate 2781f48205beScasper VOPXID_MAP_CR(vp, cr); 2782f48205beScasper 27837c478bd9Sstevel@tonic-gate ret = (*(*(vpp))->v_op->vop_open)(vpp, mode, cr); 27847c478bd9Sstevel@tonic-gate 27857c478bd9Sstevel@tonic-gate if (ret) { 27867c478bd9Sstevel@tonic-gate /* 27877c478bd9Sstevel@tonic-gate * Use the saved vp just in case the vnode ptr got trashed 27887c478bd9Sstevel@tonic-gate * by the error. 27897c478bd9Sstevel@tonic-gate */ 27902bb1cb30Sbmc VOPSTATS_UPDATE(vp, open); 27917c478bd9Sstevel@tonic-gate if ((vp->v_type == VREG) && (mode & FREAD)) 27927c478bd9Sstevel@tonic-gate atomic_add_32(&(vp->v_rdcnt), -1); 27937c478bd9Sstevel@tonic-gate if ((vp->v_type == VREG) && (mode & FWRITE)) 27947c478bd9Sstevel@tonic-gate atomic_add_32(&(vp->v_wrcnt), -1); 27957c478bd9Sstevel@tonic-gate } else { 27967c478bd9Sstevel@tonic-gate /* 27977c478bd9Sstevel@tonic-gate * Some filesystems will return a different vnode, 27987c478bd9Sstevel@tonic-gate * but the same path was still used to open it. 27997c478bd9Sstevel@tonic-gate * So if we do change the vnode and need to 28007c478bd9Sstevel@tonic-gate * copy over the path, do so here, rather than special 28017c478bd9Sstevel@tonic-gate * casing each filesystem. Adjust the vnode counts to 28027c478bd9Sstevel@tonic-gate * reflect the vnode switch. 28037c478bd9Sstevel@tonic-gate */ 28042bb1cb30Sbmc VOPSTATS_UPDATE(*vpp, open); 28057c478bd9Sstevel@tonic-gate if (*vpp != vp && *vpp != NULL) { 28067c478bd9Sstevel@tonic-gate vn_copypath(vp, *vpp); 28077c478bd9Sstevel@tonic-gate if (((*vpp)->v_type == VREG) && (mode & FREAD)) 28087c478bd9Sstevel@tonic-gate atomic_add_32(&((*vpp)->v_rdcnt), 1); 28097c478bd9Sstevel@tonic-gate if ((vp->v_type == VREG) && (mode & FREAD)) 28107c478bd9Sstevel@tonic-gate atomic_add_32(&(vp->v_rdcnt), -1); 28117c478bd9Sstevel@tonic-gate if (((*vpp)->v_type == VREG) && (mode & FWRITE)) 28127c478bd9Sstevel@tonic-gate atomic_add_32(&((*vpp)->v_wrcnt), 1); 28137c478bd9Sstevel@tonic-gate if ((vp->v_type == VREG) && (mode & FWRITE)) 28147c478bd9Sstevel@tonic-gate atomic_add_32(&(vp->v_wrcnt), -1); 28157c478bd9Sstevel@tonic-gate } 28167c478bd9Sstevel@tonic-gate } 28177c478bd9Sstevel@tonic-gate VN_RELE(vp); 28187c478bd9Sstevel@tonic-gate return (ret); 28197c478bd9Sstevel@tonic-gate } 28207c478bd9Sstevel@tonic-gate 28217c478bd9Sstevel@tonic-gate int 28227c478bd9Sstevel@tonic-gate fop_close( 28237c478bd9Sstevel@tonic-gate vnode_t *vp, 28247c478bd9Sstevel@tonic-gate int flag, 28257c478bd9Sstevel@tonic-gate int count, 28267c478bd9Sstevel@tonic-gate offset_t offset, 28277c478bd9Sstevel@tonic-gate cred_t *cr) 28287c478bd9Sstevel@tonic-gate { 28295a59a8b3Srsb int err; 28305a59a8b3Srsb 2831f48205beScasper VOPXID_MAP_CR(vp, cr); 2832f48205beScasper 28335a59a8b3Srsb err = (*(vp)->v_op->vop_close)(vp, flag, count, offset, cr); 28342bb1cb30Sbmc VOPSTATS_UPDATE(vp, close); 28357c478bd9Sstevel@tonic-gate /* 28367c478bd9Sstevel@tonic-gate * Check passed in count to handle possible dups. Vnode counts are only 28377c478bd9Sstevel@tonic-gate * kept on regular files 28387c478bd9Sstevel@tonic-gate */ 28397c478bd9Sstevel@tonic-gate if ((vp->v_type == VREG) && (count == 1)) { 28407c478bd9Sstevel@tonic-gate if (flag & FREAD) { 28417c478bd9Sstevel@tonic-gate ASSERT(vp->v_rdcnt > 0); 28427c478bd9Sstevel@tonic-gate atomic_add_32(&(vp->v_rdcnt), -1); 28437c478bd9Sstevel@tonic-gate } 28447c478bd9Sstevel@tonic-gate if (flag & FWRITE) { 28457c478bd9Sstevel@tonic-gate ASSERT(vp->v_wrcnt > 0); 28467c478bd9Sstevel@tonic-gate atomic_add_32(&(vp->v_wrcnt), -1); 28477c478bd9Sstevel@tonic-gate } 28487c478bd9Sstevel@tonic-gate } 28495a59a8b3Srsb return (err); 28507c478bd9Sstevel@tonic-gate } 28517c478bd9Sstevel@tonic-gate 28527c478bd9Sstevel@tonic-gate int 28537c478bd9Sstevel@tonic-gate fop_read( 28547c478bd9Sstevel@tonic-gate vnode_t *vp, 28557c478bd9Sstevel@tonic-gate uio_t *uiop, 28567c478bd9Sstevel@tonic-gate int ioflag, 28577c478bd9Sstevel@tonic-gate cred_t *cr, 28587c478bd9Sstevel@tonic-gate struct caller_context *ct) 28597c478bd9Sstevel@tonic-gate { 28605a59a8b3Srsb int err; 28615a59a8b3Srsb ssize_t resid_start = uiop->uio_resid; 28625a59a8b3Srsb 2863f48205beScasper VOPXID_MAP_CR(vp, cr); 2864f48205beScasper 28655a59a8b3Srsb err = (*(vp)->v_op->vop_read)(vp, uiop, ioflag, cr, ct); 28662bb1cb30Sbmc VOPSTATS_UPDATE_IO(vp, read, 28675a59a8b3Srsb read_bytes, (resid_start - uiop->uio_resid)); 28685a59a8b3Srsb return (err); 28697c478bd9Sstevel@tonic-gate } 28707c478bd9Sstevel@tonic-gate 28717c478bd9Sstevel@tonic-gate int 28727c478bd9Sstevel@tonic-gate fop_write( 28737c478bd9Sstevel@tonic-gate vnode_t *vp, 28747c478bd9Sstevel@tonic-gate uio_t *uiop, 28757c478bd9Sstevel@tonic-gate int ioflag, 28767c478bd9Sstevel@tonic-gate cred_t *cr, 28777c478bd9Sstevel@tonic-gate struct caller_context *ct) 28787c478bd9Sstevel@tonic-gate { 28795a59a8b3Srsb int err; 28805a59a8b3Srsb ssize_t resid_start = uiop->uio_resid; 28815a59a8b3Srsb 2882f48205beScasper VOPXID_MAP_CR(vp, cr); 2883f48205beScasper 28845a59a8b3Srsb err = (*(vp)->v_op->vop_write)(vp, uiop, ioflag, cr, ct); 28852bb1cb30Sbmc VOPSTATS_UPDATE_IO(vp, write, 28865a59a8b3Srsb write_bytes, (resid_start - uiop->uio_resid)); 28875a59a8b3Srsb return (err); 28887c478bd9Sstevel@tonic-gate } 28897c478bd9Sstevel@tonic-gate 28907c478bd9Sstevel@tonic-gate int 28917c478bd9Sstevel@tonic-gate fop_ioctl( 28927c478bd9Sstevel@tonic-gate vnode_t *vp, 28937c478bd9Sstevel@tonic-gate int cmd, 28947c478bd9Sstevel@tonic-gate intptr_t arg, 28957c478bd9Sstevel@tonic-gate int flag, 28967c478bd9Sstevel@tonic-gate cred_t *cr, 28977c478bd9Sstevel@tonic-gate int *rvalp) 28987c478bd9Sstevel@tonic-gate { 28995a59a8b3Srsb int err; 29005a59a8b3Srsb 2901f48205beScasper VOPXID_MAP_CR(vp, cr); 2902f48205beScasper 29035a59a8b3Srsb err = (*(vp)->v_op->vop_ioctl)(vp, cmd, arg, flag, cr, rvalp); 29042bb1cb30Sbmc VOPSTATS_UPDATE(vp, ioctl); 29055a59a8b3Srsb return (err); 29067c478bd9Sstevel@tonic-gate } 29077c478bd9Sstevel@tonic-gate 29087c478bd9Sstevel@tonic-gate int 29097c478bd9Sstevel@tonic-gate fop_setfl( 29107c478bd9Sstevel@tonic-gate vnode_t *vp, 29117c478bd9Sstevel@tonic-gate int oflags, 29127c478bd9Sstevel@tonic-gate int nflags, 29137c478bd9Sstevel@tonic-gate cred_t *cr) 29147c478bd9Sstevel@tonic-gate { 29155a59a8b3Srsb int err; 29165a59a8b3Srsb 2917f48205beScasper VOPXID_MAP_CR(vp, cr); 2918f48205beScasper 29195a59a8b3Srsb err = (*(vp)->v_op->vop_setfl)(vp, oflags, nflags, cr); 29202bb1cb30Sbmc VOPSTATS_UPDATE(vp, setfl); 29215a59a8b3Srsb return (err); 29227c478bd9Sstevel@tonic-gate } 29237c478bd9Sstevel@tonic-gate 29247c478bd9Sstevel@tonic-gate int 29257c478bd9Sstevel@tonic-gate fop_getattr( 29267c478bd9Sstevel@tonic-gate vnode_t *vp, 29277c478bd9Sstevel@tonic-gate vattr_t *vap, 29287c478bd9Sstevel@tonic-gate int flags, 29297c478bd9Sstevel@tonic-gate cred_t *cr) 29307c478bd9Sstevel@tonic-gate { 29315a59a8b3Srsb int err; 29325a59a8b3Srsb 2933f48205beScasper VOPXID_MAP_CR(vp, cr); 2934f48205beScasper 29355a59a8b3Srsb err = (*(vp)->v_op->vop_getattr)(vp, vap, flags, cr); 29362bb1cb30Sbmc VOPSTATS_UPDATE(vp, getattr); 29375a59a8b3Srsb return (err); 29387c478bd9Sstevel@tonic-gate } 29397c478bd9Sstevel@tonic-gate 29407c478bd9Sstevel@tonic-gate int 29417c478bd9Sstevel@tonic-gate fop_setattr( 29427c478bd9Sstevel@tonic-gate vnode_t *vp, 29437c478bd9Sstevel@tonic-gate vattr_t *vap, 29447c478bd9Sstevel@tonic-gate int flags, 29457c478bd9Sstevel@tonic-gate cred_t *cr, 29467c478bd9Sstevel@tonic-gate caller_context_t *ct) 29477c478bd9Sstevel@tonic-gate { 29485a59a8b3Srsb int err; 29495a59a8b3Srsb 2950f48205beScasper VOPXID_MAP_CR(vp, cr); 2951f48205beScasper 29525a59a8b3Srsb err = (*(vp)->v_op->vop_setattr)(vp, vap, flags, cr, ct); 29532bb1cb30Sbmc VOPSTATS_UPDATE(vp, setattr); 29545a59a8b3Srsb return (err); 29557c478bd9Sstevel@tonic-gate } 29567c478bd9Sstevel@tonic-gate 29577c478bd9Sstevel@tonic-gate int 29587c478bd9Sstevel@tonic-gate fop_access( 29597c478bd9Sstevel@tonic-gate vnode_t *vp, 29607c478bd9Sstevel@tonic-gate int mode, 29617c478bd9Sstevel@tonic-gate int flags, 29627c478bd9Sstevel@tonic-gate cred_t *cr) 29637c478bd9Sstevel@tonic-gate { 29645a59a8b3Srsb int err; 29655a59a8b3Srsb 2966f48205beScasper VOPXID_MAP_CR(vp, cr); 2967f48205beScasper 29685a59a8b3Srsb err = (*(vp)->v_op->vop_access)(vp, mode, flags, cr); 29692bb1cb30Sbmc VOPSTATS_UPDATE(vp, access); 29705a59a8b3Srsb return (err); 29717c478bd9Sstevel@tonic-gate } 29727c478bd9Sstevel@tonic-gate 29737c478bd9Sstevel@tonic-gate int 29747c478bd9Sstevel@tonic-gate fop_lookup( 29757c478bd9Sstevel@tonic-gate vnode_t *dvp, 29767c478bd9Sstevel@tonic-gate char *nm, 29777c478bd9Sstevel@tonic-gate vnode_t **vpp, 29787c478bd9Sstevel@tonic-gate pathname_t *pnp, 29797c478bd9Sstevel@tonic-gate int flags, 29807c478bd9Sstevel@tonic-gate vnode_t *rdir, 29817c478bd9Sstevel@tonic-gate cred_t *cr) 29827c478bd9Sstevel@tonic-gate { 2983ca2c3138Seschrock int ret; 2984ca2c3138Seschrock 2985f48205beScasper VOPXID_MAP_CR(dvp, cr); 2986f48205beScasper 2987ca2c3138Seschrock ret = (*(dvp)->v_op->vop_lookup)(dvp, nm, vpp, pnp, flags, rdir, cr); 29885a59a8b3Srsb if (ret == 0 && *vpp) { 29892bb1cb30Sbmc VOPSTATS_UPDATE(*vpp, lookup); 29905a59a8b3Srsb if ((*vpp)->v_path == NULL) { 2991ca2c3138Seschrock vn_setpath(rootdir, dvp, *vpp, nm, strlen(nm)); 29925a59a8b3Srsb } 29935a59a8b3Srsb } 2994ca2c3138Seschrock 2995ca2c3138Seschrock return (ret); 29967c478bd9Sstevel@tonic-gate } 29977c478bd9Sstevel@tonic-gate 29987c478bd9Sstevel@tonic-gate int 29997c478bd9Sstevel@tonic-gate fop_create( 30007c478bd9Sstevel@tonic-gate vnode_t *dvp, 30017c478bd9Sstevel@tonic-gate char *name, 30027c478bd9Sstevel@tonic-gate vattr_t *vap, 30037c478bd9Sstevel@tonic-gate vcexcl_t excl, 30047c478bd9Sstevel@tonic-gate int mode, 30057c478bd9Sstevel@tonic-gate vnode_t **vpp, 30067c478bd9Sstevel@tonic-gate cred_t *cr, 30077c478bd9Sstevel@tonic-gate int flag) 30087c478bd9Sstevel@tonic-gate { 30097c478bd9Sstevel@tonic-gate int ret; 30107c478bd9Sstevel@tonic-gate 3011f48205beScasper VOPXID_MAP_CR(dvp, cr); 3012f48205beScasper 30137c478bd9Sstevel@tonic-gate ret = (*(dvp)->v_op->vop_create) 30147c478bd9Sstevel@tonic-gate (dvp, name, vap, excl, mode, vpp, cr, flag); 30155a59a8b3Srsb if (ret == 0 && *vpp) { 30162bb1cb30Sbmc VOPSTATS_UPDATE(*vpp, create); 30175a59a8b3Srsb if ((*vpp)->v_path == NULL) { 3018ca2c3138Seschrock vn_setpath(rootdir, dvp, *vpp, name, strlen(name)); 30195a59a8b3Srsb } 30205a59a8b3Srsb } 30217c478bd9Sstevel@tonic-gate 30227c478bd9Sstevel@tonic-gate return (ret); 30237c478bd9Sstevel@tonic-gate } 30247c478bd9Sstevel@tonic-gate 30257c478bd9Sstevel@tonic-gate int 30267c478bd9Sstevel@tonic-gate fop_remove( 30277c478bd9Sstevel@tonic-gate vnode_t *dvp, 30287c478bd9Sstevel@tonic-gate char *nm, 30297c478bd9Sstevel@tonic-gate cred_t *cr) 30307c478bd9Sstevel@tonic-gate { 30315a59a8b3Srsb int err; 30325a59a8b3Srsb 3033f48205beScasper VOPXID_MAP_CR(dvp, cr); 3034f48205beScasper 30355a59a8b3Srsb err = (*(dvp)->v_op->vop_remove)(dvp, nm, cr); 30362bb1cb30Sbmc VOPSTATS_UPDATE(dvp, remove); 30375a59a8b3Srsb return (err); 30387c478bd9Sstevel@tonic-gate } 30397c478bd9Sstevel@tonic-gate 30407c478bd9Sstevel@tonic-gate int 30417c478bd9Sstevel@tonic-gate fop_link( 30427c478bd9Sstevel@tonic-gate vnode_t *tdvp, 30437c478bd9Sstevel@tonic-gate vnode_t *svp, 30447c478bd9Sstevel@tonic-gate char *tnm, 30457c478bd9Sstevel@tonic-gate cred_t *cr) 30467c478bd9Sstevel@tonic-gate { 30475a59a8b3Srsb int err; 30485a59a8b3Srsb 3049f48205beScasper VOPXID_MAP_CR(tdvp, cr); 3050f48205beScasper 30515a59a8b3Srsb err = (*(tdvp)->v_op->vop_link)(tdvp, svp, tnm, cr); 30522bb1cb30Sbmc VOPSTATS_UPDATE(tdvp, link); 30535a59a8b3Srsb return (err); 30547c478bd9Sstevel@tonic-gate } 30557c478bd9Sstevel@tonic-gate 30567c478bd9Sstevel@tonic-gate int 30577c478bd9Sstevel@tonic-gate fop_rename( 30587c478bd9Sstevel@tonic-gate vnode_t *sdvp, 30597c478bd9Sstevel@tonic-gate char *snm, 30607c478bd9Sstevel@tonic-gate vnode_t *tdvp, 30617c478bd9Sstevel@tonic-gate char *tnm, 30627c478bd9Sstevel@tonic-gate cred_t *cr) 30637c478bd9Sstevel@tonic-gate { 30645a59a8b3Srsb int err; 30655a59a8b3Srsb 3066f48205beScasper VOPXID_MAP_CR(tdvp, cr); 3067f48205beScasper 30685a59a8b3Srsb err = (*(sdvp)->v_op->vop_rename)(sdvp, snm, tdvp, tnm, cr); 30692bb1cb30Sbmc VOPSTATS_UPDATE(sdvp, rename); 30705a59a8b3Srsb return (err); 30717c478bd9Sstevel@tonic-gate } 30727c478bd9Sstevel@tonic-gate 30737c478bd9Sstevel@tonic-gate int 30747c478bd9Sstevel@tonic-gate fop_mkdir( 30757c478bd9Sstevel@tonic-gate vnode_t *dvp, 30767c478bd9Sstevel@tonic-gate char *dirname, 30777c478bd9Sstevel@tonic-gate vattr_t *vap, 30787c478bd9Sstevel@tonic-gate vnode_t **vpp, 30797c478bd9Sstevel@tonic-gate cred_t *cr) 30807c478bd9Sstevel@tonic-gate { 30817c478bd9Sstevel@tonic-gate int ret; 30827c478bd9Sstevel@tonic-gate 3083f48205beScasper VOPXID_MAP_CR(dvp, cr); 3084f48205beScasper 30857c478bd9Sstevel@tonic-gate ret = (*(dvp)->v_op->vop_mkdir)(dvp, dirname, vap, vpp, cr); 30865a59a8b3Srsb if (ret == 0 && *vpp) { 30872bb1cb30Sbmc VOPSTATS_UPDATE(*vpp, mkdir); 30885a59a8b3Srsb if ((*vpp)->v_path == NULL) { 30895a59a8b3Srsb vn_setpath(rootdir, dvp, *vpp, dirname, 30905a59a8b3Srsb strlen(dirname)); 30915a59a8b3Srsb } 30925a59a8b3Srsb } 30937c478bd9Sstevel@tonic-gate 30947c478bd9Sstevel@tonic-gate return (ret); 30957c478bd9Sstevel@tonic-gate } 30967c478bd9Sstevel@tonic-gate 30977c478bd9Sstevel@tonic-gate int 30987c478bd9Sstevel@tonic-gate fop_rmdir( 30997c478bd9Sstevel@tonic-gate vnode_t *dvp, 31007c478bd9Sstevel@tonic-gate char *nm, 31017c478bd9Sstevel@tonic-gate vnode_t *cdir, 31027c478bd9Sstevel@tonic-gate cred_t *cr) 31037c478bd9Sstevel@tonic-gate { 31045a59a8b3Srsb int err; 31055a59a8b3Srsb 3106f48205beScasper VOPXID_MAP_CR(dvp, cr); 3107f48205beScasper 31085a59a8b3Srsb err = (*(dvp)->v_op->vop_rmdir)(dvp, nm, cdir, cr); 31092bb1cb30Sbmc VOPSTATS_UPDATE(dvp, rmdir); 31105a59a8b3Srsb return (err); 31117c478bd9Sstevel@tonic-gate } 31127c478bd9Sstevel@tonic-gate 31137c478bd9Sstevel@tonic-gate int 31147c478bd9Sstevel@tonic-gate fop_readdir( 31157c478bd9Sstevel@tonic-gate vnode_t *vp, 31167c478bd9Sstevel@tonic-gate uio_t *uiop, 31177c478bd9Sstevel@tonic-gate cred_t *cr, 31187c478bd9Sstevel@tonic-gate int *eofp) 31197c478bd9Sstevel@tonic-gate { 31205a59a8b3Srsb int err; 31215a59a8b3Srsb ssize_t resid_start = uiop->uio_resid; 31225a59a8b3Srsb 3123f48205beScasper VOPXID_MAP_CR(vp, cr); 3124f48205beScasper 31255a59a8b3Srsb err = (*(vp)->v_op->vop_readdir)(vp, uiop, cr, eofp); 31262bb1cb30Sbmc VOPSTATS_UPDATE_IO(vp, readdir, 31275a59a8b3Srsb readdir_bytes, (resid_start - uiop->uio_resid)); 31285a59a8b3Srsb return (err); 31297c478bd9Sstevel@tonic-gate } 31307c478bd9Sstevel@tonic-gate 31317c478bd9Sstevel@tonic-gate int 31327c478bd9Sstevel@tonic-gate fop_symlink( 31337c478bd9Sstevel@tonic-gate vnode_t *dvp, 31347c478bd9Sstevel@tonic-gate char *linkname, 31357c478bd9Sstevel@tonic-gate vattr_t *vap, 31367c478bd9Sstevel@tonic-gate char *target, 31377c478bd9Sstevel@tonic-gate cred_t *cr) 31387c478bd9Sstevel@tonic-gate { 31395a59a8b3Srsb int err; 31405a59a8b3Srsb 3141f48205beScasper VOPXID_MAP_CR(dvp, cr); 3142f48205beScasper 31435a59a8b3Srsb err = (*(dvp)->v_op->vop_symlink) (dvp, linkname, vap, target, cr); 31442bb1cb30Sbmc VOPSTATS_UPDATE(dvp, symlink); 31455a59a8b3Srsb return (err); 31467c478bd9Sstevel@tonic-gate } 31477c478bd9Sstevel@tonic-gate 31487c478bd9Sstevel@tonic-gate int 31497c478bd9Sstevel@tonic-gate fop_readlink( 31507c478bd9Sstevel@tonic-gate vnode_t *vp, 31517c478bd9Sstevel@tonic-gate uio_t *uiop, 31527c478bd9Sstevel@tonic-gate cred_t *cr) 31537c478bd9Sstevel@tonic-gate { 31545a59a8b3Srsb int err; 31555a59a8b3Srsb 3156f48205beScasper VOPXID_MAP_CR(vp, cr); 3157f48205beScasper 31585a59a8b3Srsb err = (*(vp)->v_op->vop_readlink)(vp, uiop, cr); 31592bb1cb30Sbmc VOPSTATS_UPDATE(vp, readlink); 31605a59a8b3Srsb return (err); 31617c478bd9Sstevel@tonic-gate } 31627c478bd9Sstevel@tonic-gate 31637c478bd9Sstevel@tonic-gate int 31647c478bd9Sstevel@tonic-gate fop_fsync( 31657c478bd9Sstevel@tonic-gate vnode_t *vp, 31667c478bd9Sstevel@tonic-gate int syncflag, 31677c478bd9Sstevel@tonic-gate cred_t *cr) 31687c478bd9Sstevel@tonic-gate { 31695a59a8b3Srsb int err; 31705a59a8b3Srsb 3171f48205beScasper VOPXID_MAP_CR(vp, cr); 3172f48205beScasper 31735a59a8b3Srsb err = (*(vp)->v_op->vop_fsync)(vp, syncflag, cr); 31742bb1cb30Sbmc VOPSTATS_UPDATE(vp, fsync); 31755a59a8b3Srsb return (err); 31767c478bd9Sstevel@tonic-gate } 31777c478bd9Sstevel@tonic-gate 31787c478bd9Sstevel@tonic-gate void 31797c478bd9Sstevel@tonic-gate fop_inactive( 31807c478bd9Sstevel@tonic-gate vnode_t *vp, 31817c478bd9Sstevel@tonic-gate cred_t *cr) 31827c478bd9Sstevel@tonic-gate { 31835a59a8b3Srsb /* Need to update stats before vop call since we may lose the vnode */ 31842bb1cb30Sbmc VOPSTATS_UPDATE(vp, inactive); 3185f48205beScasper 3186f48205beScasper VOPXID_MAP_CR(vp, cr); 3187f48205beScasper 31887c478bd9Sstevel@tonic-gate (*(vp)->v_op->vop_inactive)(vp, cr); 31897c478bd9Sstevel@tonic-gate } 31907c478bd9Sstevel@tonic-gate 31917c478bd9Sstevel@tonic-gate int 31927c478bd9Sstevel@tonic-gate fop_fid( 31937c478bd9Sstevel@tonic-gate vnode_t *vp, 31947c478bd9Sstevel@tonic-gate fid_t *fidp) 31957c478bd9Sstevel@tonic-gate { 31965a59a8b3Srsb int err; 31975a59a8b3Srsb 31985a59a8b3Srsb err = (*(vp)->v_op->vop_fid)(vp, fidp); 31992bb1cb30Sbmc VOPSTATS_UPDATE(vp, fid); 32005a59a8b3Srsb return (err); 32017c478bd9Sstevel@tonic-gate } 32027c478bd9Sstevel@tonic-gate 32037c478bd9Sstevel@tonic-gate int 32047c478bd9Sstevel@tonic-gate fop_rwlock( 32057c478bd9Sstevel@tonic-gate vnode_t *vp, 32067c478bd9Sstevel@tonic-gate int write_lock, 32077c478bd9Sstevel@tonic-gate caller_context_t *ct) 32087c478bd9Sstevel@tonic-gate { 32095a59a8b3Srsb int ret; 32105a59a8b3Srsb 32115a59a8b3Srsb ret = ((*(vp)->v_op->vop_rwlock)(vp, write_lock, ct)); 32122bb1cb30Sbmc VOPSTATS_UPDATE(vp, rwlock); 32135a59a8b3Srsb return (ret); 32147c478bd9Sstevel@tonic-gate } 32157c478bd9Sstevel@tonic-gate 32167c478bd9Sstevel@tonic-gate void 32177c478bd9Sstevel@tonic-gate fop_rwunlock( 32187c478bd9Sstevel@tonic-gate vnode_t *vp, 32197c478bd9Sstevel@tonic-gate int write_lock, 32207c478bd9Sstevel@tonic-gate caller_context_t *ct) 32217c478bd9Sstevel@tonic-gate { 32227c478bd9Sstevel@tonic-gate (*(vp)->v_op->vop_rwunlock)(vp, write_lock, ct); 32232bb1cb30Sbmc VOPSTATS_UPDATE(vp, rwunlock); 32247c478bd9Sstevel@tonic-gate } 32257c478bd9Sstevel@tonic-gate 32267c478bd9Sstevel@tonic-gate int 32277c478bd9Sstevel@tonic-gate fop_seek( 32287c478bd9Sstevel@tonic-gate vnode_t *vp, 32297c478bd9Sstevel@tonic-gate offset_t ooff, 32307c478bd9Sstevel@tonic-gate offset_t *noffp) 32317c478bd9Sstevel@tonic-gate { 32325a59a8b3Srsb int err; 32335a59a8b3Srsb 32345a59a8b3Srsb err = (*(vp)->v_op->vop_seek)(vp, ooff, noffp); 32352bb1cb30Sbmc VOPSTATS_UPDATE(vp, seek); 32365a59a8b3Srsb return (err); 32377c478bd9Sstevel@tonic-gate } 32387c478bd9Sstevel@tonic-gate 32397c478bd9Sstevel@tonic-gate int 32407c478bd9Sstevel@tonic-gate fop_cmp( 32417c478bd9Sstevel@tonic-gate vnode_t *vp1, 32427c478bd9Sstevel@tonic-gate vnode_t *vp2) 32437c478bd9Sstevel@tonic-gate { 32445a59a8b3Srsb int err; 32455a59a8b3Srsb 32465a59a8b3Srsb err = (*(vp1)->v_op->vop_cmp)(vp1, vp2); 32472bb1cb30Sbmc VOPSTATS_UPDATE(vp1, cmp); 32485a59a8b3Srsb return (err); 32497c478bd9Sstevel@tonic-gate } 32507c478bd9Sstevel@tonic-gate 32517c478bd9Sstevel@tonic-gate int 32527c478bd9Sstevel@tonic-gate fop_frlock( 32537c478bd9Sstevel@tonic-gate vnode_t *vp, 32547c478bd9Sstevel@tonic-gate int cmd, 32557c478bd9Sstevel@tonic-gate flock64_t *bfp, 32567c478bd9Sstevel@tonic-gate int flag, 32577c478bd9Sstevel@tonic-gate offset_t offset, 32587c478bd9Sstevel@tonic-gate struct flk_callback *flk_cbp, 32597c478bd9Sstevel@tonic-gate cred_t *cr) 32607c478bd9Sstevel@tonic-gate { 32615a59a8b3Srsb int err; 32625a59a8b3Srsb 3263f48205beScasper VOPXID_MAP_CR(vp, cr); 3264f48205beScasper 32655a59a8b3Srsb err = (*(vp)->v_op->vop_frlock) 32667c478bd9Sstevel@tonic-gate (vp, cmd, bfp, flag, offset, flk_cbp, cr); 32672bb1cb30Sbmc VOPSTATS_UPDATE(vp, frlock); 32685a59a8b3Srsb return (err); 32697c478bd9Sstevel@tonic-gate } 32707c478bd9Sstevel@tonic-gate 32717c478bd9Sstevel@tonic-gate int 32727c478bd9Sstevel@tonic-gate fop_space( 32737c478bd9Sstevel@tonic-gate vnode_t *vp, 32747c478bd9Sstevel@tonic-gate int cmd, 32757c478bd9Sstevel@tonic-gate flock64_t *bfp, 32767c478bd9Sstevel@tonic-gate int flag, 32777c478bd9Sstevel@tonic-gate offset_t offset, 32787c478bd9Sstevel@tonic-gate cred_t *cr, 32797c478bd9Sstevel@tonic-gate caller_context_t *ct) 32807c478bd9Sstevel@tonic-gate { 32815a59a8b3Srsb int err; 32825a59a8b3Srsb 3283f48205beScasper VOPXID_MAP_CR(vp, cr); 3284f48205beScasper 32855a59a8b3Srsb err = (*(vp)->v_op->vop_space)(vp, cmd, bfp, flag, offset, cr, ct); 32862bb1cb30Sbmc VOPSTATS_UPDATE(vp, space); 32875a59a8b3Srsb return (err); 32887c478bd9Sstevel@tonic-gate } 32897c478bd9Sstevel@tonic-gate 32907c478bd9Sstevel@tonic-gate int 32917c478bd9Sstevel@tonic-gate fop_realvp( 32927c478bd9Sstevel@tonic-gate vnode_t *vp, 32937c478bd9Sstevel@tonic-gate vnode_t **vpp) 32947c478bd9Sstevel@tonic-gate { 32955a59a8b3Srsb int err; 32965a59a8b3Srsb 32975a59a8b3Srsb err = (*(vp)->v_op->vop_realvp)(vp, vpp); 32982bb1cb30Sbmc VOPSTATS_UPDATE(vp, realvp); 32995a59a8b3Srsb return (err); 33007c478bd9Sstevel@tonic-gate } 33017c478bd9Sstevel@tonic-gate 33027c478bd9Sstevel@tonic-gate int 33037c478bd9Sstevel@tonic-gate fop_getpage( 33047c478bd9Sstevel@tonic-gate vnode_t *vp, 33057c478bd9Sstevel@tonic-gate offset_t off, 33067c478bd9Sstevel@tonic-gate size_t len, 33077c478bd9Sstevel@tonic-gate uint_t *protp, 33087c478bd9Sstevel@tonic-gate page_t **plarr, 33097c478bd9Sstevel@tonic-gate size_t plsz, 33107c478bd9Sstevel@tonic-gate struct seg *seg, 33117c478bd9Sstevel@tonic-gate caddr_t addr, 33127c478bd9Sstevel@tonic-gate enum seg_rw rw, 33137c478bd9Sstevel@tonic-gate cred_t *cr) 33147c478bd9Sstevel@tonic-gate { 33155a59a8b3Srsb int err; 33165a59a8b3Srsb 3317f48205beScasper VOPXID_MAP_CR(vp, cr); 3318f48205beScasper 33195a59a8b3Srsb err = (*(vp)->v_op->vop_getpage) 33207c478bd9Sstevel@tonic-gate (vp, off, len, protp, plarr, plsz, seg, addr, rw, cr); 33212bb1cb30Sbmc VOPSTATS_UPDATE(vp, getpage); 33225a59a8b3Srsb return (err); 33237c478bd9Sstevel@tonic-gate } 33247c478bd9Sstevel@tonic-gate 33257c478bd9Sstevel@tonic-gate int 33267c478bd9Sstevel@tonic-gate fop_putpage( 33277c478bd9Sstevel@tonic-gate vnode_t *vp, 33287c478bd9Sstevel@tonic-gate offset_t off, 33297c478bd9Sstevel@tonic-gate size_t len, 33307c478bd9Sstevel@tonic-gate int flags, 33317c478bd9Sstevel@tonic-gate cred_t *cr) 33327c478bd9Sstevel@tonic-gate { 33335a59a8b3Srsb int err; 33345a59a8b3Srsb 3335f48205beScasper VOPXID_MAP_CR(vp, cr); 3336f48205beScasper 33375a59a8b3Srsb err = (*(vp)->v_op->vop_putpage)(vp, off, len, flags, cr); 33382bb1cb30Sbmc VOPSTATS_UPDATE(vp, putpage); 33395a59a8b3Srsb return (err); 33407c478bd9Sstevel@tonic-gate } 33417c478bd9Sstevel@tonic-gate 33427c478bd9Sstevel@tonic-gate int 33437c478bd9Sstevel@tonic-gate fop_map( 33447c478bd9Sstevel@tonic-gate vnode_t *vp, 33457c478bd9Sstevel@tonic-gate offset_t off, 33467c478bd9Sstevel@tonic-gate struct as *as, 33477c478bd9Sstevel@tonic-gate caddr_t *addrp, 33487c478bd9Sstevel@tonic-gate size_t len, 33497c478bd9Sstevel@tonic-gate uchar_t prot, 33507c478bd9Sstevel@tonic-gate uchar_t maxprot, 33517c478bd9Sstevel@tonic-gate uint_t flags, 33527c478bd9Sstevel@tonic-gate cred_t *cr) 33537c478bd9Sstevel@tonic-gate { 33545a59a8b3Srsb int err; 33555a59a8b3Srsb 3356f48205beScasper VOPXID_MAP_CR(vp, cr); 3357f48205beScasper 33585a59a8b3Srsb err = (*(vp)->v_op->vop_map) 33597c478bd9Sstevel@tonic-gate (vp, off, as, addrp, len, prot, maxprot, flags, cr); 33602bb1cb30Sbmc VOPSTATS_UPDATE(vp, map); 33615a59a8b3Srsb return (err); 33627c478bd9Sstevel@tonic-gate } 33637c478bd9Sstevel@tonic-gate 33647c478bd9Sstevel@tonic-gate int 33657c478bd9Sstevel@tonic-gate fop_addmap( 33667c478bd9Sstevel@tonic-gate vnode_t *vp, 33677c478bd9Sstevel@tonic-gate offset_t off, 33687c478bd9Sstevel@tonic-gate struct as *as, 33697c478bd9Sstevel@tonic-gate caddr_t addr, 33707c478bd9Sstevel@tonic-gate size_t len, 33717c478bd9Sstevel@tonic-gate uchar_t prot, 33727c478bd9Sstevel@tonic-gate uchar_t maxprot, 33737c478bd9Sstevel@tonic-gate uint_t flags, 33747c478bd9Sstevel@tonic-gate cred_t *cr) 33757c478bd9Sstevel@tonic-gate { 33767c478bd9Sstevel@tonic-gate int error; 33777c478bd9Sstevel@tonic-gate u_longlong_t delta; 33787c478bd9Sstevel@tonic-gate 3379f48205beScasper VOPXID_MAP_CR(vp, cr); 3380f48205beScasper 33817c478bd9Sstevel@tonic-gate error = (*(vp)->v_op->vop_addmap) 33827c478bd9Sstevel@tonic-gate (vp, off, as, addr, len, prot, maxprot, flags, cr); 33837c478bd9Sstevel@tonic-gate 33847c478bd9Sstevel@tonic-gate if ((!error) && (vp->v_type == VREG)) { 33857c478bd9Sstevel@tonic-gate delta = (u_longlong_t)btopr(len); 33867c478bd9Sstevel@tonic-gate /* 33877c478bd9Sstevel@tonic-gate * If file is declared MAP_PRIVATE, it can't be written back 33887c478bd9Sstevel@tonic-gate * even if open for write. Handle as read. 33897c478bd9Sstevel@tonic-gate */ 33907c478bd9Sstevel@tonic-gate if (flags & MAP_PRIVATE) { 33917c478bd9Sstevel@tonic-gate atomic_add_64((uint64_t *)(&(vp->v_mmap_read)), 33927c478bd9Sstevel@tonic-gate (int64_t)delta); 33937c478bd9Sstevel@tonic-gate } else { 33947c478bd9Sstevel@tonic-gate /* 33957c478bd9Sstevel@tonic-gate * atomic_add_64 forces the fetch of a 64 bit value to 33967c478bd9Sstevel@tonic-gate * be atomic on 32 bit machines 33977c478bd9Sstevel@tonic-gate */ 33987c478bd9Sstevel@tonic-gate if (maxprot & PROT_WRITE) 33997c478bd9Sstevel@tonic-gate atomic_add_64((uint64_t *)(&(vp->v_mmap_write)), 34007c478bd9Sstevel@tonic-gate (int64_t)delta); 34017c478bd9Sstevel@tonic-gate if (maxprot & PROT_READ) 34027c478bd9Sstevel@tonic-gate atomic_add_64((uint64_t *)(&(vp->v_mmap_read)), 34037c478bd9Sstevel@tonic-gate (int64_t)delta); 34047c478bd9Sstevel@tonic-gate if (maxprot & PROT_EXEC) 34057c478bd9Sstevel@tonic-gate atomic_add_64((uint64_t *)(&(vp->v_mmap_read)), 34067c478bd9Sstevel@tonic-gate (int64_t)delta); 34077c478bd9Sstevel@tonic-gate } 34087c478bd9Sstevel@tonic-gate } 34092bb1cb30Sbmc VOPSTATS_UPDATE(vp, addmap); 34107c478bd9Sstevel@tonic-gate return (error); 34117c478bd9Sstevel@tonic-gate } 34127c478bd9Sstevel@tonic-gate 34137c478bd9Sstevel@tonic-gate int 34147c478bd9Sstevel@tonic-gate fop_delmap( 34157c478bd9Sstevel@tonic-gate vnode_t *vp, 34167c478bd9Sstevel@tonic-gate offset_t off, 34177c478bd9Sstevel@tonic-gate struct as *as, 34187c478bd9Sstevel@tonic-gate caddr_t addr, 34197c478bd9Sstevel@tonic-gate size_t len, 34207c478bd9Sstevel@tonic-gate uint_t prot, 34217c478bd9Sstevel@tonic-gate uint_t maxprot, 34227c478bd9Sstevel@tonic-gate uint_t flags, 34237c478bd9Sstevel@tonic-gate cred_t *cr) 34247c478bd9Sstevel@tonic-gate { 34257c478bd9Sstevel@tonic-gate int error; 34267c478bd9Sstevel@tonic-gate u_longlong_t delta; 3427f48205beScasper 3428f48205beScasper VOPXID_MAP_CR(vp, cr); 3429f48205beScasper 34307c478bd9Sstevel@tonic-gate error = (*(vp)->v_op->vop_delmap) 34317c478bd9Sstevel@tonic-gate (vp, off, as, addr, len, prot, maxprot, flags, cr); 34327c478bd9Sstevel@tonic-gate 34337c478bd9Sstevel@tonic-gate /* 34347c478bd9Sstevel@tonic-gate * NFS calls into delmap twice, the first time 34357c478bd9Sstevel@tonic-gate * it simply establishes a callback mechanism and returns EAGAIN 34367c478bd9Sstevel@tonic-gate * while the real work is being done upon the second invocation. 34377c478bd9Sstevel@tonic-gate * We have to detect this here and only decrement the counts upon 34387c478bd9Sstevel@tonic-gate * the second delmap request. 34397c478bd9Sstevel@tonic-gate */ 34407c478bd9Sstevel@tonic-gate if ((error != EAGAIN) && (vp->v_type == VREG)) { 34417c478bd9Sstevel@tonic-gate 34427c478bd9Sstevel@tonic-gate delta = (u_longlong_t)btopr(len); 34437c478bd9Sstevel@tonic-gate 34447c478bd9Sstevel@tonic-gate if (flags & MAP_PRIVATE) { 34457c478bd9Sstevel@tonic-gate atomic_add_64((uint64_t *)(&(vp->v_mmap_read)), 34467c478bd9Sstevel@tonic-gate (int64_t)(-delta)); 34477c478bd9Sstevel@tonic-gate } else { 34487c478bd9Sstevel@tonic-gate /* 34497c478bd9Sstevel@tonic-gate * atomic_add_64 forces the fetch of a 64 bit value 34507c478bd9Sstevel@tonic-gate * to be atomic on 32 bit machines 34517c478bd9Sstevel@tonic-gate */ 34527c478bd9Sstevel@tonic-gate if (maxprot & PROT_WRITE) 34537c478bd9Sstevel@tonic-gate atomic_add_64((uint64_t *)(&(vp->v_mmap_write)), 34547c478bd9Sstevel@tonic-gate (int64_t)(-delta)); 34557c478bd9Sstevel@tonic-gate if (maxprot & PROT_READ) 34567c478bd9Sstevel@tonic-gate atomic_add_64((uint64_t *)(&(vp->v_mmap_read)), 34577c478bd9Sstevel@tonic-gate (int64_t)(-delta)); 34587c478bd9Sstevel@tonic-gate if (maxprot & PROT_EXEC) 34597c478bd9Sstevel@tonic-gate atomic_add_64((uint64_t *)(&(vp->v_mmap_read)), 34607c478bd9Sstevel@tonic-gate (int64_t)(-delta)); 34617c478bd9Sstevel@tonic-gate } 34627c478bd9Sstevel@tonic-gate } 34632bb1cb30Sbmc VOPSTATS_UPDATE(vp, delmap); 34647c478bd9Sstevel@tonic-gate return (error); 34657c478bd9Sstevel@tonic-gate } 34667c478bd9Sstevel@tonic-gate 34677c478bd9Sstevel@tonic-gate 34687c478bd9Sstevel@tonic-gate int 34697c478bd9Sstevel@tonic-gate fop_poll( 34707c478bd9Sstevel@tonic-gate vnode_t *vp, 34717c478bd9Sstevel@tonic-gate short events, 34727c478bd9Sstevel@tonic-gate int anyyet, 34737c478bd9Sstevel@tonic-gate short *reventsp, 34747c478bd9Sstevel@tonic-gate struct pollhead **phpp) 34757c478bd9Sstevel@tonic-gate { 34765a59a8b3Srsb int err; 34775a59a8b3Srsb 34785a59a8b3Srsb err = (*(vp)->v_op->vop_poll)(vp, events, anyyet, reventsp, phpp); 34792bb1cb30Sbmc VOPSTATS_UPDATE(vp, poll); 34805a59a8b3Srsb return (err); 34817c478bd9Sstevel@tonic-gate } 34827c478bd9Sstevel@tonic-gate 34837c478bd9Sstevel@tonic-gate int 34847c478bd9Sstevel@tonic-gate fop_dump( 34857c478bd9Sstevel@tonic-gate vnode_t *vp, 34867c478bd9Sstevel@tonic-gate caddr_t addr, 34877c478bd9Sstevel@tonic-gate int lbdn, 34887c478bd9Sstevel@tonic-gate int dblks) 34897c478bd9Sstevel@tonic-gate { 34905a59a8b3Srsb int err; 34915a59a8b3Srsb 34925a59a8b3Srsb err = (*(vp)->v_op->vop_dump)(vp, addr, lbdn, dblks); 34932bb1cb30Sbmc VOPSTATS_UPDATE(vp, dump); 34945a59a8b3Srsb return (err); 34957c478bd9Sstevel@tonic-gate } 34967c478bd9Sstevel@tonic-gate 34977c478bd9Sstevel@tonic-gate int 34987c478bd9Sstevel@tonic-gate fop_pathconf( 34997c478bd9Sstevel@tonic-gate vnode_t *vp, 35007c478bd9Sstevel@tonic-gate int cmd, 35017c478bd9Sstevel@tonic-gate ulong_t *valp, 35027c478bd9Sstevel@tonic-gate cred_t *cr) 35037c478bd9Sstevel@tonic-gate { 35045a59a8b3Srsb int err; 35055a59a8b3Srsb 3506f48205beScasper VOPXID_MAP_CR(vp, cr); 3507f48205beScasper 35085a59a8b3Srsb err = (*(vp)->v_op->vop_pathconf)(vp, cmd, valp, cr); 35092bb1cb30Sbmc VOPSTATS_UPDATE(vp, pathconf); 35105a59a8b3Srsb return (err); 35117c478bd9Sstevel@tonic-gate } 35127c478bd9Sstevel@tonic-gate 35137c478bd9Sstevel@tonic-gate int 35147c478bd9Sstevel@tonic-gate fop_pageio( 35157c478bd9Sstevel@tonic-gate vnode_t *vp, 35167c478bd9Sstevel@tonic-gate struct page *pp, 35177c478bd9Sstevel@tonic-gate u_offset_t io_off, 35187c478bd9Sstevel@tonic-gate size_t io_len, 35197c478bd9Sstevel@tonic-gate int flags, 35207c478bd9Sstevel@tonic-gate cred_t *cr) 35217c478bd9Sstevel@tonic-gate { 35225a59a8b3Srsb int err; 35235a59a8b3Srsb 3524f48205beScasper VOPXID_MAP_CR(vp, cr); 3525f48205beScasper 35265a59a8b3Srsb err = (*(vp)->v_op->vop_pageio)(vp, pp, io_off, io_len, flags, cr); 35272bb1cb30Sbmc VOPSTATS_UPDATE(vp, pageio); 35285a59a8b3Srsb return (err); 35297c478bd9Sstevel@tonic-gate } 35307c478bd9Sstevel@tonic-gate 35317c478bd9Sstevel@tonic-gate int 35327c478bd9Sstevel@tonic-gate fop_dumpctl( 35337c478bd9Sstevel@tonic-gate vnode_t *vp, 35347c478bd9Sstevel@tonic-gate int action, 35357c478bd9Sstevel@tonic-gate int *blkp) 35367c478bd9Sstevel@tonic-gate { 35375a59a8b3Srsb int err; 35385a59a8b3Srsb err = (*(vp)->v_op->vop_dumpctl)(vp, action, blkp); 35392bb1cb30Sbmc VOPSTATS_UPDATE(vp, dumpctl); 35405a59a8b3Srsb return (err); 35417c478bd9Sstevel@tonic-gate } 35427c478bd9Sstevel@tonic-gate 35437c478bd9Sstevel@tonic-gate void 35447c478bd9Sstevel@tonic-gate fop_dispose( 35457c478bd9Sstevel@tonic-gate vnode_t *vp, 35467c478bd9Sstevel@tonic-gate page_t *pp, 35477c478bd9Sstevel@tonic-gate int flag, 35487c478bd9Sstevel@tonic-gate int dn, 35497c478bd9Sstevel@tonic-gate cred_t *cr) 35507c478bd9Sstevel@tonic-gate { 35515a59a8b3Srsb /* Must do stats first since it's possible to lose the vnode */ 35522bb1cb30Sbmc VOPSTATS_UPDATE(vp, dispose); 3553f48205beScasper 3554f48205beScasper VOPXID_MAP_CR(vp, cr); 3555f48205beScasper 35567c478bd9Sstevel@tonic-gate (*(vp)->v_op->vop_dispose)(vp, pp, flag, dn, cr); 35577c478bd9Sstevel@tonic-gate } 35587c478bd9Sstevel@tonic-gate 35597c478bd9Sstevel@tonic-gate int 35607c478bd9Sstevel@tonic-gate fop_setsecattr( 35617c478bd9Sstevel@tonic-gate vnode_t *vp, 35627c478bd9Sstevel@tonic-gate vsecattr_t *vsap, 35637c478bd9Sstevel@tonic-gate int flag, 35647c478bd9Sstevel@tonic-gate cred_t *cr) 35657c478bd9Sstevel@tonic-gate { 35665a59a8b3Srsb int err; 35675a59a8b3Srsb 3568f48205beScasper VOPXID_MAP_CR(vp, cr); 3569f48205beScasper 35705a59a8b3Srsb err = (*(vp)->v_op->vop_setsecattr) (vp, vsap, flag, cr); 35712bb1cb30Sbmc VOPSTATS_UPDATE(vp, setsecattr); 35725a59a8b3Srsb return (err); 35737c478bd9Sstevel@tonic-gate } 35747c478bd9Sstevel@tonic-gate 35757c478bd9Sstevel@tonic-gate int 35767c478bd9Sstevel@tonic-gate fop_getsecattr( 35777c478bd9Sstevel@tonic-gate vnode_t *vp, 35787c478bd9Sstevel@tonic-gate vsecattr_t *vsap, 35797c478bd9Sstevel@tonic-gate int flag, 35807c478bd9Sstevel@tonic-gate cred_t *cr) 35817c478bd9Sstevel@tonic-gate { 35825a59a8b3Srsb int err; 35835a59a8b3Srsb 3584f48205beScasper VOPXID_MAP_CR(vp, cr); 3585f48205beScasper 35865a59a8b3Srsb err = (*(vp)->v_op->vop_getsecattr) (vp, vsap, flag, cr); 35872bb1cb30Sbmc VOPSTATS_UPDATE(vp, getsecattr); 35885a59a8b3Srsb return (err); 35897c478bd9Sstevel@tonic-gate } 35907c478bd9Sstevel@tonic-gate 35917c478bd9Sstevel@tonic-gate int 35927c478bd9Sstevel@tonic-gate fop_shrlock( 35937c478bd9Sstevel@tonic-gate vnode_t *vp, 35947c478bd9Sstevel@tonic-gate int cmd, 35957c478bd9Sstevel@tonic-gate struct shrlock *shr, 35967c478bd9Sstevel@tonic-gate int flag, 35977c478bd9Sstevel@tonic-gate cred_t *cr) 35987c478bd9Sstevel@tonic-gate { 35995a59a8b3Srsb int err; 36005a59a8b3Srsb 3601f48205beScasper VOPXID_MAP_CR(vp, cr); 3602f48205beScasper 36035a59a8b3Srsb err = (*(vp)->v_op->vop_shrlock)(vp, cmd, shr, flag, cr); 36042bb1cb30Sbmc VOPSTATS_UPDATE(vp, shrlock); 36055a59a8b3Srsb return (err); 36067c478bd9Sstevel@tonic-gate } 36077c478bd9Sstevel@tonic-gate 36087c478bd9Sstevel@tonic-gate int 3609*df2381bfSpraks fop_vnevent(vnode_t *vp, vnevent_t vnevent, vnode_t *dvp, char *fnm) 36107c478bd9Sstevel@tonic-gate { 36115a59a8b3Srsb int err; 36125a59a8b3Srsb 3613*df2381bfSpraks err = (*(vp)->v_op->vop_vnevent)(vp, vnevent, dvp, fnm); 36142bb1cb30Sbmc VOPSTATS_UPDATE(vp, vnevent); 36155a59a8b3Srsb return (err); 36167c478bd9Sstevel@tonic-gate } 3617