]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: block reservation too large for minleft allocation
authorDave Chinner <dchinner@redhat.com>
Tue, 9 May 2023 09:29:36 +0000 (11:29 +0200)
committerCarlos Maiolino <cem@kernel.org>
Tue, 9 May 2023 17:53:30 +0000 (19:53 +0200)
Source kernel commit: d5753847b216db0e553e8065aa825cfe497ad143

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>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_bmap.c
libxfs/xfs_bmap.h
libxfs/xfs_bmap_btree.c

index 719aee8edd61eaed184c0993d2e1ccacec140128..def4b7745b0683c98f3561bbbc51568365656a47 100644 (file)
@@ -4235,7 +4235,7 @@ xfs_bmapi_convert_unwritten(
        return 0;
 }
 
-static inline xfs_extlen_t
+xfs_extlen_t
 xfs_bmapi_minleft(
        struct xfs_trans        *tp,
        struct xfs_inode        *ip,
index 01c2df35c3e35a5bfac25b164b39b45b317ea544..524912f276f87857febc10647a9e71e740d18e89 100644 (file)
@@ -220,6 +220,8 @@ int xfs_bmap_add_extent_unwritten_real(struct xfs_trans *tp,
                struct xfs_inode *ip, int whichfork,
                struct xfs_iext_cursor *icur, struct xfs_btree_cur **curp,
                struct xfs_bmbt_irec *new, int *logflagsp);
+xfs_extlen_t xfs_bmapi_minleft(struct xfs_trans *tp, struct xfs_inode *ip,
+               int fork);
 
 enum xfs_bmap_intent_type {
        XFS_BMAP_MAP = 1,
index f0610afdcf38b4db7c65f44d07366e15e26c167a..efc410558a93a8d416b0ea9dce62898cd85561a0 100644 (file)
@@ -211,18 +211,16 @@ xfs_bmbt_alloc_block(
        if (args.fsbno == NULLFSBLOCK) {
                args.fsbno = be64_to_cpu(start->l);
                args.type = XFS_ALLOCTYPE_START_BNO;
+
                /*
-                * Make sure there is sufficient room left in the AG to
-                * complete a full tree split for an extent insert.  If
-                * we are converting the middle part of an extent then
-                * we may need space for two tree splits.
-                *
-                * We are relying on the caller to make the correct block
-                * reservation for this operation to succeed.  If the
-                * reservation amount is insufficient then we may fail a
-                * block allocation here and corrupt the filesystem.
+                * If we are coming here from something like unwritten extent
+                * conversion, there has been no data extent allocation already
+                * done, so we have to ensure that we attempt to locate the
+                * entire set of bmbt allocations in the same AG, as
+                * xfs_bmapi_write() would have reserved.
                 */
-               args.minleft = args.tp->t_blk_res;
+               args.minleft = xfs_bmapi_minleft(cur->bc_tp, cur->bc_ino.ip,
+                                               cur->bc_ino.whichfork);
        } else if (cur->bc_tp->t_flags & XFS_TRANS_LOWMODE) {
                args.type = XFS_ALLOCTYPE_START_BNO;
        } else {
@@ -246,6 +244,7 @@ xfs_bmbt_alloc_block(
                 * successful activate the lowspace algorithm.
                 */
                args.fsbno = 0;
+               args.minleft = 0;
                args.type = XFS_ALLOCTYPE_FIRST_AG;
                error = xfs_alloc_vextent(&args);
                if (error)