Commit Graph

344 Commits

Author SHA1 Message Date
Warner Losh
685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh
dfc016587a sys: Remove $FreeBSD$: two-line .c pattern
Remove /^#include\s+<sys/cdefs.h>.*$\n\s+__FBSDID\("\$FreeBSD\$"\);\n/
2023-08-16 11:54:30 -06:00
Warner Losh
95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Konstantin Belousov
765ad5b28d tmpfs: add the "pgread" mount option to the allowed options list for mount
Fixes:	0f613ab85e
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-08-11 21:01:49 +03:00
Konstantin Belousov
0f613ab85e tmpfs: add a knob to enable pgcache read for mount
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41334
2023-08-09 06:54:15 +03:00
Mateusz Guzik
ba8cc6d727 vfs: use __enum_uint8 for vtype and vstate
This whacks hackery around only reading v_type once.

Bump __FreeBSD_version to 1400093
2023-07-05 15:06:30 +00:00
Warner Losh
b61a573019 spdx: The BSD-2-Clause-NetBSD identifier is obsolete, drop -NetBSD
The SPDX folks have obsoleted the BSD-2-Clause-NetBSD 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
2023-05-12 10:44:04 -06:00
Mateusz Guzik
5e954b9216 tmpfs: add missing vop_fplookup ops to tmpfs_fifoop_entries
Reported by:	gbe
PR:	270917
2023-04-18 18:06:30 +00:00
Konstantin Belousov
15df90218b tmpfs: support the nosymfollow mount option
PR:	269772
Reported by:	firk@cantconnect.ru
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-02-23 15:15:17 +02:00
Konstantin Belousov
b918ee2ce4 tmpfs: remove IFF macro
Requested by:	mjg
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D38576
2023-02-15 02:57:41 +02:00
Konstantin Belousov
9ff2fbdf2d tmpfs: remove bogus MPASS(VOP_ISLOCKED(vp)) asserts
VOP_ISLOCKED() does not return bool, its only reliable use it to check
that the vnode is exclusively locked by the calling thread.  Almost all
asserts of this form repeated auto-generated assertions from
vnode_if.src for VOPs, in the incorrect way.

In two places where the assertions would be meaningful, convert them to
ASSERT_VOP_LOCKED() statements.

Reviewed by:	markj, mjg
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D38576
2023-02-15 02:57:40 +02:00
Konstantin Belousov
3a3450eda6 tmpfs_rename(): use tmpfs_access_locked instead of VOP_ACCESS()
Protect the call with the node lock. We cannot lock the fvp vnode
sleepable there, because we already own other participating vnode's
locks. Taking it without sleeping require unwinding the whole locking
state in one more place.

Note that the liveness of the node is guaranteed by the lock on the
parent directory vnode.

Reported and tested by:	pho
Fixes:	cbac1f3464956185cf95955344b6009e2cc3ae40ESC
Reviewed by:	markj, mjg
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D38557
2023-02-14 01:16:38 +02:00
Konstantin Belousov
adc3506d56 Extract tmpfs-specific part of tmpfs_access() into a helper
The helper tmpfs_access_locked() requires either the vnode or node
locked for consistency of the access check, unlike the pure vnode op.

Reviewed by:	markj, mjg
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D38557
2023-02-14 01:16:38 +02:00
Konstantin Belousov
889f074601 tmpfs_access(): style fixes and remove redundand assertions
Note that MPASS(VOP_ISLOCKED(vp)) is simply broken.

Reviewed by:	markj, mjg
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D38557
2023-02-14 01:16:38 +02:00
Fedor Uporov
cbac1f3464 Fix pjfstest issue tests/rename/09.t
Fix rename when renamed directory not owned by user,
but when user owns the sticky parent directory.

Reviewed by:    kib
MFC after:      2 week
Differential revision:  https://reviews.freebsd.org/D38245
2023-02-11 10:01:16 +03:00
Fedor Uporov
56242a4c65 Add extended attributes
The extattrs follows semantic of ufs, mean it cannot
be set to char/block devices and fifos. The attributes
are allocated using regular malloc with M_WAITOK
allocation with the own malloc tag M_TMPFSEA. The memory
consumed by extended attributes is limited to avoid OOM
triggereing by tmpfs_mount variable tm_ea_memory_max,
which is set initialy to 16 MB. The extended attributes
entries are stored as linked list in the tmpfs node.
The mount point lock is required only under setextattr
and deleteextattr to update extended attributes
memory-inuse counter, all other operations are doing
under vnode lock.

Reviewed by:    kib
MFC after:      2 week
Differential revision:  https://reviews.freebsd.org/D38052
2023-01-29 11:13:14 +03:00
Fedor Uporov
0de4895aac Fix pjfstest issue tests/rename/23.t
This test creates two files like file0 and file1,
then creates link to file1 and checks ctime on it.
Then renames file0 to file1. Then checks ctime on
link again. It is expected, that second ctime will
be higher then first ctime, because rename happen.
Add ctime updating for directory entry,
which will be deleted on rename.

Reviewed by:    kib
MFC after:      2 week
Differential revision:  https://reviews.freebsd.org/D38051
2023-01-29 11:12:32 +03:00
Fedor Uporov
9ad2d4c490 Fix pjfstest issue tests/rename/19.t
The rename call with args like:
"./dir0/dir1/.." "./dir2" will cause MPASS failure.
The tmpfs_dir_lookup() does not accept names like
'.' and '..' for lookup. Move the '.' and '..' entry
check before tmpfs_dir_lookup() call.

Reviewed by:    kib
MFC after:      2 week
Differential revision:  https://reviews.freebsd.org/D38051
2023-01-29 11:11:23 +03:00
Konstantin Belousov
1d9f3a37eb Stop cleaning MNT_LOCAL on unmount
There is no point in clearing just this flag.  Flags are reset on the
struct mount re-allocation for reuse anyway.

Reviewed by:	mckusick
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37966
2023-01-14 20:28:11 +02:00
Mateusz Guzik
829f0bcb5f vfs: add the concept of vnode state transitions
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
2022-12-26 17:35:12 +00:00
Konstantin Belousov
860399eb86 tmpfs: update changed/modified timestamps for truncates that do not change size
While there, move all error checks into the common place at the start,
and eliminate the 'out' label.

PR:	268528
Analyzed and tested by:	Mark Millard <marklmi@yahoo.com>
Reviewed by:	mckusick
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37866
2022-12-24 08:32:48 +02:00
Konstantin Belousov
4d903a1a74 tmpfs_getattr(): Only take vm_object lock on 32bit machines
Torn reads are only possible for 32bit arches.

Requested by:	mjg
Reviewed by:	mjg, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37725
2022-12-17 19:01:56 +02:00
Konstantin Belousov
37aea2649f tmpfs: for used pages, account really allocated pages, instead of file sizes
This makes tmpfs size accounting correct for the sparce files. Also
correct report st_blocks/va_bytes. Previously the reported value did not
accounted for the swapped out pages.

PR:	223015
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37097
2022-12-09 14:17:12 +02:00
Konstantin Belousov
d9dc64f158 tmpfs: make vm_object point to the tmpfs node instead of vnode
The vnode could be reclaimed and allocated again during the lifecycle of
the node, but the node cannot.  Also, referencing the node would allow
to reach it and tmpfs mount data from the object, regardless of the
state of the possibly absent vnode.

Still use swp_tmpfs for back-pointer, instead of using handle. Use of
named swap objects would incur taking the sw_alloc_sx on node allocation
and deallocation.

swp_tmpfs is renamed to swp_priv to remove the last bit of tmpfs in vm/.

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37097
2022-12-09 14:15:37 +02:00
Konstantin Belousov
83aff0f08c Add 'show tmpfs' ddb command
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37097
2022-12-09 14:15:37 +02:00
Konstantin Belousov
e77f2f9dc6 tmpfs: minor style
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37097
2022-12-09 14:15:37 +02:00
Konstantin Belousov
e9adbcdf2e tmpfs: report minimal hole size
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37024
2022-10-19 20:24:07 +03:00
Konstantin Belousov
85cff1455a tmpfs: implement FIOSEEKDATA and FIOSEEKHOLE
providing the support for lseek(2) SEEK_DATA and SEEK_HOLE.

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37024
2022-10-19 20:24:07 +03:00
Konstantin Belousov
8b32cdec9c tmpfs: order include files alphabetically
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37024
2022-10-19 20:24:07 +03:00
Konstantin Belousov
7f055843ac tmpfs: change return type of tmpfs_pages_check_avail() to bool
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37024
2022-10-19 20:24:07 +03:00
Konstantin Belousov
8bdb2695d6 tmpfs: truncate write if it would exceed the fs max file size or RLIMIT_FSIZE
PR:	164793
Reviewed by:	asomers, jah, markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D36625
2022-09-24 19:42:05 +03:00
Konstantin Belousov
b5b16659c5 tmpfs: disallow truncation to set file size past RLIMIT_FSIZE
PR:	164793
Reviewed by:	asomers, jah, markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D36625
2022-09-24 19:41:30 +03:00
Konstantin Belousov
cc65a412ae filesystems: return error from vn_rlimit_fsize() instead of EFBIG
Reviewed by:	asomers, jah, markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D36625
2022-09-24 19:41:14 +03:00
Konstantin Belousov
0f01fb01c2 tmpfs_subr.c: some style
Use 'td' as the local thread name.
Wrap long lines.
Remove unneeded blank lines.

Reviewed by:	asomers, jah, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D36625
2022-09-24 19:41:08 +03:00
Mateusz Guzik
5b5b7e2ca2 vfs: always retain path buffer after lookup
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
2022-09-17 09:10:38 +00:00
Gordon Bergling
d81e1b4429 tmpfs(5): Remove a double word in a source code comment
- s/the the/the/

MFC after:	3 days
2022-09-04 13:51:50 +02:00
Konstantin Belousov
66c5fbca77 insmntque1(): remove useless arguments
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
2022-01-31 16:49:08 +02:00
Mateusz Guzik
2a7e4cf843 Revert b58ca5df0b ("vfs: remove the now unused insmntque1")
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
2022-01-27 16:32:22 +00:00
Mateusz Guzik
5ccdfdabc8 tmpfs: stop using insmntque1
It adds nothing of value over insmntque.
2022-01-27 00:56:12 +01:00
Alan Somers
b214fcceac Change VOP_READDIR's cookies argument to a **uint64_t
The cookies argument is only used by the NFS server.  NFSv2 defines the
cookie as 32 bits on the wire, but NFSv3 increased it to 64 bits.  Our
VOP_READDIR, however, has always defined it as u_long, which is 32 bits
on some architectures.  Change it to 64 bits on all architectures.  This
doesn't matter for any in-tree file systems, but it matters for some
FUSE file systems that use 64-bit directory cookies.

PR:             260375
Reviewed by:    rmacklem
Differential Revision: https://reviews.freebsd.org/D33404
2021-12-15 20:54:57 -07:00
Mateusz Guzik
4dcdf3987c vfs: replace the MNTK_TEXT_REFS flag with VIRF_TEXT_REF
This allows to stop maintaing the VI_TEXT_REF flag and consequently
opens up fully lockless v_writecount adjustment.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D33127
2021-11-27 23:07:25 +00:00
Mateusz Guzik
1879021942 tmpfs: add vop_stdadd_writecount_nomsync to fifo vnode ops
Reported by:	yasu
Fixes: 3ffcfa599e ("vfs: add vop_stdadd_writecount_nomsync")
2021-11-26 19:32:35 +00:00
Mateusz Guzik
3ffcfa599e vfs: add vop_stdadd_writecount_nomsync
This avoids needing to inspect the mount point every time.

Reviewed by:	kib (previous version)
Differential Revision:	https://reviews.freebsd.org/D33125
2021-11-26 12:06:08 +00:00
Konstantin Belousov
80bca63cf4 tmpfs: remove write-only variables
Reviewed by:	imp, mjg
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32577
2021-10-20 21:29:49 +03:00
Mateusz Guzik
b4a58fbf64 vfs: remove cn_thread
It is always curthread.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D32453
2021-10-11 13:21:47 +00:00
Ka Ho Ng
8d7cd10ba6 tmpfs: Implement VOP_DEALLOCATE
Implementing VOP_DEALLOCATE to allow hole-punching in the same manner as
POSIX shared memory's fspacectl(SPACECTL_DEALLOC) support.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D31684
2021-08-26 05:34:54 +08:00
Ka Ho Ng
399be91098 tmpfs: Move partial page invalidation to a separate helper
The partial page invalidation code is factored out to be a separate
helper from tmpfs_reg_resize().

Sponsored by:	The FreeBSD Foundation
Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31683
2021-08-26 05:34:54 +08:00
Ka Ho Ng
a48416f844 tmpfs: Fix error being cleared after commit c12118f6ce
In tmpfs_link() error was erroneously cleared in commit c12118f6ce.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
MFC with:	c12118f6ce
2021-08-25 00:35:29 +08:00
Ka Ho Ng
c12118f6ce tmpfs: Fix styles
A lot of return statements were in the wrong style before this commit.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2021-08-24 22:45:08 +08:00
Mateusz Guzik
f4aa64528e tmpfs: save on relocking the allnode lock in tmpfs_free_node_locked 2021-05-31 23:21:15 +00:00