1/* $NetBSD: tmpfs_vnops.c,v 1.39 2007/07/23 15:41:01 jmmv Exp $ */ 2 3/*- 4 * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code --- 20 unchanged lines hidden (view full) --- 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33/* 34 * tmpfs vnode interface. 35 */ 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: stable/10/sys/fs/tmpfs/tmpfs_vnops.c 313095 2017-02-02 13:39:11Z kib $"); |
38 39#include <sys/param.h> 40#include <sys/fcntl.h> 41#include <sys/lockf.h> 42#include <sys/lock.h> 43#include <sys/namei.h> 44#include <sys/priv.h> 45#include <sys/proc.h> --- 25 unchanged lines hidden (view full) --- 71tmpfs_vn_get_ino_alloc(struct mount *mp, void *arg, int lkflags, 72 struct vnode **rvp) 73{ 74 75 return (tmpfs_alloc_vp(mp, arg, lkflags, rvp)); 76} 77 78static int |
79tmpfs_lookup1(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp) |
80{ |
81 struct tmpfs_dirent *de; 82 struct tmpfs_node *dnode, *pnode; 83 struct tmpfs_mount *tm; 84 int error; 85 86 dnode = VP_TO_TMPFS_DIR(dvp); 87 *vpp = NULLVP; 88 --- 116 unchanged lines hidden (view full) --- 205 } 206 } 207 208 /* 209 * Store the result of this lookup in the cache. Avoid this if the 210 * request was for creation, as it does not improve timings on 211 * emprical tests. 212 */ |
213 if ((cnp->cn_flags & MAKEENTRY) != 0 && tmpfs_use_nc(dvp)) |
214 cache_enter(dvp, *vpp, cnp); 215 216out: 217 /* 218 * If there were no errors, *vpp cannot be null and it must be 219 * locked. 220 */ 221 MPASS(IFF(error == 0, *vpp != NULLVP && VOP_ISLOCKED(*vpp))); 222 223 return (error); 224} 225 226static int |
227tmpfs_cached_lookup(struct vop_cachedlookup_args *v) 228{ 229 230 return (tmpfs_lookup1(v->a_dvp, v->a_vpp, v->a_cnp)); 231} 232 233static int 234tmpfs_lookup(struct vop_lookup_args *v) 235{ 236 237 return (tmpfs_lookup1(v->a_dvp, v->a_vpp, v->a_cnp)); 238} 239 240static int |
241tmpfs_create(struct vop_create_args *v) 242{ 243 struct vnode *dvp = v->a_dvp; 244 struct vnode **vpp = v->a_vpp; 245 struct componentname *cnp = v->a_cnp; 246 struct vattr *vap = v->a_vap; 247 int error; 248 249 MPASS(vap->va_type == VREG || vap->va_type == VSOCK); 250 251 error = tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL); |
252 if (error == 0 && (cnp->cn_flags & MAKEENTRY) != 0 && tmpfs_use_nc(dvp)) |
253 cache_enter(dvp, *vpp, cnp); 254 return (error); 255} 256 257static int 258tmpfs_mknod(struct vop_mknod_args *v) 259{ 260 struct vnode *dvp = v->a_dvp; --- 754 unchanged lines hidden (view full) --- 1015 /* Free the directory entry we just deleted. Note that the 1016 * node referred by it will not be removed until the vnode is 1017 * really reclaimed. */ 1018 tmpfs_free_dirent(VFS_TO_TMPFS(tvp->v_mount), tde); 1019 } 1020 1021 tmpfs_dir_attach(tdvp, de); 1022 |
1023 if (tmpfs_use_nc(fvp)) { 1024 cache_purge(fvp); 1025 if (tvp != NULL) 1026 cache_purge(tvp); 1027 cache_purge_negative(tdvp); 1028 } |
1029 1030 error = 0; 1031 1032out_locked: 1033 if (fdvp != tdvp && fdvp != tvp) 1034 VOP_UNLOCK(fdvp, 0); 1035 1036out: --- 96 unchanged lines hidden (view full) --- 1133 TMPFS_NODE_UNLOCK(node); 1134 1135 TMPFS_NODE_LOCK(dnode); 1136 dnode->tn_links--; 1137 dnode->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED | 1138 TMPFS_NODE_MODIFIED; 1139 TMPFS_NODE_UNLOCK(dnode); 1140 |
1141 if (tmpfs_use_nc(dvp)) { 1142 cache_purge(dvp); 1143 cache_purge(vp); 1144 } |
1145 1146 /* Free the directory entry we just deleted. Note that the node 1147 * referred by it will not be removed until the vnode is really 1148 * reclaimed. */ 1149 tmpfs_free_dirent(tmp, de); 1150 1151 /* Release the deleted vnode (will destroy the node, notify 1152 * interested parties and clean it from the cache). */ --- 127 unchanged lines hidden (view full) --- 1280 node = VP_TO_TMPFS_NODE(vp); 1281 tmp = VFS_TO_TMPFS(vp->v_mount); 1282 1283 if (vp->v_type == VREG) 1284 tmpfs_destroy_vobject(vp, node->tn_reg.tn_aobj); 1285 else 1286 vnode_destroy_vobject(vp); 1287 vp->v_object = NULL; |
1288 if (tmpfs_use_nc(vp)) 1289 cache_purge(vp); |
1290 1291 TMPFS_NODE_LOCK(node); 1292 tmpfs_free_vp(vp); 1293 1294 /* If the node referenced by this vnode was deleted by the user, 1295 * we must free its associated data structures (now that the vnode 1296 * is being reclaimed). */ 1297 if (node->tn_links == 0 && --- 247 unchanged lines hidden (view full) --- 1545} 1546 1547/* 1548 * Vnode operations vector used for files stored in a tmpfs file system. 1549 */ 1550struct vop_vector tmpfs_vnodeop_entries = { 1551 .vop_default = &default_vnodeops, 1552 .vop_lookup = vfs_cache_lookup, |
1553 .vop_cachedlookup = tmpfs_cached_lookup, |
1554 .vop_create = tmpfs_create, 1555 .vop_mknod = tmpfs_mknod, 1556 .vop_open = tmpfs_open, 1557 .vop_close = tmpfs_close, 1558 .vop_access = tmpfs_access, 1559 .vop_getattr = tmpfs_getattr, 1560 .vop_setattr = tmpfs_setattr, 1561 .vop_read = tmpfs_read, --- 12 unchanged lines hidden (view full) --- 1574 .vop_print = tmpfs_print, 1575 .vop_pathconf = tmpfs_pathconf, 1576 .vop_vptofh = tmpfs_vptofh, 1577 .vop_whiteout = tmpfs_whiteout, 1578 .vop_bmap = VOP_EOPNOTSUPP, 1579 .vop_vptocnp = tmpfs_vptocnp, 1580}; 1581 |
1582/* 1583 * Same vector for mounts which do not use namecache. 1584 */ 1585struct vop_vector tmpfs_vnodeop_nonc_entries = { 1586 .vop_default = &tmpfs_vnodeop_entries, 1587 .vop_lookup = tmpfs_lookup, 1588}; |