freebsd-dev/sys/fs
Jason A. Harmening fd8ad2128d unionfs: implement vnode-based cache lookup
unionfs uses a per-directory hashtable to cache subdirectory nodes.
Currently this hashtable is looked up using the directory name, but
since unionfs nodes aren't removed from the cache until they're
reclaimed, this poses some problems.  For example, if a directory is
created on a unionfs mount shortly after deleting a previous directory
with the same path, the cache may end up reusing the node for the
previous directory, including its upper/lower FS vnodes.  Operations
against those vnodes with then likely fail because the vnodes
represent deleted files; for example UFS will reject VOP_MKDIR()
against such a vnode because its effective link count is 0.  This may
then manifest as e.g. mkdir(2) or open(2) returning ENOENT for an
attempt to create a file under the re-created directory.

While it would be possible to fix this by explicitly managing the
name-based cache during delete or rename operations, or by rejecting
cache hits if the underlying FS vnodes don't match those passed to
unionfs_nodeget(), it seems cleaner to instead hash the unionfs nodes
based on their underlying FS vnodes.  Since unionfs prefers to operate
against the upper vnode if one is present, the lower vnode will only
be used for hashing as long as the upper vnode is NULL.  This should
also make hashing faster by eliminating string traversal and using
the already-computed hash index stored in each vnode.

While here, fix a couple of other cache-related issues:

--Remove 8 bytes of unnecessary baggage from each unionfs node by
  getting rid of the stored hash mask field.  The mask is knowable
  at compile time.

--When a matching node is found in the cache, reference its vnode
  using vrefl() while still holding the vnode interlock.  Previously
  unionfs_nodeget() would vref() the vnode after the interlock was
  dropped, but the vnode may be reclaimed during that window.  This
  caused intermittent panics from vn_lock(9) during unionfs stress
  testing.

Reviewed by:	kib, markj
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D32533
2021-10-24 10:05:50 -07:00
..
autofs vfs: remove cn_thread 2021-10-11 13:21:47 +00:00
cd9660 buffer pager: allow get_blksize method to return error 2021-09-17 20:29:55 +03:00
cuse Fix for loading cuse.ko via rc.d . Make sure we declare the cuse(3) 2020-10-23 08:44:53 +00:00
deadfs vn_open(): If the vnode is reclaimed during open(2), do not return error. 2021-02-12 03:02:20 +02:00
devfs vfs: remove thread argument from VOP_STAT 2021-10-11 13:22:32 +00:00
ext2fs vfs: remove cn_thread 2021-10-11 13:21:47 +00:00
fdescfs vfs: remove cn_thread 2021-10-11 13:21:47 +00:00
fifofs fifos: delegate unhandled kqueue filters to underlying filesystem 2021-10-12 02:43:07 -05:00
fuse vfs: remove cn_thread 2021-10-11 13:21:47 +00:00
mntfs Add a new "mntfs" pseudo file system which provides private device vnodes for 2020-03-06 18:41:37 +00:00
msdosfs msdosfs_rename: remove write-only variables 2021-10-20 21:29:49 +03:00
nfs Convert vm_page_alloc() callers to use vm_page_alloc_noobj(). 2021-10-19 21:22:56 -04:00
nfsclient Convert vm_page_alloc() callers to use vm_page_alloc_noobj(). 2021-10-19 21:22:56 -04:00
nfsserver vfs: remove cn_thread 2021-10-11 13:21:47 +00:00
nullfs nullfs: provide custom null_rename bypass 2021-07-27 19:58:48 +03:00
procfs Create sys/reg.h for the common code previously in machine/reg.h 2021-08-30 12:50:53 +01:00
pseudofs pseudofs: use vget_prep + vget_finish instead of vget + the interlock 2021-05-19 17:58:42 +00:00
smbfs vfs: remove cn_thread 2021-10-11 13:21:47 +00:00
tmpfs tmpfs: remove write-only variables 2021-10-20 21:29:49 +03:00
udf Make MAXPHYS tunable. Bump MAXPHYS to 1M. 2020-11-28 12:12:51 +00:00
unionfs unionfs: implement vnode-based cache lookup 2021-10-24 10:05:50 -07:00