xfs: block reservation too large for minleft allocation
authorDave Chinner <dchinner@redhat.com>
Fri, 10 Feb 2023 17:09:06 +0000 (04:09 +1100)
committerDave Chinner <dchinner@redhat.com>
Fri, 10 Feb 2023 17:09:06 +0000 (04:09 +1100)
commitd5753847b216db0e553e8065aa825cfe497ad143
tree31095502457c471345a7ee7d49e4890daa90af8b
parentf08f984c63e9980614ae3a0a574b31eaaef284b2
xfs: block reservation too large for minleft allocation

When we enter xfs_bmbt_alloc_block() without having first allocated
a data extent (i.e. tp->t_firstblock == NULLFSBLOCK) because we
are doing something like unwritten extent conversion, the transaction
block reservation is used as the minleft value.

This works for operations like unwritten extent conversion, but it
assumes that the block reservation is only for a BMBT split. THis is
not always true, and sometimes results in larger than necessary
minleft values being set. We only actually need enough space for a
btree split, something we already handle correctly in
xfs_bmapi_write() via the xfs_bmapi_minleft() calculation.

We should use xfs_bmapi_minleft() in xfs_bmbt_alloc_block() to
calculate the number of blocks a BMBT split on this inode is going to
require, not use the transaction block reservation that contains the
maximum number of blocks this transaction may consume in it...

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
fs/xfs/libxfs/xfs_bmap.c
fs/xfs/libxfs/xfs_bmap.h
fs/xfs/libxfs/xfs_bmap_btree.c