aboutsummaryrefslogtreecommitdiff
path: root/sys/fs/nullfs/null_subr.c
Commit message (Collapse)AuthorAgeFilesLines
* vfs: Initial revision of inotifyMark Johnston2025-07-041-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add an implementation of inotify_init(), inotify_add_watch(), inotify_rm_watch(), source-compatible with Linux. This provides functionality similar to kevent(2)'s EVFILT_VNODE, i.e., it lets applications monitor filesystem files for accesses. Compared to inotify, however, EVFILT_VNODE has the limitation of requiring the application to open the file to be monitored. This means that activity on a newly created file cannot be monitored reliably, and that a file descriptor per file in the hierarchy is required. inotify on the other hand allows a directory and its entries to be monitored at once. It introduces a new file descriptor type to which "watches" can be attached; a watch is a pseudo-file descriptor associated with a file or directory and a set of events to watch for. When a watched vnode is accessed, a description of the event is queued to the inotify descriptor, readable with read(2). Events for files in a watched directory include the file name. A watched vnode has its usecount bumped, so name cache entries originating from a watched directory are not evicted. Name cache entries are used to populate inotify events for files with a link in a watched directory. In particular, if a file is accessed with, say, read(2), an IN_ACCESS event will be generated for any watched hard link of the file. The inotify_add_watch_at() variant is included so that this functionality is available in capability mode; plain inotify_add_watch() is disallowed in capability mode. When a file in a nullfs mount is watched, the watch is attached to the lower vnode, such that accesses via either layer generate inotify events. Many thanks to Gleb Popov for testing this patch and finding lots of bugs. PR: 258010, 215011 Reviewed by: kib Tested by: arrowd MFC after: 3 months Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D50315
* sys: Remove ancient SCCS tags.Warner Losh2023-11-271-2/+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
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* vfs: add the concept of vnode state transitionsMateusz Guzik2022-12-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* nullfs: hash insertion without vnode lock upgradeMateusz Guzik2022-03-191-62/+52
| | | | | | | | | | Use the hash lock to serialize instead. This enables shared-locked ".." lookups. Reviewed by: markj Tested by: pho (previous version) Differential Revision: https://reviews.freebsd.org/D34466
* insmntque1(): remove useless argumentsKonstantin Belousov2022-01-311-1/+1
| | | | | | | | | | 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-2/+2
| | | | | | | | | | | | 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
* nullfs: ansify fs/nullfs/null_subr.cMateusz Guzik2022-01-271-20/+7
|
* nullfs: stop using insmntque1Mateusz Guzik2022-01-261-11/+6
| | | | It adds nothing of value over insmntque.
* vfs: add v_irflag accessorsMateusz Guzik2021-01-031-5/+3
| | | | | Reviewed by: kib (previous version) Differential Revision: https://reviews.freebsd.org/D27793
* VMIO reads: enable for nullfs upper vnode if the lower vnode supports it.Konstantin Belousov2020-08-161-0/+21
| | | | | | | | | | Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D25968 Notes: svn path=/head/; revision=364288
* Fix up various vnode-related asserts which did not dump the used vnodeMateusz Guzik2020-02-031-1/+1
| | | | Notes: svn path=/head/; revision=357446
* Fix a bug in r357199.Konstantin Belousov2020-01-301-2/+3
| | | | | | | | | | | | | | | Around a generic call to null_nodeget(), there is nothing that would prevent the unmount of the nullfs mp until we process to the insmntque1() point. Calculate the VV_ROOT flag after insmntque1() to not access mp->mnt_data before we have an exclusively locked vnode from this mount point on the mp vnode list. Reported and tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=357306
* Save lower root vnode in nullfs mnt data instead of upper.Konstantin Belousov2020-01-281-0/+2
| | | | | | | | | | | | | | | | | | | | | Nullfs needs to know the root vnode of the lower fs during the operation. Currently it caches the upper vnode of it, which is also the root of the nullfs mount. On unmount, nullfs calls vflush() with rootrefs == 1, and aborts non-forced unmount if there are any more vnodes instantiated during vflush(). This means that the reference to the root vnode after failed non-forced unmount could be lost and nullm_rootvp points to the freed memory. Fix it by storing the reference for lower vnode instead, which is kept intact during vflush(). nullfs_root() now instantiates the upper vnode of lower root. Care about VV_ROOT flag in null_nodeget(). Reported and tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=357199
* 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
* nullfs: locklessly check for entries in null_hashgetMateusz Guzik2019-12-051-0/+2
| | | | | | | During random sampling over poudriere -j 104 over 10% of calls returned NULL. Notes: svn path=/head/; revision=355415
* nullfs: lock the vnode with LK_SHARED in null_vptocnpMateusz Guzik2019-08-211-3/+0
| | | | | | | | | | | | | | null_nodeget which follows almost always finds the target vnode in the hash, avoiding insmntque1 altogether. Should it be needed, it already checks if the lock needs to be upgraded. Reviewed by: kib Tested by: pho Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D20244 Notes: svn path=/head/; revision=351360
* sys: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. 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. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326023
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96 Notes: svn path=/head/; revision=314436
* Change the getnewvnode(9) tag for nullfs from "null" to "nullfs".Edward Tomasz Napierala2016-09-151-1/+1
| | | | | | | | | It's more consistent, and besides, the "null" alone looks weird. MFC after: 1 month Notes: svn path=/head/; revision=305834
* Convert nullfs hash lock from a mutex to an rwlock.Mateusz Guzik2014-12-301-12/+12
| | | | Notes: svn path=/head/; revision=276425
* - Fix nullfs vnode reference leak in nullfs_reclaim_lowervp(). TheKonstantin Belousov2013-05-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | null_hashget() obtains the reference on the nullfs vnode, which must be dropped. - Fix a wart which existed from the introduction of the nullfs caching, do not unlock lower vnode in the nullfs_reclaim_lowervp(). It should be innocent, but now it is also formally safe. Inform the nullfs_reclaim() about this using the NULLV_NOUNLOCK flag set on nullfs inode. - Add a callback to the upper filesystems for the lower vnode unlinking. When inactivating a nullfs vnode, check if the lower vnode was unlinked, indicated by nullfs flag NULLV_DROP or VV_NOSYNC on the lower vnode, and reclaim upper vnode if so. This allows nullfs to purge cached vnodes for the unlinked lower vnode, avoiding excessive caching. Reported by: G??ran L??wkrantz <goran.lowkrantz@ismobile.com> Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=250505
* The current default size of the nullfs hash table used to lookup theKonstantin Belousov2013-01-141-10/+6
| | | | | | | | | | | | | | | | | | | existing nullfs vnode by the lower vnode is only 16 slots. Since the default mode for the nullfs is to cache the vnodes, hash has extremely huge chains. Size the nullfs hashtbl based on the current value of desiredvnodes. Use vfs_hash_index() to calculate the hash bucket for a given vnode. Pointy hat to: kib Diagnosed and reviewed by: peter Tested by: peter, pho (previous version) Sponsored by: The FreeBSD Foundation MFC after: 5 days Notes: svn path=/head/; revision=245408
* Fix reversed condition in the assertion.Konstantin Belousov2013-01-041-1/+1
| | | | | | | | Pointy hat to: kib MFC after: 13 days Notes: svn path=/head/; revision=245033
* Add the "nocache" nullfs mount option, which disables the caching ofKonstantin Belousov2013-01-031-0/+3
| | | | | | | | | | | | | | | | the free nullfs vnodes, switching nullfs behaviour to pre-r240285. The option is mostly intended as the last-resort when higher pressure on the vnode cache due to doubling of the vnode counts is not desirable. Note that disabling the cache costs more than 2x wall time in the metadata-hungry scenarious. The default is "cache". Tested and benchmarked by: pho (previous version) MFC after: 2 weeks Notes: svn path=/head/; revision=245004
* Remove the check and panic for an impossible condition. The NULLKonstantin Belousov2012-11-201-2/+0
| | | | | | | | | | lowervp vnode v_vnlock would cause panic due to NULL pointer dereference much earlier. MFC after: 1 week Notes: svn path=/head/; revision=243340
* r16312 is not any longer real since many years (likely since when VFSAttilio Rao2012-11-191-4/+0
| | | | | | | | | | | | | received granular locking) but the comment present in UFS has been copied all over other filesystems code incorrectly for several times. Removes comments that makes no sense now. Reviewed by: kib MFC after: 3 days Notes: svn path=/head/; revision=243311
* Allow shared lookups for nullfs mounts, if lower filesystem supportsKonstantin Belousov2012-09-091-11/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | it. There are two problems which shall be addressed for shared lookups use to have measurable effect on nullfs scalability: 1. When vfs_lookup() calls VOP_LOOKUP() for nullfs, which passes lookup operation to lower fs, resulting vnode is often only shared-locked. Then null_nodeget() cannot instantiate covering vnode for lower vnode, since insmntque1() and null_hashins() require exclusive lock on the lower. Change the assert that lower vnode is exclusively locked to only require any lock. If null hash failed to find pre-existing nullfs vnode for lower vnode and the vnode is shared-locked, the lower vnode lock is upgraded. 2. Nullfs reclaims its vnodes on deactivation. This is due to nullfs inability to detect reclamation of the lower vnode. Reclamation of a nullfs vnode at deactivation time prevents a reference to the lower vnode to become stale. Change nullfs VOP_INACTIVE to not reclaim the vnode, instead use the VFS_RECLAIM_LOWERVP to get notification and reclaim upper vnode together with the reclamation of the lower vnode. Note that nullfs reclamation procedure calls vput() on the lowervp vnode, temporary unlocking the vnode being reclaimed. This seems to be fine for MPSAFE filesystems, but not-MPSAFE code often put partially initialized vnode on some globally visible list, and later can decide that half-constructed vnode is not needed. If nullfs mount is created above such filesystem, then other threads might catch such not properly initialized vnode. Instead of trying to overcome this case, e.g. by recursing the lower vnode lock in null_reclaim_lowervp(), I decided to rely on nearby removal of the support for non-MPSAFE filesystems. In collaboration with: pho MFC after: 3 weeks Notes: svn path=/head/; revision=240285
* Do not expose unlocked unconstructed nullfs vnode on mount list.Konstantin Belousov2012-03-021-1/+1
| | | | | | | | | | Lock the native nullfs vnode lock before switching the locks. Tested by: pho MFC after: 1 week Notes: svn path=/head/; revision=232383
* Document that null_nodeget() cannot take shared-locked lowervp due toKonstantin Belousov2012-02-291-1/+5
| | | | | | | | | | insmntque() requirements. Tested by: pho MFC after: 1 week Notes: svn path=/head/; revision=232304
* Move the code to destroy half-contructed nullfs vnode into helperKonstantin Belousov2012-02-291-6/+13
| | | | | | | | | | | | | | | | | | | | function null_destroy_proto() from null_insmntque_dtr(). Also apply null_destroy_proto() in null_nodeget() when we raced and a vnode is found in the hash, so the currently allocated protonode shall be destroyed. Lock the vnode interlock around reassigning the v_vnlock. In fact, this path will not be exercised after several later commits, since null_nodeget() cannot take shared-locked lowervp at all due to insmntque() requirements. Reported by: rea Tested by: pho MFC after: 1 week Notes: svn path=/head/; revision=232299
* Merge a split multi-line comment.Konstantin Belousov2012-02-291-4/+1
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=232296
* Subject: NULLFS: properly destroy node hashEygene Ryabinkin2012-01-181-1/+1
| | | | | | | | | | Use hashdestroy() instead of naive free(). Approved by: kib MFC after: 2 weeks Notes: svn path=/head/; revision=230304
* In sys/fs/nullfs/null_subr.c, in a KASSERT, output the correct vnodeDimitry Andric2012-01-051-1/+1
| | | | | | | | | | pointer 'lowervp' instead of 'vp', which is uninitialized at that point. Reviewed by: kib MFC after: 1 week Notes: svn path=/head/; revision=229600
* Do the vput() for the lowervp in the null_nodeget() for error case too.Konstantin Belousov2012-01-031-0/+3
| | | | | | | | | | | | Several callers of null_nodeget() did the cleanup itself, but several missed it, most prominent being null_bypass(). Remove the cleanup from the callers, now null_nodeget() handles lowervp free itself. Reported and tested by: pho MFC after: 1 week Notes: svn path=/head/; revision=229431
* Document the state of the lowervp vnode for null_nodeget().Konstantin Belousov2012-01-031-0/+3
| | | | | | | | Tested by: pho MFC after: 1 week Notes: svn path=/head/; revision=229428
* Use the plain panic calls, without additional printing around them.Konstantin Belousov2011-11-191-14/+4
| | | | | | | | | | The debugger and dumping support is adequate. Tested by: pho MFC after: 1 week Notes: svn path=/head/; revision=227695
* Do not drop vnode interlock in null_checkvp(). null_lock() verifies thatKonstantin Belousov2009-05-311-22/+7
| | | | | | | | | | | | | | v_data is not-null before calling NULLVPTOLOWERVP(), and dropping the interlock allows for reclaim to clean v_data and free the memory. While there, remove unneeded semicolons and convert the infinite loops to panics. I have a will to remove null_checkvp() altogether, or leave it as a trivial stub, but not now. Reported and tested by: pho Notes: svn path=/head/; revision=193173
* Retire the MALLOC and FREE macros. They are an abomination unto style(9).Dag-Erling Smørgrav2008-10-231-3/+3
| | | | | | | MFC after: 3 months Notes: svn path=/head/; revision=184205
* - Simplify null_hashget() and null_hashins() by using vref() ratherJeff Roberson2008-03-291-21/+4
| | | | | | | | than a complex series of steps involving vget() without a lock type to emulate the same thing. Notes: svn path=/head/; revision=177725
* vn_lock() is currently only used with the 'curthread' passed as argument.Attilio Rao2008-01-101-1/+1
| | | | | | | | | | | | | | | | | | | Remove this argument and pass curthread directly to underlying VOP_LOCK1() VFS method. This modify makes the code cleaner and in particular remove an annoying dependence helping next lockmgr() cleanup. KPI results, obviously, changed. Manpage and FreeBSD_version will be updated through further commits. As a side note, would be valuable to say that next commits will address a similar cleanup about VFS methods, in particular vop_lock1 and vop_unlock. Tested by: Diego Sardina <siarodx at gmail dot com>, Andrea Di Pasquale <whyx dot it at gmail dot com> Notes: svn path=/head/; revision=175202
* This changes give nullfs correctly work with latest unionfs.Daichi GOTO2007-10-141-0/+7
| | | | | | | | | | Submitted by: Masanori Ozawa <ozawa@ongs.co.jp> (unionfs developer) Reviewed by: jeff, kensmith Approved by: re (kensmith) MFC after: 1 week Notes: svn path=/head/; revision=172644
* Make insmntque() externally visibile and allow it to fail (e.g. duringTor Egge2007-03-131-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | late stages of unmount). On failure, the vnode is recycled. Add insmntque1(), to allow for file system specific cleanup when recycling vnode on failure. Change getnewvnode() to no longer call insmntque(). Previously, embryonic vnodes were put onto the list of vnode belonging to a file system, which is unsafe for a file system marked MPSAFE. Change vfs_hash_insert() to no longer lock the vnode. The caller now has that responsibility. Change most file systems to lock the vnode and call insmntque() or insmntque1() after a new vnode has been sufficiently setup. Handle failed insmntque*() calls by propagating errors to callers, possibly after some file system specific cleanup. Approved by: re (kensmith) Reviewed by: kib In collaboration with: kib Notes: svn path=/head/; revision=167497
* - Assert that the lowervp is locked in null_hashget().Jeff Roberson2006-02-221-26/+21
| | | | | | | | | | | | | - Simplify the logic dealing with recycled vnodes in null_hashget() and null_hashins(). Since we hold the lower node locked in both cases the null node can not be undergoing recycling unless reclaim somehow called null_nodeget(). The logic that was in place was not safe and was essentially dead code. MFC After: 1 week Notes: svn path=/head/; revision=155898
* Normalize a significant number of kernel malloc type names:Robert Watson2005-10-311-2/+2
| | | | | | | | | | | | | | | | | | | | | | - Prefer '_' to ' ', as it results in more easily parsed results in memory monitoring tools such as vmstat. - Remove punctuation that is incompatible with using memory type names as file names, such as '/' characters. - Disambiguate some collisions by adding subsystem prefixes to some memory types. - Generally prefer lower case to upper case. - If the same type is defined in multiple architecture directories, attempt to use the same name in additional cases. Not all instances were caught in this change, so more work is required to finish this conversion. Similar changes are required for UMA zone names. Notes: svn path=/head/; revision=151897
* - Clear VI_OWEINACT before calling vget() with no lock type. We knowJeff Roberson2005-04-111-0/+7
| | | | | | | | the node is actually already locked, and VOP_INACTIVE is not desirable in this case. Notes: svn path=/head/; revision=144904
* - Assume that all lower filesystems now support proper locking. AssertJeff Roberson2005-03-151-58/+22
| | | | | | | | | | | | | | | | | | | | that they set v->v_vnlock. This is true for all filesystems in the tree. - Remove all uses of LK_THISLAYER. If the lower layer is locked, the null layer is locked. We only use vget() to get a reference now. null essentially does no locking. This fixes LOOKUP_SHARED with nullfs. - Remove the special LK_DRAIN considerations, I do not believe this is needed now as LK_DRAIN doesn't destroy the lower vnode's lock, and it's hardly used anymore. - Add one well commented hack to prevent the lowervp from going away while we're in it's VOP_LOCK routine. This can only happen if we're forcibly unmounted while some callers are waiting in the lock. In this case the lowervp could be recycled after we drop our last ref in null_reclaim(). Prevent this with a vhold(). Notes: svn path=/head/; revision=143642
* - The VI_DOOMED flag now signals the end of a vnode's relationship withJeff Roberson2005-03-131-2/+2
| | | | | | | | | | | the filesystem. Check that rather than VI_XLOCK. - VOP_INACTIVE should no longer drop the vnode lock. - The vnode lock is required around calls to vrecycle() and vgone(). Sponsored by: Isilon Systems, Inc. Notes: svn path=/head/; revision=143513
* /* -> /*- for copyright notices, minor format tweaks as necessaryWarner Losh2005-01-061-1/+1
| | | | Notes: svn path=/head/; revision=139776
* Back when VOP_* was introduced, we did not have new-style structPoul-Henning Kamp2004-12-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | initializations but we did have lofty goals and big ideals. Adjust to more contemporary circumstances and gain type checking. Replace the entire vop_t frobbing thing with properly typed structures. The only casualty is that we can not add a new VOP_ method with a loadable module. History has not given us reason to belive this would ever be feasible in the the first place. Eliminate in toto VOCALL(), vop_t, VNODEOP_SET() etc. Give coda correct prototypes and function definitions for all vop_()s. Generate a bit more data from the vnode_if.src file: a struct vop_vector and protype typedefs for all vop methods. Add a new vop_bypass() and make vop_default be a pointer to another struct vop_vector. Remove a lot of vfs_init since vop_vector is ready to use from the compiler. Cast various vop_mumble() to void * with uppercase name, for instance VOP_PANIC, VOP_NULL etc. Implement VCALL() by making vdesc_offset the offsetof() the relevant function pointer in vop_vector. This is disgusting but since the code is generated by a script comparatively safe. The alternative for nullfs etc. would be much worse. Fix up all vnode method vectors to remove casts so they become typesafe. (The bulk of this is generated by scripts) Notes: svn path=/head/; revision=138290