summaryrefslogtreecommitdiff
path: root/sys/fs/tmpfs/tmpfs_vnops.c
Commit message (Collapse)AuthorAgeFilesLines
* cache: add cache_vop_mkdir and rename cache_rename to cache_vop_renameMateusz Guzik2020-10-301-2/+2
| | | | Notes: svn path=/head/; revision=367162
* vfs: drop spurious cache_purge on rmdirMateusz Guzik2020-10-231-1/+0
| | | | | | | | | | The removed directory gets cache_purged which is sufficient to remove any entries related to the parent. Note only tmpfs, ufs and zfs are patched. Notes: svn path=/head/; revision=366975
* tmpfs: restore atime updates for reads from page cache.Konstantin Belousov2020-09-161-9/+11
| | | | | | | | | | | | | | | | | Split TMPFS_NODE_ACCCESSED bit into dedicated byte that can be updated atomically without locks or (locked) atomics. tn_update_getattr() change also contains unrelated bug fix. Reported by: lwhsu PR: 249362 Reviewed by: markj (previous version) Discussed with: mjg Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D26451 Notes: svn path=/head/; revision=365810
* Style.Konstantin Belousov2020-09-161-5/+6
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 3 days Notes: svn path=/head/; revision=365809
* Add tmpfs page cache read support.Konstantin Belousov2020-09-151-10/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | | Or it could be explained as lockless (for vnode lock) reads. Reads are performed from the node tn_obj object. Tmpfs regular vnode object lifecycle is significantly different from the normal OBJT_VNODE: it is alive as far as ref_count > 0. Ensure liveness of the tmpfs VREG node and consequently v_object inside VOP_READ_PGCACHE by referencing tmpfs node in tmpfs_open(). Provide custom tmpfs fo_close() method on file, to ensure that close is paired with open. Add tmpfs VOP_READ_PGCACHE that takes advantage of all tmpfs quirks. It is quite cheap in code size sense to support page-ins for read for tmpfs even if we do not own tmpfs vnode lock. Also, we can handle holes in tmpfs node without additional efforts, and do not have limitation of the transfer size. Reviewed by: markj Discussed with and benchmarked by: mjg (previous version) Tested by: pho Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D26346 Notes: svn path=/head/; revision=365787
* Microoptimize tmpfs node ref/unref by using atomics.Konstantin Belousov2020-09-151-1/+1
| | | | | | | | | | | | | Avoid tmpfs mount and node locks when ref count is greater than zero, which is the case until node is being destroyed by unlink or unmount. Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D26346 Notes: svn path=/head/; revision=365786
* tmpfs: drop spurious cache_purge in tmpfs_reclaimMateusz Guzik2020-09-041-2/+0
| | | | | | | vgone already performs it. Notes: svn path=/head/; revision=365338
* fs: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-1/+0
| | | | Notes: svn path=/head/; revision=365070
* cache: add cache_rename, a dedicated helper to use for renamesMateusz Guzik2020-08-201-4/+1
| | | | | | | | | While here make both tmpfs and ufs use it. No fuctional changes. Notes: svn path=/head/; revision=364419
* tmpfs: add VOP_STAT handlerMateusz Guzik2020-08-071-0/+49
| | | | Notes: svn path=/head/; revision=364045
* vfs: remove the obsolete privused argument from vaccessMateusz Guzik2020-08-051-2/+2
| | | | | | | | This brings argument count down to 6, which is passable without the stack on amd64. Notes: svn path=/head/; revision=363893
* tmpfs: add support for lockless lookupMateusz Guzik2020-07-251-2/+55
| | | | | | | | | Reviewed by: kib Tested by: pho (in a patchset) Differential Revision: https://reviews.freebsd.org/D25580 Notes: svn path=/head/; revision=363521
* tmpfs: Preserve alignment of struct fid fieldsRyan Moeller2020-06-031-5/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | On 64-bit platforms, the two short fields in `struct tmpfs_fid` are padded to the 64-bit alignment of the long field. This pushes the offsets of the subsequent fields by 4 bytes and makes `struct tmpfs_fid` bigger than `struct fid`. `tmpfs_vptofh()` casts a `struct fid *` to `struct tmpfs_fid *`, causing 4 bytes of adjacent memory to be overwritten when the struct fields are set. Through several layers of indirection and embedded structs, the adjacent memory for one particular call to `tmpfs_vptofh()` happens to be the stack canary for `nfsrvd_compound()`. Half of the canary ends up being clobbered, going unnoticed until eventually the stack check fails when `nfsrvd_compound()` returns and a panic is triggered. Instead of duplicating fields of `struct fid` in `struct tmpfs_fid`, narrow the struct to cover only the unique fields for tmpfs and assert at compile time that the struct fits in the allotted space. This way we don't have to replicate the offsets of `struct fid` fields, we just use them directly. Reviewed by: kib, mav, rmacklem Approved by: mav (mentor) MFC after: 1 week Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D25077 Notes: svn path=/head/; revision=361748
* tmpfs: inline tmpfs_updateMateusz Guzik2020-02-031-1/+1
| | | | | | | | | | It was generated to be just a jumping off point to tmpfs_itimes. While here provide a dedicated variant for getattr since we normally don't expect to need to the update from that caller. Notes: svn path=/head/; revision=357451
* Provide O_SEARCHKyle Evans2020-02-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | O_SEARCH is defined by POSIX [0] to open a directory for searching, skipping permissions checks on the directory itself after the initial open(). This is close to the semantics we've historically applied for O_EXEC on a directory, which is UB according to POSIX. Conveniently, O_SEARCH on a file is also explicitly undefined behavior according to POSIX, so O_EXEC would be a fine choice. The spec goes on to state that O_SEARCH and O_EXEC need not be distinct values, but they're not defined to be the same value. This was pointed out as an incompatibility with other systems that had made its way into libarchive, which had assumed that O_EXEC was an alias for O_SEARCH. This defines compatibility O_SEARCH/FSEARCH (equivalent to O_EXEC and FEXEC respectively) and expands our UB for O_EXEC on a directory. O_EXEC on a directory is checked in vn_open_vnode already, so for completeness we add a NOEXECCHECK when O_SEARCH has been specified on the top-level fd and do not re-check that when descending in namei. [0] https://pubs.opengroup.org/onlinepubs/9699919799/ Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D23247 Notes: svn path=/head/; revision=357412
* vfs: consistently use size_t for buflen around VOP_VPTOCNPMateusz Guzik2020-02-011-2/+2
| | | | Notes: svn path=/head/; revision=357383
* vfs: drop the mostly unused flags argument from VOP_UNLOCKMateusz Guzik2020-01-031-15/+15
| | | | | | | | | | | Filesystems which want to use it in limited capacity can employ the VOP_UNLOCK_FLAGS macro. Reviewed by: kib (previous version) Differential Revision: https://reviews.freebsd.org/D21427 Notes: svn path=/head/; revision=356337
* vfs: flatten vop vectorsMateusz Guzik2019-12-161-0/+2
| | | | | | | | | | | | | | | This eliminates the following loop from all VOP calls: while(vop != NULL && \ vop->vop_spare2 == NULL && vop->vop_bypass == NULL) vop = vop->vop_default; Reviewed by: jeff Tesetd by: pho Differential Revision: https://reviews.freebsd.org/D22738 Notes: svn path=/head/; revision=355790
* vfs: locking primitives which elide ->v_vnlock and shared locking disablementMateusz Guzik2019-12-111-0/+3
| | | | | | | | | | | | | | | | | | | Both of these features are not needed by many consumers and result in avoidable reads which in turn puts them on profiles due to cache-line ping ponging. On top of that the current lockgmr entry point is slower than necessary single-threaded. As an attempted clean up preparing for other changes, provide new routines which don't support any of the aforementioned features. With these patches in place vop_stdlock and vop_stdunlock disappear from flamegraphs during -j 104 buildkernel. Reviewed by: jeff (previous version) Tested by: pho Differential Revision: https://reviews.freebsd.org/D22665 Notes: svn path=/head/; revision=355633
* vfs: introduce v_irflag and make v_type smallerMateusz Guzik2019-12-081-1/+1
| | | | | | | | | | | | | | | | | | The current vnode layout is not smp-friendly by having frequently read data avoidably sharing cachelines with very frequently modified fields. In particular v_iflag inspected for VI_DOOMED can be found in the same line with v_usecount. Instead make it available in the same cacheline as the v_op, v_data and v_type which all get read all the time. v_type is avoidably 4 bytes while the necessary data will easily fit in 1. Shrinking it frees up 3 bytes, 2 of which get used here to introduce a new flag field with a new value: VIRF_DOOMED. Reviewed by: kib, jeff Differential Revision: https://reviews.freebsd.org/D22715 Notes: svn path=/head/; revision=355537
* tmpfs: use proper macros for permission values in tmpfs_accessMateusz Guzik2019-12-011-2/+2
| | | | | | | | | | While here group them in one var to prevent overy long lines. Perhaps a general macro of the same sort should be introduced. Requested by: kib Notes: svn path=/head/; revision=355255
* tmpfs: add fast path to tmpfs_access for common case lookupMateusz Guzik2019-11-301-0/+6
| | | | | | | | VEXEC consists of vast majority of all calls and almost all targets have at least 0111. Notes: svn path=/head/; revision=355227
* tmpfs: resolve deadlock between rename and unmount.Konstantin Belousov2019-11-241-13/+1
| | | | | | | | | | | | | | | | | | | Top-level kern_renameat() increases the writecount on the mount point, which, together with tmpfs unmount suspending the mount, already ensures that unmount cannot proceed while rename unlocks and relocks all operated vnodes. Remove vfs_busy() call from tmpfs_rename() which was done while holding a vnode lock, creating the deadlock. The only intent of the busy operation seems to be the prevention of unmount, which is already ensured. Reported and tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=355061
* Replace OBJ_MIGHTBEDIRTY with a system using atomics. Remove the TMPFS_DIRTYJeff Roberson2019-10-291-1/+1
| | | | | | | | | | | | | | flag and use the same system. This enables further fault locking improvements by allowing more faults to proceed with a shared lock. Reviewed by: kib Tested by: pho Differential Revision: https://reviews.freebsd.org/D22116 Notes: svn path=/head/; revision=354158
* tmpfs_rename: style.Konstantin Belousov2019-10-031-34/+63
| | | | | | | | | | | Reformat multi-line comments to follow style. Also fix some typos. Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=353064
* Remove unnecessary vm/vm_page.h and vm/vm_pager.h includes fromKonstantin Belousov2019-10-031-2/+0
| | | | | | | | | | | tmpfs/tmpfs_vnodes.c. Submitted by: ota@j.email.ne.jp MFC after: 1 week Differential revision: https://reviews.freebsd.org/D21881 Notes: svn path=/head/; revision=353033
* Rework v_object lifecycle for vnodes.Konstantin Belousov2019-08-291-2/+0
| | | | | | | | | | | | | | | | | | | | | | | Current implementation of vnode_create_vobject() and vnode_destroy_vobject() is written so that it prepared to handle the vm object destruction for live vnode. Practically, no filesystems use this, except for some remnants that were present in UFS till today. One of the consequences of that model is that each filesystem must call vnode_destroy_vobject() in VOP_RECLAIM() or earlier, as result all of them get rid of the v_object in reclaim. Move the call to vnode_destroy_vobject() to vgonel() before VOP_RECLAIM(). This makes v_object stable: either the object is NULL, or it is valid vm object till the vnode reclamation. Remove code from vnode_create_vobject() to handle races with the parallel destruction. Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D21412 Notes: svn path=/head/; revision=351598
* tmpfs: use VOP_NEED_INACTIVEMateusz Guzik2019-08-281-0/+22
| | | | | | | | | | Reviewed by: kib Tested by: pho Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D21371 Notes: svn path=/head/; revision=351585
* tmpfs: ignore tmpfs_set_status() if mount point is read-only.Konstantin Belousov2019-04-021-14/+19
| | | | | | | | | | | | | In particular, this fixes atimes still changing for ro tmpfs. tmpfs_set_status() gains tmpfs_mount * argument. Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D19737 Notes: svn path=/head/; revision=345800
* Remove unused argument to priv_check_cred.Mateusz Guzik2018-12-111-1/+1
| | | | | | | | | | | | | | | | Patch mostly generated with cocinnelle: @@ expression E1,E2; @@ - priv_check_cred(E1,E2,0) + priv_check_cred(E1,E2) Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=341827
* Ensure that directory entry padding bytes are zeroed.Mark Johnston2018-11-231-1/+1
| | | | | | | | | | | | | | | | | Directory entries must be padded to maintain alignment; in many filesystems the padding was not initialized, resulting in stack memory being copied out to userspace. With the ino64 work there are also some explicit pad fields in struct dirent. Add a subroutine to clear these bytes and use it in the in-tree filesystems. The NFS client is omitted for now as it was fixed separately in r340787. Reported by: Thomas Barabosch, Fraunhofer FKIE Reviewed by: kib MFC after: 3 days Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=340856
* Make vop_symlink take a const target path.Brooks Davis2018-11-021-1/+1
| | | | | | | | | | | | | | | | | | | | This will enable callers to take const paths as part of syscall decleration improvements. Where doing so is easy and non-distruptive carry the const through implementations. In UFS the value is passed to an interface that must take non-const values. In ZFS, const poisoning would touch code shared with upstream and it's not worth adding diffs. Bump __FreeBSD_version for external API consumers. Reviewed by: kib (prior version) Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D17805 Notes: svn path=/head/; revision=340055
* Use long for the last argument to VOP_PATHCONF rather than a register_t.John Baldwin2018-01-171-1/+1
| | | | | | | | | | | | | | pathconf(2) and fpathconf(2) both return a long. The kern_[f]pathconf() functions now accept a pointer to a long value rather than modifying td_retval directly. Instead, the system calls explicitly store the returned long value in td_retval[0]. Requested by: bde Reviewed by: kib Sponsored by: Chelsio Communications Notes: svn path=/head/; revision=328099
* Rework pathconf handling for FIFOs.John Baldwin2017-12-191-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On the one hand, FIFOs should respect other variables not supported by the fifofs vnode operation (such as _PC_NAME_MAX, _PC_LINK_MAX, etc.). These values are fs-specific and must come from a fs-specific method. On the other hand, filesystems that support FIFOs are required to support _PC_PIPE_BUF on directory vnodes that can contain FIFOs. Given this latter requirement, once the fs-specific VOP_PATHCONF method supports _PC_PIPE_BUF for directories, it is also suitable for FIFOs permitting a single VOP_PATHCONF method to be used for both FIFOs and non-FIFOs. To that end, retire all of the FIFO-specific pathconf methods from filesystems and change FIFO-specific vnode operation switches to use the existing fs-specific VOP_PATHCONF method. For fifofs, set it's VOP_PATHCONF to VOP_PANIC since it should no longer be used. While here, move _PC_PIPE_BUF handling out of vop_stdpathconf() so that only filesystems supporting FIFOs will report a value. In addition, only report a valid _PC_PIPE_BUF for directories and FIFOs. Discussed with: bde Reviewed by: kib (part of a larger patch) MFC after: 1 month Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D12572 Notes: svn path=/head/; revision=327004
* Update tmpfs link count handling for ino64.John Baldwin2017-12-191-3/+4
| | | | | | | | | | | | | Add a new TMPFS_LINK_MAX to use in place of LINK_MAX for link overflow checks and pathconf() reporting. Rather than storing a full 64-bit link count, just use a plain int and use INT_MAX as TMPFS_LINK_MAX. Discussed with: bde Reviewed by: kib (part of a larger patch) Sponsored by: Chelsio Communications Notes: svn path=/head/; revision=326998
* Move NAME_MAX, LINK_MAX, and CHOWN_RESTRICTED out of vop_stdpathconf().John Baldwin2017-12-191-0/+12
| | | | | | | | | | | | | | | | | | | Having all filesystems fall through to default values isn't always correct and these values can vary for different filesystem implementations. Most of these changes just use the existing default values with a few exceptions: - Don't report CHOWN_RESTRICTED for ZFS since it doesn't do the exact permissions check this claims for chown(). - Use NANDFS_NAME_LEN for NAME_MAX for nandfs. - Don't report a LINK_MAX of 0 on smbfs. Now fail with EINVAL to indicate hard links aren't supported. Requested by: bde (though perhaps not this exact implementation) Reviewed by: kib (earlier version) MFC after: 1 month Sponsored by: Chelsio Communications Notes: svn path=/head/; revision=326993
* Reduce pollution via tmpfs.h.Gleb Smirnoff2017-12-061-0/+2
| | | | Notes: svn path=/head/; revision=326607
* sys/fs: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326268
* Return 64 for pathconf(_PC_FILESIZEBITS) on tmpfs.John Baldwin2017-10-021-1/+1
| | | | | | | Sponsored by: Chelsio Communications Notes: svn path=/head/; revision=324226
* Use tmpfs_print for tmpfs FIFOs.John Baldwin2017-09-251-1/+1
| | | | | | | Reviewed by: kib (part of a larger patch) Notes: svn path=/head/; revision=323993
* Consistently use vop_stdpathconf() for default pathconf values.John Baldwin2017-07-111-21/+1
| | | | | | | | | | | | | | | | | | | Update filesystems not currently using vop_stdpathconf() in pathconf VOPs to use vop_stdpathconf() for any configuration variables that do not have filesystem-specific values. vop_stdpathconf() is used for variables that have system-wide settings as well as providing default values for some values based on system limits. Filesystems can still explicitly override individual settings. PR: 219851 Reported by: cem Reviewed by: cem, kib, ngie MFC after: 1 month Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D11541 Notes: svn path=/head/; revision=320900
* Add mount option for tmpfs(5) to not use namecache.Konstantin Belousov2017-01-191-14/+37
| | | | | | | | | | | | | | | | | | The option "nonc" disables using of namecache for the created mount, by default namecache is used. The rationale for the option is that namecache duplicates the information which is already kept in memory by tmpfs. Since it believed that namecache scales better than tmpfs, or will scale better, do not enable the option by default. On the other hand, smaller machines may benefit from lesser namecache pressure. Discussed with: mjg Tested by: pho (as part of larger patch) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=312432
* Implement VOP_VPTOCNP() for tmpfs.Konstantin Belousov2017-01-191-0/+127
| | | | | | | | | | | | | | | For directories, node->tn_spec.tn_dir.tn_parent pointer to the parent is used. For non-directories, the implementation is naive, all directory nodes are scanned to find a dirent linking the specified node. This can be significantly improved by maintaining tn_parent for all nodes, later. Tested by: pho (as part of larger patch) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=312430
* Refcount tmpfs nodes and mount structures.Konstantin Belousov2017-01-191-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | On dotdot lookup and fhtovp operations, it is possible for the file represented by tmpfs node to be removed after the thread calculated the pointer. In this case, tmpfs_alloc_vp() accesses freed memory. Introduce the reference count on the nodes. The allnodes list from tmpfs mount owns 1 reference, and threads performing unlocked operations on the node, add one transient reference. Similarly, since struct tmpfs_mount maintains the list where nodes are enlisted, refcount it by one reference from struct mount and one reference from each node on the list. Both nodes and tmpfs_mounts are removed when refcount goes to zero. Note that this means that nodes and tmpfs_mounts might survive some time after the node is deleted or tmpfs_unmount() finished. The tmpfs_alloc_vp() in these cases returns error either due to node removal (tn_nlinks == 0) or because of insmntque1(9) error. Tested by: pho (as part of larger patch) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=312428
* Rework some tmpfs lock assertions.Konstantin Belousov2017-01-191-3/+0
| | | | | | | | | | | | | | Remove TMPFS_ASSERT_ELOCKED(). Its claims are already stated by other asserts nearby and by VFS guarantees. Change TMPFS_ASSERT_LOCKED() and one inlined place to use ASSERT_VOP_(E)LOCKED() instead of hand-rolled imprecise asserts. Tested by: pho (as part of the larger patch) Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=312410
* Style fixes and comment updates.Konstantin Belousov2017-01-191-18/+33
| | | | | | | | | | | | Edit comments which explain no longer relevant details, and add locking annotations to the struct tmpfs_node members. Tested by: pho (as part of the larger patch) Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=312409
* Lock tmpfs node tn_status updates done under the shared vnode lock.Konstantin Belousov2017-01-061-8/+8
| | | | | | | | | | | | | | | | | If tmpfs vnode is only shared locked, tn_status field still needs updates to note the access time modification. Use the same locking scheme as for UFS, protect tn_status with the node interlock + shared vnode lock. Fix nearby style. Noted and reviewed by: mjg Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=311525
* Use type-independent formats for printing nlink_t and ino_t.Konstantin Belousov2017-01-061-2/+2
| | | | | | | | | | Extracted from: ino64 work by gleb, mckusick Discussed with: mckusick Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=311522
* sys/fs: spelling fixes in comments.Pedro F. Giffuni2016-04-291-1/+1
| | | | | | | No functional change. Notes: svn path=/head/; revision=298806
* Clear the cookie pointer on error in tmpfs_readdir().Mark Johnston2016-02-121-1/+4
| | | | | | | | | | | | | | | It is otherwise left dangling, and callers that request cookies always free the cookie buffer, even when VOP_READDIR(9) returns an error. This results in a double free if tmpfs_readdir() returns an error to the NFS server or the Linux getdents(2) emulation code. Reported by: pho MFC after: 1 week Security: double free of malloc(9)-backed memory Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=295574