fusefs: better handling for low-memory conditions

Under conditions of low memory, getblk can fail.  fusefs was not
handling those failures very systematically.  It was always using
PCATCH, which appears to have been originally copy/pasted from the NFS
client code, but isn't always appropriate:

* During fuse_vnode_setsize_immediate, which can be called from many
  different VOPs and from the vn_delayed_setsize mechanism, remove
  PCATCH.  Some of these callers cannot tolerate allocate failure.

* In fuse_inval_buf_range, don't assume that getblk will always succeed.

* When calling fuse_inval_buf_range from VOP_ALLOCATE,
  VOP_COPY_FILE_RANGE, or VOP_WRITE (with IO_DIRECT), return EINTR if
  the allocation fails.

* When calling fuse_inval_buf_range from VOP_DEALLOCATE, remove PCATCH.
  This VOP must not fail with EINTR.

No new tests, because I can't force any particular getblk call to fail.

PR:		293957
Sponsored by:	ConnectWise
Reported by:	zjk7@wp.pl
MFC after:	1 week
This commit is contained in:
Alan Somers
2026-03-30 08:22:07 -06:00
parent c8c9324c94
commit 374548e930
2 changed files with 18 additions and 12 deletions
+1 -5
View File
@@ -506,11 +506,7 @@ fuse_vnode_setsize_immediate(struct vnode *vp, bool shrink)
*/ */
lbn = newsize / iosize; lbn = newsize / iosize;
bp = getblk(vp, lbn, iosize, PCATCH, 0, 0); bp = getblk(vp, lbn, iosize, 0, 0, 0);
if (!bp) {
err = EINTR;
goto out;
}
if (!(bp->b_flags & B_CACHE)) if (!(bp->b_flags & B_CACHE))
goto out; /* Nothing to do */ goto out; /* Nothing to do */
MPASS(bp->b_flags & B_VMIO); MPASS(bp->b_flags & B_VMIO);
+17 -7
View File
@@ -327,7 +327,8 @@ fuse_fifo_close(struct vop_close_args *ap)
/* Invalidate a range of cached data, whether dirty of not */ /* Invalidate a range of cached data, whether dirty of not */
static int static int
fuse_inval_buf_range(struct vnode *vp, off_t filesize, off_t start, off_t end) fuse_inval_buf_range(struct vnode *vp, off_t filesize, off_t start, off_t end,
int slpflag)
{ {
struct buf *bp; struct buf *bp;
daddr_t left_lbn, end_lbn, right_lbn; daddr_t left_lbn, end_lbn, right_lbn;
@@ -339,7 +340,9 @@ fuse_inval_buf_range(struct vnode *vp, off_t filesize, off_t start, off_t end)
end_lbn = howmany(end, iosize); end_lbn = howmany(end, iosize);
left_on = start & (iosize - 1); left_on = start & (iosize - 1);
if (left_on != 0) { if (left_on != 0) {
bp = getblk(vp, left_lbn, iosize, PCATCH, 0, 0); bp = getblk(vp, left_lbn, iosize, slpflag, 0, 0);
if (!bp)
return (EINTR);
if ((bp->b_flags & B_CACHE) != 0 && bp->b_dirtyend >= left_on) { if ((bp->b_flags & B_CACHE) != 0 && bp->b_dirtyend >= left_on) {
/* /*
* Flush the dirty buffer, because we don't have a * Flush the dirty buffer, because we don't have a
@@ -358,7 +361,9 @@ fuse_inval_buf_range(struct vnode *vp, off_t filesize, off_t start, off_t end)
right_lbn = end / iosize; right_lbn = end / iosize;
new_filesize = MAX(filesize, end); new_filesize = MAX(filesize, end);
right_blksize = MIN(iosize, new_filesize - iosize * right_lbn); right_blksize = MIN(iosize, new_filesize - iosize * right_lbn);
bp = getblk(vp, right_lbn, right_blksize, PCATCH, 0, 0); bp = getblk(vp, right_lbn, right_blksize, slpflag, 0, 0);
if (!bp)
return (EINTR);
if ((bp->b_flags & B_CACHE) != 0 && bp->b_dirtyoff < right_on) { if ((bp->b_flags & B_CACHE) != 0 && bp->b_dirtyoff < right_on) {
/* /*
* Flush the dirty buffer, because we don't have a * Flush the dirty buffer, because we don't have a
@@ -726,7 +731,10 @@ fuse_vnop_allocate(struct vop_allocate_args *ap)
err = fuse_vnode_size(vp, &filesize, cred, curthread); err = fuse_vnode_size(vp, &filesize, cred, curthread);
if (err) if (err)
return (err); return (err);
fuse_inval_buf_range(vp, filesize, *offset, *offset + *len); err = fuse_inval_buf_range(vp, filesize, *offset, *offset + *len,
PCATCH);
if (err)
return (err);
fdisp_init(&fdi, sizeof(*ffi)); fdisp_init(&fdi, sizeof(*ffi));
fdisp_make_vp(&fdi, FUSE_FALLOCATE, vp, curthread, cred); fdisp_make_vp(&fdi, FUSE_FALLOCATE, vp, curthread, cred);
@@ -1020,7 +1028,7 @@ fuse_vnop_copy_file_range(struct vop_copy_file_range_args *ap)
vnode_pager_clean_sync(invp); vnode_pager_clean_sync(invp);
err = fuse_inval_buf_range(outvp, outfilesize, *ap->a_outoffp, err = fuse_inval_buf_range(outvp, outfilesize, *ap->a_outoffp,
*ap->a_outoffp + io.uio_resid); *ap->a_outoffp + io.uio_resid, PCATCH);
if (err) if (err)
goto unlock; goto unlock;
@@ -2672,7 +2680,7 @@ fuse_vnop_write(struct vop_write_args *ap)
end = start + uio->uio_resid; end = start + uio->uio_resid;
if (!pages) { if (!pages) {
err = fuse_inval_buf_range(vp, filesize, start, err = fuse_inval_buf_range(vp, filesize, start,
end); end, PCATCH);
if (err) if (err)
goto out; goto out;
} }
@@ -3206,7 +3214,9 @@ fuse_vnop_deallocate(struct vop_deallocate_args *ap)
err = fuse_vnode_size(vp, &filesize, cred, curthread); err = fuse_vnode_size(vp, &filesize, cred, curthread);
if (err) if (err)
goto out; goto out;
fuse_inval_buf_range(vp, filesize, *offset, *offset + *len); err = fuse_inval_buf_range(vp, filesize, *offset, *offset + *len, 0);
if (err)
goto out;
fdisp_init(&fdi, sizeof(*ffi)); fdisp_init(&fdi, sizeof(*ffi));
fdisp_make_vp(&fdi, FUSE_FALLOCATE, vp, curthread, cred); fdisp_make_vp(&fdi, FUSE_FALLOCATE, vp, curthread, cred);