aboutsummaryrefslogtreecommitdiff
path: root/sys/fs/devfs
Commit message (Collapse)AuthorAgeFilesLines
* devfs: unlock the directory vnode around the call to dev_clone handlerKonstantin Belousov2026-02-021-0/+20
| | | | | | | | | | | | | | | | The lock around dev_clone is unfortunate because cloner might need to take its own locks that establish the order with devfs vnodes, and then transiently participates in further VFS locks order. For instance, this way the proctree_lock or allproc_lock become involved. Unlock dvp, we can unwind if the vnode become doomed while cloner was called. Reported and tested by: pho Reviewed by: kevans, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D55028
* devfs: make destroy_dev() a release barrier for cdevpriv destructors runsKonstantin Belousov2025-10-242-3/+15
| | | | | | | | | | | | | | | | | Ensure that all destructors for cdevpriv finished running before destroy_dev() returns to the caller. Otherwise, since devfs_destroy_cdevpriv() removes the cdevpriv data from the list, drops the cdevpriv_mtx, and then starts the destructor, it is possible for destroy_dev() to return before destructor finished in other thread. This should allow drivers to safely remove cdev instance data that might be referenced by cdevpriv data. Diagnosed by: kevans Reviewed by: kevans, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D53303
* style(9): white space after ; and around binary operatorsDavid E. O'Brien2025-10-161-1/+1
| | | | | | | in for() loops. Also, use 'while', where only the conditional test of 'for' was used. Reviewed by: sjg
* vfs: retire the VREF macroMateusz Guzik2025-09-271-2/+2
| | | | | | | | | | | | It is defined as a plain use of vref. Churn generated with coccinelle: @@ expression vp; @@ - VREF(vp) + vref(vp)
* vfs: retire the NULLVP macroMateusz Guzik2025-09-271-1/+1
| | | | | | | | | | | | The kernel was already mostly using plain NULL, just whack it and be doen with the legacy. Churn generated with coccinelle: @@ @@ - NULLVP + NULL
* devfs readdir: handle short buffer same as UFSKonstantin Belousov2025-08-011-1/+8
| | | | | | | | | | | | | | Return EINVAL if this is the first dirent encountered with the short buffer, or EJUSTRETURN if something was already copied out. This is needed to pass eof check in vop_readdir_post(): we are not at eof but resid was not advanced. Reported and tested by: pho (previous version) Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D51667
* devfs: Set eofflag in devfs_readdir()Mark Johnston2025-05-291-0/+2
| | | | | | | | | | | At least vn_dir_next_dirent() checks that eofflag is set appropriately when INVARIANTS is enabled, so the omission here could cause an assertion failure. Reviewed by: kib MFC after: 2 weeks Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D50598
* sysctl(9): Ease exporting struct sizes; Discourage doing thatOlivier Certner2025-05-071-5/+2
| | | | | | | | | | | | | | | | | | | | | | | Introduce two helpers, the more general SYSCTL_SIZEOF() and a struct-specific one SYSCTL_SIZEOF_STRUCT() which prepends 'struct' in the description and in the use of sizeof() but uses the raw structure name as the knob's name. The size of the object/structure is exported under 'debug.sizeof'. Existing knobs under 'debug.sizeof' were all converted to use the helpers. Add a note before the helpers discouraging the introduction of new leaves for ad-hoc reasons. List alternative means for developers to obtain the size of arbitrary kernel structures easily (thanks to markj@ for providing these). No functional change (intended). Reviewed by: kib, markj MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D50121
* devfs: Return early from sysctl_devname() if no input is givenMark Johnston2025-03-201-0/+3
| | | | | | | Otherwise we end up searching for a device using an uninitialized key, tripping up KMSAN. MFC after: 2 weeks
* kern: Make fileops and filterops tables const where possibleMark Johnston2024-11-261-2/+2
| | | | | | No functional change intended. MFC after: 1 week
* devfs_allocv(): styleKonstantin Belousov2024-05-121-2/+1
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week
* cdevpriv(9): add iteratorKonstantin Belousov2024-03-231-0/+20
| | | | | | | Reviewed by: christos Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D44469
* kcmp(2): implement for devfs filesKonstantin Belousov2024-01-241-0/+9
| | | | | | | | | | Compare not vnodes, which are different between mount points, but actual cdev referenced by the devfs node. Reviewed by: brooks, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D43518
* devfs(5): Fix a typo in a source code commentGordon Bergling2024-01-201-1/+1
| | | | | | - s/interpeted/interpreted/ MFC after: 3 days
* sys: Remove ancient SCCS tags.Warner Losh2023-11-273-6/+0
| | | | | | | | Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl script. Sponsored by: Netflix
* devfs: add integrity asserts for cdevp_listJason A. Harmening2023-09-213-1/+16
| | | | | | | | | | | | | | It's possible for misuse of cdev KPIs or for bugs in devfs itself to result in e.g. a cdev object's container being freed while still on the global list used to populate each devfs mount; see PR 273418 for a recent example. Since a node may be marked inactive well before it is reaped from the list, add a new flag solely to track list membership, and employ it in some basic list integrity assertions to catch bad actors. Discussed with: kib, mjg MFC after: 1 week
* Fix MNT_IGNORE for devfs, fdescfs and nullfsDoug Rabson2023-08-261-1/+1
| | | | | | | | | | | | | | | | The MNT_IGNORE flag can be used to mark certain filesystem mounts so that utilities such as df(1) and mount(8) can filter out those mounts by default. This can be used, for instance, to reduce the noise from running container workloads inside jails which often have at least three and sometimes as many as ten mounts per container. The flag is supplied by the nmount(2) system call and is recorded so that it can be reported by statfs(2). Unfortunately several filesystems override the default behaviour and mask out the flag, defeating its purpose. This change preserves the MNT_IGNORE flag for those filesystems so that it can be reported correctly. MFC after: 1 week
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-167-14/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-127-7/+7
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* sys/fs: do not report blocks allocated for synthetic file systemsStefan Eßer2023-04-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | The pseudo file systems (devfs, fdescfs, procfs, etc.) report total and available blocks and inodes despite being synthetic with no underlying storage device to which those values could be applied. The current code of these file systems tends to report a fixed number of total blocks but no free blocks, and in the case of procfs, libprocfs, linsysfs also no free inodes. This can be irritating in e.g. the "df" output, since 100% of the resources seem to be in use, but it can also create warnings in monitoring tools used for capacity management. This patch makes these file systems return the same value for the total and free parameters, leading to 0% in use being displayed by "df". Since there is no resource that can be exhausted, this appears to be a sensible result. Reviewed by: mckusick Differential Revision: https://reviews.freebsd.org/D39442
* vfs: add the concept of vnode state transitionsMateusz Guzik2022-12-261-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | To quote from a comment above vput_final: <quote> * XXX Some filesystems pass in an exclusively locked vnode and strongly depend * on the lock being held all the way until VOP_INACTIVE. This in particular * happens with UFS which adds half-constructed vnodes to the hash, where they * can be found by other code. </quote> As is there is no mechanism which allows filesystems to denote that a vnode is fully initialized, consequently problems like the above are only found the hard way(tm). Add rudimentary support for state transitions, which in particular allow to assert the vnode is not legally unlocked until its fate is decided (either construction finishes or vgone is called to abort it). The new field lands in a 1-byte hole, thus it does not grow the struct. Bump __FreeBSD_version to 1400077 Reviewed by: kib (previous version) Tested by: pho Differential Revision: https://reviews.freebsd.org/D37759
* vfs: always retain path buffer after lookupMateusz Guzik2022-09-171-1/+0
| | | | | | | | This removes some of the complexity needed to maintain HASBUF and allows for removing injecting SAVENAME by filesystems. Reviewed by: kib (previous version) Differential Revision: https://reviews.freebsd.org/D36542
* devfs: stop taking the interlock in devfs_deleteMateusz Guzik2022-09-141-3/+2
| | | | It buys nothing now that vhold does not require it.
* devfs: retire the unused DEVFS_DEL_VNLOCKED flagMateusz Guzik2022-09-142-8/+3
|
* Retire clone_drain_lockMateusz Guzik2022-08-202-5/+0
| | | | | | | | | It is only ever xlocked in drain_dev_clone_events and the only consumer of that routine does not need it -- eventhandler code already makes sure the relevant callback is no longer running. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D36268
* fs: fix a few common typos in source code commentsGordon Bergling2022-02-061-1/+1
| | | | | | | | - s/quadradically/quadratically/ - s/persistant/persistent/ Obtained from: NetBSD MFC after: 3 days
* insmntque1(): remove useless argumentsKonstantin Belousov2022-01-311-14/+7
| | | | | | | | | | Also remove once-used functions to clean up after failed insmntque1(), which were destructor callbacks in previous life. Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D34071
* Revert b58ca5df0bb7 ("vfs: remove the now unused insmntque1")Mateusz Guzik2022-01-271-1/+1
| | | | | | | | | | | | I was somehow convinced that insmntque calls insmntque1 with a NULL destructor. Unfortunately this worked well enough to not immediately blow up in simple testing. Keep not using the destructor in previously patched filesystems though as it avoids unnecessary casts. Noted by: kib Reported by: pho
* devfs: stop using insmntque1Mateusz Guzik2022-01-261-5/+4
| | | | It adds nothing of value over insmntque.
* vfs: add vop_stdadd_writecount_nomsyncMateusz Guzik2021-11-261-0/+2
| | | | | | | This avoids needing to inspect the mount point every time. Reviewed by: kib (previous version) Differential Revision: https://reviews.freebsd.org/D33125
* vfs: remove thread argument from VOP_STATMateusz Guzik2021-10-111-2/+2
| | | | and fo_stat.
* vfs: remove cn_threadMateusz Guzik2021-10-111-1/+1
| | | | | | | It is always curthread. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D32453
* devfs: Avoid comparison with an uninitialized var in devfs_fp_check()Mark Johnston2021-05-031-2/+1
| | | | | | | | | | | devvn_refthread() will initialize *devp only if it succeeds, so check for success before comparing with fp->f_data. Other devvn_refthread() callers are careful to do this. Reported by: KMSAN Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D30068
* Remove #define _KERNEL hacks from libprocstatKonstantin Belousov2021-02-212-2/+9
| | | | | | | | | | | | | | | | | | Make sys/buf.h, sys/pipe.h, sys/fs/devfs/devfs*.h headers usable in userspace, assuming that the consumer has an idea what it is for. Unhide more material from sys/mount.h and sys/ufs/ufs/inode.h, sys/ufs/ufs/ufsmount.h for consumption of userspace tools, with the same caveat. Remove unacceptable hack from usr.sbin/makefs which relied on sys/buf.h being unusable in userspace, where it override struct buf with its own definition. Instead, provide struct m_buf and struct m_vnode and adapt code to use local variants. Reviewed by: mckusick Tested by: pho Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D28679
* devfs: fix use count leak when using TIOCSCTTYMateusz Guzik2021-02-091-1/+1
| | | | | | by matching devfs_ctty_ref Fixes: 3b44443626603f65 ("devfs: rework si_usecount to track opens")
* devfs(4): defer freeing until we drop devmtx ("cdev")Edward Tomasz Napierala2020-12-291-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before r332974 the old code would sometimes cause a rare lock order reversal against pagequeue, which looked roughly like this: witness_checkorder() __mtx_lock-flags() vm_page_alloc() uma_small_alloc() keg_alloc_slab() keg_fetch-slab() zone_fetch-slab() zone_import() zone_alloc_bucket() uma_zalloc_arg() bucket_alloc() uma_zfree_arg() free() devfs_metoo() devfs_populate_loop() devfs_populate() devfs_rioctl() VOP_IOCTL_APV() VOP_IOCTL() vn_ioctl() fo_ioctl() kern_ioctl() sys_ioctl() Since r332974 the original problem no longer exists, but it still makes sense to move things out of the - often congested - lock. Reviewed By: kib, markj Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D27334
* fs: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-4/+0
| | | | Notes: svn path=/head/; revision=365070
* devfs: Abstract locking assertionsConrad Meyer2020-08-122-3/+6
| | | | | | | | | | | | | | | The conversion was largely mechanical: sed(1) with: -e 's|mtx_assert(&devmtx, MA_OWNED)|dev_lock_assert_locked()|g' -e 's|mtx_assert(&devmtx, MA_NOTOWNED)|dev_lock_assert_unlocked()|g' The definitions of these abstractions in fs/devfs/devfs_int.h are the only non-mechanical change. No functional change. Notes: svn path=/head/; revision=364135
* devfs: rework si_usecount to track opensMateusz Guzik2020-08-112-16/+149
| | | | | | | | | | | This removes a lot of special casing from the VFS layer. Reviewed by: kib (previous version) Tested by: pho (previous version) Differential Revision: https://reviews.freebsd.org/D25612 Notes: svn path=/head/; revision=364113
* devfs: bool -> intMateusz Guzik2020-08-102-2/+2
| | | | | | | Fixes buildworld after r364069 Notes: svn path=/head/; revision=364076
* devfs: save on spurious relocking for devfs_populateMateusz Guzik2020-08-103-2/+16
| | | | | | | Tested by: pho Notes: svn path=/head/; revision=364069
* devfs: use cheaper lockmgr entry pointsMateusz Guzik2020-08-101-0/+6
| | | | | | | Tested by: pho Notes: svn path=/head/; revision=364068
* devfs: use vget_prep/vget_finishMateusz Guzik2020-08-101-7/+8
| | | | | | | Tested by: pho Notes: svn path=/head/; revision=364067
* vfs: remove the obsolete privused argument from vaccessMateusz Guzik2020-08-051-1/+1
| | | | | | | | This brings argument count down to 6, which is passable without the stack on amd64. Notes: svn path=/head/; revision=363893
* devfs: fix a vnode use-after-free in devfs_ioctlMateusz Guzik2020-07-041-8/+9
| | | | | | | | | | The vnode to be replaced was read with a shared lock, meaning 2 racing threads can find the same one. While here clean it up a little bit. Notes: svn path=/head/; revision=362923
* vfs: track sequential reads and writes separatelyThomas Munro2020-06-211-2/+2
| | | | | | | | | | | | | | | | | | For software like PostgreSQL and SQLite that sometimes reads sequentially while also writing sequentially some distance behind with interleaved syscalls on the same fd, performance is better on UFS if we do sequential access heuristics separately for reads and writes. Patch originally by Andrew Gierth in 2008, updated and proposed by me with his permission. Reviewed by: mjg, kib, tmunro Approved by: mjg (mentor) Obtained from: Andrew Gierth <andrew@tao11.riddles.org.uk> Differential Revision: https://reviews.freebsd.org/D25024 Notes: svn path=/head/; revision=362460
* Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)Pawel Biernacki2020-02-261-1/+2
| | | | | | | | | | | | | | | | | | | r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are still not MPSAFE (or already are but aren’t properly marked). Use it in preparation for a general review of all nodes. This is non-functional change that adds annotations to SYSCTL_NODE and SYSCTL_PROC nodes using one of the soon-to-be-required flags. Mark all obvious cases as MPSAFE. All entries that haven't been marked as MPSAFE before are by default marked as NEEDGIANT Approved by: kib (mentor, blanket) Commented by: kib, gallatin, melifaro Differential Revision: https://reviews.freebsd.org/D23718 Notes: svn path=/head/; revision=358333
* Fix up various vnode-related asserts which did not dump the used vnodeMateusz Guzik2020-02-031-2/+1
| | | | Notes: svn path=/head/; revision=357446
* Provide O_SEARCHKyle Evans2020-02-021-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | Notes: svn path=/head/; revision=357383