Commit graph

4635 commits

Author SHA1 Message Date
Alexander Motin
3540f6b4af nfsd: Reduce callouts rate.
Before this callouts were scheduled twice a seconds even if nfsd was
never used.  This reduces the rate to ~1Hz and only after nfsd first
started.

MFC after:	2 weeks

(cherry picked from commit 3455c738ac)
2022-01-23 14:57:35 -05:00
Alan Somers
eccfee8330 fusefs: implement VOP_ALLOCATE
Now posix_fallocate will be correctly forwarded to fuse file system
servers, for those that support it.

Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D33389

(cherry picked from commit 398c88c758)
2022-01-17 18:13:28 -07:00
Alan Somers
bfffd35108 fusefs: in the tests, always assume debug.try_reclaim_vnode is available
In an earlier version of the revision that created that sysctl (D20519)
the sysctl was gated by INVARIANTS, so the test had to check for it.
But in the committed version it is always available.

(cherry picked from commit 19ab361045)

fusefs: move common code from forget.cc to utils.cc

(cherry picked from commit 8d99a6b91b)

fusefs: fix .. lookups when the parent has been reclaimed.

By default, FUSE file systems are assumed not to support lookups for "."
and "..".  They must opt-in to that.  To cope with this limitation, the
fusefs kernel module caches every fuse vnode's parent's inode number,
and uses that during VOP_LOOKUP for "..".  But if the parent's vnode has
been reclaimed that won't be possible.  Previously we paniced in this
situation.  Now, we'll return ESTALE instead.  Or, if the file system
has opted into ".." lookups, we'll just do that instead.

This commit also fixes VOP_LOOKUP to respect the cache timeout for ".."
lookups, if the FUSE file system specified a finite timeout.

PR:		259974
Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D33239

(cherry picked from commit 1613087a81)
2022-01-17 18:08:25 -07:00
Alan Somers
449d02a12e fusefs: copy_file_range must update file timestamps
If FUSE_COPY_FILE_RANGE returns successfully, update the atime of the
source and the mtime and ctime of the destination.

Reviewers:	pfg
Differential Revision: https://reviews.freebsd.org/D33159

(cherry picked from commit 5169832c96)
2022-01-17 18:02:55 -07:00
Alan Somers
36ba360558 Fix a race in fusefs that can corrupt a file's size.
VOPs like VOP_SETATTR can change a file's size, with the vnode
exclusively locked.  But VOPs like VOP_LOOKUP look up the file size from
the server without the vnode locked.  So a race is possible.  For
example:

1) One thread calls VOP_SETATTR to truncate a file.  It locks the vnode
   and sends FUSE_SETATTR to the server.
2) A second thread calls VOP_LOOKUP and fetches the file's attributes from
   the server.  Then it blocks trying to acquire the vnode lock.
3) FUSE_SETATTR returns and the first thread releases the vnode lock.
4) The second thread acquires the vnode lock and caches the file's
   attributes, which are now out-of-date.

Fix this race by recording a timestamp in the vnode of the last time
that its filesize was modified.  Check that timestamp during VOP_LOOKUP
and VFS_VGET.  If it's newer than the time at which FUSE_LOOKUP was
issued to the server, ignore the attributes returned by FUSE_LOOKUP.

PR:		259071
Reported by:	Agata <chogata@moosefs.pro>
Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D33158

(cherry picked from commit 13d593a5b0)
2022-01-17 17:59:03 -07:00
Konstantin Belousov
b6f37637d8 msdosfs: use mntfs vnode for pm_devvp
(cherry picked from commit aaaa4fb54e)
2022-01-14 20:11:02 +02:00
Konstantin Belousov
1e74922c68 msdosfs: on integrity error, fire a task to remount filesystem to ro
(cherry picked from commit 41e85eeab9)
2022-01-14 20:11:02 +02:00
Konstantin Belousov
171b75b0ef msdosfs: add msdosfs_integrity_error()
(cherry picked from commit b2e4b63584)
2022-01-14 20:11:02 +02:00
Konstantin Belousov
c5c1537dc7 msdosfs: sanity check sector count from BPB
(cherry picked from commit ba2c98389b)
2022-01-14 20:11:02 +02:00
Konstantin Belousov
c1df4eef12 msdosfs: clusterfree() is used only in error handling cases
(cherry picked from commit 65990b68a2)
2022-01-14 20:11:02 +02:00
Konstantin Belousov
95a83a5fff msdosfs: do no allow lookup to return vdp except for dot lookups
(cherry picked from commit aec97963cd)
2022-01-14 20:11:02 +02:00
Konstantin Belousov
1bcbcd68f5 msdosfs: handle a case when non-dot lookup returned dvp
(cherry picked from commit 1319c433f4)
2022-01-14 20:11:02 +02:00
Konstantin Belousov
472f576064 msdosfs: take inusemap inconsistency as an error, not invariants violation
(cherry picked from commit 2c9a1c22c3)
2022-01-14 20:11:01 +02:00
Konstantin Belousov
bbab525fc1 msdosfs: handle inconsistently hashed denodes
(cherry picked from commit 595ed4d767)
2022-01-14 20:11:01 +02:00
Konstantin Belousov
1a35d94bbb mountmsdosfs(): some style
(cherry picked from commit 04fd468da0)
2022-01-09 03:20:22 +02:00
Alan Somers
8ec62f0614 nfs: don't truncate directory cookies to 32-bits in the NFS server
In NFSv2, the directory cookie was 32-bits.  NFSv3 widened it to
64-bits and SVN r22521 widened the corresponding argument in
VOP_READDIR, but FreeBSD's NFS server continued to treat the cookies as
32-bits, and 0-extended to fill the field on the wire.  Nobody ever
noticed, because every in-tree file system generates cookies that fit
comfortably within 32-bits.

Also, have better type safety for txdr_hyper.  Turn it into an inline
function that type-checks its arguments.  Prevents warnings about
shift-count-overflow.

PR:		260375
Reviewed by:	rmacklem
Differential Revision: https://reviews.freebsd.org/D33404

(cherry picked from commit 32fbc5d824)
2022-01-02 20:09:15 -07:00
Alan Somers
642399932d fusefs: invalidate the cache during copy_file_range
FUSE_COPY_FILE_RANGE instructs the server to write data to a file.
fusefs must invalidate any cached data within the written range.

PR:		260242
Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D33280

(cherry picked from commit 41ae9f9e64)
2022-01-02 20:03:54 -07:00
Alan Somers
d056bc6f40 fusefs: inline fuse_io_dispatch
This function was always confusing, because it created an H-shaped
callgraph: two functions called in and left via different paths based on
which which called.

(cherry picked from commit dc433e1530)
2022-01-02 19:54:39 -07:00
Alan Somers
139764c461 fusefs: correctly handle an inode that changes file types
Correctly handle the situation where a FUSE server unlinks a file, then
creates a new file of a different type but with the same inode number.
Previously fuse_vnop_lookup in this situation would return EAGAIN.  But
since it didn't call vgone(), the vnode couldn't be reused right away.
Fix this by immediately calling vgone() and reallocating a new vnode.

This problem can occur in three code paths, during VOP_LOOKUP,
VOP_SETATTR, or following FUSE_GETATTR, which usually happens during
VOP_GETATTR but can occur during other vops, too.  Note that the correct
response actually doesn't depend on whether the entry cache has expired.
In fact, during VOP_LOOKUP, we can't even tell.  Either it has expired
already, or else the vnode got reclaimed by vnlru.

Also, correct the error code during the VOP_SETATTR path.

PR:		258022
Reported by:	chogata@moosefs.pro
Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D33283

(cherry picked from commit 25927e068f)
2022-01-02 19:36:38 -07:00
Bjoern A. Zeeb
a34668185b modules: increase MAXMODNAME and provide backward compat
With various firmware files used by graphics and wireless drivers
we are exceeding the current 32 character module name (file path
in kldxref) length.
In order to overcome this issue bump it to the maximum path length
for the next version.
To be able to MFC provide backward compat support for another version
of the struct as the offsets for the second half change due to the
array size increase.

MAXMODNAME being defined to MAXPATHLEN needs param.h to be
included first.  With only 7 modules (or LinuxKPI module.h) not
doing that adjust them rather than including param.h in module.h [1].

Reported by:	Greg V (greg unrelenting.technology)
Sponsored by:	The FreeBSD Foundation
Suggested by:	imp [1]
Reviewed by:	imp (and others to different level)
Differential Revision:	https://reviews.freebsd.org/D32383

(cherry picked from commit df38ada293)
2021-12-30 18:26:18 +00:00
Rick Macklem
efc08dab49 nfscl: Handle CB_SEQUENCE not first op correctly
The check for "not first operation" in CB_SEQUENCE
was done after the slot, etc. was updated. This patch
moves the check to the beginning of CB_SEQUENCE
processing.

While here, also fix the check for "no CB_SEQUENCE operation first"
by moving the check to the beginning of callback operation parsing,
since the check was in a couple of the other operations, but
not all of them.

PR:	260412

(cherry picked from commit e0861304a7)
2021-12-29 17:24:55 -08:00
Rick Macklem
7aa23c7b59 rpc: Delete AUTH_NEEDS_TLS(_MUTUAL_HOST) auth_stat values
I thought that these new auth_stat values had been agreed
upon by the IETF NFSv4 working group, but that no longer
is the case.  As such, delete them and use AUTH_TOOWEAK
instead.  Leave the code that uses these new auth_stat
values in the sources #ifdef notnow, in case they are
defined in the future.

(cherry picked from commit 744c2dc7dd)
2021-12-29 17:23:30 -08:00
Rick Macklem
3c3b641a61 nfscl: add a filesize limit check to nfs_allocate()
As reported in PR#260343, nfs_allocate() did not check
the filesize rlimit. This patch adds that check.

PR:	260343

(cherry picked from commit fe04c91184)
2021-12-26 16:55:09 -08:00
Rick Macklem
030acb63d9 nfsd: Limit parsing of layout errors to maxcnt bytes
This patch decrements maxcnt by the appropriate
number of bytes during parsing and checks to see
if there is data remaining.  If not, it just returns
from nfsrv_flexlayouterr() without further processing.
This prevents the tl pointer from running off the end
of the error data pointed at by layp, if there are
flaws in the data.

PR:	260293

(cherry picked from commit c302f889e2)
2021-12-26 16:53:50 -08:00
Rick Macklem
468043bbae nfscl: Fix must_commit handling for mirrored pNFS mounts
For pNFS mounts to mirrored Flexible File layout pNFS servers,
the "must_commit" component in the nfsclwritedsdorpc
structure must be checked and the "must_commit" argument passed
into nfscl_doiods() must be updated.  Technically, only writes to
the DS with a writeverf change must be redone, but since this
occurrence will be rare, the must_commit argument to nfscl_doiosd()
is set to 1, so all writes to all DSs will be redone.

This bug would affect few, since use of mirrored pNFS servers
is rare and "writeverf" rarely changes. Normally "writeverf"
only changes when a NFS server reboots.

(cherry picked from commit 24947b701d)
2021-12-25 18:22:20 -08:00
Rick Macklem
6cccfeaafc nfscl: Fix must_commit/writeverf handling for Direct I/O
Without this patch, the KASSERT(must_commit == 0,..) can be
triggered by the writeverf in the Direct I/O write reply changing.
This is not a situation that should cause a panic(). Correct
handling is to ignore the change in "writeverf" for Direct
I/O, since it is done with NFSWRITE_FILESYNC.

This patch modifies the semantics of the "must_commit"
argument slightly, allowing an initial value of 2 to indicate
that a change in "writeverf" should be ignored.
It also fixes the KASSERT()s.

This bug would affect few, since Direct I/O is not enabled
by default and "writeverf" rarely changes. Normally "writeverf"
only changes when a NFS server reboots, however I found the
bug when testing against a Linux 5.15.1 kernel nfsd, which
replied to a NFSWRITE_FILESYNC write with a "writeverf" of all
0x0 bytes.

(cherry picked from commit ead50c94cb)
2021-12-24 16:33:57 -08:00
Rick Macklem
a41216dbe0 nfscl: Sanity check the callback tag length
The sanity check for tag length in a callback request
was broken in two ways:

It checked for a negative value, but not a large positive
value.

It did not set taglen to -1, to indicate to the code that
it should not be used.

This patch fixes both of these issues.

PR:	260266

(cherry picked from commit d9931c2561)
2021-12-22 17:36:18 -08:00
Rick Macklem
c4ad95fb8e nfscl: Check for an error return from nfsrv_getattrbits()
There were two places where the client code did not check
for a parse error return from nfsrv_getattrbits().

This patch fixes both of these cases.

PR:	260272

(cherry picked from commit ab639f2398)
2021-12-22 17:34:53 -08:00
Rick Macklem
18f5b477ee vfs: Add "ioflag" and "cred" arguments to VOP_ALLOCATE
When the NFSv4.2 server does a VOP_ALLOCATE(), it needs
the operation to be done for the RPC's credential and not
td_ucred. It also needs the writing to be done synchronously.

This patch adds "ioflag" and "cred" arguments to VOP_ALLOCATE()
and modifies vop_stdallocate() to use these arguments.

The VOP_ALLOCATE.9 man page will be patched separately.

(cherry picked from commit f0c9847a6c)
2021-12-18 14:30:25 -08:00
Rick Macklem
f15f29c975 nfsd: Fix Verify for attributes like FilesAvail
When the Verify operation calls nfsv4_loadattr(), it provides
the "struct statfs" information that can be used for doing a
compare for FilesAvail, FilesFree, FilesTotal, SpaceAvail,
SpaceFree and SpaceTotal.  However, the code erroneously
used the "struct nfsstatfs *" argument that is NULL.
This patch fixes these cases to use the correct argument
structure.  For the case of FilesAvail, the code in
nfsv4_fillattr() was factored out into a separate function
called nfsv4_filesavail(), so that it can be called from
nfsv4_loadattr() as well as nfsv4_fillattr().

In fact, most of the code in nfsv4_filesavail() is old
OpenBSD code that does not build/run on FreeBSD, but I
left it in place, in case it is of some use someday.

I am not aware of any extant NFSv4 client that does Verify
on these attributes.

PR:	260176

(cherry picked from commit 2d90ef4714)
2021-12-17 17:36:41 -08:00
Rick Macklem
fac8422a41 nfsd: Sanity check the Layouttype count
PR:	260155

(cherry picked from commit 480be96e1e)
2021-12-17 17:32:47 -08:00
Rick Macklem
6a6b08d464 nfsd: Do not try to cache a reply for NFSERR_BADSLOT
When nfsrv_checksequence() replies NFSERR_BADSLOT,
the value of nd_slotid is not valid.  As such, the
reply cannot be cached in the session.
Do not set ND_HASSEQUENCE for this case.

PR:	260076

(cherry picked from commit 33d0be8a92)
2021-12-14 17:34:05 -08:00
Rick Macklem
081d40b8ea nfsd: Sanity check the ACL attribute
When an ACL is presented to the NFSv4 server in
Setattr or Verify, parsing of the ACL assumed a
sane acecnt and sane sizes for the "who" strings.
This patch adds sanity checks for these.

The patch also fixes handling of an error
return from nfsrv_dissectacl() for one broken
case.

PR:	260111

(cherry picked from commit fd020f197d)
2021-12-14 17:32:27 -08:00
Alan Somers
0bade34633 fusefs: update atime on reads when using cached attributes
When using cached attributes, whether or not the data cache is enabled,
fusefs must update a file's atime whenever it reads from it, so long as
it wasn't mounted with -o noatime.  Update it in-kernel, and flush it to
the server on close or during the next setattr operation.

The downside is that close() will now frequently trigger a FUSE_SETATTR
upcall.  But if you care about performance, you should be using
-o noatime anyway.

Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D33145

(cherry picked from commit 91972cfcdd)

fusefs: fix 32-bit build of the tests after 91972cfcdd

(cherry picked from commit d109559ddb)
2021-12-14 15:15:53 -07:00
Alan Somers
000ce6dee1 fusefs: fix copy_file_range when extending a file
When copy_file_range extends a file, it must update the cached file
size.

Reviewed by:	rmacklem, pfg
Differential Revision: https://reviews.freebsd.org/D33151

(cherry picked from commit 65d70b3bae)
2021-12-14 14:49:56 -07:00
Alan Somers
a28611cfc8 fusefs: delete a redundant getnanouptime
It's been redundant since SVN r346060 added another getnanouptime just
above.

(cherry picked from commit 8fbae6c7bd)
2021-12-14 14:49:18 -07:00
Rick Macklem
3e8081ac88 nfscl: Sanity check the Sequence slotid in reply
The slotid in the Sequence reply must be the same as
in the request.  Check that it is the same and log
a console message if it is not, plus set it to the
correct value.

PR:	260071

(cherry picked from commit 1c15c8c0e9)
2021-12-10 18:28:14 -08:00
Rick Macklem
5b76a6b862 nfsd: Sanity check the len argument for ListXattr
The check for the original len being >= retlen needs to
be done before the "if (nd->nd_repstat == 0)" code, so
that it can be reported as too small.

PR:	260046

(cherry picked from commit 5b430a1323)
2021-12-10 18:26:22 -08:00
Rick Macklem
8e74cc2b4e nfsd: Add checks for layout errors in LayoutReturn
For a LayoutReturn when using the Flexible File Layout,
error reports may be provided in the request.
Sanity check the size of these error reports and
check that they exist before calling nfsrv_flexlayouterr().

PR:	260012

(cherry picked from commit bdd57cbb1b)
2021-12-09 16:55:47 -08:00
Rick Macklem
815a7affac nfscl: Sanity check irdcnt in nfsrpc_createsession
PR:	259996

(cherry picked from commit 22f7bcb523)
2021-12-09 16:54:18 -08:00
Alan Somers
7adb46c70f fusefs: Fix a bug during VOP_STRATEGY when the server changes file size
If the FUSE server tells the kernel that a file's size has changed, then
the kernel must invalidate any portion of that file in cache.  But the
kernel can't do that during VOP_STRATEGY, because the file's buffers are
already locked.  Instead, proceed with the write.

PR:		256937
Reported by:	Agata <chogata@moosefs.pro>
Tested by:	Agata <chogata@moosefs.pro>
Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D32332

(cherry picked from commit 032a5bd55b)
2021-12-06 22:14:10 -07:00
Alan Somers
bdd7a3f2a1 fusefs: fix a recurse-on-non-recursive lockmgr panic
fuse_vnop_bmap needs to know the file's size in order to calculate the
optimum amount of readahead.  If the file's size is unknown, it must ask
the FUSE server.  But if the file's data was previously cached and the
server reports that its size has shrunk, fusefs must invalidate the
cached data.  That's not possible during VOP_BMAP because the buffer
object is already locked.

Fix the panic by not querying the FUSE server for the file's size during
VOP_BMAP if we don't need it.  That's also a a slight performance
optimization.

PR:		256937
Reported by:	Agata <chogata@moosefs.pro>
Tested by:	Agata <chogata@moosefs.pro>

(cherry picked from commit 7430017b99)
2021-12-06 22:08:32 -07:00
Alan Somers
94b01af1e5 fusefs: quiet some cache-related warnings
If the FUSE server does something that would make our cache incoherent,
we should print a warning to the user.  However, we previously warned in
some situations when we shouldn't, such as if the file's size changed on
the server _after_ our own attribute cache had expired.  This change
suppresses the warning in cases like that.  It also moves the warning
logic to a single place within the code.

PR:		256936
Reported by:	Agata <chogata@moosefs.pro>
Tested by:	Agata <chogata@moosefs.pro>, jSML4ThWwBID69YC@protonmail.com

(cherry picked from commit 5d94aaacb5)
2021-12-06 22:04:44 -07:00
Alan Somers
dfb3365aa1 fusefs: implement FUSE_NO_OPEN_SUPPORT and FUSE_NO_OPENDIR_SUPPORT
For file systems that allow it, fusefs will skip FUSE_OPEN,
FUSE_RELEASE, FUSE_OPENDIR, and FUSE_RELEASEDIR operations, a minor
optimization.

Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D32141

(cherry picked from commit 7124d2bc3a)
2021-12-06 21:51:55 -07:00
Alan Somers
8254f96698 fusefs: diff reduction in fuse_kernel.h
Synchronize formatting and documentation in fuse_kernel.h with upstream
sources.

Reviewed by:	pfg
Differential Revision:	https://reviews.freebsd.org/D32141

(cherry picked from commit a3a1ce3794)
2021-12-06 21:50:01 -07:00
Neel Chauhan
c0e1884b11 ext2: Check for e2fs_first_dblock in ext2_compute_sb_data()
This prevents a kernel panic on a damaged ext2 superblock.

PR:			259107
Reported by:		Robert Morris <rtm@lcs.mit.edu>
Differential Revision:	https://reviews.freebsd.org/D33029

(cherry picked from commit 3dd3a395ba)
2021-12-04 14:34:20 -08:00
Neel Chauhan
5c50e93e6c ext2fs: check for eh_depth in ext4_ext_check_header()
PR:			259112
Reported by:		Robert Morris <rtm@lcs.mit.edu>
Reviewed by:		fsu (src)
Differential Revision:	https://reviews.freebsd.org/D33030

(cherry picked from commit be60d8f276)
2021-11-29 09:56:42 -08:00
Rick Macklem
0aa59ac827 pNFS: Add nfsstats counters for number of Layouts
For pNFS, Layouts are issued by the server to indicate
where a file's data resides on the DS(s).  This patch
adds counters for how many layouts are allocated to
the nfsstatsv1 structure, using two reserved fields.

(cherry picked from commit ce9676de86)
2021-11-26 18:20:16 -08:00
Rick Macklem
6e8e261f0d nfscl: Add a LayoutError RPC for NFSv4.2 pNFS mounts
If a pNFS server's DS runs out of disk space, it replies
NFSERR_NOSPC to the client doing writing.  For the Linux
client, it then sends a LayoutError RPC to the MDS server to
tell it about the error.  This patch adds the same to the
FreeBSD NFSv4.2 pNFS client, to maintain Linux compatible
behaviour, particlularily for non-FreeBSD pNFS servers.

(cherry picked from commit 44744f7538)
2021-11-24 16:32:09 -08:00
Rick Macklem
354988ca3f nfsd: Fix the NFSv4.2 pNFS MDS server for NFSERR_NOSPC via LayoutError
If a pNFS server's DS runs out of disk space, it replies
NFSERR_NOSPC to the client doing writing.  For the Linux
client, it then sends a LayoutError RPC to the MDS server to
tell it about the error and keeps retrying, doing repeated
LayoutGets to the MDS and Write RPCs to the DS.  The Linux client is
"stuck" until disk space on the DS is free'd up unless
a subsequent LayoutGet request is sent a NFSERR_NOSPC
reply.
The looping problem still occurs for NFSv4.1 mounts, but no
fix for this is known at this time.

This patch changes the pNFS MDS server to reply to LayoutGet
operations with NFSERR_NOSPC once a LayoutError reports the
problem, until the DS has available space.  This keeps the Linux
NFSv4.2 from looping.

Found during recent testing because of issues w.r.t. a DS
being out of space found during a recent IEFT NFSv4 working
group testing event.

(cherry picked from commit f8dc06303b)
2021-11-24 14:35:03 -08:00