tmpfs_vnops.c (313094) | tmpfs_vnops.c (313095) |
---|---|
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> | 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 313094 2017-02-02 13:38:01Z kib $"); | 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 | 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_lookup(struct vop_cachedlookup_args *v) | 79tmpfs_lookup1(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp) |
80{ | 80{ |
81 struct vnode *dvp = v->a_dvp; 82 struct vnode **vpp = v->a_vpp; 83 struct componentname *cnp = v->a_cnp; | |
84 struct tmpfs_dirent *de; 85 struct tmpfs_node *dnode, *pnode; 86 struct tmpfs_mount *tm; 87 int error; 88 89 dnode = VP_TO_TMPFS_DIR(dvp); 90 *vpp = NULLVP; 91 --- 116 unchanged lines hidden (view full) --- 208 } 209 } 210 211 /* 212 * Store the result of this lookup in the cache. Avoid this if the 213 * request was for creation, as it does not improve timings on 214 * emprical tests. 215 */ | 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 */ |
216 if ((cnp->cn_flags & MAKEENTRY) != 0) | 213 if ((cnp->cn_flags & MAKEENTRY) != 0 && tmpfs_use_nc(dvp)) |
217 cache_enter(dvp, *vpp, cnp); 218 219out: 220 /* 221 * If there were no errors, *vpp cannot be null and it must be 222 * locked. 223 */ 224 MPASS(IFF(error == 0, *vpp != NULLVP && VOP_ISLOCKED(*vpp))); 225 226 return (error); 227} 228 229static int | 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 |
|
230tmpfs_create(struct vop_create_args *v) 231{ 232 struct vnode *dvp = v->a_dvp; 233 struct vnode **vpp = v->a_vpp; 234 struct componentname *cnp = v->a_cnp; 235 struct vattr *vap = v->a_vap; 236 int error; 237 238 MPASS(vap->va_type == VREG || vap->va_type == VSOCK); 239 240 error = tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL); | 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); |
241 if (error == 0 && (cnp->cn_flags & MAKEENTRY) != 0) | 252 if (error == 0 && (cnp->cn_flags & MAKEENTRY) != 0 && tmpfs_use_nc(dvp)) |
242 cache_enter(dvp, *vpp, cnp); 243 return (error); 244} 245 246static int 247tmpfs_mknod(struct vop_mknod_args *v) 248{ 249 struct vnode *dvp = v->a_dvp; --- 754 unchanged lines hidden (view full) --- 1004 /* Free the directory entry we just deleted. Note that the 1005 * node referred by it will not be removed until the vnode is 1006 * really reclaimed. */ 1007 tmpfs_free_dirent(VFS_TO_TMPFS(tvp->v_mount), tde); 1008 } 1009 1010 tmpfs_dir_attach(tdvp, de); 1011 | 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 |
1012 cache_purge(fvp); 1013 if (tvp != NULL) 1014 cache_purge(tvp); 1015 cache_purge_negative(tdvp); | 1023 if (tmpfs_use_nc(fvp)) { 1024 cache_purge(fvp); 1025 if (tvp != NULL) 1026 cache_purge(tvp); 1027 cache_purge_negative(tdvp); 1028 } |
1016 1017 error = 0; 1018 1019out_locked: 1020 if (fdvp != tdvp && fdvp != tvp) 1021 VOP_UNLOCK(fdvp, 0); 1022 1023out: --- 96 unchanged lines hidden (view full) --- 1120 TMPFS_NODE_UNLOCK(node); 1121 1122 TMPFS_NODE_LOCK(dnode); 1123 dnode->tn_links--; 1124 dnode->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED | 1125 TMPFS_NODE_MODIFIED; 1126 TMPFS_NODE_UNLOCK(dnode); 1127 | 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 |
1128 cache_purge(dvp); 1129 cache_purge(vp); | 1141 if (tmpfs_use_nc(dvp)) { 1142 cache_purge(dvp); 1143 cache_purge(vp); 1144 } |
1130 1131 /* Free the directory entry we just deleted. Note that the node 1132 * referred by it will not be removed until the vnode is really 1133 * reclaimed. */ 1134 tmpfs_free_dirent(tmp, de); 1135 1136 /* Release the deleted vnode (will destroy the node, notify 1137 * interested parties and clean it from the cache). */ --- 127 unchanged lines hidden (view full) --- 1265 node = VP_TO_TMPFS_NODE(vp); 1266 tmp = VFS_TO_TMPFS(vp->v_mount); 1267 1268 if (vp->v_type == VREG) 1269 tmpfs_destroy_vobject(vp, node->tn_reg.tn_aobj); 1270 else 1271 vnode_destroy_vobject(vp); 1272 vp->v_object = NULL; | 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; |
1273 cache_purge(vp); | 1288 if (tmpfs_use_nc(vp)) 1289 cache_purge(vp); |
1274 1275 TMPFS_NODE_LOCK(node); 1276 tmpfs_free_vp(vp); 1277 1278 /* If the node referenced by this vnode was deleted by the user, 1279 * we must free its associated data structures (now that the vnode 1280 * is being reclaimed). */ 1281 if (node->tn_links == 0 && --- 247 unchanged lines hidden (view full) --- 1529} 1530 1531/* 1532 * Vnode operations vector used for files stored in a tmpfs file system. 1533 */ 1534struct vop_vector tmpfs_vnodeop_entries = { 1535 .vop_default = &default_vnodeops, 1536 .vop_lookup = vfs_cache_lookup, | 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, |
1537 .vop_cachedlookup = tmpfs_lookup, | 1553 .vop_cachedlookup = tmpfs_cached_lookup, |
1538 .vop_create = tmpfs_create, 1539 .vop_mknod = tmpfs_mknod, 1540 .vop_open = tmpfs_open, 1541 .vop_close = tmpfs_close, 1542 .vop_access = tmpfs_access, 1543 .vop_getattr = tmpfs_getattr, 1544 .vop_setattr = tmpfs_setattr, 1545 .vop_read = tmpfs_read, --- 12 unchanged lines hidden (view full) --- 1558 .vop_print = tmpfs_print, 1559 .vop_pathconf = tmpfs_pathconf, 1560 .vop_vptofh = tmpfs_vptofh, 1561 .vop_whiteout = tmpfs_whiteout, 1562 .vop_bmap = VOP_EOPNOTSUPP, 1563 .vop_vptocnp = tmpfs_vptocnp, 1564}; 1565 | 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}; |
|