xfs: don't return too-short extents from xfs_rtallocate_extent_block

If xfs_rtallocate_extent_block is asked for a variable-sized allocation,
it will try to return the best-sized free extent, which is apparently
the largest one that it finds starting in this rtbitmap block.  It will
then trim the size of the extent as needed to align it with prod.

However, it misses one thing -- rounding down the best-fit candidate to
the required alignment could make the extent shorter than minlen.  In
the case where minlen > 1, we'd rather the caller relaxed its alignment
requirements and tried again, as the allocator already supports that.

Returning a too-short extent that causes xfs_bmapi_write to return
ENOSR if there aren't enough nmaps to handle multiple new allocations,
which can then cause filesystem shutdowns.

I haven't seen this happen on any production systems, but then I don't
think it's very common to set a per-file extent size hint on realtime
files.  I tripped it while working on the rtgroups feature and pounding
on the realtime allocator enthusiastically.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Darrick J. Wong 2024-08-30 15:37:02 -07:00
parent 86a0264ef2
commit cb59233e82

View File

@ -289,16 +289,9 @@ xfs_rtallocate_extent_block(
return error;
}
/*
* Searched the whole thing & didn't find a maxlen free extent.
*/
if (minlen > maxlen || besti == -1) {
/*
* Allocation failed. Set *nextp to the next block to try.
*/
*nextp = next;
return -ENOSPC;
}
/* Searched the whole thing & didn't find a maxlen free extent. */
if (minlen > maxlen || besti == -1)
goto nospace;
/*
* If size should be a multiple of prod, make that so.
@ -311,12 +304,20 @@ xfs_rtallocate_extent_block(
bestlen -= p;
}
/* Don't return a too-short extent. */
if (bestlen < minlen)
goto nospace;
/*
* Pick besti for bestlen & return that.
*/
*len = bestlen;
*rtx = besti;
return 0;
nospace:
/* Allocation failed. Set *nextp to the next block to try. */
*nextp = next;
return -ENOSPC;
}
/*