Index: vendor-sys/illumos/dist/uts/common/fs/vnode.c =================================================================== --- vendor-sys/illumos/dist/uts/common/fs/vnode.c (revision 323525) +++ vendor-sys/illumos/dist/uts/common/fs/vnode.c (revision 323526) @@ -1,4579 +1,4726 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2013, Joyent, Inc. All rights reserved. + * Copyright 2017, Joyent, Inc. * Copyright 2016 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2011, 2017 by Delphix. All rights reserved. */ /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * University Copyright- Copyright (c) 1982, 1986, 1988 * The Regents of the University of California * All Rights Reserved * * University Acknowledgment- Portions of this document are derived from * software developed by the University of California, Berkeley, and its * contributors. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include +#include +#include /* Determine if this vnode is a file that is read-only */ #define ISROFILE(vp) \ ((vp)->v_type != VCHR && (vp)->v_type != VBLK && \ (vp)->v_type != VFIFO && vn_is_readonly(vp)) /* Tunable via /etc/system; used only by admin/install */ int nfs_global_client_only; /* * Array of vopstats_t for per-FS-type vopstats. This array has the same * number of entries as and parallel to the vfssw table. (Arguably, it could * be part of the vfssw table.) Once it's initialized, it's accessed using * the same fstype index that is used to index into the vfssw table. */ vopstats_t **vopstats_fstype; /* vopstats initialization template used for fast initialization via bcopy() */ static vopstats_t *vs_templatep; /* Kmem cache handle for vsk_anchor_t allocations */ kmem_cache_t *vsk_anchor_cache; /* file events cleanup routine */ extern void free_fopdata(vnode_t *); /* * Root of AVL tree for the kstats associated with vopstats. Lock protects * updates to vsktat_tree. */ avl_tree_t vskstat_tree; kmutex_t vskstat_tree_lock; /* Global variable which enables/disables the vopstats collection */ int vopstats_enabled = 1; +/* Global used for empty/invalid v_path */ +char *vn_vpath_empty = ""; + /* * forward declarations for internal vnode specific data (vsd) */ static void *vsd_realloc(void *, size_t, size_t); /* * forward declarations for reparse point functions */ static int fs_reparse_mark(char *target, vattr_t *vap, xvattr_t *xvattr); /* * VSD -- VNODE SPECIFIC DATA * The v_data pointer is typically used by a file system to store a * pointer to the file system's private node (e.g. ufs inode, nfs rnode). * However, there are times when additional project private data needs * to be stored separately from the data (node) pointed to by v_data. * This additional data could be stored by the file system itself or * by a completely different kernel entity. VSD provides a way for * callers to obtain a key and store a pointer to private data associated * with a vnode. * * Callers are responsible for protecting the vsd by holding v_vsd_lock * for calls to vsd_set() and vsd_get(). */ /* * vsd_lock protects: * vsd_nkeys - creation and deletion of vsd keys * vsd_list - insertion and deletion of vsd_node in the vsd_list * vsd_destructor - adding and removing destructors to the list */ static kmutex_t vsd_lock; static uint_t vsd_nkeys; /* size of destructor array */ /* list of vsd_node's */ static list_t *vsd_list = NULL; /* per-key destructor funcs */ static void (**vsd_destructor)(void *); /* * The following is the common set of actions needed to update the * vopstats structure from a vnode op. Both VOPSTATS_UPDATE() and * VOPSTATS_UPDATE_IO() do almost the same thing, except for the * recording of the bytes transferred. Since the code is similar * but small, it is nearly a duplicate. Consequently any changes * to one may need to be reflected in the other. * Rundown of the variables: * vp - Pointer to the vnode * counter - Partial name structure member to update in vopstats for counts * bytecounter - Partial name structure member to update in vopstats for bytes * bytesval - Value to update in vopstats for bytes * fstype - Index into vsanchor_fstype[], same as index into vfssw[] * vsp - Pointer to vopstats structure (either in vfs or vsanchor_fstype[i]) */ #define VOPSTATS_UPDATE(vp, counter) { \ vfs_t *vfsp = (vp)->v_vfsp; \ if (vfsp && vfsp->vfs_implp && \ (vfsp->vfs_flag & VFS_STATS) && (vp)->v_type != VBAD) { \ vopstats_t *vsp = &vfsp->vfs_vopstats; \ uint64_t *stataddr = &(vsp->n##counter.value.ui64); \ extern void __dtrace_probe___fsinfo_##counter(vnode_t *, \ size_t, uint64_t *); \ __dtrace_probe___fsinfo_##counter(vp, 0, stataddr); \ (*stataddr)++; \ if ((vsp = vfsp->vfs_fstypevsp) != NULL) { \ vsp->n##counter.value.ui64++; \ } \ } \ } #define VOPSTATS_UPDATE_IO(vp, counter, bytecounter, bytesval) { \ vfs_t *vfsp = (vp)->v_vfsp; \ if (vfsp && vfsp->vfs_implp && \ (vfsp->vfs_flag & VFS_STATS) && (vp)->v_type != VBAD) { \ vopstats_t *vsp = &vfsp->vfs_vopstats; \ uint64_t *stataddr = &(vsp->n##counter.value.ui64); \ extern void __dtrace_probe___fsinfo_##counter(vnode_t *, \ size_t, uint64_t *); \ __dtrace_probe___fsinfo_##counter(vp, bytesval, stataddr); \ (*stataddr)++; \ vsp->bytecounter.value.ui64 += bytesval; \ if ((vsp = vfsp->vfs_fstypevsp) != NULL) { \ vsp->n##counter.value.ui64++; \ vsp->bytecounter.value.ui64 += bytesval; \ } \ } \ } /* * If the filesystem does not support XIDs map credential * If the vfsp is NULL, perhaps we should also map? */ #define VOPXID_MAP_CR(vp, cr) { \ vfs_t *vfsp = (vp)->v_vfsp; \ if (vfsp != NULL && (vfsp->vfs_flag & VFS_XID) == 0) \ cr = crgetmapped(cr); \ } /* * Convert stat(2) formats to vnode types and vice versa. (Knows about * numerical order of S_IFMT and vnode types.) */ enum vtype iftovt_tab[] = { VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON, VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VNON }; ushort_t vttoif_tab[] = { 0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, S_IFIFO, S_IFDOOR, 0, S_IFSOCK, S_IFPORT, 0 }; /* * The system vnode cache. */ kmem_cache_t *vn_cache; /* * Vnode operations vector. */ static const fs_operation_trans_def_t vn_ops_table[] = { VOPNAME_OPEN, offsetof(struct vnodeops, vop_open), fs_nosys, fs_nosys, VOPNAME_CLOSE, offsetof(struct vnodeops, vop_close), fs_nosys, fs_nosys, VOPNAME_READ, offsetof(struct vnodeops, vop_read), fs_nosys, fs_nosys, VOPNAME_WRITE, offsetof(struct vnodeops, vop_write), fs_nosys, fs_nosys, VOPNAME_IOCTL, offsetof(struct vnodeops, vop_ioctl), fs_nosys, fs_nosys, VOPNAME_SETFL, offsetof(struct vnodeops, vop_setfl), fs_setfl, fs_nosys, VOPNAME_GETATTR, offsetof(struct vnodeops, vop_getattr), fs_nosys, fs_nosys, VOPNAME_SETATTR, offsetof(struct vnodeops, vop_setattr), fs_nosys, fs_nosys, VOPNAME_ACCESS, offsetof(struct vnodeops, vop_access), fs_nosys, fs_nosys, VOPNAME_LOOKUP, offsetof(struct vnodeops, vop_lookup), fs_nosys, fs_nosys, VOPNAME_CREATE, offsetof(struct vnodeops, vop_create), fs_nosys, fs_nosys, VOPNAME_REMOVE, offsetof(struct vnodeops, vop_remove), fs_nosys, fs_nosys, VOPNAME_LINK, offsetof(struct vnodeops, vop_link), fs_nosys, fs_nosys, VOPNAME_RENAME, offsetof(struct vnodeops, vop_rename), fs_nosys, fs_nosys, VOPNAME_MKDIR, offsetof(struct vnodeops, vop_mkdir), fs_nosys, fs_nosys, VOPNAME_RMDIR, offsetof(struct vnodeops, vop_rmdir), fs_nosys, fs_nosys, VOPNAME_READDIR, offsetof(struct vnodeops, vop_readdir), fs_nosys, fs_nosys, VOPNAME_SYMLINK, offsetof(struct vnodeops, vop_symlink), fs_nosys, fs_nosys, VOPNAME_READLINK, offsetof(struct vnodeops, vop_readlink), fs_nosys, fs_nosys, VOPNAME_FSYNC, offsetof(struct vnodeops, vop_fsync), fs_nosys, fs_nosys, VOPNAME_INACTIVE, offsetof(struct vnodeops, vop_inactive), fs_nosys, fs_nosys, VOPNAME_FID, offsetof(struct vnodeops, vop_fid), fs_nosys, fs_nosys, VOPNAME_RWLOCK, offsetof(struct vnodeops, vop_rwlock), fs_rwlock, fs_rwlock, VOPNAME_RWUNLOCK, offsetof(struct vnodeops, vop_rwunlock), (fs_generic_func_p) fs_rwunlock, (fs_generic_func_p) fs_rwunlock, /* no errors allowed */ VOPNAME_SEEK, offsetof(struct vnodeops, vop_seek), fs_nosys, fs_nosys, VOPNAME_CMP, offsetof(struct vnodeops, vop_cmp), fs_cmp, fs_cmp, /* no errors allowed */ VOPNAME_FRLOCK, offsetof(struct vnodeops, vop_frlock), fs_frlock, fs_nosys, VOPNAME_SPACE, offsetof(struct vnodeops, vop_space), fs_nosys, fs_nosys, VOPNAME_REALVP, offsetof(struct vnodeops, vop_realvp), fs_nosys, fs_nosys, VOPNAME_GETPAGE, offsetof(struct vnodeops, vop_getpage), fs_nosys, fs_nosys, VOPNAME_PUTPAGE, offsetof(struct vnodeops, vop_putpage), fs_nosys, fs_nosys, VOPNAME_MAP, offsetof(struct vnodeops, vop_map), (fs_generic_func_p) fs_nosys_map, (fs_generic_func_p) fs_nosys_map, VOPNAME_ADDMAP, offsetof(struct vnodeops, vop_addmap), (fs_generic_func_p) fs_nosys_addmap, (fs_generic_func_p) fs_nosys_addmap, VOPNAME_DELMAP, offsetof(struct vnodeops, vop_delmap), fs_nosys, fs_nosys, VOPNAME_POLL, offsetof(struct vnodeops, vop_poll), (fs_generic_func_p) fs_poll, (fs_generic_func_p) fs_nosys_poll, VOPNAME_DUMP, offsetof(struct vnodeops, vop_dump), fs_nosys, fs_nosys, VOPNAME_PATHCONF, offsetof(struct vnodeops, vop_pathconf), fs_pathconf, fs_nosys, VOPNAME_PAGEIO, offsetof(struct vnodeops, vop_pageio), fs_nosys, fs_nosys, VOPNAME_DUMPCTL, offsetof(struct vnodeops, vop_dumpctl), fs_nosys, fs_nosys, VOPNAME_DISPOSE, offsetof(struct vnodeops, vop_dispose), (fs_generic_func_p) fs_dispose, (fs_generic_func_p) fs_nodispose, VOPNAME_SETSECATTR, offsetof(struct vnodeops, vop_setsecattr), fs_nosys, fs_nosys, VOPNAME_GETSECATTR, offsetof(struct vnodeops, vop_getsecattr), fs_fab_acl, fs_nosys, VOPNAME_SHRLOCK, offsetof(struct vnodeops, vop_shrlock), fs_shrlock, fs_nosys, VOPNAME_VNEVENT, offsetof(struct vnodeops, vop_vnevent), (fs_generic_func_p) fs_vnevent_nosupport, (fs_generic_func_p) fs_vnevent_nosupport, VOPNAME_REQZCBUF, offsetof(struct vnodeops, vop_reqzcbuf), fs_nosys, fs_nosys, VOPNAME_RETZCBUF, offsetof(struct vnodeops, vop_retzcbuf), fs_nosys, fs_nosys, NULL, 0, NULL, NULL }; /* Extensible attribute (xva) routines. */ /* * Zero out the structure, set the size of the requested/returned bitmaps, * set AT_XVATTR in the embedded vattr_t's va_mask, and set up the pointer * to the returned attributes array. */ void xva_init(xvattr_t *xvap) { bzero(xvap, sizeof (xvattr_t)); xvap->xva_mapsize = XVA_MAPSIZE; xvap->xva_magic = XVA_MAGIC; xvap->xva_vattr.va_mask = AT_XVATTR; xvap->xva_rtnattrmapp = &(xvap->xva_rtnattrmap)[0]; } /* * If AT_XVATTR is set, returns a pointer to the embedded xoptattr_t * structure. Otherwise, returns NULL. */ xoptattr_t * xva_getxoptattr(xvattr_t *xvap) { xoptattr_t *xoap = NULL; if (xvap->xva_vattr.va_mask & AT_XVATTR) xoap = &xvap->xva_xoptattrs; return (xoap); } /* * Used by the AVL routines to compare two vsk_anchor_t structures in the tree. * We use the f_fsid reported by VFS_STATVFS() since we use that for the * kstat name. */ static int vska_compar(const void *n1, const void *n2) { int ret; ulong_t p1 = ((vsk_anchor_t *)n1)->vsk_fsid; ulong_t p2 = ((vsk_anchor_t *)n2)->vsk_fsid; if (p1 < p2) { ret = -1; } else if (p1 > p2) { ret = 1; } else { ret = 0; } return (ret); } /* * Used to create a single template which will be bcopy()ed to a newly * allocated vsanchor_combo_t structure in new_vsanchor(), below. */ static vopstats_t * create_vopstats_template() { vopstats_t *vsp; vsp = kmem_alloc(sizeof (vopstats_t), KM_SLEEP); bzero(vsp, sizeof (*vsp)); /* Start fresh */ /* VOP_OPEN */ kstat_named_init(&vsp->nopen, "nopen", KSTAT_DATA_UINT64); /* VOP_CLOSE */ kstat_named_init(&vsp->nclose, "nclose", KSTAT_DATA_UINT64); /* VOP_READ I/O */ kstat_named_init(&vsp->nread, "nread", KSTAT_DATA_UINT64); kstat_named_init(&vsp->read_bytes, "read_bytes", KSTAT_DATA_UINT64); /* VOP_WRITE I/O */ kstat_named_init(&vsp->nwrite, "nwrite", KSTAT_DATA_UINT64); kstat_named_init(&vsp->write_bytes, "write_bytes", KSTAT_DATA_UINT64); /* VOP_IOCTL */ kstat_named_init(&vsp->nioctl, "nioctl", KSTAT_DATA_UINT64); /* VOP_SETFL */ kstat_named_init(&vsp->nsetfl, "nsetfl", KSTAT_DATA_UINT64); /* VOP_GETATTR */ kstat_named_init(&vsp->ngetattr, "ngetattr", KSTAT_DATA_UINT64); /* VOP_SETATTR */ kstat_named_init(&vsp->nsetattr, "nsetattr", KSTAT_DATA_UINT64); /* VOP_ACCESS */ kstat_named_init(&vsp->naccess, "naccess", KSTAT_DATA_UINT64); /* VOP_LOOKUP */ kstat_named_init(&vsp->nlookup, "nlookup", KSTAT_DATA_UINT64); /* VOP_CREATE */ kstat_named_init(&vsp->ncreate, "ncreate", KSTAT_DATA_UINT64); /* VOP_REMOVE */ kstat_named_init(&vsp->nremove, "nremove", KSTAT_DATA_UINT64); /* VOP_LINK */ kstat_named_init(&vsp->nlink, "nlink", KSTAT_DATA_UINT64); /* VOP_RENAME */ kstat_named_init(&vsp->nrename, "nrename", KSTAT_DATA_UINT64); /* VOP_MKDIR */ kstat_named_init(&vsp->nmkdir, "nmkdir", KSTAT_DATA_UINT64); /* VOP_RMDIR */ kstat_named_init(&vsp->nrmdir, "nrmdir", KSTAT_DATA_UINT64); /* VOP_READDIR I/O */ kstat_named_init(&vsp->nreaddir, "nreaddir", KSTAT_DATA_UINT64); kstat_named_init(&vsp->readdir_bytes, "readdir_bytes", KSTAT_DATA_UINT64); /* VOP_SYMLINK */ kstat_named_init(&vsp->nsymlink, "nsymlink", KSTAT_DATA_UINT64); /* VOP_READLINK */ kstat_named_init(&vsp->nreadlink, "nreadlink", KSTAT_DATA_UINT64); /* VOP_FSYNC */ kstat_named_init(&vsp->nfsync, "nfsync", KSTAT_DATA_UINT64); /* VOP_INACTIVE */ kstat_named_init(&vsp->ninactive, "ninactive", KSTAT_DATA_UINT64); /* VOP_FID */ kstat_named_init(&vsp->nfid, "nfid", KSTAT_DATA_UINT64); /* VOP_RWLOCK */ kstat_named_init(&vsp->nrwlock, "nrwlock", KSTAT_DATA_UINT64); /* VOP_RWUNLOCK */ kstat_named_init(&vsp->nrwunlock, "nrwunlock", KSTAT_DATA_UINT64); /* VOP_SEEK */ kstat_named_init(&vsp->nseek, "nseek", KSTAT_DATA_UINT64); /* VOP_CMP */ kstat_named_init(&vsp->ncmp, "ncmp", KSTAT_DATA_UINT64); /* VOP_FRLOCK */ kstat_named_init(&vsp->nfrlock, "nfrlock", KSTAT_DATA_UINT64); /* VOP_SPACE */ kstat_named_init(&vsp->nspace, "nspace", KSTAT_DATA_UINT64); /* VOP_REALVP */ kstat_named_init(&vsp->nrealvp, "nrealvp", KSTAT_DATA_UINT64); /* VOP_GETPAGE */ kstat_named_init(&vsp->ngetpage, "ngetpage", KSTAT_DATA_UINT64); /* VOP_PUTPAGE */ kstat_named_init(&vsp->nputpage, "nputpage", KSTAT_DATA_UINT64); /* VOP_MAP */ kstat_named_init(&vsp->nmap, "nmap", KSTAT_DATA_UINT64); /* VOP_ADDMAP */ kstat_named_init(&vsp->naddmap, "naddmap", KSTAT_DATA_UINT64); /* VOP_DELMAP */ kstat_named_init(&vsp->ndelmap, "ndelmap", KSTAT_DATA_UINT64); /* VOP_POLL */ kstat_named_init(&vsp->npoll, "npoll", KSTAT_DATA_UINT64); /* VOP_DUMP */ kstat_named_init(&vsp->ndump, "ndump", KSTAT_DATA_UINT64); /* VOP_PATHCONF */ kstat_named_init(&vsp->npathconf, "npathconf", KSTAT_DATA_UINT64); /* VOP_PAGEIO */ kstat_named_init(&vsp->npageio, "npageio", KSTAT_DATA_UINT64); /* VOP_DUMPCTL */ kstat_named_init(&vsp->ndumpctl, "ndumpctl", KSTAT_DATA_UINT64); /* VOP_DISPOSE */ kstat_named_init(&vsp->ndispose, "ndispose", KSTAT_DATA_UINT64); /* VOP_SETSECATTR */ kstat_named_init(&vsp->nsetsecattr, "nsetsecattr", KSTAT_DATA_UINT64); /* VOP_GETSECATTR */ kstat_named_init(&vsp->ngetsecattr, "ngetsecattr", KSTAT_DATA_UINT64); /* VOP_SHRLOCK */ kstat_named_init(&vsp->nshrlock, "nshrlock", KSTAT_DATA_UINT64); /* VOP_VNEVENT */ kstat_named_init(&vsp->nvnevent, "nvnevent", KSTAT_DATA_UINT64); /* VOP_REQZCBUF */ kstat_named_init(&vsp->nreqzcbuf, "nreqzcbuf", KSTAT_DATA_UINT64); /* VOP_RETZCBUF */ kstat_named_init(&vsp->nretzcbuf, "nretzcbuf", KSTAT_DATA_UINT64); return (vsp); } /* * Creates a kstat structure associated with a vopstats structure. */ kstat_t * new_vskstat(char *ksname, vopstats_t *vsp) { kstat_t *ksp; if (!vopstats_enabled) { return (NULL); } ksp = kstat_create("unix", 0, ksname, "misc", KSTAT_TYPE_NAMED, sizeof (vopstats_t)/sizeof (kstat_named_t), KSTAT_FLAG_VIRTUAL|KSTAT_FLAG_WRITABLE); if (ksp) { ksp->ks_data = vsp; kstat_install(ksp); } return (ksp); } /* * Called from vfsinit() to initialize the support mechanisms for vopstats */ void vopstats_startup() { if (!vopstats_enabled) return; /* * Creates the AVL tree which holds per-vfs vopstat anchors. This * is necessary since we need to check if a kstat exists before we * attempt to create it. Also, initialize its lock. */ avl_create(&vskstat_tree, vska_compar, sizeof (vsk_anchor_t), offsetof(vsk_anchor_t, vsk_node)); mutex_init(&vskstat_tree_lock, NULL, MUTEX_DEFAULT, NULL); vsk_anchor_cache = kmem_cache_create("vsk_anchor_cache", sizeof (vsk_anchor_t), sizeof (uintptr_t), NULL, NULL, NULL, NULL, NULL, 0); /* * Set up the array of pointers for the vopstats-by-FS-type. * The entries will be allocated/initialized as each file system * goes through modload/mod_installfs. */ vopstats_fstype = (vopstats_t **)kmem_zalloc( (sizeof (vopstats_t *) * nfstype), KM_SLEEP); /* Set up the global vopstats initialization template */ vs_templatep = create_vopstats_template(); } /* * We need to have the all of the counters zeroed. * The initialization of the vopstats_t includes on the order of * 50 calls to kstat_named_init(). Rather that do that on every call, * we do it once in a template (vs_templatep) then bcopy it over. */ void initialize_vopstats(vopstats_t *vsp) { if (vsp == NULL) return; bcopy(vs_templatep, vsp, sizeof (vopstats_t)); } /* * If possible, determine which vopstats by fstype to use and * return a pointer to the caller. */ vopstats_t * get_fstype_vopstats(vfs_t *vfsp, struct vfssw *vswp) { int fstype = 0; /* Index into vfssw[] */ vopstats_t *vsp = NULL; if (vfsp == NULL || (vfsp->vfs_flag & VFS_STATS) == 0 || !vopstats_enabled) return (NULL); /* * Set up the fstype. We go to so much trouble because all versions * of NFS use the same fstype in their vfs even though they have * distinct entries in the vfssw[] table. * NOTE: A special vfs (e.g., EIO_vfs) may not have an entry. */ if (vswp) { fstype = vswp - vfssw; /* Gets us the index */ } else { fstype = vfsp->vfs_fstype; } /* * Point to the per-fstype vopstats. The only valid values are * non-zero positive values less than the number of vfssw[] table * entries. */ if (fstype > 0 && fstype < nfstype) { vsp = vopstats_fstype[fstype]; } return (vsp); } /* * Generate a kstat name, create the kstat structure, and allocate a * vsk_anchor_t to hold it together. Return the pointer to the vsk_anchor_t * to the caller. This must only be called from a mount. */ vsk_anchor_t * get_vskstat_anchor(vfs_t *vfsp) { char kstatstr[KSTAT_STRLEN]; /* kstat name for vopstats */ statvfs64_t statvfsbuf; /* Needed to find f_fsid */ vsk_anchor_t *vskp = NULL; /* vfs <--> kstat anchor */ kstat_t *ksp; /* Ptr to new kstat */ avl_index_t where; /* Location in the AVL tree */ if (vfsp == NULL || vfsp->vfs_implp == NULL || (vfsp->vfs_flag & VFS_STATS) == 0 || !vopstats_enabled) return (NULL); /* Need to get the fsid to build a kstat name */ if (VFS_STATVFS(vfsp, &statvfsbuf) == 0) { /* Create a name for our kstats based on fsid */ (void) snprintf(kstatstr, KSTAT_STRLEN, "%s%lx", VOPSTATS_STR, statvfsbuf.f_fsid); /* Allocate and initialize the vsk_anchor_t */ vskp = kmem_cache_alloc(vsk_anchor_cache, KM_SLEEP); bzero(vskp, sizeof (*vskp)); vskp->vsk_fsid = statvfsbuf.f_fsid; mutex_enter(&vskstat_tree_lock); if (avl_find(&vskstat_tree, vskp, &where) == NULL) { avl_insert(&vskstat_tree, vskp, where); mutex_exit(&vskstat_tree_lock); /* * Now that we've got the anchor in the AVL * tree, we can create the kstat. */ ksp = new_vskstat(kstatstr, &vfsp->vfs_vopstats); if (ksp) { vskp->vsk_ksp = ksp; } } else { /* Oops, found one! Release memory and lock. */ mutex_exit(&vskstat_tree_lock); kmem_cache_free(vsk_anchor_cache, vskp); vskp = NULL; } } return (vskp); } /* * We're in the process of tearing down the vfs and need to cleanup * the data structures associated with the vopstats. Must only be called * from dounmount(). */ void teardown_vopstats(vfs_t *vfsp) { vsk_anchor_t *vskap; avl_index_t where; if (vfsp == NULL || vfsp->vfs_implp == NULL || (vfsp->vfs_flag & VFS_STATS) == 0 || !vopstats_enabled) return; /* This is a safe check since VFS_STATS must be set (see above) */ if ((vskap = vfsp->vfs_vskap) == NULL) return; /* Whack the pointer right away */ vfsp->vfs_vskap = NULL; /* Lock the tree, remove the node, and delete the kstat */ mutex_enter(&vskstat_tree_lock); if (avl_find(&vskstat_tree, vskap, &where)) { avl_remove(&vskstat_tree, vskap); } if (vskap->vsk_ksp) { kstat_delete(vskap->vsk_ksp); } mutex_exit(&vskstat_tree_lock); kmem_cache_free(vsk_anchor_cache, vskap); } /* * Read or write a vnode. Called from kernel code. */ int vn_rdwr( enum uio_rw rw, struct vnode *vp, caddr_t base, ssize_t len, offset_t offset, enum uio_seg seg, int ioflag, rlim64_t ulimit, /* meaningful only if rw is UIO_WRITE */ cred_t *cr, ssize_t *residp) { struct uio uio; struct iovec iov; int error; int in_crit = 0; if (rw == UIO_WRITE && ISROFILE(vp)) return (EROFS); if (len < 0) return (EIO); VOPXID_MAP_CR(vp, cr); iov.iov_base = base; iov.iov_len = len; uio.uio_iov = &iov; uio.uio_iovcnt = 1; uio.uio_loffset = offset; uio.uio_segflg = (short)seg; uio.uio_resid = len; uio.uio_llimit = ulimit; /* * We have to enter the critical region before calling VOP_RWLOCK * to avoid a deadlock with ufs. */ if (nbl_need_check(vp)) { int svmand; nbl_start_crit(vp, RW_READER); in_crit = 1; error = nbl_svmand(vp, cr, &svmand); if (error != 0) goto done; if (nbl_conflict(vp, rw == UIO_WRITE ? NBL_WRITE : NBL_READ, uio.uio_offset, uio.uio_resid, svmand, NULL)) { error = EACCES; goto done; } } (void) VOP_RWLOCK(vp, rw == UIO_WRITE ? V_WRITELOCK_TRUE : V_WRITELOCK_FALSE, NULL); if (rw == UIO_WRITE) { uio.uio_fmode = FWRITE; uio.uio_extflg = UIO_COPY_DEFAULT; error = VOP_WRITE(vp, &uio, ioflag, cr, NULL); } else { uio.uio_fmode = FREAD; uio.uio_extflg = UIO_COPY_CACHED; error = VOP_READ(vp, &uio, ioflag, cr, NULL); } VOP_RWUNLOCK(vp, rw == UIO_WRITE ? V_WRITELOCK_TRUE : V_WRITELOCK_FALSE, NULL); if (residp) *residp = uio.uio_resid; else if (uio.uio_resid) error = EIO; done: if (in_crit) nbl_end_crit(vp); return (error); } /* * Release a vnode. Call VOP_INACTIVE on last reference or * decrement reference count. * * To avoid race conditions, the v_count is left at 1 for * the call to VOP_INACTIVE. This prevents another thread * from reclaiming and releasing the vnode *before* the * VOP_INACTIVE routine has a chance to destroy the vnode. * We can't have more than 1 thread calling VOP_INACTIVE * on a vnode. */ void vn_rele(vnode_t *vp) { VERIFY(vp->v_count > 0); mutex_enter(&vp->v_lock); if (vp->v_count == 1) { mutex_exit(&vp->v_lock); VOP_INACTIVE(vp, CRED(), NULL); return; } VN_RELE_LOCKED(vp); mutex_exit(&vp->v_lock); } /* * Release a vnode referenced by the DNLC. Multiple DNLC references are treated * as a single reference, so v_count is not decremented until the last DNLC hold * is released. This makes it possible to distinguish vnodes that are referenced * only by the DNLC. */ void vn_rele_dnlc(vnode_t *vp) { VERIFY((vp->v_count > 0) && (vp->v_count_dnlc > 0)); mutex_enter(&vp->v_lock); if (--vp->v_count_dnlc == 0) { if (vp->v_count == 1) { mutex_exit(&vp->v_lock); VOP_INACTIVE(vp, CRED(), NULL); return; } VN_RELE_LOCKED(vp); } mutex_exit(&vp->v_lock); } /* * Like vn_rele() except that it clears v_stream under v_lock. * This is used by sockfs when it dismantles the association between * the sockfs node and the vnode in the underlying file system. * v_lock has to be held to prevent a thread coming through the lookupname * path from accessing a stream head that is going away. */ void vn_rele_stream(vnode_t *vp) { VERIFY(vp->v_count > 0); mutex_enter(&vp->v_lock); vp->v_stream = NULL; if (vp->v_count == 1) { mutex_exit(&vp->v_lock); VOP_INACTIVE(vp, CRED(), NULL); return; } VN_RELE_LOCKED(vp); mutex_exit(&vp->v_lock); } static void vn_rele_inactive(vnode_t *vp) { VOP_INACTIVE(vp, CRED(), NULL); } /* * Like vn_rele() except if we are going to call VOP_INACTIVE() then do it * asynchronously using a taskq. This can avoid deadlocks caused by re-entering * the file system as a result of releasing the vnode. Note, file systems * already have to handle the race where the vnode is incremented before the * inactive routine is called and does its locking. * * Warning: Excessive use of this routine can lead to performance problems. * This is because taskqs throttle back allocation if too many are created. */ void vn_rele_async(vnode_t *vp, taskq_t *taskq) { VERIFY(vp->v_count > 0); mutex_enter(&vp->v_lock); if (vp->v_count == 1) { mutex_exit(&vp->v_lock); VERIFY(taskq_dispatch(taskq, (task_func_t *)vn_rele_inactive, vp, TQ_SLEEP) != NULL); return; } VN_RELE_LOCKED(vp); mutex_exit(&vp->v_lock); } int vn_open( char *pnamep, enum uio_seg seg, int filemode, int createmode, struct vnode **vpp, enum create crwhy, mode_t umask) { return (vn_openat(pnamep, seg, filemode, createmode, vpp, crwhy, umask, NULL, -1)); } /* * Open/create a vnode. * This may be callable by the kernel, the only known use * of user context being that the current user credentials * are used for permissions. crwhy is defined iff filemode & FCREAT. */ int vn_openat( char *pnamep, enum uio_seg seg, int filemode, int createmode, struct vnode **vpp, enum create crwhy, mode_t umask, struct vnode *startvp, int fd) { struct vnode *vp; int mode; int accessflags; int error; int in_crit = 0; int open_done = 0; int shrlock_done = 0; struct vattr vattr; enum symfollow follow; int estale_retry = 0; struct shrlock shr; struct shr_locowner shr_own; mode = 0; accessflags = 0; if (filemode & FREAD) mode |= VREAD; if (filemode & (FWRITE|FTRUNC)) mode |= VWRITE; if (filemode & (FSEARCH|FEXEC|FXATTRDIROPEN)) mode |= VEXEC; /* symlink interpretation */ if (filemode & FNOFOLLOW) follow = NO_FOLLOW; else follow = FOLLOW; if (filemode & FAPPEND) accessflags |= V_APPEND; top: if (filemode & FCREAT) { enum vcexcl excl; /* * Wish to create a file. */ vattr.va_type = VREG; vattr.va_mode = createmode; vattr.va_mask = AT_TYPE|AT_MODE; if (filemode & FTRUNC) { vattr.va_size = 0; vattr.va_mask |= AT_SIZE; } if (filemode & FEXCL) excl = EXCL; else excl = NONEXCL; if (error = vn_createat(pnamep, seg, &vattr, excl, mode, &vp, crwhy, (filemode & ~(FTRUNC|FEXCL)), umask, startvp)) return (error); } else { /* * Wish to open a file. Just look it up. */ if (error = lookupnameat(pnamep, seg, follow, NULLVPP, &vp, startvp)) { if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) goto top; return (error); } /* * Get the attributes to check whether file is large. * We do this only if the FOFFMAX flag is not set and * only for regular files. */ if (!(filemode & FOFFMAX) && (vp->v_type == VREG)) { vattr.va_mask = AT_SIZE; if ((error = VOP_GETATTR(vp, &vattr, 0, CRED(), NULL))) { goto out; } if (vattr.va_size > (u_offset_t)MAXOFF32_T) { /* * Large File API - regular open fails * if FOFFMAX flag is set in file mode */ error = EOVERFLOW; goto out; } } /* * Can't write directories, active texts, or * read-only filesystems. Can't truncate files * on which mandatory locking is in effect. */ if (filemode & (FWRITE|FTRUNC)) { /* * Allow writable directory if VDIROPEN flag is set. */ if (vp->v_type == VDIR && !(vp->v_flag & VDIROPEN)) { error = EISDIR; goto out; } if (ISROFILE(vp)) { error = EROFS; goto out; } /* * Can't truncate files on which * sysv mandatory locking is in effect. */ if (filemode & FTRUNC) { vnode_t *rvp; if (VOP_REALVP(vp, &rvp, NULL) != 0) rvp = vp; if (rvp->v_filocks != NULL) { vattr.va_mask = AT_MODE; if ((error = VOP_GETATTR(vp, &vattr, 0, CRED(), NULL)) == 0 && MANDLOCK(vp, vattr.va_mode)) error = EAGAIN; } } if (error) goto out; } /* * Check permissions. */ if (error = VOP_ACCESS(vp, mode, accessflags, CRED(), NULL)) goto out; /* * Require FSEARCH to return a directory. * Require FEXEC to return a regular file. */ if ((filemode & FSEARCH) && vp->v_type != VDIR) { error = ENOTDIR; goto out; } if ((filemode & FEXEC) && vp->v_type != VREG) { error = ENOEXEC; /* XXX: error code? */ goto out; } } /* * Do remaining checks for FNOFOLLOW and FNOLINKS. */ if ((filemode & FNOFOLLOW) && vp->v_type == VLNK) { error = ELOOP; goto out; } if (filemode & FNOLINKS) { vattr.va_mask = AT_NLINK; if ((error = VOP_GETATTR(vp, &vattr, 0, CRED(), NULL))) { goto out; } if (vattr.va_nlink != 1) { error = EMLINK; goto out; } } /* * Opening a socket corresponding to the AF_UNIX pathname * in the filesystem name space is not supported. * However, VSOCK nodes in namefs are supported in order * to make fattach work for sockets. * * XXX This uses VOP_REALVP to distinguish between * an unopened namefs node (where VOP_REALVP returns a * different VSOCK vnode) and a VSOCK created by vn_create * in some file system (where VOP_REALVP would never return * a different vnode). */ if (vp->v_type == VSOCK) { struct vnode *nvp; error = VOP_REALVP(vp, &nvp, NULL); if (error != 0 || nvp == NULL || nvp == vp || nvp->v_type != VSOCK) { error = EOPNOTSUPP; goto out; } } if ((vp->v_type == VREG) && nbl_need_check(vp)) { /* get share reservation */ shr.s_access = 0; if (filemode & FWRITE) shr.s_access |= F_WRACC; if (filemode & FREAD) shr.s_access |= F_RDACC; shr.s_deny = 0; shr.s_sysid = 0; shr.s_pid = ttoproc(curthread)->p_pid; shr_own.sl_pid = shr.s_pid; shr_own.sl_id = fd; shr.s_own_len = sizeof (shr_own); shr.s_owner = (caddr_t)&shr_own; error = VOP_SHRLOCK(vp, F_SHARE_NBMAND, &shr, filemode, CRED(), NULL); if (error) goto out; shrlock_done = 1; /* nbmand conflict check if truncating file */ if ((filemode & FTRUNC) && !(filemode & FCREAT)) { nbl_start_crit(vp, RW_READER); in_crit = 1; vattr.va_mask = AT_SIZE; if (error = VOP_GETATTR(vp, &vattr, 0, CRED(), NULL)) goto out; if (nbl_conflict(vp, NBL_WRITE, 0, vattr.va_size, 0, NULL)) { error = EACCES; goto out; } } } /* * Do opening protocol. */ error = VOP_OPEN(&vp, filemode, CRED(), NULL); if (error) goto out; open_done = 1; /* * Truncate if required. */ if ((filemode & FTRUNC) && !(filemode & FCREAT)) { vattr.va_size = 0; vattr.va_mask = AT_SIZE; if ((error = VOP_SETATTR(vp, &vattr, 0, CRED(), NULL)) != 0) goto out; } out: ASSERT(vp->v_count > 0); if (in_crit) { nbl_end_crit(vp); in_crit = 0; } if (error) { if (open_done) { (void) VOP_CLOSE(vp, filemode, 1, (offset_t)0, CRED(), NULL); open_done = 0; shrlock_done = 0; } if (shrlock_done) { (void) VOP_SHRLOCK(vp, F_UNSHARE, &shr, 0, CRED(), NULL); shrlock_done = 0; } /* * The following clause was added to handle a problem * with NFS consistency. It is possible that a lookup * of the file to be opened succeeded, but the file * itself doesn't actually exist on the server. This * is chiefly due to the DNLC containing an entry for * the file which has been removed on the server. In * this case, we just start over. If there was some * other cause for the ESTALE error, then the lookup * of the file will fail and the error will be returned * above instead of looping around from here. */ VN_RELE(vp); if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) goto top; } else *vpp = vp; return (error); } /* * The following two accessor functions are for the NFSv4 server. Since there * is no VOP_OPEN_UP/DOWNGRADE we need a way for the NFS server to keep the * vnode open counts correct when a client "upgrades" an open or does an * open_downgrade. In NFS, an upgrade or downgrade can not only change the * open mode (add or subtract read or write), but also change the share/deny * modes. However, share reservations are not integrated with OPEN, yet, so * we need to handle each separately. These functions are cleaner than having * the NFS server manipulate the counts directly, however, nobody else should * use these functions. */ void vn_open_upgrade( vnode_t *vp, int filemode) { ASSERT(vp->v_type == VREG); if (filemode & FREAD) atomic_inc_32(&vp->v_rdcnt); if (filemode & FWRITE) atomic_inc_32(&vp->v_wrcnt); } void vn_open_downgrade( vnode_t *vp, int filemode) { ASSERT(vp->v_type == VREG); if (filemode & FREAD) { ASSERT(vp->v_rdcnt > 0); atomic_dec_32(&vp->v_rdcnt); } if (filemode & FWRITE) { ASSERT(vp->v_wrcnt > 0); atomic_dec_32(&vp->v_wrcnt); } } int vn_create( char *pnamep, enum uio_seg seg, struct vattr *vap, enum vcexcl excl, int mode, struct vnode **vpp, enum create why, int flag, mode_t umask) { return (vn_createat(pnamep, seg, vap, excl, mode, vpp, why, flag, umask, NULL)); } /* * Create a vnode (makenode). */ int vn_createat( char *pnamep, enum uio_seg seg, struct vattr *vap, enum vcexcl excl, int mode, struct vnode **vpp, enum create why, int flag, mode_t umask, struct vnode *startvp) { struct vnode *dvp; /* ptr to parent dir vnode */ struct vnode *vp = NULL; struct pathname pn; int error; int in_crit = 0; struct vattr vattr; enum symfollow follow; int estale_retry = 0; uint32_t auditing = AU_AUDITING(); ASSERT((vap->va_mask & (AT_TYPE|AT_MODE)) == (AT_TYPE|AT_MODE)); /* symlink interpretation */ if ((flag & FNOFOLLOW) || excl == EXCL) follow = NO_FOLLOW; else follow = FOLLOW; flag &= ~(FNOFOLLOW|FNOLINKS); top: /* * Lookup directory. * If new object is a file, call lower level to create it. * Note that it is up to the lower level to enforce exclusive * creation, if the file is already there. * This allows the lower level to do whatever * locking or protocol that is needed to prevent races. * If the new object is directory call lower level to make * the new directory, with "." and "..". */ if (error = pn_get(pnamep, seg, &pn)) return (error); if (auditing) audit_vncreate_start(); dvp = NULL; *vpp = NULL; /* * lookup will find the parent directory for the vnode. * When it is done the pn holds the name of the entry * in the directory. * If this is a non-exclusive create we also find the node itself. */ error = lookuppnat(&pn, NULL, follow, &dvp, (excl == EXCL) ? NULLVPP : vpp, startvp); if (error) { pn_free(&pn); if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) goto top; if (why == CRMKDIR && error == EINVAL) error = EEXIST; /* SVID */ return (error); } if (why != CRMKNOD) vap->va_mode &= ~VSVTX; /* * If default ACLs are defined for the directory don't apply the * umask if umask is passed. */ if (umask) { vsecattr_t vsec; vsec.vsa_aclcnt = 0; vsec.vsa_aclentp = NULL; vsec.vsa_dfaclcnt = 0; vsec.vsa_dfaclentp = NULL; vsec.vsa_mask = VSA_DFACLCNT; error = VOP_GETSECATTR(dvp, &vsec, 0, CRED(), NULL); /* * If error is ENOSYS then treat it as no error * Don't want to force all file systems to support * aclent_t style of ACL's. */ if (error == ENOSYS) error = 0; if (error) { if (*vpp != NULL) VN_RELE(*vpp); goto out; } else { /* * Apply the umask if no default ACLs. */ if (vsec.vsa_dfaclcnt == 0) vap->va_mode &= ~umask; /* * VOP_GETSECATTR() may have allocated memory for * ACLs we didn't request, so double-check and * free it if necessary. */ if (vsec.vsa_aclcnt && vsec.vsa_aclentp != NULL) kmem_free((caddr_t)vsec.vsa_aclentp, vsec.vsa_aclcnt * sizeof (aclent_t)); if (vsec.vsa_dfaclcnt && vsec.vsa_dfaclentp != NULL) kmem_free((caddr_t)vsec.vsa_dfaclentp, vsec.vsa_dfaclcnt * sizeof (aclent_t)); } } /* * In general we want to generate EROFS if the file system is * readonly. However, POSIX (IEEE Std. 1003.1) section 5.3.1 * documents the open system call, and it says that O_CREAT has no * effect if the file already exists. Bug 1119649 states * that open(path, O_CREAT, ...) fails when attempting to open an * existing file on a read only file system. Thus, the first part * of the following if statement has 3 checks: * if the file exists && * it is being open with write access && * the file system is read only * then generate EROFS */ if ((*vpp != NULL && (mode & VWRITE) && ISROFILE(*vpp)) || (*vpp == NULL && dvp->v_vfsp->vfs_flag & VFS_RDONLY)) { if (*vpp) VN_RELE(*vpp); error = EROFS; } else if (excl == NONEXCL && *vpp != NULL) { vnode_t *rvp; /* * File already exists. If a mandatory lock has been * applied, return error. */ vp = *vpp; if (VOP_REALVP(vp, &rvp, NULL) != 0) rvp = vp; if ((vap->va_mask & AT_SIZE) && nbl_need_check(vp)) { nbl_start_crit(vp, RW_READER); in_crit = 1; } if (rvp->v_filocks != NULL || rvp->v_shrlocks != NULL) { vattr.va_mask = AT_MODE|AT_SIZE; if (error = VOP_GETATTR(vp, &vattr, 0, CRED(), NULL)) { goto out; } if (MANDLOCK(vp, vattr.va_mode)) { error = EAGAIN; goto out; } /* * File cannot be truncated if non-blocking mandatory * locks are currently on the file. */ if ((vap->va_mask & AT_SIZE) && in_crit) { u_offset_t offset; ssize_t length; offset = vap->va_size > vattr.va_size ? vattr.va_size : vap->va_size; length = vap->va_size > vattr.va_size ? vap->va_size - vattr.va_size : vattr.va_size - vap->va_size; if (nbl_conflict(vp, NBL_WRITE, offset, length, 0, NULL)) { error = EACCES; goto out; } } } /* * If the file is the root of a VFS, we've crossed a * mount point and the "containing" directory that we * acquired above (dvp) is irrelevant because it's in * a different file system. We apply VOP_CREATE to the * target itself instead of to the containing directory * and supply a null path name to indicate (conventionally) * the node itself as the "component" of interest. * * The intercession of the file system is necessary to * ensure that the appropriate permission checks are * done. */ if (vp->v_flag & VROOT) { ASSERT(why != CRMKDIR); error = VOP_CREATE(vp, "", vap, excl, mode, vpp, CRED(), flag, NULL, NULL); /* * If the create succeeded, it will have created * a new reference to the vnode. Give up the * original reference. The assertion should not * get triggered because NBMAND locks only apply to * VREG files. And if in_crit is non-zero for some * reason, detect that here, rather than when we * deference a null vp. */ ASSERT(in_crit == 0); VN_RELE(vp); vp = NULL; goto out; } /* * Large File API - non-large open (FOFFMAX flag not set) * of regular file fails if the file size exceeds MAXOFF32_T. */ if (why != CRMKDIR && !(flag & FOFFMAX) && (vp->v_type == VREG)) { vattr.va_mask = AT_SIZE; if ((error = VOP_GETATTR(vp, &vattr, 0, CRED(), NULL))) { goto out; } if ((vattr.va_size > (u_offset_t)MAXOFF32_T)) { error = EOVERFLOW; goto out; } } } if (error == 0) { /* * Call mkdir() if specified, otherwise create(). */ int must_be_dir = pn_fixslash(&pn); /* trailing '/'? */ if (why == CRMKDIR) /* * N.B., if vn_createat() ever requests * case-insensitive behavior then it will need * to be passed to VOP_MKDIR(). VOP_CREATE() * will already get it via "flag" */ error = VOP_MKDIR(dvp, pn.pn_path, vap, vpp, CRED(), NULL, 0, NULL); else if (!must_be_dir) error = VOP_CREATE(dvp, pn.pn_path, vap, excl, mode, vpp, CRED(), flag, NULL, NULL); else error = ENOTDIR; } out: if (auditing) audit_vncreate_finish(*vpp, error); if (in_crit) { nbl_end_crit(vp); in_crit = 0; } if (vp != NULL) { VN_RELE(vp); vp = NULL; } pn_free(&pn); VN_RELE(dvp); /* * The following clause was added to handle a problem * with NFS consistency. It is possible that a lookup * of the file to be created succeeded, but the file * itself doesn't actually exist on the server. This * is chiefly due to the DNLC containing an entry for * the file which has been removed on the server. In * this case, we just start over. If there was some * other cause for the ESTALE error, then the lookup * of the file will fail and the error will be returned * above instead of looping around from here. */ if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) goto top; return (error); } int vn_link(char *from, char *to, enum uio_seg seg) { return (vn_linkat(NULL, from, NO_FOLLOW, NULL, to, seg)); } int vn_linkat(vnode_t *fstartvp, char *from, enum symfollow follow, vnode_t *tstartvp, char *to, enum uio_seg seg) { struct vnode *fvp; /* from vnode ptr */ struct vnode *tdvp; /* to directory vnode ptr */ struct pathname pn; int error; struct vattr vattr; dev_t fsid; int estale_retry = 0; uint32_t auditing = AU_AUDITING(); top: fvp = tdvp = NULL; if (error = pn_get(to, seg, &pn)) return (error); if (auditing && fstartvp != NULL) audit_setfsat_path(1); if (error = lookupnameat(from, seg, follow, NULLVPP, &fvp, fstartvp)) goto out; if (auditing && tstartvp != NULL) audit_setfsat_path(3); if (error = lookuppnat(&pn, NULL, NO_FOLLOW, &tdvp, NULLVPP, tstartvp)) goto out; /* * Make sure both source vnode and target directory vnode are * in the same vfs and that it is writeable. */ vattr.va_mask = AT_FSID; if (error = VOP_GETATTR(fvp, &vattr, 0, CRED(), NULL)) goto out; fsid = vattr.va_fsid; vattr.va_mask = AT_FSID; if (error = VOP_GETATTR(tdvp, &vattr, 0, CRED(), NULL)) goto out; if (fsid != vattr.va_fsid) { error = EXDEV; goto out; } if (tdvp->v_vfsp->vfs_flag & VFS_RDONLY) { error = EROFS; goto out; } /* * Do the link. */ (void) pn_fixslash(&pn); error = VOP_LINK(tdvp, fvp, pn.pn_path, CRED(), NULL, 0); out: pn_free(&pn); if (fvp) VN_RELE(fvp); if (tdvp) VN_RELE(tdvp); if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) goto top; return (error); } int vn_rename(char *from, char *to, enum uio_seg seg) { return (vn_renameat(NULL, from, NULL, to, seg)); } int vn_renameat(vnode_t *fdvp, char *fname, vnode_t *tdvp, char *tname, enum uio_seg seg) { int error; struct vattr vattr; struct pathname fpn; /* from pathname */ struct pathname tpn; /* to pathname */ dev_t fsid; int in_crit_src, in_crit_targ; vnode_t *fromvp, *fvp; vnode_t *tovp, *targvp; int estale_retry = 0; uint32_t auditing = AU_AUDITING(); top: fvp = fromvp = tovp = targvp = NULL; in_crit_src = in_crit_targ = 0; /* * Get to and from pathnames. */ if (error = pn_get(fname, seg, &fpn)) return (error); if (error = pn_get(tname, seg, &tpn)) { pn_free(&fpn); return (error); } /* * First we need to resolve the correct directories * The passed in directories may only be a starting point, * but we need the real directories the file(s) live in. * For example the fname may be something like usr/lib/sparc * and we were passed in the / directory, but we need to * use the lib directory for the rename. */ if (auditing && fdvp != NULL) audit_setfsat_path(1); /* * Lookup to and from directories. */ if (error = lookuppnat(&fpn, NULL, NO_FOLLOW, &fromvp, &fvp, fdvp)) { goto out; } /* * Make sure there is an entry. */ if (fvp == NULL) { error = ENOENT; goto out; } if (auditing && tdvp != NULL) audit_setfsat_path(3); if (error = lookuppnat(&tpn, NULL, NO_FOLLOW, &tovp, &targvp, tdvp)) { goto out; } /* * Make sure both the from vnode directory and the to directory * are in the same vfs and the to directory is writable. * We check fsid's, not vfs pointers, so loopback fs works. */ if (fromvp != tovp) { vattr.va_mask = AT_FSID; if (error = VOP_GETATTR(fromvp, &vattr, 0, CRED(), NULL)) goto out; fsid = vattr.va_fsid; vattr.va_mask = AT_FSID; if (error = VOP_GETATTR(tovp, &vattr, 0, CRED(), NULL)) goto out; if (fsid != vattr.va_fsid) { error = EXDEV; goto out; } } if (tovp->v_vfsp->vfs_flag & VFS_RDONLY) { error = EROFS; goto out; } if (targvp && (fvp != targvp)) { nbl_start_crit(targvp, RW_READER); in_crit_targ = 1; if (nbl_conflict(targvp, NBL_REMOVE, 0, 0, 0, NULL)) { error = EACCES; goto out; } } if (nbl_need_check(fvp)) { nbl_start_crit(fvp, RW_READER); in_crit_src = 1; if (nbl_conflict(fvp, NBL_RENAME, 0, 0, 0, NULL)) { error = EACCES; goto out; } } /* * Do the rename. */ (void) pn_fixslash(&tpn); error = VOP_RENAME(fromvp, fpn.pn_path, tovp, tpn.pn_path, CRED(), NULL, 0); out: pn_free(&fpn); pn_free(&tpn); if (in_crit_src) nbl_end_crit(fvp); if (in_crit_targ) nbl_end_crit(targvp); if (fromvp) VN_RELE(fromvp); if (tovp) VN_RELE(tovp); if (targvp) VN_RELE(targvp); if (fvp) VN_RELE(fvp); if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) goto top; return (error); } /* * Remove a file or directory. */ int vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag) { return (vn_removeat(NULL, fnamep, seg, dirflag)); } int vn_removeat(vnode_t *startvp, char *fnamep, enum uio_seg seg, enum rm dirflag) { struct vnode *vp; /* entry vnode */ struct vnode *dvp; /* ptr to parent dir vnode */ struct vnode *coveredvp; struct pathname pn; /* name of entry */ enum vtype vtype; int error; struct vfs *vfsp; struct vfs *dvfsp; /* ptr to parent dir vfs */ int in_crit = 0; int estale_retry = 0; top: if (error = pn_get(fnamep, seg, &pn)) return (error); dvp = vp = NULL; if (error = lookuppnat(&pn, NULL, NO_FOLLOW, &dvp, &vp, startvp)) { pn_free(&pn); if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) goto top; return (error); } /* * Make sure there is an entry. */ if (vp == NULL) { error = ENOENT; goto out; } vfsp = vp->v_vfsp; dvfsp = dvp->v_vfsp; /* * If the named file is the root of a mounted filesystem, fail, * unless it's marked unlinkable. In that case, unmount the * filesystem and proceed to unlink the covered vnode. (If the * covered vnode is a directory, use rmdir instead of unlink, * to avoid file system corruption.) */ if (vp->v_flag & VROOT) { if ((vfsp->vfs_flag & VFS_UNLINKABLE) == 0) { error = EBUSY; goto out; } /* * Namefs specific code starts here. */ if (dirflag == RMDIRECTORY) { /* * User called rmdir(2) on a file that has * been namefs mounted on top of. Since * namefs doesn't allow directories to * be mounted on other files we know * vp is not of type VDIR so fail to operation. */ error = ENOTDIR; goto out; } /* * If VROOT is still set after grabbing vp->v_lock, * noone has finished nm_unmount so far and coveredvp * is valid. * If we manage to grab vn_vfswlock(coveredvp) before releasing * vp->v_lock, any race window is eliminated. */ mutex_enter(&vp->v_lock); if ((vp->v_flag & VROOT) == 0) { /* Someone beat us to the unmount */ mutex_exit(&vp->v_lock); error = EBUSY; goto out; } vfsp = vp->v_vfsp; coveredvp = vfsp->vfs_vnodecovered; ASSERT(coveredvp); /* * Note: Implementation of vn_vfswlock shows that ordering of * v_lock / vn_vfswlock is not an issue here. */ error = vn_vfswlock(coveredvp); mutex_exit(&vp->v_lock); if (error) goto out; VN_HOLD(coveredvp); VN_RELE(vp); error = dounmount(vfsp, 0, CRED()); /* * Unmounted the namefs file system; now get * the object it was mounted over. */ vp = coveredvp; /* * If namefs was mounted over a directory, then * we want to use rmdir() instead of unlink(). */ if (vp->v_type == VDIR) dirflag = RMDIRECTORY; if (error) goto out; } /* * Make sure filesystem is writeable. * We check the parent directory's vfs in case this is an lofs vnode. */ if (dvfsp && dvfsp->vfs_flag & VFS_RDONLY) { error = EROFS; goto out; } vtype = vp->v_type; /* * If there is the possibility of an nbmand share reservation, make * sure it's okay to remove the file. Keep a reference to the * vnode, so that we can exit the nbl critical region after * calling VOP_REMOVE. * If there is no possibility of an nbmand share reservation, * release the vnode reference now. Filesystems like NFS may * behave differently if there is an extra reference, so get rid of * this one. Fortunately, we can't have nbmand mounts on NFS * filesystems. */ if (nbl_need_check(vp)) { nbl_start_crit(vp, RW_READER); in_crit = 1; if (nbl_conflict(vp, NBL_REMOVE, 0, 0, 0, NULL)) { error = EACCES; goto out; } } else { VN_RELE(vp); vp = NULL; } if (dirflag == RMDIRECTORY) { /* * Caller is using rmdir(2), which can only be applied to * directories. */ if (vtype != VDIR) { error = ENOTDIR; } else { vnode_t *cwd; proc_t *pp = curproc; mutex_enter(&pp->p_lock); cwd = PTOU(pp)->u_cdir; VN_HOLD(cwd); mutex_exit(&pp->p_lock); error = VOP_RMDIR(dvp, pn.pn_path, cwd, CRED(), NULL, 0); VN_RELE(cwd); } } else { /* * Unlink(2) can be applied to anything. */ error = VOP_REMOVE(dvp, pn.pn_path, CRED(), NULL, 0); } out: pn_free(&pn); if (in_crit) { nbl_end_crit(vp); in_crit = 0; } if (vp != NULL) VN_RELE(vp); if (dvp != NULL) VN_RELE(dvp); if ((error == ESTALE) && fs_need_estale_retry(estale_retry++)) goto top; return (error); } /* * Utility function to compare equality of vnodes. * Compare the underlying real vnodes, if there are underlying vnodes. * This is a more thorough comparison than the VN_CMP() macro provides. */ int vn_compare(vnode_t *vp1, vnode_t *vp2) { vnode_t *realvp; if (vp1 != NULL && VOP_REALVP(vp1, &realvp, NULL) == 0) vp1 = realvp; if (vp2 != NULL && VOP_REALVP(vp2, &realvp, NULL) == 0) vp2 = realvp; return (VN_CMP(vp1, vp2)); } /* * The number of locks to hash into. This value must be a power * of 2 minus 1 and should probably also be prime. */ #define NUM_BUCKETS 1023 struct vn_vfslocks_bucket { kmutex_t vb_lock; vn_vfslocks_entry_t *vb_list; char pad[64 - sizeof (kmutex_t) - sizeof (void *)]; }; /* * Total number of buckets will be NUM_BUCKETS + 1 . */ #pragma align 64(vn_vfslocks_buckets) static struct vn_vfslocks_bucket vn_vfslocks_buckets[NUM_BUCKETS + 1]; #define VN_VFSLOCKS_SHIFT 9 #define VN_VFSLOCKS_HASH(vfsvpptr) \ ((((intptr_t)(vfsvpptr)) >> VN_VFSLOCKS_SHIFT) & NUM_BUCKETS) /* * vn_vfslocks_getlock() uses an HASH scheme to generate * rwstlock using vfs/vnode pointer passed to it. * * vn_vfslocks_rele() releases a reference in the * HASH table which allows the entry allocated by * vn_vfslocks_getlock() to be freed at a later * stage when the refcount drops to zero. */ vn_vfslocks_entry_t * vn_vfslocks_getlock(void *vfsvpptr) { struct vn_vfslocks_bucket *bp; vn_vfslocks_entry_t *vep; vn_vfslocks_entry_t *tvep; ASSERT(vfsvpptr != NULL); bp = &vn_vfslocks_buckets[VN_VFSLOCKS_HASH(vfsvpptr)]; mutex_enter(&bp->vb_lock); for (vep = bp->vb_list; vep != NULL; vep = vep->ve_next) { if (vep->ve_vpvfs == vfsvpptr) { vep->ve_refcnt++; mutex_exit(&bp->vb_lock); return (vep); } } mutex_exit(&bp->vb_lock); vep = kmem_alloc(sizeof (*vep), KM_SLEEP); rwst_init(&vep->ve_lock, NULL, RW_DEFAULT, NULL); vep->ve_vpvfs = (char *)vfsvpptr; vep->ve_refcnt = 1; mutex_enter(&bp->vb_lock); for (tvep = bp->vb_list; tvep != NULL; tvep = tvep->ve_next) { if (tvep->ve_vpvfs == vfsvpptr) { tvep->ve_refcnt++; mutex_exit(&bp->vb_lock); /* * There is already an entry in the hash * destroy what we just allocated. */ rwst_destroy(&vep->ve_lock); kmem_free(vep, sizeof (*vep)); return (tvep); } } vep->ve_next = bp->vb_list; bp->vb_list = vep; mutex_exit(&bp->vb_lock); return (vep); } void vn_vfslocks_rele(vn_vfslocks_entry_t *vepent) { struct vn_vfslocks_bucket *bp; vn_vfslocks_entry_t *vep; vn_vfslocks_entry_t *pvep; ASSERT(vepent != NULL); ASSERT(vepent->ve_vpvfs != NULL); bp = &vn_vfslocks_buckets[VN_VFSLOCKS_HASH(vepent->ve_vpvfs)]; mutex_enter(&bp->vb_lock); vepent->ve_refcnt--; if ((int32_t)vepent->ve_refcnt < 0) cmn_err(CE_PANIC, "vn_vfslocks_rele: refcount negative"); if (vepent->ve_refcnt == 0) { for (vep = bp->vb_list; vep != NULL; vep = vep->ve_next) { if (vep->ve_vpvfs == vepent->ve_vpvfs) { if (bp->vb_list == vep) bp->vb_list = vep->ve_next; else { /* LINTED */ pvep->ve_next = vep->ve_next; } mutex_exit(&bp->vb_lock); rwst_destroy(&vep->ve_lock); kmem_free(vep, sizeof (*vep)); return; } pvep = vep; } cmn_err(CE_PANIC, "vn_vfslocks_rele: vp/vfs not found"); } mutex_exit(&bp->vb_lock); } /* * vn_vfswlock_wait is used to implement a lock which is logically a writers * lock protecting the v_vfsmountedhere field. * vn_vfswlock_wait has been modified to be similar to vn_vfswlock, * except that it blocks to acquire the lock VVFSLOCK. * * traverse() and routines re-implementing part of traverse (e.g. autofs) * need to hold this lock. mount(), vn_rename(), vn_remove() and so on * need the non-blocking version of the writers lock i.e. vn_vfswlock */ int vn_vfswlock_wait(vnode_t *vp) { int retval; vn_vfslocks_entry_t *vpvfsentry; ASSERT(vp != NULL); vpvfsentry = vn_vfslocks_getlock(vp); retval = rwst_enter_sig(&vpvfsentry->ve_lock, RW_WRITER); if (retval == EINTR) { vn_vfslocks_rele(vpvfsentry); return (EINTR); } return (retval); } int vn_vfsrlock_wait(vnode_t *vp) { int retval; vn_vfslocks_entry_t *vpvfsentry; ASSERT(vp != NULL); vpvfsentry = vn_vfslocks_getlock(vp); retval = rwst_enter_sig(&vpvfsentry->ve_lock, RW_READER); if (retval == EINTR) { vn_vfslocks_rele(vpvfsentry); return (EINTR); } return (retval); } /* * vn_vfswlock is used to implement a lock which is logically a writers lock * protecting the v_vfsmountedhere field. */ int vn_vfswlock(vnode_t *vp) { vn_vfslocks_entry_t *vpvfsentry; /* * If vp is NULL then somebody is trying to lock the covered vnode * of /. (vfs_vnodecovered is NULL for /). This situation will * only happen when unmounting /. Since that operation will fail * anyway, return EBUSY here instead of in VFS_UNMOUNT. */ if (vp == NULL) return (EBUSY); vpvfsentry = vn_vfslocks_getlock(vp); if (rwst_tryenter(&vpvfsentry->ve_lock, RW_WRITER)) return (0); vn_vfslocks_rele(vpvfsentry); return (EBUSY); } int vn_vfsrlock(vnode_t *vp) { vn_vfslocks_entry_t *vpvfsentry; /* * If vp is NULL then somebody is trying to lock the covered vnode * of /. (vfs_vnodecovered is NULL for /). This situation will * only happen when unmounting /. Since that operation will fail * anyway, return EBUSY here instead of in VFS_UNMOUNT. */ if (vp == NULL) return (EBUSY); vpvfsentry = vn_vfslocks_getlock(vp); if (rwst_tryenter(&vpvfsentry->ve_lock, RW_READER)) return (0); vn_vfslocks_rele(vpvfsentry); return (EBUSY); } void vn_vfsunlock(vnode_t *vp) { vn_vfslocks_entry_t *vpvfsentry; /* * ve_refcnt needs to be decremented twice. * 1. To release refernce after a call to vn_vfslocks_getlock() * 2. To release the reference from the locking routines like * vn_vfsrlock/vn_vfswlock etc,. */ vpvfsentry = vn_vfslocks_getlock(vp); vn_vfslocks_rele(vpvfsentry); rwst_exit(&vpvfsentry->ve_lock); vn_vfslocks_rele(vpvfsentry); } int vn_vfswlock_held(vnode_t *vp) { int held; vn_vfslocks_entry_t *vpvfsentry; ASSERT(vp != NULL); vpvfsentry = vn_vfslocks_getlock(vp); held = rwst_lock_held(&vpvfsentry->ve_lock, RW_WRITER); vn_vfslocks_rele(vpvfsentry); return (held); } int vn_make_ops( const char *name, /* Name of file system */ const fs_operation_def_t *templ, /* Operation specification */ vnodeops_t **actual) /* Return the vnodeops */ { int unused_ops; int error; *actual = (vnodeops_t *)kmem_alloc(sizeof (vnodeops_t), KM_SLEEP); (*actual)->vnop_name = name; error = fs_build_vector(*actual, &unused_ops, vn_ops_table, templ); if (error) { kmem_free(*actual, sizeof (vnodeops_t)); } #if DEBUG if (unused_ops != 0) cmn_err(CE_WARN, "vn_make_ops: %s: %d operations supplied " "but not used", name, unused_ops); #endif return (error); } /* * Free the vnodeops created as a result of vn_make_ops() */ void vn_freevnodeops(vnodeops_t *vnops) { kmem_free(vnops, sizeof (vnodeops_t)); } /* * Vnode cache. */ /* ARGSUSED */ static int vn_cache_constructor(void *buf, void *cdrarg, int kmflags) { struct vnode *vp; vp = buf; mutex_init(&vp->v_lock, NULL, MUTEX_DEFAULT, NULL); mutex_init(&vp->v_vsd_lock, NULL, MUTEX_DEFAULT, NULL); cv_init(&vp->v_cv, NULL, CV_DEFAULT, NULL); rw_init(&vp->v_nbllock, NULL, RW_DEFAULT, NULL); vp->v_femhead = NULL; /* Must be done before vn_reinit() */ - vp->v_path = NULL; + vp->v_path = vn_vpath_empty; + vp->v_path_stamp = 0; vp->v_mpssdata = NULL; vp->v_vsd = NULL; vp->v_fopdata = NULL; return (0); } /* ARGSUSED */ static void vn_cache_destructor(void *buf, void *cdrarg) { struct vnode *vp; vp = buf; rw_destroy(&vp->v_nbllock); cv_destroy(&vp->v_cv); mutex_destroy(&vp->v_vsd_lock); mutex_destroy(&vp->v_lock); } void vn_create_cache(void) { /* LINTED */ ASSERT((1 << VNODE_ALIGN_LOG2) == P2ROUNDUP(sizeof (struct vnode), VNODE_ALIGN)); vn_cache = kmem_cache_create("vn_cache", sizeof (struct vnode), VNODE_ALIGN, vn_cache_constructor, vn_cache_destructor, NULL, NULL, NULL, 0); } void vn_destroy_cache(void) { kmem_cache_destroy(vn_cache); } /* * Used by file systems when fs-specific nodes (e.g., ufs inodes) are * cached by the file system and vnodes remain associated. */ void vn_recycle(vnode_t *vp) { ASSERT(vp->v_pages == NULL); + VERIFY(vp->v_path != NULL); /* * XXX - This really belongs in vn_reinit(), but we have some issues * with the counts. Best to have it here for clean initialization. */ vp->v_rdcnt = 0; vp->v_wrcnt = 0; vp->v_mmap_read = 0; vp->v_mmap_write = 0; /* * If FEM was in use, make sure everything gets cleaned up * NOTE: vp->v_femhead is initialized to NULL in the vnode * constructor. */ if (vp->v_femhead) { /* XXX - There should be a free_femhead() that does all this */ ASSERT(vp->v_femhead->femh_list == NULL); mutex_destroy(&vp->v_femhead->femh_lock); kmem_free(vp->v_femhead, sizeof (*(vp->v_femhead))); vp->v_femhead = NULL; } - if (vp->v_path) { + if (vp->v_path != vn_vpath_empty) { kmem_free(vp->v_path, strlen(vp->v_path) + 1); - vp->v_path = NULL; + vp->v_path = vn_vpath_empty; } + vp->v_path_stamp = 0; if (vp->v_fopdata != NULL) { free_fopdata(vp); } vp->v_mpssdata = NULL; vsd_free(vp); } /* * Used to reset the vnode fields including those that are directly accessible * as well as those which require an accessor function. * * Does not initialize: * synchronization objects: v_lock, v_vsd_lock, v_nbllock, v_cv * v_data (since FS-nodes and vnodes point to each other and should * be updated simultaneously) * v_op (in case someone needs to make a VOP call on this object) */ void vn_reinit(vnode_t *vp) { vp->v_count = 1; vp->v_count_dnlc = 0; vp->v_vfsp = NULL; vp->v_stream = NULL; vp->v_vfsmountedhere = NULL; vp->v_flag = 0; vp->v_type = VNON; vp->v_rdev = NODEV; vp->v_filocks = NULL; vp->v_shrlocks = NULL; vp->v_pages = NULL; vp->v_locality = NULL; vp->v_xattrdir = NULL; + /* + * In a few specific instances, vn_reinit() is used to initialize + * locally defined vnode_t instances. Lacking the construction offered + * by vn_alloc(), these vnodes require v_path initialization. + */ + if (vp->v_path == NULL) { + vp->v_path = vn_vpath_empty; + } + /* Handles v_femhead, v_path, and the r/w/map counts */ vn_recycle(vp); } vnode_t * vn_alloc(int kmflag) { vnode_t *vp; vp = kmem_cache_alloc(vn_cache, kmflag); if (vp != NULL) { vp->v_femhead = NULL; /* Must be done before vn_reinit() */ vp->v_fopdata = NULL; vn_reinit(vp); } return (vp); } void vn_free(vnode_t *vp) { ASSERT(vp->v_shrlocks == NULL); ASSERT(vp->v_filocks == NULL); /* * Some file systems call vn_free() with v_count of zero, * some with v_count of 1. In any case, the value should * never be anything else. */ ASSERT((vp->v_count == 0) || (vp->v_count == 1)); ASSERT(vp->v_count_dnlc == 0); - if (vp->v_path != NULL) { + VERIFY(vp->v_path != NULL); + if (vp->v_path != vn_vpath_empty) { kmem_free(vp->v_path, strlen(vp->v_path) + 1); - vp->v_path = NULL; + vp->v_path = vn_vpath_empty; } /* If FEM was in use, make sure everything gets cleaned up */ if (vp->v_femhead) { /* XXX - There should be a free_femhead() that does all this */ ASSERT(vp->v_femhead->femh_list == NULL); mutex_destroy(&vp->v_femhead->femh_lock); kmem_free(vp->v_femhead, sizeof (*(vp->v_femhead))); vp->v_femhead = NULL; } if (vp->v_fopdata != NULL) { free_fopdata(vp); } vp->v_mpssdata = NULL; vsd_free(vp); kmem_cache_free(vn_cache, vp); } /* * vnode status changes, should define better states than 1, 0. */ void vn_reclaim(vnode_t *vp) { vfs_t *vfsp = vp->v_vfsp; if (vfsp == NULL || vfsp->vfs_implp == NULL || vfsp->vfs_femhead == NULL) { return; } (void) VFS_VNSTATE(vfsp, vp, VNTRANS_RECLAIMED); } void vn_idle(vnode_t *vp) { vfs_t *vfsp = vp->v_vfsp; if (vfsp == NULL || vfsp->vfs_implp == NULL || vfsp->vfs_femhead == NULL) { return; } (void) VFS_VNSTATE(vfsp, vp, VNTRANS_IDLED); } void vn_exists(vnode_t *vp) { vfs_t *vfsp = vp->v_vfsp; if (vfsp == NULL || vfsp->vfs_implp == NULL || vfsp->vfs_femhead == NULL) { return; } (void) VFS_VNSTATE(vfsp, vp, VNTRANS_EXISTS); } void vn_invalid(vnode_t *vp) { vfs_t *vfsp = vp->v_vfsp; if (vfsp == NULL || vfsp->vfs_implp == NULL || vfsp->vfs_femhead == NULL) { return; } (void) VFS_VNSTATE(vfsp, vp, VNTRANS_DESTROYED); } /* Vnode event notification */ int vnevent_support(vnode_t *vp, caller_context_t *ct) { if (vp == NULL) return (EINVAL); return (VOP_VNEVENT(vp, VE_SUPPORT, NULL, NULL, ct)); } void vnevent_rename_src(vnode_t *vp, vnode_t *dvp, char *name, caller_context_t *ct) { if (vp == NULL || vp->v_femhead == NULL) { return; } (void) VOP_VNEVENT(vp, VE_RENAME_SRC, dvp, name, ct); } void vnevent_rename_dest(vnode_t *vp, vnode_t *dvp, char *name, caller_context_t *ct) { if (vp == NULL || vp->v_femhead == NULL) { return; } (void) VOP_VNEVENT(vp, VE_RENAME_DEST, dvp, name, ct); } void vnevent_rename_dest_dir(vnode_t *vp, caller_context_t *ct) { if (vp == NULL || vp->v_femhead == NULL) { return; } (void) VOP_VNEVENT(vp, VE_RENAME_DEST_DIR, NULL, NULL, ct); } void vnevent_remove(vnode_t *vp, vnode_t *dvp, char *name, caller_context_t *ct) { if (vp == NULL || vp->v_femhead == NULL) { return; } (void) VOP_VNEVENT(vp, VE_REMOVE, dvp, name, ct); } void vnevent_rmdir(vnode_t *vp, vnode_t *dvp, char *name, caller_context_t *ct) { if (vp == NULL || vp->v_femhead == NULL) { return; } (void) VOP_VNEVENT(vp, VE_RMDIR, dvp, name, ct); } void vnevent_pre_rename_src(vnode_t *vp, vnode_t *dvp, char *name, caller_context_t *ct) { if (vp == NULL || vp->v_femhead == NULL) { return; } (void) VOP_VNEVENT(vp, VE_PRE_RENAME_SRC, dvp, name, ct); } void vnevent_pre_rename_dest(vnode_t *vp, vnode_t *dvp, char *name, caller_context_t *ct) { if (vp == NULL || vp->v_femhead == NULL) { return; } (void) VOP_VNEVENT(vp, VE_PRE_RENAME_DEST, dvp, name, ct); } void vnevent_pre_rename_dest_dir(vnode_t *vp, vnode_t *nvp, char *name, caller_context_t *ct) { if (vp == NULL || vp->v_femhead == NULL) { return; } (void) VOP_VNEVENT(vp, VE_PRE_RENAME_DEST_DIR, nvp, name, ct); } void vnevent_create(vnode_t *vp, caller_context_t *ct) { if (vp == NULL || vp->v_femhead == NULL) { return; } (void) VOP_VNEVENT(vp, VE_CREATE, NULL, NULL, ct); } void vnevent_link(vnode_t *vp, caller_context_t *ct) { if (vp == NULL || vp->v_femhead == NULL) { return; } (void) VOP_VNEVENT(vp, VE_LINK, NULL, NULL, ct); } void vnevent_mountedover(vnode_t *vp, caller_context_t *ct) { if (vp == NULL || vp->v_femhead == NULL) { return; } (void) VOP_VNEVENT(vp, VE_MOUNTEDOVER, NULL, NULL, ct); } void vnevent_truncate(vnode_t *vp, caller_context_t *ct) { if (vp == NULL || vp->v_femhead == NULL) { return; } (void) VOP_VNEVENT(vp, VE_TRUNCATE, NULL, NULL, ct); } /* * Vnode accessors. */ int vn_is_readonly(vnode_t *vp) { return (vp->v_vfsp->vfs_flag & VFS_RDONLY); } int vn_has_flocks(vnode_t *vp) { return (vp->v_filocks != NULL); } int vn_has_mandatory_locks(vnode_t *vp, int mode) { return ((vp->v_filocks != NULL) && (MANDLOCK(vp, mode))); } int vn_has_cached_data(vnode_t *vp) { return (vp->v_pages != NULL); } /* * Return 0 if the vnode in question shouldn't be permitted into a zone via * zone_enter(2). */ int vn_can_change_zones(vnode_t *vp) { struct vfssw *vswp; int allow = 1; vnode_t *rvp; if (nfs_global_client_only != 0) return (1); /* * We always want to look at the underlying vnode if there is one. */ if (VOP_REALVP(vp, &rvp, NULL) != 0) rvp = vp; /* * Some pseudo filesystems (including doorfs) don't actually register * their vfsops_t, so the following may return NULL; we happily let * such vnodes switch zones. */ vswp = vfs_getvfsswbyvfsops(vfs_getops(rvp->v_vfsp)); if (vswp != NULL) { if (vswp->vsw_flag & VSW_NOTZONESAFE) allow = 0; vfs_unrefvfssw(vswp); } return (allow); } /* * Return nonzero if the vnode is a mount point, zero if not. */ int vn_ismntpt(vnode_t *vp) { return (vp->v_vfsmountedhere != NULL); } /* Retrieve the vfs (if any) mounted on this vnode */ vfs_t * vn_mountedvfs(vnode_t *vp) { return (vp->v_vfsmountedhere); } /* * Return nonzero if the vnode is referenced by the dnlc, zero if not. */ int vn_in_dnlc(vnode_t *vp) { return (vp->v_count_dnlc > 0); } /* * vn_has_other_opens() checks whether a particular file is opened by more than * just the caller and whether the open is for read and/or write. * This routine is for calling after the caller has already called VOP_OPEN() * and the caller wishes to know if they are the only one with it open for * the mode(s) specified. * * Vnode counts are only kept on regular files (v_type=VREG). */ int vn_has_other_opens( vnode_t *vp, v_mode_t mode) { ASSERT(vp != NULL); switch (mode) { case V_WRITE: if (vp->v_wrcnt > 1) return (V_TRUE); break; case V_RDORWR: if ((vp->v_rdcnt > 1) || (vp->v_wrcnt > 1)) return (V_TRUE); break; case V_RDANDWR: if ((vp->v_rdcnt > 1) && (vp->v_wrcnt > 1)) return (V_TRUE); break; case V_READ: if (vp->v_rdcnt > 1) return (V_TRUE); break; } return (V_FALSE); } /* * vn_is_opened() checks whether a particular file is opened and * whether the open is for read and/or write. * * Vnode counts are only kept on regular files (v_type=VREG). */ int vn_is_opened( vnode_t *vp, v_mode_t mode) { ASSERT(vp != NULL); switch (mode) { case V_WRITE: if (vp->v_wrcnt) return (V_TRUE); break; case V_RDANDWR: if (vp->v_rdcnt && vp->v_wrcnt) return (V_TRUE); break; case V_RDORWR: if (vp->v_rdcnt || vp->v_wrcnt) return (V_TRUE); break; case V_READ: if (vp->v_rdcnt) return (V_TRUE); break; } return (V_FALSE); } /* * vn_is_mapped() checks whether a particular file is mapped and whether * the file is mapped read and/or write. */ int vn_is_mapped( vnode_t *vp, v_mode_t mode) { ASSERT(vp != NULL); #if !defined(_LP64) switch (mode) { /* * The atomic_add_64_nv functions force atomicity in the * case of 32 bit architectures. Otherwise the 64 bit values * require two fetches. The value of the fields may be * (potentially) changed between the first fetch and the * second */ case V_WRITE: if (atomic_add_64_nv((&(vp->v_mmap_write)), 0)) return (V_TRUE); break; case V_RDANDWR: if ((atomic_add_64_nv((&(vp->v_mmap_read)), 0)) && (atomic_add_64_nv((&(vp->v_mmap_write)), 0))) return (V_TRUE); break; case V_RDORWR: if ((atomic_add_64_nv((&(vp->v_mmap_read)), 0)) || (atomic_add_64_nv((&(vp->v_mmap_write)), 0))) return (V_TRUE); break; case V_READ: if (atomic_add_64_nv((&(vp->v_mmap_read)), 0)) return (V_TRUE); break; } #else switch (mode) { case V_WRITE: if (vp->v_mmap_write) return (V_TRUE); break; case V_RDANDWR: if (vp->v_mmap_read && vp->v_mmap_write) return (V_TRUE); break; case V_RDORWR: if (vp->v_mmap_read || vp->v_mmap_write) return (V_TRUE); break; case V_READ: if (vp->v_mmap_read) return (V_TRUE); break; } #endif return (V_FALSE); } /* * Set the operations vector for a vnode. * * FEM ensures that the v_femhead pointer is filled in before the * v_op pointer is changed. This means that if the v_femhead pointer * is NULL, and the v_op field hasn't changed since before which checked * the v_femhead pointer; then our update is ok - we are not racing with * FEM. */ void vn_setops(vnode_t *vp, vnodeops_t *vnodeops) { vnodeops_t *op; ASSERT(vp != NULL); ASSERT(vnodeops != NULL); op = vp->v_op; membar_consumer(); /* * If vp->v_femhead == NULL, then we'll call atomic_cas_ptr() to do * the compare-and-swap on vp->v_op. If either fails, then FEM is * in effect on the vnode and we need to have FEM deal with it. */ if (vp->v_femhead != NULL || atomic_cas_ptr(&vp->v_op, op, vnodeops) != op) { fem_setvnops(vp, vnodeops); } } /* * Retrieve the operations vector for a vnode * As with vn_setops(above); make sure we aren't racing with FEM. * FEM sets the v_op to a special, internal, vnodeops that wouldn't * make sense to the callers of this routine. */ vnodeops_t * vn_getops(vnode_t *vp) { vnodeops_t *op; ASSERT(vp != NULL); op = vp->v_op; membar_consumer(); if (vp->v_femhead == NULL && op == vp->v_op) { return (op); } else { return (fem_getvnops(vp)); } } /* * Returns non-zero (1) if the vnodeops matches that of the vnode. * Returns zero (0) if not. */ int vn_matchops(vnode_t *vp, vnodeops_t *vnodeops) { return (vn_getops(vp) == vnodeops); } /* * Returns non-zero (1) if the specified operation matches the * corresponding operation for that the vnode. * Returns zero (0) if not. */ #define MATCHNAME(n1, n2) (((n1)[0] == (n2)[0]) && (strcmp((n1), (n2)) == 0)) int vn_matchopval(vnode_t *vp, char *vopname, fs_generic_func_p funcp) { const fs_operation_trans_def_t *otdp; fs_generic_func_p *loc = NULL; vnodeops_t *vop = vn_getops(vp); ASSERT(vopname != NULL); for (otdp = vn_ops_table; otdp->name != NULL; otdp++) { if (MATCHNAME(otdp->name, vopname)) { loc = (fs_generic_func_p *) ((char *)(vop) + otdp->offset); break; } } return ((loc != NULL) && (*loc == funcp)); } /* * fs_new_caller_id() needs to return a unique ID on a given local system. * The IDs do not need to survive across reboots. These are primarily * used so that (FEM) monitors can detect particular callers (such as * the NFS server) to a given vnode/vfs operation. */ u_longlong_t fs_new_caller_id() { static uint64_t next_caller_id = 0LL; /* First call returns 1 */ return ((u_longlong_t)atomic_inc_64_nv(&next_caller_id)); } /* - * Given a starting vnode and a path, updates the path in the target vnode in - * a safe manner. If the vnode already has path information embedded, then the - * cached path is left untouched. + * The value stored in v_path is relative to rootdir, located in the global + * zone. Zones or chroot environments which reside deeper inside the VFS + * hierarchy will have a relative view of MAXPATHLEN since they are unaware of + * what lies below their perceived root. In order to keep v_path usable for + * these child environments, its allocations are allowed to exceed MAXPATHLEN. + * + * An upper bound of max_vnode_path is placed upon v_path allocations to + * prevent the system from going too wild at the behest of pathological + * behavior from the operator. */ - size_t max_vnode_path = 4 * MAXPATHLEN; + void -vn_setpath(vnode_t *rootvp, struct vnode *startvp, struct vnode *vp, - const char *path, size_t plen) +vn_clearpath(vnode_t *vp, hrtime_t compare_stamp) { - char *rpath; - vnode_t *base; - size_t rpathlen, rpathalloc; - int doslash = 1; + char *buf; - if (*path == '/') { - base = rootvp; - path++; - plen--; - } else { - base = startvp; - } - + mutex_enter(&vp->v_lock); /* - * We cannot grab base->v_lock while we hold vp->v_lock because of - * the potential for deadlock. + * If the snapshot of v_path_stamp passed in via compare_stamp does not + * match the present value on the vnode, it indicates that subsequent + * changes have occurred. The v_path value is not cleared in this case + * since the new value may be valid. */ - mutex_enter(&base->v_lock); - if (base->v_path == NULL) { - mutex_exit(&base->v_lock); + if (compare_stamp != 0 && vp->v_path_stamp != compare_stamp) { + mutex_exit(&vp->v_lock); return; } + buf = vp->v_path; + vp->v_path = vn_vpath_empty; + vp->v_path_stamp = 0; + mutex_exit(&vp->v_lock); + if (buf != vn_vpath_empty) { + kmem_free(buf, strlen(buf) + 1); + } +} - rpathlen = strlen(base->v_path); - rpathalloc = rpathlen + plen + 1; - /* Avoid adding a slash if there's already one there */ - if (base->v_path[rpathlen-1] == '/') - doslash = 0; - else - rpathalloc++; +static void +vn_setpath_common(vnode_t *pvp, vnode_t *vp, const char *name, size_t len, + boolean_t is_rename) +{ + char *buf, *oldbuf; + hrtime_t pstamp; + size_t baselen, buflen = 0; - /* - * We don't want to call kmem_alloc(KM_SLEEP) with kernel locks held, - * so we must do this dance. If, by chance, something changes the path, - * just give up since there is no real harm. - */ - mutex_exit(&base->v_lock); + /* Handle the vn_setpath_str case. */ + if (pvp == NULL) { + if (len + 1 > max_vnode_path) { + DTRACE_PROBE4(vn__setpath__too__long, vnode_t *, pvp, + vnode_t *, vp, char *, name, size_t, len + 1); + return; + } + buf = kmem_alloc(len + 1, KM_SLEEP); + bcopy(name, buf, len); + buf[len] = '\0'; - /* Paths should stay within reason */ - if (rpathalloc > max_vnode_path) + mutex_enter(&vp->v_lock); + oldbuf = vp->v_path; + vp->v_path = buf; + vp->v_path_stamp = gethrtime(); + mutex_exit(&vp->v_lock); + if (oldbuf != vn_vpath_empty) { + kmem_free(oldbuf, strlen(oldbuf) + 1); + } return; + } - rpath = kmem_alloc(rpathalloc, KM_SLEEP); + /* Take snapshot of parent dir */ + mutex_enter(&pvp->v_lock); - mutex_enter(&base->v_lock); - if (base->v_path == NULL || strlen(base->v_path) != rpathlen) { - mutex_exit(&base->v_lock); - kmem_free(rpath, rpathalloc); + if ((pvp->v_flag & VTRAVERSE) != 0) { + /* + * When the parent vnode has VTRAVERSE set in its flags, normal + * assumptions about v_path calculation no longer apply. The + * primary situation where this occurs is via the VFS tricks + * which procfs plays in order to allow /proc/PID/(root|cwd) to + * yield meaningful results. + * + * When this flag is set, v_path on the child must not be + * updated since the calculated value is likely to be + * incorrect, given the current context. + */ + mutex_exit(&pvp->v_lock); return; } - bcopy(base->v_path, rpath, rpathlen); - mutex_exit(&base->v_lock); - if (doslash) - rpath[rpathlen++] = '/'; - bcopy(path, rpath + rpathlen, plen); - rpath[rpathlen + plen] = '\0'; +retrybuf: + if (pvp->v_path == vn_vpath_empty) { + /* + * Without v_path from the parent directory, generating a child + * path from the name is impossible. + */ + if (len > 0) { + pstamp = pvp->v_path_stamp; + mutex_exit(&pvp->v_lock); + vn_clearpath(vp, pstamp); + return; + } + /* + * The only feasible case here is where a NUL lookup is being + * performed on rootdir prior to its v_path being populated. + */ + ASSERT(pvp->v_path_stamp == 0); + baselen = 0; + pstamp = 0; + } else { + pstamp = pvp->v_path_stamp; + baselen = strlen(pvp->v_path); + /* ignore a trailing slash if present */ + if (pvp->v_path[baselen - 1] == '/') { + /* This should only the be case for rootdir */ + ASSERT(baselen == 1 && pvp == rootdir); + baselen--; + } + } + mutex_exit(&pvp->v_lock); + + if (buflen != 0) { + /* Free the existing (mis-sized) buffer in case of retry */ + kmem_free(buf, buflen); + } + /* base, '/', name and trailing NUL */ + buflen = baselen + len + 2; + if (buflen > max_vnode_path) { + DTRACE_PROBE4(vn__setpath_too__long, vnode_t *, pvp, + vnode_t *, vp, char *, name, size_t, buflen); + return; + } + buf = kmem_alloc(buflen, KM_SLEEP); + + mutex_enter(&pvp->v_lock); + if (pvp->v_path_stamp != pstamp) { + size_t vlen; + + /* + * Since v_path_stamp changed on the parent, it is likely that + * v_path has been altered as well. If the length does not + * exactly match what was previously measured, the buffer + * allocation must be repeated for proper sizing. + */ + if (pvp->v_path == vn_vpath_empty) { + /* Give up if parent lack v_path */ + mutex_exit(&pvp->v_lock); + kmem_free(buf, buflen); + return; + } + vlen = strlen(pvp->v_path); + if (pvp->v_path[vlen - 1] == '/') { + vlen--; + } + if (vlen != baselen) { + goto retrybuf; + } + } + bcopy(pvp->v_path, buf, baselen); + mutex_exit(&pvp->v_lock); + + buf[baselen] = '/'; + baselen++; + bcopy(name, &buf[baselen], len + 1); + mutex_enter(&vp->v_lock); - if (vp->v_path != NULL) { + if (vp->v_path_stamp == 0) { + /* never-visited vnode can inherit stamp from parent */ + ASSERT(vp->v_path == vn_vpath_empty); + vp->v_path_stamp = pstamp; + vp->v_path = buf; mutex_exit(&vp->v_lock); - kmem_free(rpath, rpathalloc); + } else if (vp->v_path_stamp < pstamp || is_rename) { + /* + * Install the updated path and stamp, ensuring that the v_path + * pointer is valid at all times for dtrace. + */ + oldbuf = vp->v_path; + vp->v_path = buf; + vp->v_path_stamp = gethrtime(); + mutex_exit(&vp->v_lock); + kmem_free(oldbuf, strlen(oldbuf) + 1); } else { - vp->v_path = rpath; + /* + * If the timestamp matches or is greater, it means another + * thread performed the update first while locks were dropped + * here to make the allocation. We defer to the newer value. + */ mutex_exit(&vp->v_lock); + kmem_free(buf, buflen); } + ASSERT(MUTEX_NOT_HELD(&vp->v_lock)); } -/* - * Sets the path to the vnode to be the given string, regardless of current - * context. The string must be a complete path from rootdir. This is only used - * by fsop_root() for setting the path based on the mountpoint. - */ void -vn_setpath_str(struct vnode *vp, const char *str, size_t len) +vn_updatepath(vnode_t *pvp, vnode_t *vp, const char *name) { - char *buf = kmem_alloc(len + 1, KM_SLEEP); + size_t len; - mutex_enter(&vp->v_lock); - if (vp->v_path != NULL) { - mutex_exit(&vp->v_lock); - kmem_free(buf, len + 1); + /* + * If the parent is older or empty, there's nothing further to do. + */ + if (pvp->v_path == vn_vpath_empty || + pvp->v_path_stamp <= vp->v_path_stamp) { return; } - vp->v_path = buf; - bcopy(str, vp->v_path, len); - vp->v_path[len] = '\0'; + /* + * Given the lack of appropriate context, meaningful updates to v_path + * cannot be made for during lookups for the '.' or '..' entries. + */ + len = strlen(name); + if (len == 0 || (len == 1 && name[0] == '.') || + (len == 2 && name[0] == '.' && name[1] == '.')) { + return; + } - mutex_exit(&vp->v_lock); + vn_setpath_common(pvp, vp, name, len, B_FALSE); } /* + * Given a starting vnode and a path, updates the path in the target vnode in + * a safe manner. If the vnode already has path information embedded, then the + * cached path is left untouched. + */ +/* ARGSUSED */ +void +vn_setpath(vnode_t *rootvp, vnode_t *pvp, vnode_t *vp, const char *name, + size_t len) +{ + vn_setpath_common(pvp, vp, name, len, B_FALSE); +} + +/* + * Sets the path to the vnode to be the given string, regardless of current + * context. The string must be a complete path from rootdir. This is only used + * by fsop_root() for setting the path based on the mountpoint. + */ +void +vn_setpath_str(vnode_t *vp, const char *str, size_t len) +{ + vn_setpath_common(NULL, vp, str, len, B_FALSE); +} + +/* * Called from within filesystem's vop_rename() to handle renames once the * target vnode is available. */ void -vn_renamepath(vnode_t *dvp, vnode_t *vp, const char *nm, size_t len) +vn_renamepath(vnode_t *pvp, vnode_t *vp, const char *name, size_t len) { - char *tmp; - - mutex_enter(&vp->v_lock); - tmp = vp->v_path; - vp->v_path = NULL; - mutex_exit(&vp->v_lock); - vn_setpath(rootdir, dvp, vp, nm, len); - if (tmp != NULL) - kmem_free(tmp, strlen(tmp) + 1); + vn_setpath_common(pvp, vp, name, len, B_TRUE); } /* * Similar to vn_setpath_str(), this function sets the path of the destination * vnode to the be the same as the source vnode. */ void vn_copypath(struct vnode *src, struct vnode *dst) { char *buf; - int alloc; + hrtime_t stamp; + size_t buflen; mutex_enter(&src->v_lock); - if (src->v_path == NULL) { + if (src->v_path == vn_vpath_empty) { mutex_exit(&src->v_lock); return; } - alloc = strlen(src->v_path) + 1; - - /* avoid kmem_alloc() with lock held */ + buflen = strlen(src->v_path) + 1; mutex_exit(&src->v_lock); - buf = kmem_alloc(alloc, KM_SLEEP); + + buf = kmem_alloc(buflen, KM_SLEEP); + mutex_enter(&src->v_lock); - if (src->v_path == NULL || strlen(src->v_path) + 1 != alloc) { + if (src->v_path == vn_vpath_empty || + strlen(src->v_path) + 1 != buflen) { mutex_exit(&src->v_lock); - kmem_free(buf, alloc); + kmem_free(buf, buflen); return; } - bcopy(src->v_path, buf, alloc); + bcopy(src->v_path, buf, buflen); + stamp = src->v_path_stamp; mutex_exit(&src->v_lock); mutex_enter(&dst->v_lock); - if (dst->v_path != NULL) { + if (dst->v_path != vn_vpath_empty) { mutex_exit(&dst->v_lock); - kmem_free(buf, alloc); + kmem_free(buf, buflen); return; } dst->v_path = buf; + dst->v_path_stamp = stamp; mutex_exit(&dst->v_lock); } + /* * XXX Private interface for segvn routines that handle vnode * large page segments. * * return 1 if vp's file system VOP_PAGEIO() implementation * can be safely used instead of VOP_GETPAGE() for handling * pagefaults against regular non swap files. VOP_PAGEIO() * interface is considered safe here if its implementation * is very close to VOP_GETPAGE() implementation. * e.g. It zero's out the part of the page beyond EOF. Doesn't * panic if there're file holes but instead returns an error. * Doesn't assume file won't be changed by user writes, etc. * * return 0 otherwise. * * For now allow segvn to only use VOP_PAGEIO() with ufs and nfs. */ int vn_vmpss_usepageio(vnode_t *vp) { vfs_t *vfsp = vp->v_vfsp; char *fsname = vfssw[vfsp->vfs_fstype].vsw_name; char *pageio_ok_fss[] = {"ufs", "nfs", NULL}; char **fsok = pageio_ok_fss; if (fsname == NULL) { return (0); } for (; *fsok; fsok++) { if (strcmp(*fsok, fsname) == 0) { return (1); } } return (0); } /* VOP_XXX() macros call the corresponding fop_xxx() function */ int fop_open( vnode_t **vpp, int mode, cred_t *cr, caller_context_t *ct) { int ret; vnode_t *vp = *vpp; VN_HOLD(vp); /* * Adding to the vnode counts before calling open * avoids the need for a mutex. It circumvents a race * condition where a query made on the vnode counts results in a * false negative. The inquirer goes away believing the file is * not open when there is an open on the file already under way. * * The counts are meant to prevent NFS from granting a delegation * when it would be dangerous to do so. * * The vnode counts are only kept on regular files */ if ((*vpp)->v_type == VREG) { if (mode & FREAD) atomic_inc_32(&(*vpp)->v_rdcnt); if (mode & FWRITE) atomic_inc_32(&(*vpp)->v_wrcnt); } VOPXID_MAP_CR(vp, cr); ret = (*(*(vpp))->v_op->vop_open)(vpp, mode, cr, ct); if (ret) { /* * Use the saved vp just in case the vnode ptr got trashed * by the error. */ VOPSTATS_UPDATE(vp, open); if ((vp->v_type == VREG) && (mode & FREAD)) atomic_dec_32(&vp->v_rdcnt); if ((vp->v_type == VREG) && (mode & FWRITE)) atomic_dec_32(&vp->v_wrcnt); } else { /* * Some filesystems will return a different vnode, * but the same path was still used to open it. * So if we do change the vnode and need to * copy over the path, do so here, rather than special * casing each filesystem. Adjust the vnode counts to * reflect the vnode switch. */ VOPSTATS_UPDATE(*vpp, open); if (*vpp != vp && *vpp != NULL) { vn_copypath(vp, *vpp); if (((*vpp)->v_type == VREG) && (mode & FREAD)) atomic_inc_32(&(*vpp)->v_rdcnt); if ((vp->v_type == VREG) && (mode & FREAD)) atomic_dec_32(&vp->v_rdcnt); if (((*vpp)->v_type == VREG) && (mode & FWRITE)) atomic_inc_32(&(*vpp)->v_wrcnt); if ((vp->v_type == VREG) && (mode & FWRITE)) atomic_dec_32(&vp->v_wrcnt); } } VN_RELE(vp); return (ret); } int fop_close( vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_close)(vp, flag, count, offset, cr, ct); VOPSTATS_UPDATE(vp, close); /* * Check passed in count to handle possible dups. Vnode counts are only * kept on regular files */ if ((vp->v_type == VREG) && (count == 1)) { if (flag & FREAD) { ASSERT(vp->v_rdcnt > 0); atomic_dec_32(&vp->v_rdcnt); } if (flag & FWRITE) { ASSERT(vp->v_wrcnt > 0); atomic_dec_32(&vp->v_wrcnt); } } return (err); } int fop_read( vnode_t *vp, uio_t *uiop, int ioflag, cred_t *cr, caller_context_t *ct) { int err; ssize_t resid_start = uiop->uio_resid; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_read)(vp, uiop, ioflag, cr, ct); VOPSTATS_UPDATE_IO(vp, read, read_bytes, (resid_start - uiop->uio_resid)); return (err); } int fop_write( vnode_t *vp, uio_t *uiop, int ioflag, cred_t *cr, caller_context_t *ct) { int err; ssize_t resid_start = uiop->uio_resid; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_write)(vp, uiop, ioflag, cr, ct); VOPSTATS_UPDATE_IO(vp, write, write_bytes, (resid_start - uiop->uio_resid)); return (err); } int fop_ioctl( vnode_t *vp, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_ioctl)(vp, cmd, arg, flag, cr, rvalp, ct); VOPSTATS_UPDATE(vp, ioctl); return (err); } int fop_setfl( vnode_t *vp, int oflags, int nflags, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_setfl)(vp, oflags, nflags, cr, ct); VOPSTATS_UPDATE(vp, setfl); return (err); } int fop_getattr( vnode_t *vp, vattr_t *vap, int flags, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); /* * If this file system doesn't understand the xvattr extensions * then turn off the xvattr bit. */ if (vfs_has_feature(vp->v_vfsp, VFSFT_XVATTR) == 0) { vap->va_mask &= ~AT_XVATTR; } /* * We're only allowed to skip the ACL check iff we used a 32 bit * ACE mask with VOP_ACCESS() to determine permissions. */ if ((flags & ATTR_NOACLCHECK) && vfs_has_feature(vp->v_vfsp, VFSFT_ACEMASKONACCESS) == 0) { return (EINVAL); } err = (*(vp)->v_op->vop_getattr)(vp, vap, flags, cr, ct); VOPSTATS_UPDATE(vp, getattr); return (err); } int fop_setattr( vnode_t *vp, vattr_t *vap, int flags, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); /* * If this file system doesn't understand the xvattr extensions * then turn off the xvattr bit. */ if (vfs_has_feature(vp->v_vfsp, VFSFT_XVATTR) == 0) { vap->va_mask &= ~AT_XVATTR; } /* * We're only allowed to skip the ACL check iff we used a 32 bit * ACE mask with VOP_ACCESS() to determine permissions. */ if ((flags & ATTR_NOACLCHECK) && vfs_has_feature(vp->v_vfsp, VFSFT_ACEMASKONACCESS) == 0) { return (EINVAL); } err = (*(vp)->v_op->vop_setattr)(vp, vap, flags, cr, ct); VOPSTATS_UPDATE(vp, setattr); return (err); } int fop_access( vnode_t *vp, int mode, int flags, cred_t *cr, caller_context_t *ct) { int err; if ((flags & V_ACE_MASK) && vfs_has_feature(vp->v_vfsp, VFSFT_ACEMASKONACCESS) == 0) { return (EINVAL); } VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_access)(vp, mode, flags, cr, ct); VOPSTATS_UPDATE(vp, access); return (err); } int fop_lookup( vnode_t *dvp, char *nm, vnode_t **vpp, pathname_t *pnp, int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct, int *deflags, /* Returned per-dirent flags */ pathname_t *ppnp) /* Returned case-preserved name in directory */ { int ret; /* * If this file system doesn't support case-insensitive access * and said access is requested, fail quickly. It is required * that if the vfs supports case-insensitive lookup, it also * supports extended dirent flags. */ if (flags & FIGNORECASE && (vfs_has_feature(dvp->v_vfsp, VFSFT_CASEINSENSITIVE) == 0 && vfs_has_feature(dvp->v_vfsp, VFSFT_NOCASESENSITIVE) == 0)) return (EINVAL); VOPXID_MAP_CR(dvp, cr); if ((flags & LOOKUP_XATTR) && (flags & LOOKUP_HAVE_SYSATTR_DIR) == 0) { ret = xattr_dir_lookup(dvp, vpp, flags, cr); } else { ret = (*(dvp)->v_op->vop_lookup) (dvp, nm, vpp, pnp, flags, rdir, cr, ct, deflags, ppnp); } if (ret == 0 && *vpp) { VOPSTATS_UPDATE(*vpp, lookup); - if ((*vpp)->v_path == NULL) { - vn_setpath(rootdir, dvp, *vpp, nm, strlen(nm)); - } + vn_updatepath(dvp, *vpp, nm); } return (ret); } int fop_create( vnode_t *dvp, char *name, vattr_t *vap, vcexcl_t excl, int mode, vnode_t **vpp, cred_t *cr, int flags, caller_context_t *ct, vsecattr_t *vsecp) /* ACL to set during create */ { int ret; if (vsecp != NULL && vfs_has_feature(dvp->v_vfsp, VFSFT_ACLONCREATE) == 0) { return (EINVAL); } /* * If this file system doesn't support case-insensitive access * and said access is requested, fail quickly. */ if (flags & FIGNORECASE && (vfs_has_feature(dvp->v_vfsp, VFSFT_CASEINSENSITIVE) == 0 && vfs_has_feature(dvp->v_vfsp, VFSFT_NOCASESENSITIVE) == 0)) return (EINVAL); VOPXID_MAP_CR(dvp, cr); ret = (*(dvp)->v_op->vop_create) (dvp, name, vap, excl, mode, vpp, cr, flags, ct, vsecp); if (ret == 0 && *vpp) { VOPSTATS_UPDATE(*vpp, create); - if ((*vpp)->v_path == NULL) { - vn_setpath(rootdir, dvp, *vpp, name, strlen(name)); - } + vn_updatepath(dvp, *vpp, name); } return (ret); } int fop_remove( vnode_t *dvp, char *nm, cred_t *cr, caller_context_t *ct, int flags) { int err; /* * If this file system doesn't support case-insensitive access * and said access is requested, fail quickly. */ if (flags & FIGNORECASE && (vfs_has_feature(dvp->v_vfsp, VFSFT_CASEINSENSITIVE) == 0 && vfs_has_feature(dvp->v_vfsp, VFSFT_NOCASESENSITIVE) == 0)) return (EINVAL); VOPXID_MAP_CR(dvp, cr); err = (*(dvp)->v_op->vop_remove)(dvp, nm, cr, ct, flags); VOPSTATS_UPDATE(dvp, remove); return (err); } int fop_link( vnode_t *tdvp, vnode_t *svp, char *tnm, cred_t *cr, caller_context_t *ct, int flags) { int err; /* * If the target file system doesn't support case-insensitive access * and said access is requested, fail quickly. */ if (flags & FIGNORECASE && (vfs_has_feature(tdvp->v_vfsp, VFSFT_CASEINSENSITIVE) == 0 && vfs_has_feature(tdvp->v_vfsp, VFSFT_NOCASESENSITIVE) == 0)) return (EINVAL); VOPXID_MAP_CR(tdvp, cr); err = (*(tdvp)->v_op->vop_link)(tdvp, svp, tnm, cr, ct, flags); VOPSTATS_UPDATE(tdvp, link); return (err); } int fop_rename( vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm, cred_t *cr, caller_context_t *ct, int flags) { int err; /* * If the file system involved does not support * case-insensitive access and said access is requested, fail * quickly. */ if (flags & FIGNORECASE && ((vfs_has_feature(sdvp->v_vfsp, VFSFT_CASEINSENSITIVE) == 0 && vfs_has_feature(sdvp->v_vfsp, VFSFT_NOCASESENSITIVE) == 0))) return (EINVAL); VOPXID_MAP_CR(tdvp, cr); err = (*(sdvp)->v_op->vop_rename)(sdvp, snm, tdvp, tnm, cr, ct, flags); VOPSTATS_UPDATE(sdvp, rename); return (err); } int fop_mkdir( vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp, cred_t *cr, caller_context_t *ct, int flags, vsecattr_t *vsecp) /* ACL to set during create */ { int ret; if (vsecp != NULL && vfs_has_feature(dvp->v_vfsp, VFSFT_ACLONCREATE) == 0) { return (EINVAL); } /* * If this file system doesn't support case-insensitive access * and said access is requested, fail quickly. */ if (flags & FIGNORECASE && (vfs_has_feature(dvp->v_vfsp, VFSFT_CASEINSENSITIVE) == 0 && vfs_has_feature(dvp->v_vfsp, VFSFT_NOCASESENSITIVE) == 0)) return (EINVAL); VOPXID_MAP_CR(dvp, cr); ret = (*(dvp)->v_op->vop_mkdir) (dvp, dirname, vap, vpp, cr, ct, flags, vsecp); if (ret == 0 && *vpp) { VOPSTATS_UPDATE(*vpp, mkdir); - if ((*vpp)->v_path == NULL) { - vn_setpath(rootdir, dvp, *vpp, dirname, - strlen(dirname)); - } + vn_updatepath(dvp, *vpp, dirname); } return (ret); } int fop_rmdir( vnode_t *dvp, char *nm, vnode_t *cdir, cred_t *cr, caller_context_t *ct, int flags) { int err; /* * If this file system doesn't support case-insensitive access * and said access is requested, fail quickly. */ if (flags & FIGNORECASE && (vfs_has_feature(dvp->v_vfsp, VFSFT_CASEINSENSITIVE) == 0 && vfs_has_feature(dvp->v_vfsp, VFSFT_NOCASESENSITIVE) == 0)) return (EINVAL); VOPXID_MAP_CR(dvp, cr); err = (*(dvp)->v_op->vop_rmdir)(dvp, nm, cdir, cr, ct, flags); VOPSTATS_UPDATE(dvp, rmdir); return (err); } int fop_readdir( vnode_t *vp, uio_t *uiop, cred_t *cr, int *eofp, caller_context_t *ct, int flags) { int err; ssize_t resid_start = uiop->uio_resid; /* * If this file system doesn't support retrieving directory * entry flags and said access is requested, fail quickly. */ if (flags & V_RDDIR_ENTFLAGS && vfs_has_feature(vp->v_vfsp, VFSFT_DIRENTFLAGS) == 0) return (EINVAL); VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_readdir)(vp, uiop, cr, eofp, ct, flags); VOPSTATS_UPDATE_IO(vp, readdir, readdir_bytes, (resid_start - uiop->uio_resid)); return (err); } int fop_symlink( vnode_t *dvp, char *linkname, vattr_t *vap, char *target, cred_t *cr, caller_context_t *ct, int flags) { int err; xvattr_t xvattr; /* * If this file system doesn't support case-insensitive access * and said access is requested, fail quickly. */ if (flags & FIGNORECASE && (vfs_has_feature(dvp->v_vfsp, VFSFT_CASEINSENSITIVE) == 0 && vfs_has_feature(dvp->v_vfsp, VFSFT_NOCASESENSITIVE) == 0)) return (EINVAL); VOPXID_MAP_CR(dvp, cr); /* check for reparse point */ if ((vfs_has_feature(dvp->v_vfsp, VFSFT_REPARSE)) && (strncmp(target, FS_REPARSE_TAG_STR, strlen(FS_REPARSE_TAG_STR)) == 0)) { if (!fs_reparse_mark(target, vap, &xvattr)) vap = (vattr_t *)&xvattr; } err = (*(dvp)->v_op->vop_symlink) (dvp, linkname, vap, target, cr, ct, flags); VOPSTATS_UPDATE(dvp, symlink); return (err); } int fop_readlink( vnode_t *vp, uio_t *uiop, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_readlink)(vp, uiop, cr, ct); VOPSTATS_UPDATE(vp, readlink); return (err); } int fop_fsync( vnode_t *vp, int syncflag, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_fsync)(vp, syncflag, cr, ct); VOPSTATS_UPDATE(vp, fsync); return (err); } void fop_inactive( vnode_t *vp, cred_t *cr, caller_context_t *ct) { /* Need to update stats before vop call since we may lose the vnode */ VOPSTATS_UPDATE(vp, inactive); VOPXID_MAP_CR(vp, cr); (*(vp)->v_op->vop_inactive)(vp, cr, ct); } int fop_fid( vnode_t *vp, fid_t *fidp, caller_context_t *ct) { int err; err = (*(vp)->v_op->vop_fid)(vp, fidp, ct); VOPSTATS_UPDATE(vp, fid); return (err); } int fop_rwlock( vnode_t *vp, int write_lock, caller_context_t *ct) { int ret; ret = ((*(vp)->v_op->vop_rwlock)(vp, write_lock, ct)); VOPSTATS_UPDATE(vp, rwlock); return (ret); } void fop_rwunlock( vnode_t *vp, int write_lock, caller_context_t *ct) { (*(vp)->v_op->vop_rwunlock)(vp, write_lock, ct); VOPSTATS_UPDATE(vp, rwunlock); } int fop_seek( vnode_t *vp, offset_t ooff, offset_t *noffp, caller_context_t *ct) { int err; err = (*(vp)->v_op->vop_seek)(vp, ooff, noffp, ct); VOPSTATS_UPDATE(vp, seek); return (err); } int fop_cmp( vnode_t *vp1, vnode_t *vp2, caller_context_t *ct) { int err; err = (*(vp1)->v_op->vop_cmp)(vp1, vp2, ct); VOPSTATS_UPDATE(vp1, cmp); return (err); } int fop_frlock( vnode_t *vp, int cmd, flock64_t *bfp, int flag, offset_t offset, struct flk_callback *flk_cbp, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_frlock) (vp, cmd, bfp, flag, offset, flk_cbp, cr, ct); VOPSTATS_UPDATE(vp, frlock); return (err); } int fop_space( vnode_t *vp, int cmd, flock64_t *bfp, int flag, offset_t offset, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_space)(vp, cmd, bfp, flag, offset, cr, ct); VOPSTATS_UPDATE(vp, space); return (err); } int fop_realvp( vnode_t *vp, vnode_t **vpp, caller_context_t *ct) { int err; err = (*(vp)->v_op->vop_realvp)(vp, vpp, ct); VOPSTATS_UPDATE(vp, realvp); return (err); } int fop_getpage( vnode_t *vp, offset_t off, size_t len, uint_t *protp, page_t **plarr, size_t plsz, struct seg *seg, caddr_t addr, enum seg_rw rw, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_getpage) (vp, off, len, protp, plarr, plsz, seg, addr, rw, cr, ct); VOPSTATS_UPDATE(vp, getpage); return (err); } int fop_putpage( vnode_t *vp, offset_t off, size_t len, int flags, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_putpage)(vp, off, len, flags, cr, ct); VOPSTATS_UPDATE(vp, putpage); return (err); } int fop_map( vnode_t *vp, offset_t off, struct as *as, caddr_t *addrp, size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_map) (vp, off, as, addrp, len, prot, maxprot, flags, cr, ct); VOPSTATS_UPDATE(vp, map); return (err); } int fop_addmap( vnode_t *vp, offset_t off, struct as *as, caddr_t addr, size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr, caller_context_t *ct) { int error; u_longlong_t delta; VOPXID_MAP_CR(vp, cr); error = (*(vp)->v_op->vop_addmap) (vp, off, as, addr, len, prot, maxprot, flags, cr, ct); if ((!error) && (vp->v_type == VREG)) { delta = (u_longlong_t)btopr(len); /* * If file is declared MAP_PRIVATE, it can't be written back * even if open for write. Handle as read. */ if (flags & MAP_PRIVATE) { atomic_add_64((uint64_t *)(&(vp->v_mmap_read)), (int64_t)delta); } else { /* * atomic_add_64 forces the fetch of a 64 bit value to * be atomic on 32 bit machines */ if (maxprot & PROT_WRITE) atomic_add_64((uint64_t *)(&(vp->v_mmap_write)), (int64_t)delta); if (maxprot & PROT_READ) atomic_add_64((uint64_t *)(&(vp->v_mmap_read)), (int64_t)delta); if (maxprot & PROT_EXEC) atomic_add_64((uint64_t *)(&(vp->v_mmap_read)), (int64_t)delta); } } VOPSTATS_UPDATE(vp, addmap); return (error); } int fop_delmap( vnode_t *vp, offset_t off, struct as *as, caddr_t addr, size_t len, uint_t prot, uint_t maxprot, uint_t flags, cred_t *cr, caller_context_t *ct) { int error; u_longlong_t delta; VOPXID_MAP_CR(vp, cr); error = (*(vp)->v_op->vop_delmap) (vp, off, as, addr, len, prot, maxprot, flags, cr, ct); /* * NFS calls into delmap twice, the first time * it simply establishes a callback mechanism and returns EAGAIN * while the real work is being done upon the second invocation. * We have to detect this here and only decrement the counts upon * the second delmap request. */ if ((error != EAGAIN) && (vp->v_type == VREG)) { delta = (u_longlong_t)btopr(len); if (flags & MAP_PRIVATE) { atomic_add_64((uint64_t *)(&(vp->v_mmap_read)), (int64_t)(-delta)); } else { /* * atomic_add_64 forces the fetch of a 64 bit value * to be atomic on 32 bit machines */ if (maxprot & PROT_WRITE) atomic_add_64((uint64_t *)(&(vp->v_mmap_write)), (int64_t)(-delta)); if (maxprot & PROT_READ) atomic_add_64((uint64_t *)(&(vp->v_mmap_read)), (int64_t)(-delta)); if (maxprot & PROT_EXEC) atomic_add_64((uint64_t *)(&(vp->v_mmap_read)), (int64_t)(-delta)); } } VOPSTATS_UPDATE(vp, delmap); return (error); } int fop_poll( vnode_t *vp, short events, int anyyet, short *reventsp, struct pollhead **phpp, caller_context_t *ct) { int err; err = (*(vp)->v_op->vop_poll)(vp, events, anyyet, reventsp, phpp, ct); VOPSTATS_UPDATE(vp, poll); return (err); } int fop_dump( vnode_t *vp, caddr_t addr, offset_t lbdn, offset_t dblks, caller_context_t *ct) { int err; /* ensure lbdn and dblks can be passed safely to bdev_dump */ if ((lbdn != (daddr_t)lbdn) || (dblks != (int)dblks)) return (EIO); err = (*(vp)->v_op->vop_dump)(vp, addr, lbdn, dblks, ct); VOPSTATS_UPDATE(vp, dump); return (err); } int fop_pathconf( vnode_t *vp, int cmd, ulong_t *valp, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_pathconf)(vp, cmd, valp, cr, ct); VOPSTATS_UPDATE(vp, pathconf); return (err); } int fop_pageio( vnode_t *vp, struct page *pp, u_offset_t io_off, size_t io_len, int flags, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_pageio)(vp, pp, io_off, io_len, flags, cr, ct); VOPSTATS_UPDATE(vp, pageio); return (err); } int fop_dumpctl( vnode_t *vp, int action, offset_t *blkp, caller_context_t *ct) { int err; err = (*(vp)->v_op->vop_dumpctl)(vp, action, blkp, ct); VOPSTATS_UPDATE(vp, dumpctl); return (err); } void fop_dispose( vnode_t *vp, page_t *pp, int flag, int dn, cred_t *cr, caller_context_t *ct) { /* Must do stats first since it's possible to lose the vnode */ VOPSTATS_UPDATE(vp, dispose); VOPXID_MAP_CR(vp, cr); (*(vp)->v_op->vop_dispose)(vp, pp, flag, dn, cr, ct); } int fop_setsecattr( vnode_t *vp, vsecattr_t *vsap, int flag, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); /* * We're only allowed to skip the ACL check iff we used a 32 bit * ACE mask with VOP_ACCESS() to determine permissions. */ if ((flag & ATTR_NOACLCHECK) && vfs_has_feature(vp->v_vfsp, VFSFT_ACEMASKONACCESS) == 0) { return (EINVAL); } err = (*(vp)->v_op->vop_setsecattr) (vp, vsap, flag, cr, ct); VOPSTATS_UPDATE(vp, setsecattr); return (err); } int fop_getsecattr( vnode_t *vp, vsecattr_t *vsap, int flag, cred_t *cr, caller_context_t *ct) { int err; /* * We're only allowed to skip the ACL check iff we used a 32 bit * ACE mask with VOP_ACCESS() to determine permissions. */ if ((flag & ATTR_NOACLCHECK) && vfs_has_feature(vp->v_vfsp, VFSFT_ACEMASKONACCESS) == 0) { return (EINVAL); } VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_getsecattr) (vp, vsap, flag, cr, ct); VOPSTATS_UPDATE(vp, getsecattr); return (err); } int fop_shrlock( vnode_t *vp, int cmd, struct shrlock *shr, int flag, cred_t *cr, caller_context_t *ct) { int err; VOPXID_MAP_CR(vp, cr); err = (*(vp)->v_op->vop_shrlock)(vp, cmd, shr, flag, cr, ct); VOPSTATS_UPDATE(vp, shrlock); return (err); } int fop_vnevent(vnode_t *vp, vnevent_t vnevent, vnode_t *dvp, char *fnm, caller_context_t *ct) { int err; err = (*(vp)->v_op->vop_vnevent)(vp, vnevent, dvp, fnm, ct); VOPSTATS_UPDATE(vp, vnevent); return (err); } int fop_reqzcbuf(vnode_t *vp, enum uio_rw ioflag, xuio_t *uiop, cred_t *cr, caller_context_t *ct) { int err; if (vfs_has_feature(vp->v_vfsp, VFSFT_ZEROCOPY_SUPPORTED) == 0) return (ENOTSUP); err = (*(vp)->v_op->vop_reqzcbuf)(vp, ioflag, uiop, cr, ct); VOPSTATS_UPDATE(vp, reqzcbuf); return (err); } int fop_retzcbuf(vnode_t *vp, xuio_t *uiop, cred_t *cr, caller_context_t *ct) { int err; if (vfs_has_feature(vp->v_vfsp, VFSFT_ZEROCOPY_SUPPORTED) == 0) return (ENOTSUP); err = (*(vp)->v_op->vop_retzcbuf)(vp, uiop, cr, ct); VOPSTATS_UPDATE(vp, retzcbuf); return (err); } /* * Default destructor * Needed because NULL destructor means that the key is unused */ /* ARGSUSED */ void vsd_defaultdestructor(void *value) {} /* * Create a key (index into per vnode array) * Locks out vsd_create, vsd_destroy, and vsd_free * May allocate memory with lock held */ void vsd_create(uint_t *keyp, void (*destructor)(void *)) { int i; uint_t nkeys; /* * if key is allocated, do nothing */ mutex_enter(&vsd_lock); if (*keyp) { mutex_exit(&vsd_lock); return; } /* * find an unused key */ if (destructor == NULL) destructor = vsd_defaultdestructor; for (i = 0; i < vsd_nkeys; ++i) if (vsd_destructor[i] == NULL) break; /* * if no unused keys, increase the size of the destructor array */ if (i == vsd_nkeys) { if ((nkeys = (vsd_nkeys << 1)) == 0) nkeys = 1; vsd_destructor = (void (**)(void *))vsd_realloc((void *)vsd_destructor, (size_t)(vsd_nkeys * sizeof (void (*)(void *))), (size_t)(nkeys * sizeof (void (*)(void *)))); vsd_nkeys = nkeys; } /* * allocate the next available unused key */ vsd_destructor[i] = destructor; *keyp = i + 1; /* create vsd_list, if it doesn't exist */ if (vsd_list == NULL) { vsd_list = kmem_alloc(sizeof (list_t), KM_SLEEP); list_create(vsd_list, sizeof (struct vsd_node), offsetof(struct vsd_node, vs_nodes)); } mutex_exit(&vsd_lock); } /* * Destroy a key * * Assumes that the caller is preventing vsd_set and vsd_get * Locks out vsd_create, vsd_destroy, and vsd_free * May free memory with lock held */ void vsd_destroy(uint_t *keyp) { uint_t key; struct vsd_node *vsd; /* * protect the key namespace and our destructor lists */ mutex_enter(&vsd_lock); key = *keyp; *keyp = 0; ASSERT(key <= vsd_nkeys); /* * if the key is valid */ if (key != 0) { uint_t k = key - 1; /* * for every vnode with VSD, call key's destructor */ for (vsd = list_head(vsd_list); vsd != NULL; vsd = list_next(vsd_list, vsd)) { /* * no VSD for key in this vnode */ if (key > vsd->vs_nkeys) continue; /* * call destructor for key */ if (vsd->vs_value[k] && vsd_destructor[k]) (*vsd_destructor[k])(vsd->vs_value[k]); /* * reset value for key */ vsd->vs_value[k] = NULL; } /* * actually free the key (NULL destructor == unused) */ vsd_destructor[k] = NULL; } mutex_exit(&vsd_lock); } /* * Quickly return the per vnode value that was stored with the specified key * Assumes the caller is protecting key from vsd_create and vsd_destroy * Assumes the caller is holding v_vsd_lock to protect the vsd. */ void * vsd_get(vnode_t *vp, uint_t key) { struct vsd_node *vsd; ASSERT(vp != NULL); ASSERT(mutex_owned(&vp->v_vsd_lock)); vsd = vp->v_vsd; if (key && vsd != NULL && key <= vsd->vs_nkeys) return (vsd->vs_value[key - 1]); return (NULL); } /* * Set a per vnode value indexed with the specified key * Assumes the caller is holding v_vsd_lock to protect the vsd. */ int vsd_set(vnode_t *vp, uint_t key, void *value) { struct vsd_node *vsd; ASSERT(vp != NULL); ASSERT(mutex_owned(&vp->v_vsd_lock)); if (key == 0) return (EINVAL); vsd = vp->v_vsd; if (vsd == NULL) vsd = vp->v_vsd = kmem_zalloc(sizeof (*vsd), KM_SLEEP); /* * If the vsd was just allocated, vs_nkeys will be 0, so the following * code won't happen and we will continue down and allocate space for * the vs_value array. * If the caller is replacing one value with another, then it is up * to the caller to free/rele/destroy the previous value (if needed). */ if (key <= vsd->vs_nkeys) { vsd->vs_value[key - 1] = value; return (0); } ASSERT(key <= vsd_nkeys); if (vsd->vs_nkeys == 0) { mutex_enter(&vsd_lock); /* lock out vsd_destroy() */ /* * Link onto list of all VSD nodes. */ list_insert_head(vsd_list, vsd); mutex_exit(&vsd_lock); } /* * Allocate vnode local storage and set the value for key */ vsd->vs_value = vsd_realloc(vsd->vs_value, vsd->vs_nkeys * sizeof (void *), key * sizeof (void *)); vsd->vs_nkeys = key; vsd->vs_value[key - 1] = value; return (0); } /* * Called from vn_free() to run the destructor function for each vsd * Locks out vsd_create and vsd_destroy * Assumes that the destructor *DOES NOT* use vsd */ void vsd_free(vnode_t *vp) { int i; struct vsd_node *vsd = vp->v_vsd; if (vsd == NULL) return; if (vsd->vs_nkeys == 0) { kmem_free(vsd, sizeof (*vsd)); vp->v_vsd = NULL; return; } /* * lock out vsd_create and vsd_destroy, call * the destructor, and mark the value as destroyed. */ mutex_enter(&vsd_lock); for (i = 0; i < vsd->vs_nkeys; i++) { if (vsd->vs_value[i] && vsd_destructor[i]) (*vsd_destructor[i])(vsd->vs_value[i]); vsd->vs_value[i] = NULL; } /* * remove from linked list of VSD nodes */ list_remove(vsd_list, vsd); mutex_exit(&vsd_lock); /* * free up the VSD */ kmem_free(vsd->vs_value, vsd->vs_nkeys * sizeof (void *)); kmem_free(vsd, sizeof (struct vsd_node)); vp->v_vsd = NULL; } /* * realloc */ static void * vsd_realloc(void *old, size_t osize, size_t nsize) { void *new; new = kmem_zalloc(nsize, KM_SLEEP); if (old) { bcopy(old, new, osize); kmem_free(old, osize); } return (new); } /* * Setup the extensible system attribute for creating a reparse point. * The symlink data 'target' is validated for proper format of a reparse * string and a check also made to make sure the symlink data does not * point to an existing file. * * return 0 if ok else -1. */ static int fs_reparse_mark(char *target, vattr_t *vap, xvattr_t *xvattr) { xoptattr_t *xoap; if ((!target) || (!vap) || (!xvattr)) return (-1); /* validate reparse string */ if (reparse_validate((const char *)target)) return (-1); xva_init(xvattr); xvattr->xva_vattr = *vap; xvattr->xva_vattr.va_mask |= AT_XVATTR; xoap = xva_getxoptattr(xvattr); ASSERT(xoap); XVA_SET_REQ(xvattr, XAT_REPARSE); xoap->xoa_reparse = 1; return (0); } /* * Function to check whether a symlink is a reparse point. * Return B_TRUE if it is a reparse point, else return B_FALSE */ boolean_t vn_is_reparse(vnode_t *vp, cred_t *cr, caller_context_t *ct) { xvattr_t xvattr; xoptattr_t *xoap; if ((vp->v_type != VLNK) || !(vfs_has_feature(vp->v_vfsp, VFSFT_XVATTR))) return (B_FALSE); xva_init(&xvattr); xoap = xva_getxoptattr(&xvattr); ASSERT(xoap); XVA_SET_REQ(&xvattr, XAT_REPARSE); if (VOP_GETATTR(vp, &xvattr.xva_vattr, 0, cr, ct)) return (B_FALSE); if ((!(xvattr.xva_vattr.va_mask & AT_XVATTR)) || (!(XVA_ISSET_RTN(&xvattr, XAT_REPARSE)))) return (B_FALSE); return (xoap->xoa_reparse ? B_TRUE : B_FALSE); } Index: vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_dir.c =================================================================== --- vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_dir.c (revision 323525) +++ vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_dir.c (revision 323526) @@ -1,1131 +1,1132 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2016 by Delphix. All rights reserved. * Copyright 2017 Nexenta Systems, Inc. + * Copyright (c) 2015, Joyent, Inc. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "fs/fs_subr.h" #include #include #include #include #include #include #include #include #include /* * zfs_match_find() is used by zfs_dirent_lock() to peform zap lookups * of names after deciding which is the appropriate lookup interface. */ static int zfs_match_find(zfsvfs_t *zfsvfs, znode_t *dzp, char *name, matchtype_t mt, boolean_t update, int *deflags, pathname_t *rpnp, uint64_t *zoid) { int error; if (zfsvfs->z_norm) { boolean_t conflict = B_FALSE; size_t bufsz = 0; char *buf = NULL; if (rpnp) { buf = rpnp->pn_buf; bufsz = rpnp->pn_bufsize; } /* * In the non-mixed case we only expect there would ever * be one match, but we need to use the normalizing lookup. */ error = zap_lookup_norm(zfsvfs->z_os, dzp->z_id, name, 8, 1, zoid, mt, buf, bufsz, &conflict); if (!error && deflags) *deflags = conflict ? ED_CASE_CONFLICT : 0; } else { error = zap_lookup(zfsvfs->z_os, dzp->z_id, name, 8, 1, zoid); } *zoid = ZFS_DIRENT_OBJ(*zoid); if (error == ENOENT && update) dnlc_update(ZTOV(dzp), name, DNLC_NO_VNODE); return (error); } /* * Lock a directory entry. A dirlock on protects that name * in dzp's directory zap object. As long as you hold a dirlock, you can * assume two things: (1) dzp cannot be reaped, and (2) no other thread * can change the zap entry for (i.e. link or unlink) this name. * * Input arguments: * dzp - znode for directory * name - name of entry to lock * flag - ZNEW: if the entry already exists, fail with EEXIST. * ZEXISTS: if the entry does not exist, fail with ENOENT. * ZSHARED: allow concurrent access with other ZSHARED callers. * ZXATTR: we want dzp's xattr directory * ZCILOOK: On a mixed sensitivity file system, * this lookup should be case-insensitive. * ZCIEXACT: On a purely case-insensitive file system, * this lookup should be case-sensitive. * ZRENAMING: we are locking for renaming, force narrow locks * ZHAVELOCK: Don't grab the z_name_lock for this call. The * current thread already holds it. * * Output arguments: * zpp - pointer to the znode for the entry (NULL if there isn't one) * dlpp - pointer to the dirlock for this entry (NULL on error) * direntflags - (case-insensitive lookup only) * flags if multiple case-sensitive matches exist in directory * realpnp - (case-insensitive lookup only) * actual name matched within the directory * * Return value: 0 on success or errno on failure. * * NOTE: Always checks for, and rejects, '.' and '..'. * NOTE: For case-insensitive file systems we take wide locks (see below), * but return znode pointers to a single match. */ int zfs_dirent_lock(zfs_dirlock_t **dlpp, znode_t *dzp, char *name, znode_t **zpp, int flag, int *direntflags, pathname_t *realpnp) { zfsvfs_t *zfsvfs = dzp->z_zfsvfs; zfs_dirlock_t *dl; boolean_t update; matchtype_t mt = 0; uint64_t zoid; vnode_t *vp = NULL; int error = 0; int cmpflags; *zpp = NULL; *dlpp = NULL; /* * Verify that we are not trying to lock '.', '..', or '.zfs' */ if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')) || zfs_has_ctldir(dzp) && strcmp(name, ZFS_CTLDIR_NAME) == 0) return (SET_ERROR(EEXIST)); /* * Case sensitivity and normalization preferences are set when * the file system is created. These are stored in the * zfsvfs->z_case and zfsvfs->z_norm fields. These choices * affect what vnodes can be cached in the DNLC, how we * perform zap lookups, and the "width" of our dirlocks. * * A normal dirlock locks a single name. Note that with * normalization a name can be composed multiple ways, but * when normalized, these names all compare equal. A wide * dirlock locks multiple names. We need these when the file * system is supporting mixed-mode access. It is sometimes * necessary to lock all case permutations of file name at * once so that simultaneous case-insensitive/case-sensitive * behaves as rationally as possible. */ /* * When matching we may need to normalize & change case according to * FS settings. * * Note that a normalized match is necessary for a case insensitive * filesystem when the lookup request is not exact because normalization * can fold case independent of normalizing code point sequences. * * See the table above zfs_dropname(). */ if (zfsvfs->z_norm != 0) { mt = MT_NORMALIZE; /* * Determine if the match needs to honor the case specified in * lookup, and if so keep track of that so that during * normalization we don't fold case. */ if ((zfsvfs->z_case == ZFS_CASE_INSENSITIVE && (flag & ZCIEXACT)) || (zfsvfs->z_case == ZFS_CASE_MIXED && !(flag & ZCILOOK))) { mt |= MT_MATCH_CASE; } } /* * Only look in or update the DNLC if we are looking for the * name on a file system that does not require normalization * or case folding. We can also look there if we happen to be * on a non-normalizing, mixed sensitivity file system IF we * are looking for the exact name. * * Maybe can add TO-UPPERed version of name to dnlc in ci-only * case for performance improvement? */ update = !zfsvfs->z_norm || (zfsvfs->z_case == ZFS_CASE_MIXED && !(zfsvfs->z_norm & ~U8_TEXTPREP_TOUPPER) && !(flag & ZCILOOK)); /* * ZRENAMING indicates we are in a situation where we should * take narrow locks regardless of the file system's * preferences for normalizing and case folding. This will * prevent us deadlocking trying to grab the same wide lock * twice if the two names happen to be case-insensitive * matches. */ if (flag & ZRENAMING) cmpflags = 0; else cmpflags = zfsvfs->z_norm; /* * Wait until there are no locks on this name. * * Don't grab the the lock if it is already held. However, cannot * have both ZSHARED and ZHAVELOCK together. */ ASSERT(!(flag & ZSHARED) || !(flag & ZHAVELOCK)); if (!(flag & ZHAVELOCK)) rw_enter(&dzp->z_name_lock, RW_READER); mutex_enter(&dzp->z_lock); for (;;) { if (dzp->z_unlinked) { mutex_exit(&dzp->z_lock); if (!(flag & ZHAVELOCK)) rw_exit(&dzp->z_name_lock); return (SET_ERROR(ENOENT)); } for (dl = dzp->z_dirlocks; dl != NULL; dl = dl->dl_next) { if ((u8_strcmp(name, dl->dl_name, 0, cmpflags, U8_UNICODE_LATEST, &error) == 0) || error != 0) break; } if (error != 0) { mutex_exit(&dzp->z_lock); if (!(flag & ZHAVELOCK)) rw_exit(&dzp->z_name_lock); return (SET_ERROR(ENOENT)); } if (dl == NULL) { /* * Allocate a new dirlock and add it to the list. */ dl = kmem_alloc(sizeof (zfs_dirlock_t), KM_SLEEP); cv_init(&dl->dl_cv, NULL, CV_DEFAULT, NULL); dl->dl_name = name; dl->dl_sharecnt = 0; dl->dl_namelock = 0; dl->dl_namesize = 0; dl->dl_dzp = dzp; dl->dl_next = dzp->z_dirlocks; dzp->z_dirlocks = dl; break; } if ((flag & ZSHARED) && dl->dl_sharecnt != 0) break; cv_wait(&dl->dl_cv, &dzp->z_lock); } /* * If the z_name_lock was NOT held for this dirlock record it. */ if (flag & ZHAVELOCK) dl->dl_namelock = 1; if ((flag & ZSHARED) && ++dl->dl_sharecnt > 1 && dl->dl_namesize == 0) { /* * We're the second shared reference to dl. Make a copy of * dl_name in case the first thread goes away before we do. * Note that we initialize the new name before storing its * pointer into dl_name, because the first thread may load * dl->dl_name at any time. It'll either see the old value, * which belongs to it, or the new shared copy; either is OK. */ dl->dl_namesize = strlen(dl->dl_name) + 1; name = kmem_alloc(dl->dl_namesize, KM_SLEEP); bcopy(dl->dl_name, name, dl->dl_namesize); dl->dl_name = name; } mutex_exit(&dzp->z_lock); /* * We have a dirlock on the name. (Note that it is the dirlock, * not the dzp's z_lock, that protects the name in the zap object.) * See if there's an object by this name; if so, put a hold on it. */ if (flag & ZXATTR) { error = sa_lookup(dzp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs), &zoid, sizeof (zoid)); if (error == 0) error = (zoid == 0 ? ENOENT : 0); } else { if (update) vp = dnlc_lookup(ZTOV(dzp), name); if (vp == DNLC_NO_VNODE) { VN_RELE(vp); error = SET_ERROR(ENOENT); } else if (vp) { if (flag & ZNEW) { zfs_dirent_unlock(dl); VN_RELE(vp); return (SET_ERROR(EEXIST)); } *dlpp = dl; *zpp = VTOZ(vp); return (0); } else { error = zfs_match_find(zfsvfs, dzp, name, mt, update, direntflags, realpnp, &zoid); } } if (error) { if (error != ENOENT || (flag & ZEXISTS)) { zfs_dirent_unlock(dl); return (error); } } else { if (flag & ZNEW) { zfs_dirent_unlock(dl); return (SET_ERROR(EEXIST)); } error = zfs_zget(zfsvfs, zoid, zpp); if (error) { zfs_dirent_unlock(dl); return (error); } if (!(flag & ZXATTR) && update) dnlc_update(ZTOV(dzp), name, ZTOV(*zpp)); } *dlpp = dl; return (0); } /* * Unlock this directory entry and wake anyone who was waiting for it. */ void zfs_dirent_unlock(zfs_dirlock_t *dl) { znode_t *dzp = dl->dl_dzp; zfs_dirlock_t **prev_dl, *cur_dl; mutex_enter(&dzp->z_lock); if (!dl->dl_namelock) rw_exit(&dzp->z_name_lock); if (dl->dl_sharecnt > 1) { dl->dl_sharecnt--; mutex_exit(&dzp->z_lock); return; } prev_dl = &dzp->z_dirlocks; while ((cur_dl = *prev_dl) != dl) prev_dl = &cur_dl->dl_next; *prev_dl = dl->dl_next; cv_broadcast(&dl->dl_cv); mutex_exit(&dzp->z_lock); if (dl->dl_namesize != 0) kmem_free(dl->dl_name, dl->dl_namesize); cv_destroy(&dl->dl_cv); kmem_free(dl, sizeof (*dl)); } /* * Look up an entry in a directory. * * NOTE: '.' and '..' are handled as special cases because * no directory entries are actually stored for them. If this is * the root of a filesystem, then '.zfs' is also treated as a * special pseudo-directory. */ int zfs_dirlook(znode_t *dzp, char *name, vnode_t **vpp, int flags, int *deflg, pathname_t *rpnp) { zfs_dirlock_t *dl; znode_t *zp; int error = 0; uint64_t parent; if (name[0] == 0 || (name[0] == '.' && name[1] == 0)) { *vpp = ZTOV(dzp); VN_HOLD(*vpp); } else if (name[0] == '.' && name[1] == '.' && name[2] == 0) { zfsvfs_t *zfsvfs = dzp->z_zfsvfs; /* * If we are a snapshot mounted under .zfs, return * the vp for the snapshot directory. */ if ((error = sa_lookup(dzp->z_sa_hdl, SA_ZPL_PARENT(zfsvfs), &parent, sizeof (parent))) != 0) return (error); if (parent == dzp->z_id && zfsvfs->z_parent != zfsvfs) { error = zfsctl_root_lookup(zfsvfs->z_parent->z_ctldir, "snapshot", vpp, NULL, 0, NULL, kcred, NULL, NULL, NULL); return (error); } rw_enter(&dzp->z_parent_lock, RW_READER); error = zfs_zget(zfsvfs, parent, &zp); if (error == 0) *vpp = ZTOV(zp); rw_exit(&dzp->z_parent_lock); } else if (zfs_has_ctldir(dzp) && strcmp(name, ZFS_CTLDIR_NAME) == 0) { *vpp = zfsctl_root(dzp); } else { int zf; zf = ZEXISTS | ZSHARED; if (flags & FIGNORECASE) zf |= ZCILOOK; error = zfs_dirent_lock(&dl, dzp, name, &zp, zf, deflg, rpnp); if (error == 0) { *vpp = ZTOV(zp); zfs_dirent_unlock(dl); dzp->z_zn_prefetch = B_TRUE; /* enable prefetching */ } rpnp = NULL; } if ((flags & FIGNORECASE) && rpnp && !error) (void) strlcpy(rpnp->pn_buf, name, rpnp->pn_bufsize); return (error); } /* * unlinked Set (formerly known as the "delete queue") Error Handling * * When dealing with the unlinked set, we dmu_tx_hold_zap(), but we * don't specify the name of the entry that we will be manipulating. We * also fib and say that we won't be adding any new entries to the * unlinked set, even though we might (this is to lower the minimum file * size that can be deleted in a full filesystem). So on the small * chance that the nlink list is using a fat zap (ie. has more than * 2000 entries), we *may* not pre-read a block that's needed. * Therefore it is remotely possible for some of the assertions * regarding the unlinked set below to fail due to i/o error. On a * nondebug system, this will result in the space being leaked. */ void zfs_unlinked_add(znode_t *zp, dmu_tx_t *tx) { zfsvfs_t *zfsvfs = zp->z_zfsvfs; ASSERT(zp->z_unlinked); ASSERT(zp->z_links == 0); VERIFY3U(0, ==, zap_add_int(zfsvfs->z_os, zfsvfs->z_unlinkedobj, zp->z_id, tx)); } /* * Clean up any znodes that had no links when we either crashed or * (force) umounted the file system. */ void zfs_unlinked_drain(zfsvfs_t *zfsvfs) { zap_cursor_t zc; zap_attribute_t zap; dmu_object_info_t doi; znode_t *zp; int error; /* * Interate over the contents of the unlinked set. */ for (zap_cursor_init(&zc, zfsvfs->z_os, zfsvfs->z_unlinkedobj); zap_cursor_retrieve(&zc, &zap) == 0; zap_cursor_advance(&zc)) { /* * See what kind of object we have in list */ error = dmu_object_info(zfsvfs->z_os, zap.za_first_integer, &doi); if (error != 0) continue; ASSERT((doi.doi_type == DMU_OT_PLAIN_FILE_CONTENTS) || (doi.doi_type == DMU_OT_DIRECTORY_CONTENTS)); /* * We need to re-mark these list entries for deletion, * so we pull them back into core and set zp->z_unlinked. */ error = zfs_zget(zfsvfs, zap.za_first_integer, &zp); /* * We may pick up znodes that are already marked for deletion. * This could happen during the purge of an extended attribute * directory. All we need to do is skip over them, since they * are already in the system marked z_unlinked. */ if (error != 0) continue; zp->z_unlinked = B_TRUE; VN_RELE(ZTOV(zp)); } zap_cursor_fini(&zc); } /* * Delete the entire contents of a directory. Return a count * of the number of entries that could not be deleted. If we encounter * an error, return a count of at least one so that the directory stays * in the unlinked set. * * NOTE: this function assumes that the directory is inactive, * so there is no need to lock its entries before deletion. * Also, it assumes the directory contents is *only* regular * files. */ static int zfs_purgedir(znode_t *dzp) { zap_cursor_t zc; zap_attribute_t zap; znode_t *xzp; dmu_tx_t *tx; zfsvfs_t *zfsvfs = dzp->z_zfsvfs; zfs_dirlock_t dl; int skipped = 0; int error; for (zap_cursor_init(&zc, zfsvfs->z_os, dzp->z_id); (error = zap_cursor_retrieve(&zc, &zap)) == 0; zap_cursor_advance(&zc)) { error = zfs_zget(zfsvfs, ZFS_DIRENT_OBJ(zap.za_first_integer), &xzp); if (error) { skipped += 1; continue; } ASSERT((ZTOV(xzp)->v_type == VREG) || (ZTOV(xzp)->v_type == VLNK)); tx = dmu_tx_create(zfsvfs->z_os); dmu_tx_hold_sa(tx, dzp->z_sa_hdl, B_FALSE); dmu_tx_hold_zap(tx, dzp->z_id, FALSE, zap.za_name); dmu_tx_hold_sa(tx, xzp->z_sa_hdl, B_FALSE); dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL); /* Is this really needed ? */ zfs_sa_upgrade_txholds(tx, xzp); dmu_tx_mark_netfree(tx); error = dmu_tx_assign(tx, TXG_WAIT); if (error) { dmu_tx_abort(tx); VN_RELE(ZTOV(xzp)); skipped += 1; continue; } bzero(&dl, sizeof (dl)); dl.dl_dzp = dzp; dl.dl_name = zap.za_name; error = zfs_link_destroy(&dl, xzp, tx, 0, NULL); if (error) skipped += 1; dmu_tx_commit(tx); VN_RELE(ZTOV(xzp)); } zap_cursor_fini(&zc); if (error != ENOENT) skipped += 1; return (skipped); } void zfs_rmnode(znode_t *zp) { zfsvfs_t *zfsvfs = zp->z_zfsvfs; objset_t *os = zfsvfs->z_os; znode_t *xzp = NULL; dmu_tx_t *tx; uint64_t acl_obj; uint64_t xattr_obj; int error; ASSERT(zp->z_links == 0); ASSERT(ZTOV(zp)->v_count == 0); /* * If this is an attribute directory, purge its contents. */ if (ZTOV(zp)->v_type == VDIR && (zp->z_pflags & ZFS_XATTR)) { if (zfs_purgedir(zp) != 0) { /* * Not enough space to delete some xattrs. * Leave it in the unlinked set. */ zfs_znode_dmu_fini(zp); zfs_znode_free(zp); return; } } else { /* * Free up all the data in the file. We don't do this for * XATTR directories because we need truncate and remove to be * in the same tx, like in zfs_znode_delete(). Otherwise, if * we crash here we'll end up with an inconsistent truncated * zap object in the delete queue. Note a truncated file is * harmless since it only contains user data. */ error = dmu_free_long_range(os, zp->z_id, 0, DMU_OBJECT_END); if (error) { /* * Not enough space or we were interrupted by unmount. * Leave the file in the unlinked set. */ zfs_znode_dmu_fini(zp); zfs_znode_free(zp); return; } } /* * If the file has extended attributes, we're going to unlink * the xattr dir. */ error = sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs), &xattr_obj, sizeof (xattr_obj)); if (error == 0 && xattr_obj) { error = zfs_zget(zfsvfs, xattr_obj, &xzp); ASSERT(error == 0); } acl_obj = zfs_external_acl(zp); /* * Set up the final transaction. */ tx = dmu_tx_create(os); dmu_tx_hold_free(tx, zp->z_id, 0, DMU_OBJECT_END); dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL); if (xzp) { dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, TRUE, NULL); dmu_tx_hold_sa(tx, xzp->z_sa_hdl, B_FALSE); } if (acl_obj) dmu_tx_hold_free(tx, acl_obj, 0, DMU_OBJECT_END); zfs_sa_upgrade_txholds(tx, zp); error = dmu_tx_assign(tx, TXG_WAIT); if (error) { /* * Not enough space to delete the file. Leave it in the * unlinked set, leaking it until the fs is remounted (at * which point we'll call zfs_unlinked_drain() to process it). */ dmu_tx_abort(tx); zfs_znode_dmu_fini(zp); zfs_znode_free(zp); goto out; } if (xzp) { ASSERT(error == 0); mutex_enter(&xzp->z_lock); xzp->z_unlinked = B_TRUE; /* mark xzp for deletion */ xzp->z_links = 0; /* no more links to it */ VERIFY(0 == sa_update(xzp->z_sa_hdl, SA_ZPL_LINKS(zfsvfs), &xzp->z_links, sizeof (xzp->z_links), tx)); mutex_exit(&xzp->z_lock); zfs_unlinked_add(xzp, tx); } /* Remove this znode from the unlinked set */ VERIFY3U(0, ==, zap_remove_int(zfsvfs->z_os, zfsvfs->z_unlinkedobj, zp->z_id, tx)); zfs_znode_delete(zp, tx); dmu_tx_commit(tx); out: if (xzp) VN_RELE(ZTOV(xzp)); } static uint64_t zfs_dirent(znode_t *zp, uint64_t mode) { uint64_t de = zp->z_id; if (zp->z_zfsvfs->z_version >= ZPL_VERSION_DIRENT_TYPE) de |= IFTODT(mode) << 60; return (de); } /* * Link zp into dl. Can only fail if zp has been unlinked. */ int zfs_link_create(zfs_dirlock_t *dl, znode_t *zp, dmu_tx_t *tx, int flag) { znode_t *dzp = dl->dl_dzp; zfsvfs_t *zfsvfs = zp->z_zfsvfs; vnode_t *vp = ZTOV(zp); uint64_t value; int zp_is_dir = (vp->v_type == VDIR); sa_bulk_attr_t bulk[5]; uint64_t mtime[2], ctime[2]; int count = 0; int error; mutex_enter(&zp->z_lock); if (!(flag & ZRENAMING)) { if (zp->z_unlinked) { /* no new links to unlinked zp */ ASSERT(!(flag & (ZNEW | ZEXISTS))); mutex_exit(&zp->z_lock); return (SET_ERROR(ENOENT)); } zp->z_links++; SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), NULL, &zp->z_links, sizeof (zp->z_links)); } SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_PARENT(zfsvfs), NULL, &dzp->z_id, sizeof (dzp->z_id)); SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL, &zp->z_pflags, sizeof (zp->z_pflags)); if (!(flag & ZNEW)) { SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, ctime, sizeof (ctime)); zfs_tstamp_update_setup(zp, STATE_CHANGED, mtime, ctime, B_TRUE); } error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx); ASSERT(error == 0); mutex_exit(&zp->z_lock); mutex_enter(&dzp->z_lock); dzp->z_size++; dzp->z_links += zp_is_dir; count = 0; SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs), NULL, &dzp->z_size, sizeof (dzp->z_size)); SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), NULL, &dzp->z_links, sizeof (dzp->z_links)); SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, mtime, sizeof (mtime)); SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, ctime, sizeof (ctime)); SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL, &dzp->z_pflags, sizeof (dzp->z_pflags)); zfs_tstamp_update_setup(dzp, CONTENT_MODIFIED, mtime, ctime, B_TRUE); error = sa_bulk_update(dzp->z_sa_hdl, bulk, count, tx); ASSERT(error == 0); mutex_exit(&dzp->z_lock); value = zfs_dirent(zp, zp->z_mode); error = zap_add(zp->z_zfsvfs->z_os, dzp->z_id, dl->dl_name, 8, 1, &value, tx); ASSERT(error == 0); dnlc_update(ZTOV(dzp), dl->dl_name, vp); return (0); } /* * The match type in the code for this function should conform to: * * ------------------------------------------------------------------------ * fs type | z_norm | lookup type | match type * ---------|-------------|-------------|---------------------------------- * CS !norm | 0 | 0 | 0 (exact) * CS norm | formX | 0 | MT_NORMALIZE * CI !norm | upper | !ZCIEXACT | MT_NORMALIZE * CI !norm | upper | ZCIEXACT | MT_NORMALIZE | MT_MATCH_CASE * CI norm | upper|formX | !ZCIEXACT | MT_NORMALIZE * CI norm | upper|formX | ZCIEXACT | MT_NORMALIZE | MT_MATCH_CASE * CM !norm | upper | !ZCILOOK | MT_NORMALIZE | MT_MATCH_CASE * CM !norm | upper | ZCILOOK | MT_NORMALIZE * CM norm | upper|formX | !ZCILOOK | MT_NORMALIZE | MT_MATCH_CASE * CM norm | upper|formX | ZCILOOK | MT_NORMALIZE * * Abbreviations: * CS = Case Sensitive, CI = Case Insensitive, CM = Case Mixed * upper = case folding set by fs type on creation (U8_TEXTPREP_TOUPPER) * formX = unicode normalization form set on fs creation */ static int zfs_dropname(zfs_dirlock_t *dl, znode_t *zp, znode_t *dzp, dmu_tx_t *tx, int flag) { int error; if (zp->z_zfsvfs->z_norm) { matchtype_t mt = MT_NORMALIZE; if ((zp->z_zfsvfs->z_case == ZFS_CASE_INSENSITIVE && (flag & ZCIEXACT)) || (zp->z_zfsvfs->z_case == ZFS_CASE_MIXED && !(flag & ZCILOOK))) { mt |= MT_MATCH_CASE; } error = zap_remove_norm(zp->z_zfsvfs->z_os, dzp->z_id, dl->dl_name, mt, tx); } else { error = zap_remove(zp->z_zfsvfs->z_os, dzp->z_id, dl->dl_name, tx); } return (error); } /* * Unlink zp from dl, and mark zp for deletion if this was the last link. * Can fail if zp is a mount point (EBUSY) or a non-empty directory (EEXIST). * If 'unlinkedp' is NULL, we put unlinked znodes on the unlinked list. * If it's non-NULL, we use it to indicate whether the znode needs deletion, * and it's the caller's job to do it. */ int zfs_link_destroy(zfs_dirlock_t *dl, znode_t *zp, dmu_tx_t *tx, int flag, boolean_t *unlinkedp) { znode_t *dzp = dl->dl_dzp; zfsvfs_t *zfsvfs = dzp->z_zfsvfs; vnode_t *vp = ZTOV(zp); int zp_is_dir = (vp->v_type == VDIR); boolean_t unlinked = B_FALSE; sa_bulk_attr_t bulk[5]; uint64_t mtime[2], ctime[2]; int count = 0; int error; dnlc_remove(ZTOV(dzp), dl->dl_name); if (!(flag & ZRENAMING)) { if (vn_vfswlock(vp)) /* prevent new mounts on zp */ return (SET_ERROR(EBUSY)); if (vn_ismntpt(vp)) { /* don't remove mount point */ vn_vfsunlock(vp); return (SET_ERROR(EBUSY)); } mutex_enter(&zp->z_lock); if (zp_is_dir && !zfs_dirempty(zp)) { mutex_exit(&zp->z_lock); vn_vfsunlock(vp); return (SET_ERROR(EEXIST)); } /* * If we get here, we are going to try to remove the object. * First try removing the name from the directory; if that * fails, return the error. */ error = zfs_dropname(dl, zp, dzp, tx, flag); if (error != 0) { mutex_exit(&zp->z_lock); vn_vfsunlock(vp); return (error); } if (zp->z_links <= zp_is_dir) { zfs_panic_recover("zfs: link count on %s is %u, " "should be at least %u", - zp->z_vnode->v_path ? zp->z_vnode->v_path : - "", (int)zp->z_links, - zp_is_dir + 1); + zp->z_vnode->v_path != vn_vpath_empty ? + zp->z_vnode->v_path : "", + (int)zp->z_links, zp_is_dir + 1); zp->z_links = zp_is_dir + 1; } if (--zp->z_links == zp_is_dir) { zp->z_unlinked = B_TRUE; zp->z_links = 0; unlinked = B_TRUE; } else { SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, sizeof (ctime)); SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL, &zp->z_pflags, sizeof (zp->z_pflags)); zfs_tstamp_update_setup(zp, STATE_CHANGED, mtime, ctime, B_TRUE); } SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), NULL, &zp->z_links, sizeof (zp->z_links)); error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx); count = 0; ASSERT(error == 0); mutex_exit(&zp->z_lock); vn_vfsunlock(vp); } else { error = zfs_dropname(dl, zp, dzp, tx, flag); if (error != 0) return (error); } mutex_enter(&dzp->z_lock); dzp->z_size--; /* one dirent removed */ dzp->z_links -= zp_is_dir; /* ".." link from zp */ SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), NULL, &dzp->z_links, sizeof (dzp->z_links)); SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs), NULL, &dzp->z_size, sizeof (dzp->z_size)); SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, ctime, sizeof (ctime)); SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, mtime, sizeof (mtime)); SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL, &dzp->z_pflags, sizeof (dzp->z_pflags)); zfs_tstamp_update_setup(dzp, CONTENT_MODIFIED, mtime, ctime, B_TRUE); error = sa_bulk_update(dzp->z_sa_hdl, bulk, count, tx); ASSERT(error == 0); mutex_exit(&dzp->z_lock); if (unlinkedp != NULL) *unlinkedp = unlinked; else if (unlinked) zfs_unlinked_add(zp, tx); return (0); } /* * Indicate whether the directory is empty. Works with or without z_lock * held, but can only be consider a hint in the latter case. Returns true * if only "." and ".." remain and there's no work in progress. */ boolean_t zfs_dirempty(znode_t *dzp) { return (dzp->z_size == 2 && dzp->z_dirlocks == 0); } int zfs_make_xattrdir(znode_t *zp, vattr_t *vap, vnode_t **xvpp, cred_t *cr) { zfsvfs_t *zfsvfs = zp->z_zfsvfs; znode_t *xzp; dmu_tx_t *tx; int error; zfs_acl_ids_t acl_ids; boolean_t fuid_dirtied; uint64_t parent; *xvpp = NULL; if (error = zfs_zaccess(zp, ACE_WRITE_NAMED_ATTRS, 0, B_FALSE, cr)) return (error); if ((error = zfs_acl_ids_create(zp, IS_XATTR, vap, cr, NULL, &acl_ids)) != 0) return (error); if (zfs_acl_ids_overquota(zfsvfs, &acl_ids)) { zfs_acl_ids_free(&acl_ids); return (SET_ERROR(EDQUOT)); } tx = dmu_tx_create(zfsvfs->z_os); dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes + ZFS_SA_BASE_ATTR_SIZE); dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE); dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL); fuid_dirtied = zfsvfs->z_fuid_dirty; if (fuid_dirtied) zfs_fuid_txhold(zfsvfs, tx); error = dmu_tx_assign(tx, TXG_WAIT); if (error) { zfs_acl_ids_free(&acl_ids); dmu_tx_abort(tx); return (error); } zfs_mknode(zp, vap, tx, cr, IS_XATTR, &xzp, &acl_ids); if (fuid_dirtied) zfs_fuid_sync(zfsvfs, tx); #ifdef DEBUG error = sa_lookup(xzp->z_sa_hdl, SA_ZPL_PARENT(zfsvfs), &parent, sizeof (parent)); ASSERT(error == 0 && parent == zp->z_id); #endif VERIFY(0 == sa_update(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs), &xzp->z_id, sizeof (xzp->z_id), tx)); (void) zfs_log_create(zfsvfs->z_log, tx, TX_MKXATTR, zp, xzp, "", NULL, acl_ids.z_fuidp, vap); zfs_acl_ids_free(&acl_ids); dmu_tx_commit(tx); *xvpp = ZTOV(xzp); return (0); } /* * Return a znode for the extended attribute directory for zp. * ** If the directory does not already exist, it is created ** * * IN: zp - znode to obtain attribute directory from * cr - credentials of caller * flags - flags from the VOP_LOOKUP call * * OUT: xzpp - pointer to extended attribute znode * * RETURN: 0 on success * error number on failure */ int zfs_get_xattrdir(znode_t *zp, vnode_t **xvpp, cred_t *cr, int flags) { zfsvfs_t *zfsvfs = zp->z_zfsvfs; znode_t *xzp; zfs_dirlock_t *dl; vattr_t va; int error; top: error = zfs_dirent_lock(&dl, zp, "", &xzp, ZXATTR, NULL, NULL); if (error) return (error); if (xzp != NULL) { *xvpp = ZTOV(xzp); zfs_dirent_unlock(dl); return (0); } if (!(flags & CREATE_XATTR_DIR)) { zfs_dirent_unlock(dl); return (SET_ERROR(ENOENT)); } if (zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) { zfs_dirent_unlock(dl); return (SET_ERROR(EROFS)); } /* * The ability to 'create' files in an attribute * directory comes from the write_xattr permission on the base file. * * The ability to 'search' an attribute directory requires * read_xattr permission on the base file. * * Once in a directory the ability to read/write attributes * is controlled by the permissions on the attribute file. */ va.va_mask = AT_TYPE | AT_MODE | AT_UID | AT_GID; va.va_type = VDIR; va.va_mode = S_IFDIR | S_ISVTX | 0777; zfs_fuid_map_ids(zp, cr, &va.va_uid, &va.va_gid); error = zfs_make_xattrdir(zp, &va, xvpp, cr); zfs_dirent_unlock(dl); if (error == ERESTART) { /* NB: we already did dmu_tx_wait() if necessary */ goto top; } return (error); } /* * Decide whether it is okay to remove within a sticky directory. * * In sticky directories, write access is not sufficient; * you can remove entries from a directory only if: * * you own the directory, * you own the entry, * the entry is a plain file and you have write access, * or you are privileged (checked in secpolicy...). * * The function returns 0 if remove access is granted. */ int zfs_sticky_remove_access(znode_t *zdp, znode_t *zp, cred_t *cr) { uid_t uid; uid_t downer; uid_t fowner; zfsvfs_t *zfsvfs = zdp->z_zfsvfs; if (zdp->z_zfsvfs->z_replay) return (0); if ((zdp->z_mode & S_ISVTX) == 0) return (0); downer = zfs_fuid_map_id(zfsvfs, zdp->z_uid, cr, ZFS_OWNER); fowner = zfs_fuid_map_id(zfsvfs, zp->z_uid, cr, ZFS_OWNER); if ((uid = crgetuid(cr)) == downer || uid == fowner || (ZTOV(zp)->v_type == VREG && zfs_zaccess(zp, ACE_WRITE_DATA, 0, B_FALSE, cr) == 0)) return (0); else return (secpolicy_vnode_remove(cr)); } Index: vendor-sys/illumos/dist/uts/common/sys/vnode.h =================================================================== --- vendor-sys/illumos/dist/uts/common/sys/vnode.h (revision 323525) +++ vendor-sys/illumos/dist/uts/common/sys/vnode.h (revision 323526) @@ -1,1479 +1,1549 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2013, Joyent, Inc. All rights reserved. + * Copyright (c) 2017, Joyent, Inc. * Copyright (c) 2011, 2017 by Delphix. All rights reserved. */ /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * University Copyright- Copyright (c) 1982, 1986, 1988 * The Regents of the University of California * All Rights Reserved * * University Acknowledgment- Portions of this document are derived from * software developed by the University of California, Berkeley, and its * contributors. */ #ifndef _SYS_VNODE_H #define _SYS_VNODE_H #include #include #include #include #include #include #include #include #include #include #include #ifdef _KERNEL #include #include #endif /* _KERNEL */ #ifdef __cplusplus extern "C" { #endif /* * Statistics for all vnode operations. * All operations record number of ops (since boot/mount/zero'ed). * Certain I/O operations (read, write, readdir) also record number * of bytes transferred. * This appears in two places in the system: one is embedded in each * vfs_t. There is also an array of vopstats_t structures allocated * on a per-fstype basis. */ #define VOPSTATS_STR "vopstats_" /* Initial string for vopstat kstats */ typedef struct vopstats { kstat_named_t nopen; /* VOP_OPEN */ kstat_named_t nclose; /* VOP_CLOSE */ kstat_named_t nread; /* VOP_READ */ kstat_named_t read_bytes; kstat_named_t nwrite; /* VOP_WRITE */ kstat_named_t write_bytes; kstat_named_t nioctl; /* VOP_IOCTL */ kstat_named_t nsetfl; /* VOP_SETFL */ kstat_named_t ngetattr; /* VOP_GETATTR */ kstat_named_t nsetattr; /* VOP_SETATTR */ kstat_named_t naccess; /* VOP_ACCESS */ kstat_named_t nlookup; /* VOP_LOOKUP */ kstat_named_t ncreate; /* VOP_CREATE */ kstat_named_t nremove; /* VOP_REMOVE */ kstat_named_t nlink; /* VOP_LINK */ kstat_named_t nrename; /* VOP_RENAME */ kstat_named_t nmkdir; /* VOP_MKDIR */ kstat_named_t nrmdir; /* VOP_RMDIR */ kstat_named_t nreaddir; /* VOP_READDIR */ kstat_named_t readdir_bytes; kstat_named_t nsymlink; /* VOP_SYMLINK */ kstat_named_t nreadlink; /* VOP_READLINK */ kstat_named_t nfsync; /* VOP_FSYNC */ kstat_named_t ninactive; /* VOP_INACTIVE */ kstat_named_t nfid; /* VOP_FID */ kstat_named_t nrwlock; /* VOP_RWLOCK */ kstat_named_t nrwunlock; /* VOP_RWUNLOCK */ kstat_named_t nseek; /* VOP_SEEK */ kstat_named_t ncmp; /* VOP_CMP */ kstat_named_t nfrlock; /* VOP_FRLOCK */ kstat_named_t nspace; /* VOP_SPACE */ kstat_named_t nrealvp; /* VOP_REALVP */ kstat_named_t ngetpage; /* VOP_GETPAGE */ kstat_named_t nputpage; /* VOP_PUTPAGE */ kstat_named_t nmap; /* VOP_MAP */ kstat_named_t naddmap; /* VOP_ADDMAP */ kstat_named_t ndelmap; /* VOP_DELMAP */ kstat_named_t npoll; /* VOP_POLL */ kstat_named_t ndump; /* VOP_DUMP */ kstat_named_t npathconf; /* VOP_PATHCONF */ kstat_named_t npageio; /* VOP_PAGEIO */ kstat_named_t ndumpctl; /* VOP_DUMPCTL */ kstat_named_t ndispose; /* VOP_DISPOSE */ kstat_named_t nsetsecattr; /* VOP_SETSECATTR */ kstat_named_t ngetsecattr; /* VOP_GETSECATTR */ kstat_named_t nshrlock; /* VOP_SHRLOCK */ kstat_named_t nvnevent; /* VOP_VNEVENT */ kstat_named_t nreqzcbuf; /* VOP_REQZCBUF */ kstat_named_t nretzcbuf; /* VOP_RETZCBUF */ } vopstats_t; /* * The vnode is the focus of all file activity in UNIX. * A vnode is allocated for each active file, each current * directory, each mounted-on file, and the root. * * Each vnode is usually associated with a file-system-specific node (for * UFS, this is the in-memory inode). Generally, a vnode and an fs-node * should be created and destroyed together as a pair. * * If a vnode is reused for a new file, it should be reinitialized by calling * either vn_reinit() or vn_recycle(). * * vn_reinit() resets the entire vnode as if it was returned by vn_alloc(). * The caller is responsible for setting up the entire vnode after calling * vn_reinit(). This is important when using kmem caching where the vnode is * allocated by a constructor, for instance. * * vn_recycle() is used when the file system keeps some state around in both * the vnode and the associated FS-node. In UFS, for example, the inode of * a deleted file can be reused immediately. The v_data, v_vfsp, v_op, etc. * remains the same but certain fields related to the previous instance need * to be reset. In particular: * v_femhead * v_path * v_rdcnt, v_wrcnt * v_mmap_read, v_mmap_write */ /* * vnode types. VNON means no type. These values are unrelated to * values in on-disk inodes. */ typedef enum vtype { VNON = 0, VREG = 1, VDIR = 2, VBLK = 3, VCHR = 4, VLNK = 5, VFIFO = 6, VDOOR = 7, VPROC = 8, VSOCK = 9, VPORT = 10, VBAD = 11 } vtype_t; /* * VSD - Vnode Specific Data * Used to associate additional private data with a vnode. */ struct vsd_node { list_node_t vs_nodes; /* list of all VSD nodes */ uint_t vs_nkeys; /* entries in value array */ void **vs_value; /* array of value/key */ }; /* * Many of the fields in the vnode are read-only once they are initialized * at vnode creation time. Other fields are protected by locks. * * IMPORTANT: vnodes should be created ONLY by calls to vn_alloc(). They * may not be embedded into the file-system specific node (inode). The * size of vnodes may change. * * The v_lock protects: * v_flag * v_stream * v_count * v_shrlocks * v_path * v_vsd * v_xattrdir * * A special lock (implemented by vn_vfswlock in vnode.c) protects: * v_vfsmountedhere * * The global flock_lock mutex (in flock.c) protects: * v_filocks * * IMPORTANT NOTE: * * The following vnode fields are considered public and may safely be * accessed by file systems or other consumers: * * v_lock * v_flag * v_count * v_data * v_vfsp * v_stream * v_type * v_rdev * * ALL OTHER FIELDS SHOULD BE ACCESSED ONLY BY THE OWNER OF THAT FIELD. * In particular, file systems should not access other fields; they may * change or even be removed. The functionality which was once provided * by these fields is available through vn_* functions. + * + * VNODE PATH THEORY: + * In each vnode, the v_path field holds a cached version of the canonical + * filesystem path which that node represents. Because vnodes lack contextual + * information about their own name or position in the VFS hierarchy, this path + * must be calculated when the vnode is instantiated by operations such as + * fop_create, fop_lookup, or fop_mkdir. During said operations, both the + * parent vnode (and its cached v_path) and future name are known, so the + * v_path of the resulting object can easily be set. + * + * The caching nature of v_path is complicated in the face of directory + * renames. Filesystem drivers are responsible for calling vn_renamepath when + * a fop_rename operation succeeds. While the v_path on the renamed vnode will + * be updated, existing children of the directory (direct, or at deeper levels) + * will now possess v_path caches which are stale. + * + * It is expensive (and for non-directories, impossible) to recalculate stale + * v_path entries during operations such as vnodetopath. The best time during + * which to correct such wrongs is the same as when v_path is first + * initialized: during fop_create/fop_lookup/fop_mkdir/etc, where adequate + * context is available to generate the current path. + * + * In order to quickly detect stale v_path entries (without full lookup + * verification) to trigger a v_path update, the v_path_stamp field has been + * added to vnode_t. As part of successful fop_create/fop_lookup/fop_mkdir + * operations, where the name and parent vnode are available, the following + * rules are used to determine updates to the child: + * + * 1. If the parent lacks a v_path, clear any existing v_path and v_path_stamp + * on the child. Until the parent v_path is refreshed to a valid state, the + * child v_path must be considered invalid too. + * + * 2. If the child lacks a v_path (implying v_path_stamp == 0), it inherits the + * v_path_stamp value from its parent and its v_path is updated. + * + * 3. If the child v_path_stamp is less than v_path_stamp in the parent, it is + * an indication that the child v_path is stale. The v_path is updated and + * v_path_stamp in the child is set to the current hrtime(). + * + * It does _not_ inherit the parent v_path_stamp in order to propagate the + * the time of v_path invalidation through the directory structure. This + * prevents concurrent invalidations (operating with a now-incorrect v_path) + * at deeper levels in the tree from persisting. + * + * 4. If the child v_path_stamp is greater or equal to the parent, no action + * needs to be taken. + * + * Note that fop_rename operations do not follow this ruleset. They perform an + * explicit update of v_path and v_path_stamp (setting it to the current time) + * + * With these constraints in place, v_path invalidations and updates should + * proceed in a timely manner as vnodes are accessed. While there still are + * limited cases where vnodetopath operations will fail, the risk is minimized. */ struct fem_head; /* from fem.h */ typedef struct vnode { kmutex_t v_lock; /* protects vnode fields */ uint_t v_flag; /* vnode flags (see below) */ uint_t v_count; /* reference count */ void *v_data; /* private data for fs */ struct vfs *v_vfsp; /* ptr to containing VFS */ struct stdata *v_stream; /* associated stream */ enum vtype v_type; /* vnode type */ dev_t v_rdev; /* device (VCHR, VBLK) */ /* PRIVATE FIELDS BELOW - DO NOT USE */ struct vfs *v_vfsmountedhere; /* ptr to vfs mounted here */ struct vnodeops *v_op; /* vnode operations */ struct page *v_pages; /* vnode pages list */ struct filock *v_filocks; /* ptr to filock list */ struct shrlocklist *v_shrlocks; /* ptr to shrlock list */ krwlock_t v_nbllock; /* sync for NBMAND locks */ kcondvar_t v_cv; /* synchronize locking */ void *v_locality; /* hook for locality info */ struct fem_head *v_femhead; /* fs monitoring */ char *v_path; /* cached path */ + hrtime_t v_path_stamp; /* timestamp for cached path */ uint_t v_rdcnt; /* open for read count (VREG only) */ uint_t v_wrcnt; /* open for write count (VREG only) */ u_longlong_t v_mmap_read; /* mmap read count */ u_longlong_t v_mmap_write; /* mmap write count */ void *v_mpssdata; /* info for large page mappings */ void *v_fopdata; /* list of file ops event watches */ kmutex_t v_vsd_lock; /* protects v_vsd field */ struct vsd_node *v_vsd; /* vnode specific data */ struct vnode *v_xattrdir; /* unnamed extended attr dir (GFS) */ uint_t v_count_dnlc; /* dnlc reference count */ } vnode_t; #define IS_DEVVP(vp) \ ((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO) #define VNODE_ALIGN 64 /* Count of low-order 0 bits in a vnode *, based on size and alignment. */ #if defined(_LP64) #define VNODE_ALIGN_LOG2 8 #else #define VNODE_ALIGN_LOG2 7 #endif /* * vnode flags. */ #define VROOT 0x01 /* root of its file system */ #define VNOCACHE 0x02 /* don't keep cache pages on vnode */ #define VNOMAP 0x04 /* file cannot be mapped/faulted */ #define VDUP 0x08 /* file should be dup'ed rather then opened */ #define VNOSWAP 0x10 /* file cannot be used as virtual swap device */ #define VNOMOUNT 0x20 /* file cannot be covered by mount */ #define VISSWAP 0x40 /* vnode is being used for swap */ #define VSWAPLIKE 0x80 /* vnode acts like swap (but may not be) */ #define IS_SWAPVP(vp) (((vp)->v_flag & (VISSWAP | VSWAPLIKE)) != 0) typedef struct vn_vfslocks_entry { rwstlock_t ve_lock; void *ve_vpvfs; struct vn_vfslocks_entry *ve_next; uint32_t ve_refcnt; char pad[64 - sizeof (rwstlock_t) - 2 * sizeof (void *) - \ sizeof (uint32_t)]; } vn_vfslocks_entry_t; /* * The following two flags are used to lock the v_vfsmountedhere field */ #define VVFSLOCK 0x100 #define VVFSWAIT 0x200 /* * Used to serialize VM operations on a vnode */ #define VVMLOCK 0x400 /* * Tell vn_open() not to fail a directory open for writing but * to go ahead and call VOP_OPEN() to let the filesystem check. */ #define VDIROPEN 0x800 /* * Flag to let the VM system know that this file is most likely a binary * or shared library since it has been mmap()ed EXEC at some time. */ #define VVMEXEC 0x1000 #define VPXFS 0x2000 /* clustering: global fs proxy vnode */ #define IS_PXFSVP(vp) ((vp)->v_flag & VPXFS) #define V_XATTRDIR 0x4000 /* attribute unnamed directory */ #define IS_XATTRDIR(vp) ((vp)->v_flag & V_XATTRDIR) #define V_LOCALITY 0x8000 /* whether locality aware */ /* * Flag that indicates the VM should maintain the v_pages list with all modified * pages on one end and unmodified pages at the other. This makes finding dirty * pages to write back to disk much faster at the expense of taking a minor * fault on the first store instruction which touches a writable page. */ #define VMODSORT (0x10000) #define IS_VMODSORT(vp) \ (pvn_vmodsort_supported != 0 && ((vp)->v_flag & VMODSORT) != 0) #define VISSWAPFS 0x20000 /* vnode is being used for swapfs */ /* * The mdb memstat command assumes that IS_SWAPFSVP only uses the * vnode's v_flag field. If this changes, cache the additional * fields in mdb; see vn_get in mdb/common/modules/genunix/memory.c */ #define IS_SWAPFSVP(vp) (((vp)->v_flag & VISSWAPFS) != 0) #define V_SYSATTR 0x40000 /* vnode is a GFS system attribute */ /* + * Indication that VOP_LOOKUP operations on this vnode may yield results from a + * different VFS instance. The main use of this is to suppress v_path + * calculation logic when filesystems such as procfs emit results which defy + * expectations about normal VFS behavior. + */ +#define VTRAVERSE 0x80000 + +/* * Vnode attributes. A bit-mask is supplied as part of the * structure to indicate the attributes the caller wants to * set (setattr) or extract (getattr). */ /* * Note that va_nodeid and va_nblocks are 64bit data type. * We support large files over NFSV3. With Solaris client and * Server that generates 64bit ino's and sizes these fields * will overflow if they are 32 bit sizes. */ typedef struct vattr { uint_t va_mask; /* bit-mask of attributes */ vtype_t va_type; /* vnode type (for create) */ mode_t va_mode; /* file access mode */ uid_t va_uid; /* owner user id */ gid_t va_gid; /* owner group id */ dev_t va_fsid; /* file system id (dev for now) */ u_longlong_t va_nodeid; /* node id */ nlink_t va_nlink; /* number of references to file */ u_offset_t va_size; /* file size in bytes */ timestruc_t va_atime; /* time of last access */ timestruc_t va_mtime; /* time of last modification */ timestruc_t va_ctime; /* time of last status change */ dev_t va_rdev; /* device the file represents */ uint_t va_blksize; /* fundamental block size */ u_longlong_t va_nblocks; /* # of blocks allocated */ uint_t va_seq; /* sequence number */ } vattr_t; #define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */ /* * Structure of all optional attributes. */ typedef struct xoptattr { timestruc_t xoa_createtime; /* Create time of file */ uint8_t xoa_archive; uint8_t xoa_system; uint8_t xoa_readonly; uint8_t xoa_hidden; uint8_t xoa_nounlink; uint8_t xoa_immutable; uint8_t xoa_appendonly; uint8_t xoa_nodump; uint8_t xoa_opaque; uint8_t xoa_av_quarantined; uint8_t xoa_av_modified; uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ]; uint8_t xoa_reparse; uint64_t xoa_generation; uint8_t xoa_offline; uint8_t xoa_sparse; } xoptattr_t; /* * The xvattr structure is really a variable length structure that * is made up of: * - The classic vattr_t (xva_vattr) * - a 32 bit quantity (xva_mapsize) that specifies the size of the * attribute bitmaps in 32 bit words. * - A pointer to the returned attribute bitmap (needed because the * previous element, the requested attribute bitmap) is variable lenth. * - The requested attribute bitmap, which is an array of 32 bit words. * Callers use the XVA_SET_REQ() macro to set the bits corresponding to * the attributes that are being requested. * - The returned attribute bitmap, which is an array of 32 bit words. * File systems that support optional attributes use the XVA_SET_RTN() * macro to set the bits corresponding to the attributes that are being * returned. * - The xoptattr_t structure which contains the attribute values * * xva_mapsize determines how many words in the attribute bitmaps. * Immediately following the attribute bitmaps is the xoptattr_t. * xva_getxoptattr() is used to get the pointer to the xoptattr_t * section. */ #define XVA_MAPSIZE 3 /* Size of attr bitmaps */ #define XVA_MAGIC 0x78766174 /* Magic # for verification */ /* * The xvattr structure is an extensible structure which permits optional * attributes to be requested/returned. File systems may or may not support * optional attributes. They do so at their own discretion but if they do * support optional attributes, they must register the VFSFT_XVATTR feature * so that the optional attributes can be set/retrived. * * The fields of the xvattr structure are: * * xva_vattr - The first element of an xvattr is a legacy vattr structure * which includes the common attributes. If AT_XVATTR is set in the va_mask * then the entire structure is treated as an xvattr. If AT_XVATTR is not * set, then only the xva_vattr structure can be used. * * xva_magic - 0x78766174 (hex for "xvat"). Magic number for verification. * * xva_mapsize - Size of requested and returned attribute bitmaps. * * xva_rtnattrmapp - Pointer to xva_rtnattrmap[]. We need this since the * size of the array before it, xva_reqattrmap[], could change which means * the location of xva_rtnattrmap[] could change. This will allow unbundled * file systems to find the location of xva_rtnattrmap[] when the sizes change. * * xva_reqattrmap[] - Array of requested attributes. Attributes are * represented by a specific bit in a specific element of the attribute * map array. Callers set the bits corresponding to the attributes * that the caller wants to get/set. * * xva_rtnattrmap[] - Array of attributes that the file system was able to * process. Not all file systems support all optional attributes. This map * informs the caller which attributes the underlying file system was able * to set/get. (Same structure as the requested attributes array in terms * of each attribute corresponding to specific bits and array elements.) * * xva_xoptattrs - Structure containing values of optional attributes. * These values are only valid if the corresponding bits in xva_reqattrmap * are set and the underlying file system supports those attributes. */ typedef struct xvattr { vattr_t xva_vattr; /* Embedded vattr structure */ uint32_t xva_magic; /* Magic Number */ uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */ uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */ uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */ uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */ xoptattr_t xva_xoptattrs; /* Optional attributes */ } xvattr_t; #ifdef _SYSCALL32 /* * For bigtypes time_t changed to 64 bit on the 64-bit kernel. * Define an old version for user/kernel interface */ #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 #pragma pack(4) #endif typedef struct vattr32 { uint32_t va_mask; /* bit-mask of attributes */ vtype_t va_type; /* vnode type (for create) */ mode32_t va_mode; /* file access mode */ uid32_t va_uid; /* owner user id */ gid32_t va_gid; /* owner group id */ dev32_t va_fsid; /* file system id (dev for now) */ u_longlong_t va_nodeid; /* node id */ nlink_t va_nlink; /* number of references to file */ u_offset_t va_size; /* file size in bytes */ timestruc32_t va_atime; /* time of last access */ timestruc32_t va_mtime; /* time of last modification */ timestruc32_t va_ctime; /* time of last status change */ dev32_t va_rdev; /* device the file represents */ uint32_t va_blksize; /* fundamental block size */ u_longlong_t va_nblocks; /* # of blocks allocated */ uint32_t va_seq; /* sequence number */ } vattr32_t; #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 #pragma pack() #endif #else /* not _SYSCALL32 */ #define vattr32 vattr typedef vattr_t vattr32_t; #endif /* _SYSCALL32 */ /* * Attributes of interest to the caller of setattr or getattr. */ #define AT_TYPE 0x00001 #define AT_MODE 0x00002 #define AT_UID 0x00004 #define AT_GID 0x00008 #define AT_FSID 0x00010 #define AT_NODEID 0x00020 #define AT_NLINK 0x00040 #define AT_SIZE 0x00080 #define AT_ATIME 0x00100 #define AT_MTIME 0x00200 #define AT_CTIME 0x00400 #define AT_RDEV 0x00800 #define AT_BLKSIZE 0x01000 #define AT_NBLOCKS 0x02000 /* 0x04000 */ /* unused */ #define AT_SEQ 0x08000 /* * If AT_XVATTR is set then there are additional bits to process in * the xvattr_t's attribute bitmap. If this is not set then the bitmap * MUST be ignored. Note that this bit must be set/cleared explicitly. * That is, setting AT_ALL will NOT set AT_XVATTR. */ #define AT_XVATTR 0x10000 #define AT_ALL (AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\ AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\ AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_SEQ) #define AT_STAT (AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\ AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV|AT_TYPE) #define AT_TIMES (AT_ATIME|AT_MTIME|AT_CTIME) #define AT_NOSET (AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\ AT_BLKSIZE|AT_NBLOCKS|AT_SEQ) /* * Attribute bits used in the extensible attribute's (xva's) attribute * bitmaps. Note that the bitmaps are made up of a variable length number * of 32-bit words. The convention is to use XAT{n}_{attrname} where "n" * is the element in the bitmap (starting at 1). This convention is for * the convenience of the maintainer to keep track of which element each * attribute belongs to. * * NOTE THAT CONSUMERS MUST *NOT* USE THE XATn_* DEFINES DIRECTLY. CONSUMERS * MUST USE THE XAT_* DEFINES. */ #define XAT0_INDEX 0LL /* Index into bitmap for XAT0 attrs */ #define XAT0_CREATETIME 0x00000001 /* Create time of file */ #define XAT0_ARCHIVE 0x00000002 /* Archive */ #define XAT0_SYSTEM 0x00000004 /* System */ #define XAT0_READONLY 0x00000008 /* Readonly */ #define XAT0_HIDDEN 0x00000010 /* Hidden */ #define XAT0_NOUNLINK 0x00000020 /* Nounlink */ #define XAT0_IMMUTABLE 0x00000040 /* immutable */ #define XAT0_APPENDONLY 0x00000080 /* appendonly */ #define XAT0_NODUMP 0x00000100 /* nodump */ #define XAT0_OPAQUE 0x00000200 /* opaque */ #define XAT0_AV_QUARANTINED 0x00000400 /* anti-virus quarantine */ #define XAT0_AV_MODIFIED 0x00000800 /* anti-virus modified */ #define XAT0_AV_SCANSTAMP 0x00001000 /* anti-virus scanstamp */ #define XAT0_REPARSE 0x00002000 /* FS reparse point */ #define XAT0_GEN 0x00004000 /* object generation number */ #define XAT0_OFFLINE 0x00008000 /* offline */ #define XAT0_SPARSE 0x00010000 /* sparse */ #define XAT0_ALL_ATTRS (XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \ XAT0_READONLY|XAT0_HIDDEN|XAT0_NOUNLINK|XAT0_IMMUTABLE|XAT0_APPENDONLY| \ XAT0_NODUMP|XAT0_OPAQUE|XAT0_AV_QUARANTINED| XAT0_AV_MODIFIED| \ XAT0_AV_SCANSTAMP|XAT0_REPARSE|XATO_GEN|XAT0_OFFLINE|XAT0_SPARSE) /* Support for XAT_* optional attributes */ #define XVA_MASK 0xffffffff /* Used to mask off 32 bits */ #define XVA_SHFT 32 /* Used to shift index */ /* * Used to pry out the index and attribute bits from the XAT_* attributes * defined below. Note that we're masking things down to 32 bits then * casting to uint32_t. */ #define XVA_INDEX(attr) ((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK)) #define XVA_ATTRBIT(attr) ((uint32_t)((attr) & XVA_MASK)) /* * The following defines present a "flat namespace" so that consumers don't * need to keep track of which element belongs to which bitmap entry. * * NOTE THAT THESE MUST NEVER BE OR-ed TOGETHER */ #define XAT_CREATETIME ((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME) #define XAT_ARCHIVE ((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE) #define XAT_SYSTEM ((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM) #define XAT_READONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY) #define XAT_HIDDEN ((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN) #define XAT_NOUNLINK ((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK) #define XAT_IMMUTABLE ((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE) #define XAT_APPENDONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY) #define XAT_NODUMP ((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP) #define XAT_OPAQUE ((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE) #define XAT_AV_QUARANTINED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED) #define XAT_AV_MODIFIED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED) #define XAT_AV_SCANSTAMP ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP) #define XAT_REPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_REPARSE) #define XAT_GEN ((XAT0_INDEX << XVA_SHFT) | XAT0_GEN) #define XAT_OFFLINE ((XAT0_INDEX << XVA_SHFT) | XAT0_OFFLINE) #define XAT_SPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_SPARSE) /* * The returned attribute map array (xva_rtnattrmap[]) is located past the * requested attribute map array (xva_reqattrmap[]). Its location changes * when the array sizes change. We use a separate pointer in a known location * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[]. This is * set in xva_init() */ #define XVA_RTNATTRMAP(xvap) ((xvap)->xva_rtnattrmapp) /* * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap * of requested attributes (xva_reqattrmap[]). */ #define XVA_SET_REQ(xvap, attr) \ ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ ASSERT((xvap)->xva_magic == XVA_MAGIC); \ (xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr) /* * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap * of requested attributes (xva_reqattrmap[]). */ #define XVA_CLR_REQ(xvap, attr) \ ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ ASSERT((xvap)->xva_magic == XVA_MAGIC); \ (xvap)->xva_reqattrmap[XVA_INDEX(attr)] &= ~XVA_ATTRBIT(attr) /* * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap * of returned attributes (xva_rtnattrmap[]). */ #define XVA_SET_RTN(xvap, attr) \ ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ ASSERT((xvap)->xva_magic == XVA_MAGIC); \ (XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr) /* * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[]) * to see of the corresponding attribute bit is set. If so, returns non-zero. */ #define XVA_ISSET_REQ(xvap, attr) \ ((((xvap)->xva_vattr.va_mask | AT_XVATTR) && \ ((xvap)->xva_magic == XVA_MAGIC) && \ ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \ ((xvap)->xva_reqattrmap[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0) /* * XVA_ISSET_RTN() checks the returned attribute bitmap (xva_rtnattrmap[]) * to see of the corresponding attribute bit is set. If so, returns non-zero. */ #define XVA_ISSET_RTN(xvap, attr) \ ((((xvap)->xva_vattr.va_mask | AT_XVATTR) && \ ((xvap)->xva_magic == XVA_MAGIC) && \ ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \ ((XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0) /* * Modes. Some values same as S_xxx entries from stat.h for convenience. */ #define VSUID 04000 /* set user id on execution */ #define VSGID 02000 /* set group id on execution */ #define VSVTX 01000 /* save swapped text even after use */ /* * Permissions. */ #define VREAD 00400 #define VWRITE 00200 #define VEXEC 00100 #define MODEMASK 07777 /* mode bits plus permission bits */ #define PERMMASK 00777 /* permission bits */ /* * VOP_ACCESS flags */ #define V_ACE_MASK 0x1 /* mask represents NFSv4 ACE permissions */ #define V_APPEND 0x2 /* want to do append only check */ /* * Check whether mandatory file locking is enabled. */ #define MANDMODE(mode) (((mode) & (VSGID|(VEXEC>>3))) == VSGID) #define MANDLOCK(vp, mode) ((vp)->v_type == VREG && MANDMODE(mode)) /* * Flags for vnode operations. */ enum rm { RMFILE, RMDIRECTORY }; /* rm or rmdir (remove) */ enum symfollow { NO_FOLLOW, FOLLOW }; /* follow symlinks (or not) */ enum vcexcl { NONEXCL, EXCL }; /* (non)excl create */ enum create { CRCREAT, CRMKNOD, CRMKDIR }; /* reason for create */ typedef enum rm rm_t; typedef enum symfollow symfollow_t; typedef enum vcexcl vcexcl_t; typedef enum create create_t; /* * Vnode Events - Used by VOP_VNEVENT * The VE_PRE_RENAME_* events fire before the rename operation and are * primarily used for specialized applications, such as NFSv4 delegation, which * need to know about rename before it occurs. */ typedef enum vnevent { VE_SUPPORT = 0, /* Query */ VE_RENAME_SRC = 1, /* Rename, with vnode as source */ VE_RENAME_DEST = 2, /* Rename, with vnode as target/destination */ VE_REMOVE = 3, /* Remove of vnode's name */ VE_RMDIR = 4, /* Remove of directory vnode's name */ VE_CREATE = 5, /* Create with vnode's name which exists */ VE_LINK = 6, /* Link with vnode's name as source */ VE_RENAME_DEST_DIR = 7, /* Rename with vnode as target dir */ VE_MOUNTEDOVER = 8, /* File or Filesystem got mounted over vnode */ VE_TRUNCATE = 9, /* Truncate */ VE_PRE_RENAME_SRC = 10, /* Pre-rename, with vnode as source */ VE_PRE_RENAME_DEST = 11, /* Pre-rename, with vnode as target/dest. */ VE_PRE_RENAME_DEST_DIR = 12 /* Pre-rename with vnode as target dir */ } vnevent_t; /* * Values for checking vnode open and map counts */ enum v_mode { V_READ, V_WRITE, V_RDORWR, V_RDANDWR }; typedef enum v_mode v_mode_t; #define V_TRUE 1 #define V_FALSE 0 /* * Structure used on VOP_GETSECATTR and VOP_SETSECATTR operations */ typedef struct vsecattr { uint_t vsa_mask; /* See below */ int vsa_aclcnt; /* ACL entry count */ void *vsa_aclentp; /* pointer to ACL entries */ int vsa_dfaclcnt; /* default ACL entry count */ void *vsa_dfaclentp; /* pointer to default ACL entries */ size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */ uint_t vsa_aclflags; /* ACE ACL flags */ } vsecattr_t; /* vsa_mask values */ #define VSA_ACL 0x0001 #define VSA_ACLCNT 0x0002 #define VSA_DFACL 0x0004 #define VSA_DFACLCNT 0x0008 #define VSA_ACE 0x0010 #define VSA_ACECNT 0x0020 #define VSA_ACE_ALLTYPES 0x0040 #define VSA_ACE_ACLFLAGS 0x0080 /* get/set ACE ACL flags */ /* * Structure used by various vnode operations to determine * the context (pid, host, identity) of a caller. * * The cc_caller_id is used to identify one or more callers who invoke * operations, possibly on behalf of others. For example, the NFS * server could have it's own cc_caller_id which can be detected by * vnode/vfs operations or (FEM) monitors on those operations. New * caller IDs are generated by fs_new_caller_id(). */ typedef struct caller_context { pid_t cc_pid; /* Process ID of the caller */ int cc_sysid; /* System ID, used for remote calls */ u_longlong_t cc_caller_id; /* Identifier for (set of) caller(s) */ ulong_t cc_flags; } caller_context_t; /* * Flags for caller context. The caller sets CC_DONTBLOCK if it does not * want to block inside of a FEM monitor. The monitor will set CC_WOULDBLOCK * and return EAGAIN if the operation would have blocked. */ #define CC_WOULDBLOCK 0x01 #define CC_DONTBLOCK 0x02 /* * Structure tags for function prototypes, defined elsewhere. */ struct pathname; struct fid; struct flock64; struct flk_callback; struct shrlock; struct page; struct seg; struct as; struct pollhead; struct taskq; #ifdef _KERNEL /* * VNODE_OPS defines all the vnode operations. It is used to define * the vnodeops structure (below) and the fs_func_p union (vfs_opreg.h). */ #define VNODE_OPS \ int (*vop_open)(vnode_t **, int, cred_t *, \ caller_context_t *); \ int (*vop_close)(vnode_t *, int, int, offset_t, cred_t *, \ caller_context_t *); \ int (*vop_read)(vnode_t *, uio_t *, int, cred_t *, \ caller_context_t *); \ int (*vop_write)(vnode_t *, uio_t *, int, cred_t *, \ caller_context_t *); \ int (*vop_ioctl)(vnode_t *, int, intptr_t, int, cred_t *, \ int *, caller_context_t *); \ int (*vop_setfl)(vnode_t *, int, int, cred_t *, \ caller_context_t *); \ int (*vop_getattr)(vnode_t *, vattr_t *, int, cred_t *, \ caller_context_t *); \ int (*vop_setattr)(vnode_t *, vattr_t *, int, cred_t *, \ caller_context_t *); \ int (*vop_access)(vnode_t *, int, int, cred_t *, \ caller_context_t *); \ int (*vop_lookup)(vnode_t *, char *, vnode_t **, \ struct pathname *, \ int, vnode_t *, cred_t *, \ caller_context_t *, int *, \ struct pathname *); \ int (*vop_create)(vnode_t *, char *, vattr_t *, vcexcl_t, \ int, vnode_t **, cred_t *, int, \ caller_context_t *, vsecattr_t *); \ int (*vop_remove)(vnode_t *, char *, cred_t *, \ caller_context_t *, int); \ int (*vop_link)(vnode_t *, vnode_t *, char *, cred_t *, \ caller_context_t *, int); \ int (*vop_rename)(vnode_t *, char *, vnode_t *, char *, \ cred_t *, caller_context_t *, int); \ int (*vop_mkdir)(vnode_t *, char *, vattr_t *, vnode_t **, \ cred_t *, caller_context_t *, int, \ vsecattr_t *); \ int (*vop_rmdir)(vnode_t *, char *, vnode_t *, cred_t *, \ caller_context_t *, int); \ int (*vop_readdir)(vnode_t *, uio_t *, cred_t *, int *, \ caller_context_t *, int); \ int (*vop_symlink)(vnode_t *, char *, vattr_t *, char *, \ cred_t *, caller_context_t *, int); \ int (*vop_readlink)(vnode_t *, uio_t *, cred_t *, \ caller_context_t *); \ int (*vop_fsync)(vnode_t *, int, cred_t *, \ caller_context_t *); \ void (*vop_inactive)(vnode_t *, cred_t *, \ caller_context_t *); \ int (*vop_fid)(vnode_t *, struct fid *, \ caller_context_t *); \ int (*vop_rwlock)(vnode_t *, int, caller_context_t *); \ void (*vop_rwunlock)(vnode_t *, int, caller_context_t *); \ int (*vop_seek)(vnode_t *, offset_t, offset_t *, \ caller_context_t *); \ int (*vop_cmp)(vnode_t *, vnode_t *, caller_context_t *); \ int (*vop_frlock)(vnode_t *, int, struct flock64 *, \ int, offset_t, \ struct flk_callback *, cred_t *, \ caller_context_t *); \ int (*vop_space)(vnode_t *, int, struct flock64 *, \ int, offset_t, \ cred_t *, caller_context_t *); \ int (*vop_realvp)(vnode_t *, vnode_t **, \ caller_context_t *); \ int (*vop_getpage)(vnode_t *, offset_t, size_t, uint_t *, \ struct page **, size_t, struct seg *, \ caddr_t, enum seg_rw, cred_t *, \ caller_context_t *); \ int (*vop_putpage)(vnode_t *, offset_t, size_t, \ int, cred_t *, caller_context_t *); \ int (*vop_map)(vnode_t *, offset_t, struct as *, \ caddr_t *, size_t, \ uchar_t, uchar_t, uint_t, cred_t *, \ caller_context_t *); \ int (*vop_addmap)(vnode_t *, offset_t, struct as *, \ caddr_t, size_t, \ uchar_t, uchar_t, uint_t, cred_t *, \ caller_context_t *); \ int (*vop_delmap)(vnode_t *, offset_t, struct as *, \ caddr_t, size_t, \ uint_t, uint_t, uint_t, cred_t *, \ caller_context_t *); \ int (*vop_poll)(vnode_t *, short, int, short *, \ struct pollhead **, \ caller_context_t *); \ int (*vop_dump)(vnode_t *, caddr_t, offset_t, offset_t, \ caller_context_t *); \ int (*vop_pathconf)(vnode_t *, int, ulong_t *, cred_t *, \ caller_context_t *); \ int (*vop_pageio)(vnode_t *, struct page *, \ u_offset_t, size_t, int, cred_t *, \ caller_context_t *); \ int (*vop_dumpctl)(vnode_t *, int, offset_t *, \ caller_context_t *); \ void (*vop_dispose)(vnode_t *, struct page *, \ int, int, cred_t *, \ caller_context_t *); \ int (*vop_setsecattr)(vnode_t *, vsecattr_t *, \ int, cred_t *, caller_context_t *); \ int (*vop_getsecattr)(vnode_t *, vsecattr_t *, \ int, cred_t *, caller_context_t *); \ int (*vop_shrlock)(vnode_t *, int, struct shrlock *, \ int, cred_t *, caller_context_t *); \ int (*vop_vnevent)(vnode_t *, vnevent_t, vnode_t *, \ char *, caller_context_t *); \ int (*vop_reqzcbuf)(vnode_t *, enum uio_rw, xuio_t *, \ cred_t *, caller_context_t *); \ int (*vop_retzcbuf)(vnode_t *, xuio_t *, cred_t *, \ caller_context_t *) /* NB: No ";" */ /* * Operations on vnodes. Note: File systems must never operate directly * on a 'vnodeops' structure -- it WILL change in future releases! They * must use vn_make_ops() to create the structure. */ typedef struct vnodeops { const char *vnop_name; VNODE_OPS; /* Signatures of all vnode operations (vops) */ } vnodeops_t; typedef int (*fs_generic_func_p) (); /* Generic vop/vfsop/femop/fsemop ptr */ extern int fop_open(vnode_t **, int, cred_t *, caller_context_t *); extern int fop_close(vnode_t *, int, int, offset_t, cred_t *, caller_context_t *); extern int fop_read(vnode_t *, uio_t *, int, cred_t *, caller_context_t *); extern int fop_write(vnode_t *, uio_t *, int, cred_t *, caller_context_t *); extern int fop_ioctl(vnode_t *, int, intptr_t, int, cred_t *, int *, caller_context_t *); extern int fop_setfl(vnode_t *, int, int, cred_t *, caller_context_t *); extern int fop_getattr(vnode_t *, vattr_t *, int, cred_t *, caller_context_t *); extern int fop_setattr(vnode_t *, vattr_t *, int, cred_t *, caller_context_t *); extern int fop_access(vnode_t *, int, int, cred_t *, caller_context_t *); extern int fop_lookup(vnode_t *, char *, vnode_t **, struct pathname *, int, vnode_t *, cred_t *, caller_context_t *, int *, struct pathname *); extern int fop_create(vnode_t *, char *, vattr_t *, vcexcl_t, int, vnode_t **, cred_t *, int, caller_context_t *, vsecattr_t *); extern int fop_remove(vnode_t *vp, char *, cred_t *, caller_context_t *, int); extern int fop_link(vnode_t *, vnode_t *, char *, cred_t *, caller_context_t *, int); extern int fop_rename(vnode_t *, char *, vnode_t *, char *, cred_t *, caller_context_t *, int); extern int fop_mkdir(vnode_t *, char *, vattr_t *, vnode_t **, cred_t *, caller_context_t *, int, vsecattr_t *); extern int fop_rmdir(vnode_t *, char *, vnode_t *, cred_t *, caller_context_t *, int); extern int fop_readdir(vnode_t *, uio_t *, cred_t *, int *, caller_context_t *, int); extern int fop_symlink(vnode_t *, char *, vattr_t *, char *, cred_t *, caller_context_t *, int); extern int fop_readlink(vnode_t *, uio_t *, cred_t *, caller_context_t *); extern int fop_fsync(vnode_t *, int, cred_t *, caller_context_t *); extern void fop_inactive(vnode_t *, cred_t *, caller_context_t *); extern int fop_fid(vnode_t *, struct fid *, caller_context_t *); extern int fop_rwlock(vnode_t *, int, caller_context_t *); extern void fop_rwunlock(vnode_t *, int, caller_context_t *); extern int fop_seek(vnode_t *, offset_t, offset_t *, caller_context_t *); extern int fop_cmp(vnode_t *, vnode_t *, caller_context_t *); extern int fop_frlock(vnode_t *, int, struct flock64 *, int, offset_t, struct flk_callback *, cred_t *, caller_context_t *); extern int fop_space(vnode_t *, int, struct flock64 *, int, offset_t, cred_t *, caller_context_t *); extern int fop_realvp(vnode_t *, vnode_t **, caller_context_t *); extern int fop_getpage(vnode_t *, offset_t, size_t, uint_t *, struct page **, size_t, struct seg *, caddr_t, enum seg_rw, cred_t *, caller_context_t *); extern int fop_putpage(vnode_t *, offset_t, size_t, int, cred_t *, caller_context_t *); extern int fop_map(vnode_t *, offset_t, struct as *, caddr_t *, size_t, uchar_t, uchar_t, uint_t, cred_t *cr, caller_context_t *); extern int fop_addmap(vnode_t *, offset_t, struct as *, caddr_t, size_t, uchar_t, uchar_t, uint_t, cred_t *, caller_context_t *); extern int fop_delmap(vnode_t *, offset_t, struct as *, caddr_t, size_t, uint_t, uint_t, uint_t, cred_t *, caller_context_t *); extern int fop_poll(vnode_t *, short, int, short *, struct pollhead **, caller_context_t *); extern int fop_dump(vnode_t *, caddr_t, offset_t, offset_t, caller_context_t *); extern int fop_pathconf(vnode_t *, int, ulong_t *, cred_t *, caller_context_t *); extern int fop_pageio(vnode_t *, struct page *, u_offset_t, size_t, int, cred_t *, caller_context_t *); extern int fop_dumpctl(vnode_t *, int, offset_t *, caller_context_t *); extern void fop_dispose(vnode_t *, struct page *, int, int, cred_t *, caller_context_t *); extern int fop_setsecattr(vnode_t *, vsecattr_t *, int, cred_t *, caller_context_t *); extern int fop_getsecattr(vnode_t *, vsecattr_t *, int, cred_t *, caller_context_t *); extern int fop_shrlock(vnode_t *, int, struct shrlock *, int, cred_t *, caller_context_t *); extern int fop_vnevent(vnode_t *, vnevent_t, vnode_t *, char *, caller_context_t *); extern int fop_reqzcbuf(vnode_t *, enum uio_rw, xuio_t *, cred_t *, caller_context_t *); extern int fop_retzcbuf(vnode_t *, xuio_t *, cred_t *, caller_context_t *); #endif /* _KERNEL */ #define VOP_OPEN(vpp, mode, cr, ct) \ fop_open(vpp, mode, cr, ct) #define VOP_CLOSE(vp, f, c, o, cr, ct) \ fop_close(vp, f, c, o, cr, ct) #define VOP_READ(vp, uiop, iof, cr, ct) \ fop_read(vp, uiop, iof, cr, ct) #define VOP_WRITE(vp, uiop, iof, cr, ct) \ fop_write(vp, uiop, iof, cr, ct) #define VOP_IOCTL(vp, cmd, a, f, cr, rvp, ct) \ fop_ioctl(vp, cmd, a, f, cr, rvp, ct) #define VOP_SETFL(vp, f, a, cr, ct) \ fop_setfl(vp, f, a, cr, ct) #define VOP_GETATTR(vp, vap, f, cr, ct) \ fop_getattr(vp, vap, f, cr, ct) #define VOP_SETATTR(vp, vap, f, cr, ct) \ fop_setattr(vp, vap, f, cr, ct) #define VOP_ACCESS(vp, mode, f, cr, ct) \ fop_access(vp, mode, f, cr, ct) #define VOP_LOOKUP(vp, cp, vpp, pnp, f, rdir, cr, ct, defp, rpnp) \ fop_lookup(vp, cp, vpp, pnp, f, rdir, cr, ct, defp, rpnp) #define VOP_CREATE(dvp, p, vap, ex, mode, vpp, cr, flag, ct, vsap) \ fop_create(dvp, p, vap, ex, mode, vpp, cr, flag, ct, vsap) #define VOP_REMOVE(dvp, p, cr, ct, f) \ fop_remove(dvp, p, cr, ct, f) #define VOP_LINK(tdvp, fvp, p, cr, ct, f) \ fop_link(tdvp, fvp, p, cr, ct, f) #define VOP_RENAME(fvp, fnm, tdvp, tnm, cr, ct, f) \ fop_rename(fvp, fnm, tdvp, tnm, cr, ct, f) #define VOP_MKDIR(dp, p, vap, vpp, cr, ct, f, vsap) \ fop_mkdir(dp, p, vap, vpp, cr, ct, f, vsap) #define VOP_RMDIR(dp, p, cdir, cr, ct, f) \ fop_rmdir(dp, p, cdir, cr, ct, f) #define VOP_READDIR(vp, uiop, cr, eofp, ct, f) \ fop_readdir(vp, uiop, cr, eofp, ct, f) #define VOP_SYMLINK(dvp, lnm, vap, tnm, cr, ct, f) \ fop_symlink(dvp, lnm, vap, tnm, cr, ct, f) #define VOP_READLINK(vp, uiop, cr, ct) \ fop_readlink(vp, uiop, cr, ct) #define VOP_FSYNC(vp, syncflag, cr, ct) \ fop_fsync(vp, syncflag, cr, ct) #define VOP_INACTIVE(vp, cr, ct) \ fop_inactive(vp, cr, ct) #define VOP_FID(vp, fidp, ct) \ fop_fid(vp, fidp, ct) #define VOP_RWLOCK(vp, w, ct) \ fop_rwlock(vp, w, ct) #define VOP_RWUNLOCK(vp, w, ct) \ fop_rwunlock(vp, w, ct) #define VOP_SEEK(vp, ooff, noffp, ct) \ fop_seek(vp, ooff, noffp, ct) #define VOP_CMP(vp1, vp2, ct) \ fop_cmp(vp1, vp2, ct) #define VOP_FRLOCK(vp, cmd, a, f, o, cb, cr, ct) \ fop_frlock(vp, cmd, a, f, o, cb, cr, ct) #define VOP_SPACE(vp, cmd, a, f, o, cr, ct) \ fop_space(vp, cmd, a, f, o, cr, ct) #define VOP_REALVP(vp1, vp2, ct) \ fop_realvp(vp1, vp2, ct) #define VOP_GETPAGE(vp, of, sz, pr, pl, ps, sg, a, rw, cr, ct) \ fop_getpage(vp, of, sz, pr, pl, ps, sg, a, rw, cr, ct) #define VOP_PUTPAGE(vp, of, sz, fl, cr, ct) \ fop_putpage(vp, of, sz, fl, cr, ct) #define VOP_MAP(vp, of, as, a, sz, p, mp, fl, cr, ct) \ fop_map(vp, of, as, a, sz, p, mp, fl, cr, ct) #define VOP_ADDMAP(vp, of, as, a, sz, p, mp, fl, cr, ct) \ fop_addmap(vp, of, as, a, sz, p, mp, fl, cr, ct) #define VOP_DELMAP(vp, of, as, a, sz, p, mp, fl, cr, ct) \ fop_delmap(vp, of, as, a, sz, p, mp, fl, cr, ct) #define VOP_POLL(vp, events, anyyet, reventsp, phpp, ct) \ fop_poll(vp, events, anyyet, reventsp, phpp, ct) #define VOP_DUMP(vp, addr, bn, count, ct) \ fop_dump(vp, addr, bn, count, ct) #define VOP_PATHCONF(vp, cmd, valp, cr, ct) \ fop_pathconf(vp, cmd, valp, cr, ct) #define VOP_PAGEIO(vp, pp, io_off, io_len, flags, cr, ct) \ fop_pageio(vp, pp, io_off, io_len, flags, cr, ct) #define VOP_DUMPCTL(vp, action, blkp, ct) \ fop_dumpctl(vp, action, blkp, ct) #define VOP_DISPOSE(vp, pp, flag, dn, cr, ct) \ fop_dispose(vp, pp, flag, dn, cr, ct) #define VOP_GETSECATTR(vp, vsap, f, cr, ct) \ fop_getsecattr(vp, vsap, f, cr, ct) #define VOP_SETSECATTR(vp, vsap, f, cr, ct) \ fop_setsecattr(vp, vsap, f, cr, ct) #define VOP_SHRLOCK(vp, cmd, shr, f, cr, ct) \ fop_shrlock(vp, cmd, shr, f, cr, ct) #define VOP_VNEVENT(vp, vnevent, dvp, fnm, ct) \ fop_vnevent(vp, vnevent, dvp, fnm, ct) #define VOP_REQZCBUF(vp, rwflag, xuiop, cr, ct) \ fop_reqzcbuf(vp, rwflag, xuiop, cr, ct) #define VOP_RETZCBUF(vp, xuiop, cr, ct) \ fop_retzcbuf(vp, xuiop, cr, ct) #define VOPNAME_OPEN "open" #define VOPNAME_CLOSE "close" #define VOPNAME_READ "read" #define VOPNAME_WRITE "write" #define VOPNAME_IOCTL "ioctl" #define VOPNAME_SETFL "setfl" #define VOPNAME_GETATTR "getattr" #define VOPNAME_SETATTR "setattr" #define VOPNAME_ACCESS "access" #define VOPNAME_LOOKUP "lookup" #define VOPNAME_CREATE "create" #define VOPNAME_REMOVE "remove" #define VOPNAME_LINK "link" #define VOPNAME_RENAME "rename" #define VOPNAME_MKDIR "mkdir" #define VOPNAME_RMDIR "rmdir" #define VOPNAME_READDIR "readdir" #define VOPNAME_SYMLINK "symlink" #define VOPNAME_READLINK "readlink" #define VOPNAME_FSYNC "fsync" #define VOPNAME_INACTIVE "inactive" #define VOPNAME_FID "fid" #define VOPNAME_RWLOCK "rwlock" #define VOPNAME_RWUNLOCK "rwunlock" #define VOPNAME_SEEK "seek" #define VOPNAME_CMP "cmp" #define VOPNAME_FRLOCK "frlock" #define VOPNAME_SPACE "space" #define VOPNAME_REALVP "realvp" #define VOPNAME_GETPAGE "getpage" #define VOPNAME_PUTPAGE "putpage" #define VOPNAME_MAP "map" #define VOPNAME_ADDMAP "addmap" #define VOPNAME_DELMAP "delmap" #define VOPNAME_POLL "poll" #define VOPNAME_DUMP "dump" #define VOPNAME_PATHCONF "pathconf" #define VOPNAME_PAGEIO "pageio" #define VOPNAME_DUMPCTL "dumpctl" #define VOPNAME_DISPOSE "dispose" #define VOPNAME_GETSECATTR "getsecattr" #define VOPNAME_SETSECATTR "setsecattr" #define VOPNAME_SHRLOCK "shrlock" #define VOPNAME_VNEVENT "vnevent" #define VOPNAME_REQZCBUF "reqzcbuf" #define VOPNAME_RETZCBUF "retzcbuf" /* * Flags for VOP_LOOKUP * * Defined in file.h, but also possible, FIGNORECASE and FSEARCH * */ #define LOOKUP_DIR 0x01 /* want parent dir vp */ #define LOOKUP_XATTR 0x02 /* lookup up extended attr dir */ #define CREATE_XATTR_DIR 0x04 /* Create extended attr dir */ #define LOOKUP_HAVE_SYSATTR_DIR 0x08 /* Already created virtual GFS dir */ /* * Flags for VOP_READDIR */ #define V_RDDIR_ENTFLAGS 0x01 /* request dirent flags */ #define V_RDDIR_ACCFILTER 0x02 /* filter out inaccessible dirents */ /* * Flags for VOP_RWLOCK/VOP_RWUNLOCK * VOP_RWLOCK will return the flag that was actually set, or -1 if none. */ #define V_WRITELOCK_TRUE (1) /* Request write-lock on the vnode */ #define V_WRITELOCK_FALSE (0) /* Request read-lock on the vnode */ /* * Flags for VOP_DUMPCTL */ #define DUMP_ALLOC 0 #define DUMP_FREE 1 #define DUMP_SCAN 2 /* * Public vnode manipulation functions. */ #ifdef _KERNEL vnode_t *vn_alloc(int); void vn_reinit(vnode_t *); void vn_recycle(vnode_t *); void vn_free(vnode_t *); int vn_is_readonly(vnode_t *); int vn_is_opened(vnode_t *, v_mode_t); int vn_is_mapped(vnode_t *, v_mode_t); int vn_has_other_opens(vnode_t *, v_mode_t); void vn_open_upgrade(vnode_t *, int); void vn_open_downgrade(vnode_t *, int); int vn_can_change_zones(vnode_t *vp); int vn_has_flocks(vnode_t *); int vn_has_mandatory_locks(vnode_t *, int); int vn_has_cached_data(vnode_t *); void vn_setops(vnode_t *, vnodeops_t *); vnodeops_t *vn_getops(vnode_t *); int vn_matchops(vnode_t *, vnodeops_t *); int vn_matchopval(vnode_t *, char *, fs_generic_func_p); int vn_ismntpt(vnode_t *); struct vfs *vn_mountedvfs(vnode_t *); int vn_in_dnlc(vnode_t *); void vn_create_cache(void); void vn_destroy_cache(void); void vn_freevnodeops(vnodeops_t *); int vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode, struct vnode **vpp, enum create crwhy, mode_t umask); int vn_openat(char *pnamep, enum uio_seg seg, int filemode, int createmode, struct vnode **vpp, enum create crwhy, mode_t umask, struct vnode *startvp, int fd); int vn_create(char *pnamep, enum uio_seg seg, struct vattr *vap, enum vcexcl excl, int mode, struct vnode **vpp, enum create why, int flag, mode_t umask); int vn_createat(char *pnamep, enum uio_seg seg, struct vattr *vap, enum vcexcl excl, int mode, struct vnode **vpp, enum create why, int flag, mode_t umask, struct vnode *startvp); int vn_rdwr(enum uio_rw rw, struct vnode *vp, caddr_t base, ssize_t len, offset_t offset, enum uio_seg seg, int ioflag, rlim64_t ulimit, cred_t *cr, ssize_t *residp); void vn_rele(struct vnode *vp); void vn_rele_async(struct vnode *vp, struct taskq *taskq); void vn_rele_dnlc(struct vnode *vp); void vn_rele_stream(struct vnode *vp); int vn_link(char *from, char *to, enum uio_seg seg); int vn_linkat(vnode_t *fstartvp, char *from, enum symfollow follow, vnode_t *tstartvp, char *to, enum uio_seg seg); int vn_rename(char *from, char *to, enum uio_seg seg); int vn_renameat(vnode_t *fdvp, char *fname, vnode_t *tdvp, char *tname, enum uio_seg seg); int vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag); int vn_removeat(vnode_t *startvp, char *fnamep, enum uio_seg seg, enum rm dirflag); int vn_compare(vnode_t *vp1, vnode_t *vp2); int vn_vfswlock(struct vnode *vp); int vn_vfswlock_wait(struct vnode *vp); int vn_vfsrlock(struct vnode *vp); int vn_vfsrlock_wait(struct vnode *vp); void vn_vfsunlock(struct vnode *vp); int vn_vfswlock_held(struct vnode *vp); vnode_t *specvp(struct vnode *vp, dev_t dev, vtype_t type, struct cred *cr); vnode_t *makespecvp(dev_t dev, vtype_t type); vn_vfslocks_entry_t *vn_vfslocks_getlock(void *); void vn_vfslocks_rele(vn_vfslocks_entry_t *); boolean_t vn_is_reparse(vnode_t *, cred_t *, caller_context_t *); void vn_copypath(struct vnode *src, struct vnode *dst); void vn_setpath_str(struct vnode *vp, const char *str, size_t len); void vn_setpath(vnode_t *rootvp, struct vnode *startvp, struct vnode *vp, const char *path, size_t plen); void vn_renamepath(vnode_t *dvp, vnode_t *vp, const char *nm, size_t len); +/* Private vnode manipulation functions */ +void vn_clearpath(vnode_t *, hrtime_t); +void vn_updatepath(vnode_t *, vnode_t *, const char *); + + /* Vnode event notification */ void vnevent_rename_src(vnode_t *, vnode_t *, char *, caller_context_t *); void vnevent_rename_dest(vnode_t *, vnode_t *, char *, caller_context_t *); void vnevent_remove(vnode_t *, vnode_t *, char *, caller_context_t *); void vnevent_rmdir(vnode_t *, vnode_t *, char *, caller_context_t *); void vnevent_create(vnode_t *, caller_context_t *); void vnevent_link(vnode_t *, caller_context_t *); void vnevent_rename_dest_dir(vnode_t *, caller_context_t *ct); void vnevent_mountedover(vnode_t *, caller_context_t *); void vnevent_truncate(vnode_t *, caller_context_t *); int vnevent_support(vnode_t *, caller_context_t *); void vnevent_pre_rename_src(vnode_t *, vnode_t *, char *, caller_context_t *); void vnevent_pre_rename_dest(vnode_t *, vnode_t *, char *, caller_context_t *); void vnevent_pre_rename_dest_dir(vnode_t *, vnode_t *, char *, caller_context_t *); /* Vnode specific data */ void vsd_create(uint_t *, void (*)(void *)); void vsd_destroy(uint_t *); void *vsd_get(vnode_t *, uint_t); int vsd_set(vnode_t *, uint_t, void *); void vsd_free(vnode_t *); /* * Extensible vnode attribute (xva) routines: * xva_init() initializes an xvattr_t (zero struct, init mapsize, set AT_XATTR) * xva_getxoptattr() returns a ponter to the xoptattr_t section of xvattr_t */ void xva_init(xvattr_t *); xoptattr_t *xva_getxoptattr(xvattr_t *); /* Get ptr to xoptattr_t */ void xattr_init(void); /* Initialize vnodeops for xattrs */ /* GFS tunnel for xattrs */ int xattr_dir_lookup(vnode_t *, vnode_t **, int, cred_t *); /* Reparse Point */ void reparse_point_init(void); /* Context identification */ u_longlong_t fs_new_caller_id(); int vn_vmpss_usepageio(vnode_t *); + +/* Empty v_path placeholder */ +extern char *vn_vpath_empty; /* * Needed for use of IS_VMODSORT() in kernel. */ extern uint_t pvn_vmodsort_supported; /* * All changes to v_count should be done through VN_HOLD() or VN_RELE(), or * one of their variants. This makes it possible to ensure proper locking, * and to guarantee that all modifications are accompanied by a firing of * the vn-hold or vn-rele SDT DTrace probe. * * Example DTrace command for tracing vnode references using these probes: * * dtrace -q -n 'sdt:::vn-hold,sdt:::vn-rele * { * this->vp = (vnode_t *)arg0; * printf("%s %s(%p[%s]) %d\n", execname, probename, this->vp, * this->vp->v_path == NULL ? "NULL" : stringof(this->vp->v_path), * this->vp->v_count) * }' */ #define VN_HOLD_LOCKED(vp) { \ ASSERT(mutex_owned(&(vp)->v_lock)); \ (vp)->v_count++; \ DTRACE_PROBE1(vn__hold, vnode_t *, vp); \ } #define VN_HOLD(vp) { \ mutex_enter(&(vp)->v_lock); \ VN_HOLD_LOCKED(vp); \ mutex_exit(&(vp)->v_lock); \ } #define VN_RELE(vp) { \ vn_rele(vp); \ } #define VN_RELE_ASYNC(vp, taskq) { \ vn_rele_async(vp, taskq); \ } #define VN_RELE_LOCKED(vp) { \ ASSERT(mutex_owned(&(vp)->v_lock)); \ ASSERT((vp)->v_count >= 1); \ (vp)->v_count--; \ DTRACE_PROBE1(vn__rele, vnode_t *, vp); \ } #define VN_SET_VFS_TYPE_DEV(vp, vfsp, type, dev) { \ (vp)->v_vfsp = (vfsp); \ (vp)->v_type = (type); \ (vp)->v_rdev = (dev); \ } /* * Compare two vnodes for equality. In general this macro should be used * in preference to calling VOP_CMP directly. */ #define VN_CMP(VP1, VP2) ((VP1) == (VP2) ? 1 : \ ((VP1) && (VP2) && (vn_getops(VP1) == vn_getops(VP2)) ? \ VOP_CMP(VP1, VP2, NULL) : 0)) /* * Some well-known global vnodes used by the VM system to name pages. */ extern struct vnode kvps[]; typedef enum { KV_KVP, /* vnode for all segkmem pages */ KV_ZVP, /* vnode for all ZFS pages */ #if defined(__sparc) KV_MPVP, /* vnode for all page_t meta-pages */ KV_PROMVP, /* vnode for all PROM pages */ #endif /* __sparc */ KV_MAX /* total number of vnodes in kvps[] */ } kvps_index_t; #define VN_ISKAS(vp) ((vp) >= &kvps[0] && (vp) < &kvps[KV_MAX]) #endif /* _KERNEL */ /* * Flags to VOP_SETATTR/VOP_GETATTR. */ #define ATTR_UTIME 0x01 /* non-default utime(2) request */ #define ATTR_EXEC 0x02 /* invocation from exec(2) */ #define ATTR_COMM 0x04 /* yield common vp attributes */ #define ATTR_HINT 0x08 /* information returned will be `hint' */ #define ATTR_REAL 0x10 /* yield attributes of the real vp */ #define ATTR_NOACLCHECK 0x20 /* Don't check ACL when checking permissions */ #define ATTR_TRIGGER 0x40 /* Mount first if vnode is a trigger mount */ /* * Generally useful macros. */ #define VBSIZE(vp) ((vp)->v_vfsp->vfs_bsize) #define VTOZONE(vp) ((vp)->v_vfsp->vfs_zone) #define NULLVP ((struct vnode *)0) #define NULLVPP ((struct vnode **)0) #ifdef _KERNEL /* * Structure used while handling asynchronous VOP_PUTPAGE operations. */ struct async_reqs { struct async_reqs *a_next; /* pointer to next arg struct */ struct vnode *a_vp; /* vnode pointer */ u_offset_t a_off; /* offset in file */ uint_t a_len; /* size of i/o request */ int a_flags; /* flags to indicate operation type */ struct cred *a_cred; /* cred pointer */ ushort_t a_prealloced; /* set if struct is pre-allocated */ }; /* * VN_DISPOSE() -- given a page pointer, safely invoke VOP_DISPOSE(). * Note that there is no guarantee that the page passed in will be * freed. If that is required, then a check after calling VN_DISPOSE would * be necessary to ensure the page was freed. */ #define VN_DISPOSE(pp, flag, dn, cr) { \ if ((pp)->p_vnode != NULL && !VN_ISKAS((pp)->p_vnode)) \ VOP_DISPOSE((pp)->p_vnode, (pp), (flag), (dn), (cr), NULL); \ else if ((flag) == B_FREE) \ page_free((pp), (dn)); \ else \ page_destroy((pp), (dn)); \ } #endif /* _KERNEL */ #ifdef __cplusplus } #endif #endif /* _SYS_VNODE_H */