Home | History | Annotate | Download | only in tmpfs
History log of /src/sys/fs/tmpfs/tmpfs_subr.c
RevisionDateAuthorComments
 1.117  29-Apr-2023  riastradh tmpfs: Assert no arithmetic overflow in directory node tn_size.

Need >2^57 directory entries before this is a problem. If we created
a million per second, this would take over 4000 years.
 1.116  29-Apr-2023  riastradh tmpfs: Refuse sizes that overflow round_page.

Reported-by: syzbot+8dbeee84de15f86df65b@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=4a27b9fe074f8d4b0afbe22969339b8dfdb157e8
 1.115  29-Apr-2023  riastradh tmpfs: Nix trailing whitespace. No functional change intended.
 1.114  20-Oct-2021  thorpej branches: 1.114.4;
Overhaul of the EVFILT_VNODE kevent(2) filter:

- Centralize vnode kevent handling in the VOP_*() wrappers, rather than
forcing each individual file system to deal with it (except VOP_RENAME(),
because VOP_RENAME() is a mess and we currently have 2 different ways
of handling it; at least it's reasonably well-centralized in the "new"
way).
- Add support for NOTE_OPEN, NOTE_CLOSE, NOTE_CLOSE_WRITE, and NOTE_READ,
compatible with the same events in FreeBSD.
- Track which kevent notifications clients are interested in receiving
to avoid doing work for events no one cares about (avoiding, e.g.
taking locks and traversing the klist to send a NOTE_WRITE when
someone is merely watching for a file to be deleted, for example).

In support of the above:

- Add support in vnode_if.sh for specifying PRE- and POST-op handlers,
to be invoked before and after vop_pre() and vop_post(), respectively.
Basic idea from FreeBSD, but implemented differently.
- Add support in vnode_if.sh for specifying CONTEXT fields in the
vop_*_args structures. These context fields are used to convey information
between the file system VOP function and the VOP wrapper, but do not
occupy an argument slot in the VOP_*() call itself. These context fields
are initialized and subsequently interpreted by PRE- and POST-op handlers.
- Version VOP_REMOVE(), uses the a context field for the file system to report
back the resulting link count of the target vnode. Return this in tmpfs,
udf, nfs, chfs, ext2fs, lfs, and ufs.

NetBSD 9.99.92.
 1.113  05-Sep-2020  riastradh Round of uvm.h cleanup.

The poorly named uvm.h is generally supposed to be for uvm-internal
users only.

- Narrow it to files that actually need it -- mostly files that need
to query whether curlwp is the pagedaemon, which should maybe be
exposed by an external header.

- Use uvm_extern.h where feasible and uvm_*.h for things not exposed
by it. We should split up uvm_extern.h but this will serve for now
to reduce the uvm.h dependencies.

- Use uvm_stat.h and #ifdef UVMHIST uvm.h for files that use
UVMHIST(ubchist), since ubchist is declared in uvm.h but the
reference evaporates if UVMHIST is not defined, so we reduce header
file dependencies.

- Make uvm_device.h and uvm_swap.h independently includable while
here.

ok chs@
 1.112  17-May-2020  ad PR kern/55268: tmpfs is slow

tmpfs_getpages(): handle the PGO_LOCKED case and implement lazy update of
atime/mtime.
 1.111  16-May-2020  christos Add ACL support for FFS. From FreeBSD.
 1.110  12-May-2020  ad cache_enter_id(): give it a boolean parameter to indicate whether the cached
identity is valid.
 1.109  23-Apr-2020  ad PR kern/54759 (vm.ubc_direct deadlock when read()/write() into mapping of itself)

- Add new flag UBC_ISMAPPED which tells ubc_uiomove() the object is mmap()ed
somewhere. Use it to decide whether to do direct-mapped copy, rather than
poking around directly in the vnode in ubc_uiomove(), which is ugly and
doesn't work for tmpfs. It would be nicer to contain all this in UVM but
the filesystem provides the needed locking here (VV_MAPPED) and to
reinvent that would suck more.

- Rename UBC_UNMAP_FLAG() to UBC_VNODE_FLAGS(). Pass in UBC_ISMAPPED where
appropriate.
 1.108  04-Apr-2020  ad branches: 1.108.2;
Merge the remaining changes from the ad-namecache branch, affecting namei()
and getcwd():

- push vnode locking back as far as possible.
- do most lookups directly in the namecache, avoiding vnode locks & refs.
- don't block new refs to vnodes across VOP_INACTIVE().
- get shared locks for VOP_LOOKUP() if the file system supports it.
- correct lock types for VOP_ACCESS() / VOP_GETATTR() in a few places.

Possible future enhancements:

- make the lookups lockless.
- support dotdot lookups by being lockless and inferring absence of chroot.
- maybe make it work for layered file systems.
- avoid vnode references at the root & cwd.
 1.107  14-Mar-2020  ad tmpfs_reg_resize(): do nothing if newsize == oldsize.
 1.106  23-Feb-2020  ad UVM locking changes, proposed on tech-kern:

- Change the lock on uvm_object, vm_amap and vm_anon to be a RW lock.
- Break v_interlock and vmobjlock apart. v_interlock remains a mutex.
- Do partial PV list locking in the x86 pmap. Others to follow later.
 1.105  18-Sep-2019  christos branches: 1.105.2;
Add newly created vnodes to the namei cache. The rest of the filesystems
already did that (or they don't support writing). Discussed in tech-kern.
 1.104  01-Jan-2019  hannken branches: 1.104.4;
Add "void *extra" argument to vcache_new() so a file system may
pass more information about the file to create.

Welcome to 8.99.30
 1.103  28-May-2018  chs branches: 1.103.2;
allow tmpfs files to be larger than 4GB.
 1.102  04-Jan-2017  hannken branches: 1.102.8; 1.102.14;
Change tmpfs_chsize() to update mtime etc. even if "length == node->tn_size".

Adresses PR kern/51762 "mtime not updated by open(O_TRUNC)"
 1.101  29-Oct-2015  leot branches: 1.101.2;
Make sure that nde->td_node is NULL for asserts.
Thanks and from Mindaugas Rasiukevicius.

Fixes PR kern/50381.
 1.100  07-Jul-2015  justin This enum is likely to be made unsigned by the compiler, so the assertion
will not work and clang objects with -Wtautological-constant-out-of-range-compare
 1.99  06-Jul-2015  hannken Change tmpfs to vcache.
- Use tmpfs node address as key.
- Remove tn_vlock, field tn_vnode now protected by vcache.
- Add a hold count to tmpfs node to prevent nodes from disappearing
while tmpfs_fhtovp() trys to vcache_get() them. Last holder
destroys reclaimed nodes.
- Remove the now unneeded parent unlock/lock for lookup of '..'.
 1.98  20-Apr-2015  riastradh Make vget always return vnode unlocked.

Convert callers who want locks to use vn_lock afterward.

Add extra argument so the compiler will report stragglers.
 1.97  08-Sep-2014  gson branches: 1.97.2;
Store symlinks without a NUL terminator so that lstat(2) returns the
correct length. Fixes the tmpfs part of PR kern/48864.
 1.96  23-Jan-2014  hannken branches: 1.96.4;
Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30
 1.95  17-Jan-2014  hannken Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29
 1.94  08-Jan-2014  pedro Allocate direntp on the stack in tmpfs_dir_getdents(), thus saving
calls to kmem_zalloc() and kmem_free(); OK rmind@. From OpenBSD.
 1.93  03-Jan-2014  hannken Fix a race where thread1 runs VOP_REMOVE() and gets preempted in
tmpfs_reclaim() before the call to tmpfs_free_node(). Thread2
runs VFS_FHTOVP() and gets a new vnode attached to the node thread1
is about to destroy.

Change tmpfs_alloc_node() to always assign non-zero generation number
and tmpfs_inactive() to set the generation number of unlinked nodes
to zero.
 1.92  24-Nov-2013  rmind - tmpfs_construct_node: prevent from the new node construction if the
directory was removed. Fixes the crash reported by Nicolas Joly.
- tmpfs_reclaim: avoid race by checking tn_links with the vnode locked.
 1.91  23-Nov-2013  rmind tmpfs_reg_resize: use size_t.
 1.90  23-Nov-2013  rmind - Simplify tmpfs_update(), eliminate tmpfs_note_t::tn_status and deferred
timestamp updates. Fix some incorrect updates and plug some missing ones.
Should fix PR/48385.
- tmpfs_rmdir: avoid O(n) scan when the directory is not empty and whiteout
entries were never added.
 1.89  21-Nov-2013  rmind tmpfs_dir_getdotents: fix the recent regression, set the correct
d_fileno value for dot-dot. Spotted by Pedro Martelletto, thanks!
 1.88  18-Nov-2013  rmind Make tmpfs_node_t::tn_gen a 32-bit number, keep it in sync with tmpfs_fid_t.
Also, change tn_status to unsigned while here.
 1.87  16-Nov-2013  rmind tmpfs_dir_getdents: avoid leaking kernel memory to the userspace.
From Pedro Martelletto.

XXX: regress/sys/fs/getdents should be a part of the test suite
 1.86  11-Nov-2013  rmind tmpfs_alloc_node: use cprng_fast64(), the old random(9) shall be removed.
 1.85  10-Nov-2013  rmind Handle whiteout case in tmpfs_dir_detach() and tmpfs_unmount().
 1.84  10-Nov-2013  christos mark variable __diagused
 1.83  08-Nov-2013  rmind tmpfs: replace the broken tmpfs_dircookie() logic which uses the node
address truncated to 31 bits (required for 32-bit readdir compatibility,
e.g. linux32). Instead, assign 2^31 range using the following logic:
- The first half of the 2^31 is assigned incrementally (the fast path).
- When exceeded, use the second half of 2^31, but manage with vmem(9).

It will require 2 billion files per-directory to trigger vmem(9) usage.
Also, while here, add some fixes for tmpfs_unmount().

Should fix PR/47739, PR/47480, PR/46088 and PR/41068.
Thanks to wiz@ for stress testing.
 1.82  01-Nov-2013  rmind tmpfs: fix the zero-length symlink target case as NetBSD supports them.
 1.81  31-Oct-2013  rmind tmpfs_alloc_node: it is less error-prone to store the link path with
the NIL terminator included. Adjust tmpfs_readlink() to exclude NIL.
Also, remove the check for zero-length and add some asserts.
 1.80  04-Oct-2013  rmind - tmpfs_remove: check 'appendable' flag for the parent directory as well.
Patch from Pedro Martelletto.
- tmpfs_dir_detach: remove missleading check.
- tmpfs_link: remove unused variable.
 1.79  13-Mar-2012  elad branches: 1.79.2; 1.79.4;
Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.
 1.78  19-Nov-2011  tls branches: 1.78.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.77  27-Aug-2011  hannken branches: 1.77.2;
Finish and enable whiteout support for tmpfs:

- Enable VOP tmpfs_whiteout().
- Support ISWHITEOUT in tmpfs_alloc_file().
- Support DOWHITEOUT in tmpfs_remove() and tmpfs_rmdir().
- Make rmdir on a directory containing whiteouts working.

Should fix PR #35112 (tmpfs doesn't play well with unionfs).
 1.76  30-Jun-2011  enami Backout previous. May be I need more coffee.
 1.75  30-Jun-2011  enami - Use << PAGE_SHIFT rather than calling round_page again.
- No need to call uao_dropswap_range() here since uao_dropswap()
is already called for each pages by uvm_vnp_setsize().
 1.74  16-Jun-2011  hannken Rename uvm_vnp_zerorange(struct vnode *, off_t, size_t) to
ubc_zerorange(struct uvm_object *, off_t, size_t, int) changing
the first argument to an uvm_object and adding a flags argument.

Modify tmpfs_reg_resize() to zero the backing store (aobj) instead
of the vnode. Ubc_purge() no longer panics when unmounting tmpfs.

Keep uvm_vnp_zerorange() until the next kernel version bump.
 1.73  12-Jun-2011  rmind Welcome to 5.99.53! Merge rmind-uvmplock branch:

- Reorganize locking in UVM and provide extra serialisation for pmap(9).
New lock order: [vmpage-owner-lock] -> pmap-lock.

- Simplify locking in some pmap(9) modules by removing P->V locking.

- Use lock object on vmobjlock (and thus vnode_t::v_interlock) to share
the locks amongst UVM objects where necessary (tmpfs, layerfs, unionfs).

- Rewrite and optimise x86 TLB shootdown code, make it simpler and cleaner.
Add TLBSTATS option for x86 to collect statistics about TLB shootdowns.

- Unify /dev/mem et al in MI code and provide required locking (removes
kernel-lock on some ports). Also, avoid cache-aliasing issues.

Thanks to Andrew Doran and Joerg Sonnenberger, as their initial patches
formed the core changes of this branch.
 1.72  29-May-2011  rmind branches: 1.72.2;
Fix non-DEBUG build.
 1.71  29-May-2011  rmind - Rework and document inode reference counting. Also document inode life
cycle (destruction part). Perform link counting in tmpfs_dir_attach()
and tmpfs_dir_detach(), instead of alloc/free and arbitrary places.
Fixes PR/44285, PR/44288, PR/44657 and likely PR/42484.

- Fix the race between the lookup and inode destruction. Fixes PR/43167
and its duplicates PR/40088, PR/40757.

- Improve tmpfs_rename() locking a little, fix kqueue event notifications
and also fix PR/43617. Add simplistic tmpfs_parentcheck_p(); to be
expanded and used for further rename() locking fixes.

- Cache directory entry "hint" in the tmpfs node, add tmpfs_dir_cached(),
and thus avoid unnecessary lookup in tmpfs_remove() and tmpfs_rmdir().

- Set correct _PC_FILESIZEBITS value in tmpfs_pathconf(). Fixes PR/43576.

- Few minor fixes.
 1.70  25-May-2011  rmind tmpfs_update: comment out assert for now.
 1.69  25-May-2011  rmind tmpfs_dir_lookup: use 'name' variable in memcmp() as intended; fix warning.
 1.68  24-May-2011  rmind - tmpfs_lookup: cache (cnp->cn_flags & ISLASTCN) in const bool; de-indent.
- Group tmpfs_{alloc,free}_dirent() with other dirent routines.

No functional changes.
 1.67  24-May-2011  rmind - Describe some locking.
- Add VOP argument comments, add some asserts.
- Update/fix/remove outdated/missleading comments.
- Clean up, de-indent, KNF, misc.

No functional changes intended.
 1.66  24-May-2011  rmind tmpfs_free_node: comment out assert, which can fire e.g. on shutdown.
 1.65  24-May-2011  rmind - tmpfs_alloc_node/tmpfs_free_node: move inode limiting into tmpfs_node_get()
and tmpfs_node_put(), update outdated/wrong comments and move/add asserts.
- tmpfs_mount: check for the version of arguments a bit earlier.
 1.64  22-May-2011  rmind tmpfs_alloc_vp:
- Do not check for vn_lock(9) error, if LK_RETRY.
- Fix/improve comments.
 1.63  01-Apr-2011  hannken Make zero length symlinks work on tmpfs.

Fixes PR #43843 (tmpfs dies with kassert panic for 0 length symlink target)
 1.62  13-Jan-2011  pooka branches: 1.62.2;
Add some support for unionfs (not built by default). It's still
missing at least opaque directory support, but until someone figures
out how that should work on ffs (see PR kern/kern/44383), there's
no point in trying to figure out how it should work here.
 1.61  30-Nov-2010  dholland Abolish the SAVENAME and HASBUF flags. There is now always a buffer,
so the path in a struct componentname is now always valid during VOP
calls.
 1.60  30-Nov-2010  dholland Abolish struct componentname's cn_pnbuf. Use the path buffer in the
pathbuf object passed to namei as work space instead. (For now a pnbuf
pointer appears in struct nameidata, to support certain unclean things
that haven't been fixed yet, but it will be going away in the future.)

This removes the need for the SAVENAME and HASBUF namei flags.
 1.59  21-Jul-2010  hannken Make holding v_interlock mandatory for callers of vget().

Announced some time ago on tech-kern.
 1.58  02-Jul-2010  rmind tmpfs_lookup: add comment, de-ident main path. No functional change.
tmpfs_dir_attach: add assert.
 1.57  22-Jun-2010  rmind Replace tmpfs_pool custom allocator code with a simpler layer for memory
accounting. Use wired memory (which can be limited) for meta-data, and
kmem(9) for string allocations.

Close PR/31944. Fix PR/38361 while here. OK ad@.
 1.56  11-Nov-2009  rmind branches: 1.56.2; 1.56.4;
Simplify tmpfs_itimes() and use vfs_timestamp(). Also, replace unnecessary
kmem_zalloc()s with kmem_alloc()s.
 1.55  03-Sep-2009  pooka "kauth_action_t = KAUTH_VNODE_WRITE_FLAGS;" must be C**. However,
we still use plain ISO C, so additionally supply the variable name.
Compile-tested only, but at least that's some testing.
 1.54  03-Sep-2009  elad Implement the vnode scope and adapt tmpfs to use it.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/07/04/msg005404.html
 1.53  07-May-2009  elad Extract the open-coded authorization logic for chtimes() from various
file-systems and put it in a single function, genfs_can_chtimes().

This also makes UDF follow the same policy as all other file-systems.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/04/27/msg004951.html
 1.52  22-Apr-2009  elad Per discussion on tech-kern@:

- Replace use of label/goto with returns

- Rename, change prototype of, and move functions from vfs_subr.c to
genfs_vnops.c
 1.51  20-Apr-2009  elad Refactor some duplicated file-system code.

Proposed and received no objections on tech-kern@:

http://mail-index.netbsd.org/tech-kern/2009/04/18/msg004843.html
 1.50  11-Apr-2009  markd For chown make auth checks consistent with UFS. Fixes PR kern/40933.
 1.49  10-Apr-2009  yamt - tmpfs_dir_lookup: simplify.
- add some assertions.
 1.48  19-Jun-2008  christos branches: 1.48.4; 1.48.6; 1.48.10;
- setting the birthdate is valid in setattr.
- don't call nanotime if not needed.
- don't call tempfs_update() if tempfs_chtimes succeeded, because it just did.
 1.47  28-Apr-2008  martin branches: 1.47.2; 1.47.4;
Remove clause 3 and 4 from TNF licenses
 1.46  06-Feb-2008  jmmv branches: 1.46.6; 1.46.8; 1.46.10;
u_int is not a C99 standard type, so spell it out completely as
unsigned int.
 1.45  06-Feb-2008  jmmv Drop trailing whitespace.
 1.44  24-Jan-2008  ad specfs changes for PR kern/37717 (raidclose() is no longer called on
shutdown). There are still problems with device access and a PR will be
filed.

- Kill checkalias(). Allow multiple vnodes to reference a single device.

- Don't play dangerous tricks with block vnodes to ensure that only one
vnode can describe a block device. Instead, prohibit concurrent opens of
block devices. As a bonus remove the unreliable code that prevents
multiple file system mounts on the same device. It's no longer needed.

- Track opens by vnode and by device. Issue cdev_close() when the last open
goes away, instead of abusing vnode::v_usecount to tell if the device is
open.
 1.43  02-Jan-2008  ad Merge vmlocking2 to head.
 1.42  08-Dec-2007  pooka branches: 1.42.4;
Remove cn_lwp from struct componentname. curlwp should be used
from on. The NDINIT() macro no longer takes the lwp parameter and
associates the credentials of the calling thread with the namei
structure.
 1.41  26-Nov-2007  pooka branches: 1.41.2;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern
 1.40  10-Nov-2007  ad Back out the tmpfs changes; there appears to be a bug lurking.
 1.39  06-Nov-2007  ad Merge from vmlocking.
 1.38  10-Oct-2007  ad branches: 1.38.4;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.
 1.37  24-Sep-2007  rumble Avoid stack allocation of large dirent structures in foo_readdir().
 1.36  06-Aug-2007  pooka branches: 1.36.2; 1.36.4; 1.36.6;
When resizing a node, first drop extra pages and zero tail, and only
then set the new size. Otherwise zerolen will always be, well, 0.
 1.35  09-Jul-2007  ad branches: 1.35.2; 1.35.6;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.34  22-Feb-2007  thorpej branches: 1.34.4; 1.34.6;
TRUE -> true, FALSE -> false
 1.33  21-Feb-2007  thorpej Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
 1.32  04-Jan-2007  elad branches: 1.32.2;
Consistent usage of KAUTH_GENERIC_ISSUSER.
 1.31  02-Jan-2007  elad Add KAUTH_SYSTEM_CHSYSFLAGS so we can get rid of the last three
securelevel references (ufs, ext2fs, tmpfs).

Intentionally undocumented.
 1.30  16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.29  09-Nov-2006  jmmv Audit kqueue notifications. The reference behavior is taken from MFS and
is represented in the regression tests.
 1.28  05-Nov-2006  jmmv Randomly initialize the node's generation to make file handles less
predictable. This solves a problem that may appear when serving a tmpfs
over NFS: if the server reboots, newly allocated files should have
different file handles; otherwise the remote clients could access files
they were not supposed to touch.
 1.27  05-Nov-2006  jmmv Truncate directory cookies to 31 bits to avoid problems exposed in Linux
binaries which cast the returned values to 64-bits and fail due to sign
expansion. More details are provided in the big comment in tmpfs.h that
describes how the new tmpfs_dircookie works.

This is a rather ugly hack that shall be fixed with a cleaner solution,
but this resolves the problem in an effective way.

Fixes kern PR/32034.
 1.26  30-Oct-2006  jmmv Grr... cvs diff scrolled too much and I didn't notice there were some
unwanted changes in this file. Revert them; sorry.
 1.25  30-Oct-2006  jmmv When renaming a file, we have to modify the mtime of the directory holding
it, not the mtime of the file itself. This fixes the problems exposed when
unpacking software under a tmpfs and trying to build it because dependencies
were not calculated properly (e.g. autoconf 2.60 as reported by tls@).
 1.24  12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.23  03-Sep-2006  christos branches: 1.23.2; 1.23.4;
comment out empty code
 1.22  23-Jul-2006  ad Use the LWP cached credentials where sane.
 1.21  07-Jun-2006  kardel branches: 1.21.4;
merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html
 1.20  15-May-2006  christos branches: 1.20.2;
kauth fallout
 1.19  14-May-2006  elad integrate kauth.
 1.18  16-Feb-2006  jmmv branches: 1.18.2; 1.18.4; 1.18.6;
Do not use unnamed structures/unions without instances; they break the
build under vax because of gcc 2.95. Found by he@.
 1.17  11-Dec-2005  christos branches: 1.17.2; 1.17.4; 1.17.6;
merge ktrace-lwp.
 1.16  28-Nov-2005  dan take into account memory used for file cache pages, and wired pages,
when calculating potential free space
 1.15  28-Nov-2005  dan simplify calculation of free swap space using uvm-exported statistics,
with thanks to yamt@ for useful hints.
 1.14  11-Nov-2005  yamt branches: 1.14.2;
- ignore truncation for VCHR/VBLK/VFIFO as it used to be
before yamt-vop merge. PR/32049 from Atsushi Onoe.
- reject setattr which attempts to change size of VLNK/VSOCK.
 1.13  08-Nov-2005  yamt branches: 1.13.2;
tmpfs_reg_resize: drop swap slots on truncation.
fix a problem pointed by jmmv@.
 1.12  02-Nov-2005  yamt merge yamt-vop branch. remove following VOPs.

VOP_BLKATOFF
VOP_VALLOC
VOP_BALLOC
VOP_REALLOCBLKS
VOP_VFREE
VOP_TRUNCATE
VOP_UPDATE
 1.11  30-Sep-2005  jmmv branches: 1.11.2;
Explicitly initialize the tn_lockf field. I expect problems in some
situations otherwise...
 1.10  28-Sep-2005  yamt tmpfs_getattr: return up-to-date timestamps.
 1.9  27-Sep-2005  jmmv Some style fixes in comments.
 1.8  23-Sep-2005  jmmv Kill the tmpfs(9) manual page; it was just documenting internal details of
tmpfs' "API" and was already rotting.

Instead, merge all the relevant comments into the code. This includes
acknowledgements to Google's Summer of Code 2005 program (they were in the
AUTHORS section of tmpfs(9) before), so all the files need to be changed
to include this sentence alongside the title. (Note that this was not a
requirement of the program.)
 1.7  17-Sep-2005  yamt fix buffer overrun for symbolic links. PR/31325.
 1.6  16-Sep-2005  yamt tmpfs_dir_getdotdotdent: correct fileid.
 1.5  15-Sep-2005  yamt change the way to handle directory "offsets" so that
they won't be changed when removing entries in the directory.
some applications like cvs rely on this.
 1.4  13-Sep-2005  yamt - don't waste/leak kva.
- implement getpages/putpages. support mmap.
- eliminate meaningless memcpy.
- ubcify.
 1.3  12-Sep-2005  christos convert to use it nanotime, but don't call it unless it is necessary.
 1.2  10-Sep-2005  jmmv wiz@ remembers that the preferred way to spell file-system in NetBSD is
file system.
 1.1  10-Sep-2005  jmmv Initial addition of tmpfs, an efficient memory file-system. This project
was developed as part of Google's Summer of Code 2005 program. This
change adds the kernel code, the mount_tmpfs utility, a regression test
suite and does all other related changes to integrate these.

The file-system is still *experimental*. Therefore, it is disabled by
default in all kernels. However, as typically done, a commented-out
entry is added in them to ease its setup.

Note that I haven't commited the required mountd(8) changes to be able
to export tmpfs file-systems because NFS support is still very unstable
and because, before enabling it, I'd like to do some other changes.

OK'ed by my project mentor, William Studenmund (wrstuden@).
 1.11.2.2  29-Oct-2005  yamt as tmpfs_update never fails, make it return void.
suggested by Chuck Silvers.
 1.11.2.1  20-Oct-2005  yamt adapt tmpfs.
 1.13.2.4  11-Dec-2005  christos Sync with head.
 1.13.2.3  12-Nov-2005  skrll Adapt to branch
 1.13.2.2  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.13.2.1  08-Nov-2005  skrll file tmpfs_subr.c was added on branch ktrace-lwp on 2005-11-10 14:09:44 +0000
 1.14.2.1  29-Nov-2005  yamt sync with head.
 1.17.6.4  01-Jun-2006  kardel Sync with head.
 1.17.6.3  22-Apr-2006  simonb Sync with head.
 1.17.6.2  05-Feb-2006  simonb In the *itimes functions, just call getnanotime() at the start of
the function and use the result if needed, rather than the previous
conditional calls/assignments method. The code is clearer this way,
and benchmarks at about the same speed.
 1.17.6.1  04-Feb-2006  simonb Adapt for timecounters: mostly use get*time() and use "time_second"
instead of "time.tv_sec".
 1.17.4.1  09-Sep-2006  rpaulo sync with head
 1.17.2.1  18-Feb-2006  yamt sync with head.
 1.18.6.1  24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.18.4.3  18-Apr-2006  elad adapt to kauth, pointed out by yamt@, thanks!
 1.18.4.2  10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.18.4.1  08-Mar-2006  elad Adapt to kernel authorization KPI.
 1.18.2.4  03-Sep-2006  yamt sync with head.
 1.18.2.3  11-Aug-2006  yamt sync with head
 1.18.2.2  26-Jun-2006  yamt sync with head.
 1.18.2.1  24-May-2006  yamt sync with head.
 1.20.2.1  19-Jun-2006  chap Sync with head.
 1.21.4.10  11-Feb-2008  yamt sync with head.
 1.21.4.9  04-Feb-2008  yamt sync with head.
 1.21.4.8  21-Jan-2008  yamt sync with head
 1.21.4.7  07-Dec-2007  yamt sync with head
 1.21.4.6  27-Oct-2007  yamt sync with head.
 1.21.4.5  03-Sep-2007  yamt sync with head.
 1.21.4.4  26-Feb-2007  yamt sync with head.
 1.21.4.3  30-Dec-2006  yamt sync with head.
 1.21.4.2  21-Jun-2006  yamt sync with head.
 1.21.4.1  07-Jun-2006  yamt file tmpfs_subr.c was added on branch yamt-lazymbuf on 2006-06-21 15:09:36 +0000
 1.23.4.2  10-Dec-2006  yamt sync with head.
 1.23.4.1  22-Oct-2006  yamt sync with head
 1.23.2.2  12-Jan-2007  ad Sync with head.
 1.23.2.1  18-Nov-2006  ad Sync with head.
 1.32.2.1  27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.34.6.1  11-Jul-2007  mjf Sync with head.
 1.34.4.11  23-Oct-2007  ad Sync with head.
 1.34.4.10  09-Oct-2007  ad Sync with head.
 1.34.4.9  09-Oct-2007  ad Sync with head.
 1.34.4.8  08-Oct-2007  ad - Don't leave nodes dangling in order to keep track of the inode generation
number. Free them back to the pool as soon as the referenced file becomes
unused. Using arc4random() for the generation and ino_t based off the
node's in-core address is just about as as good as a disk-based file
system is going to give.
- Add assertion to catch empty directories with linkcount > 1 being freed.
This fires frequently but I haven't tracked the bug down yet..
- Use kmem_alloc.
 1.34.4.7  18-Sep-2007  ad tmpfs_alloc_vp: deal with vget() failure. Another thread may be reclaiming
the vnode.
 1.34.4.6  16-Sep-2007  ad Fix another minor concurrency problem.
 1.34.4.5  22-Aug-2007  ad Fix some more concurrency problems.
 1.34.4.4  21-Aug-2007  ad - Add locking around tmpfs shared data structures and mark it MP safe.
It's enough to last for about 45m of fsx+postmark, but it doesn't
survive SGI fsstress yet.
- Close a race where multiple vnodes could maybe have been allocated
for a tmpnode with linkcount > 1.
 1.34.4.3  20-Aug-2007  ad Sync with HEAD.
 1.34.4.2  17-Jun-2007  ad - Increase the number of thread priorities from 128 to 256. How the space
is set up is to be revisited.
- Implement soft interrupts as kernel threads. A generic implementation
is provided, with hooks for fast-path MD code that can run the interrupt
threads over the top of other threads executing in the kernel.
- Split vnode::v_flag into three fields, depending on how the flag is
locked (by the interlock, by the vnode lock, by the file system).
- Miscellaneous locking fixes and improvements.
 1.34.4.1  05-Apr-2007  ad Compile fixes.
 1.35.6.7  09-Dec-2007  jmcneill Sync with HEAD.
 1.35.6.6  27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.35.6.5  11-Nov-2007  joerg Sync with HEAD.
 1.35.6.4  06-Nov-2007  joerg Sync with HEAD.
 1.35.6.3  26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.35.6.2  02-Oct-2007  joerg Sync with HEAD.
 1.35.6.1  09-Aug-2007  jmcneill Sync with HEAD.
 1.35.2.1  15-Aug-2007  skrll Sync with HEAD.
 1.36.6.2  06-Aug-2007  pooka When resizing a node, first drop extra pages and zero tail, and only
then set the new size. Otherwise zerolen will always be, well, 0.
 1.36.6.1  06-Aug-2007  pooka file tmpfs_subr.c was added on branch matt-mips64 on 2007-08-06 16:08:56 +0000
 1.36.4.2  14-Oct-2007  yamt sync with head.
 1.36.4.1  06-Oct-2007  yamt sync with head.
 1.36.2.4  23-Mar-2008  matt sync with HEAD
 1.36.2.3  09-Jan-2008  matt sync with HEAD
 1.36.2.2  08-Nov-2007  matt sync with -HEAD
 1.36.2.1  06-Nov-2007  matt sync with HEAD
 1.38.4.4  18-Feb-2008  mjf Sync with HEAD.
 1.38.4.3  27-Dec-2007  mjf Sync with HEAD.
 1.38.4.2  08-Dec-2007  mjf Sync with HEAD.
 1.38.4.1  19-Nov-2007  mjf Sync with HEAD.
 1.41.2.8  26-Dec-2007  ad Sync with head.
 1.41.2.7  15-Dec-2007  ad tmpfs_reg_resize: drop swapslots after resizing to work around a panic.
It may not be necessary to drop the swapslots at this point.
 1.41.2.6  15-Dec-2007  ad Fix accounting problem that allowed a tmpfs to be filled beyond its limit
when running multithreaded.
 1.41.2.5  13-Dec-2007  yamt don't leak linkcount on errors.
 1.41.2.4  12-Dec-2007  ad Minor corrections to previous.
 1.41.2.3  12-Dec-2007  ad - Don't use LK_RETRY in tmpfs_alloc_vp().
- Reduce cosmetic diffs to head.
 1.41.2.2  08-Dec-2007  ad Reduce coverage of the per-mount lock by using atomic ops.
 1.41.2.1  04-Dec-2007  ad Pull the vmlocking changes into a new branch.
 1.42.4.1  02-Jan-2008  bouyer Sync with HEAD
 1.46.10.6  11-Aug-2010  yamt sync with head.
 1.46.10.5  11-Mar-2010  yamt sync with head
 1.46.10.4  16-Sep-2009  yamt sync with head
 1.46.10.3  16-May-2009  yamt sync with head
 1.46.10.2  04-May-2009  yamt sync with head.
 1.46.10.1  16-May-2008  yamt sync with head.
 1.46.8.1  18-May-2008  yamt sync with head.
 1.46.6.2  29-Jun-2008  mjf Sync with HEAD.
 1.46.6.1  02-Jun-2008  mjf Sync with HEAD.
 1.47.4.1  27-Jun-2008  simonb Sync with head.
 1.47.2.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.48.10.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.48.6.1  12-Apr-2009  snj Pull up following revision(s) (requested by markd in ticket #689):
sys/fs/tmpfs/tmpfs_subr.c: revision 1.50
For chown make auth checks consistent with UFS. Fixes PR kern/40933.
 1.48.4.1  28-Apr-2009  skrll Sync with HEAD.
 1.56.4.9  31-May-2011  rmind sync with head
 1.56.4.8  31-May-2011  rmind tmpfs_alloc_vp: perform lock sharing only for VREG.
 1.56.4.7  30-May-2011  rmind - Amend getnewvnode(9) to take the lock for sharing, not a vnode.
- Update tmpfs to perform vnode and UVM object lock sharing correctly.
 1.56.4.6  22-May-2011  rmind Fix vnode interlock sharing.
 1.56.4.5  19-May-2011  rmind Implement sharing of vnode_t::v_interlock amongst vnodes:
- Lock is shared amongst UVM objects using uvm_obj_setlock() or getnewvnode().
- Adjust vnode cache to handle unsharing, add VI_LOCKSHARE flag for that.
- Use sharing in tmpfs and layerfs for underlying object.
- Simplify locking in ubc_fault().
- Sprinkle some asserts.

Discussed with ad@.
 1.56.4.4  21-Apr-2011  rmind sync with head
 1.56.4.3  05-Mar-2011  rmind sync with head
 1.56.4.2  03-Jul-2010  rmind sync with head
 1.56.4.1  16-Mar-2010  rmind Change struct uvm_object::vmobjlock to be dynamically allocated with
mutex_obj_alloc(). It allows us to share the locks among UVM objects.
 1.56.2.1  17-Aug-2010  uebayasi Sync with HEAD.
 1.62.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.72.2.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.77.2.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.77.2.1  17-Apr-2012  yamt sync with head
 1.78.2.1  05-Apr-2012  mrg sync to latest -current.
 1.79.4.1  18-May-2014  rmind sync with head
 1.79.2.2  03-Dec-2017  jdolecek update from HEAD
 1.79.2.1  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.96.4.2  08-Nov-2015  riz Pull up following revision(s) (requested by leot in ticket #1023):
sys/fs/tmpfs/tmpfs_subr.c: revision 1.101
Make sure that nde->td_node is NULL for asserts.
Thanks and from Mindaugas Rasiukevicius.
Fixes PR kern/50381.
 1.96.4.1  22-Dec-2014  msaitoh branches: 1.96.4.1.2;
Pull up following revision(s) (requested by gson in ticket #344):
sys/fs/tmpfs/tmpfs_vnops.c: revision 1.121
sys/fs/tmpfs/tmpfs_subr.c: revision 1.97
Store symlinks without a NUL terminator so that lstat(2) returns the
correct length. Fixes the tmpfs part of PR kern/48864.
 1.96.4.1.2.1  08-Nov-2015  riz Pull up following revision(s) (requested by leot in ticket #1023):
sys/fs/tmpfs/tmpfs_subr.c: revision 1.101
Make sure that nde->td_node is NULL for asserts.
Thanks and from Mindaugas Rasiukevicius.
Fixes PR kern/50381.
 1.97.2.4  05-Feb-2017  skrll Sync with HEAD
 1.97.2.3  27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.97.2.2  22-Sep-2015  skrll Sync with HEAD
 1.97.2.1  06-Jun-2015  skrll Sync with HEAD
 1.101.2.1  07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.102.14.2  18-Jan-2019  pgoyette Synch with HEAD
 1.102.14.1  25-Jun-2018  pgoyette Sync with HEAD
 1.102.8.1  01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1872):

sys/fs/tmpfs/tmpfs_subr.c: revision 1.116
sys/fs/tmpfs/tmpfs_subr.c: revision 1.117

tmpfs: Refuse sizes that overflow round_page.

tmpfs: Assert no arithmetic overflow in directory node tn_size.
Need >2^57 directory entries before this is a problem. If we created
a million per second, this would take over 4000 years.
 1.103.2.3  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.103.2.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.103.2.1  10-Jun-2019  christos Sync with HEAD
 1.104.4.1  01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1691):

sys/fs/tmpfs/tmpfs_subr.c: revision 1.116
sys/fs/tmpfs/tmpfs_subr.c: revision 1.117

tmpfs: Refuse sizes that overflow round_page.

tmpfs: Assert no arithmetic overflow in directory node tn_size.
Need >2^57 directory entries before this is a problem. If we created
a million per second, this would take over 4000 years.
 1.105.2.3  29-Feb-2020  ad Sync with head.
 1.105.2.2  24-Jan-2020  ad - Put all the namecache stuff back into vnode_impl_t.
- Tidy vfs_cache.c up, finish the comments.
- Finalise how ID information is entered to the cache.
- Handle very small/old systems.
 1.105.2.1  17-Jan-2020  ad vfs_lookup:

- Do the easy component name lookups directly in the namecache without
taking vnode locks nor vnode references (between the start and the leaf /
parent), which seems to largely solve the lock contention problem with
namei(). It needs support from the file system, which has to tell the
name cache about directory permissions (only ffs and tmpfs tried so far),
and I'm not sure how or if it can work with layered file systems yet.
Work in progress.

vfs_cache:

- Make the rbtree operations more efficient: inline the lookup, and key on a
64-bit hash value (32 bits plus 16 bits length) rather than names.

- Take namecache stuff out of vnode_impl, and take the rwlocks, and put them
all together an an nchnode struct which is mapped 1:1: with vnodes. Saves
memory and nicer cache profile.

- Add a routine to help vfs_lookup do its easy component name lookups.

- Report some more stats.

- Tidy up the file a bit.
 1.108.2.1  25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.114.4.1  01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #289):

sys/fs/tmpfs/tmpfs_subr.c: revision 1.116
sys/fs/tmpfs/tmpfs_subr.c: revision 1.117

tmpfs: Refuse sizes that overflow round_page.

tmpfs: Assert no arithmetic overflow in directory node tn_size.
Need >2^57 directory entries before this is a problem. If we created
a million per second, this would take over 4000 years.

RSS XML Feed