]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: move the zero records logic into xfs_bmap_broot_space_calc
authorDarrick J. Wong <djwong@kernel.org>
Wed, 29 May 2024 04:11:28 +0000 (21:11 -0700)
committerChristoph Hellwig <hch@lst.de>
Mon, 12 Aug 2024 07:35:28 +0000 (09:35 +0200)
The bmap btree cannot ever have zero records in an incore btree block.
If the number of records drops to zero, that means we're converting the
fork to extents format and are trying to remove the tree.  This logic
won't hold for the future realtime rmap btree, so move the logic into
the bmbt code.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
fs/xfs/libxfs/xfs_bmap_btree.h
fs/xfs/libxfs/xfs_inode_fork.c

index 921c3e02469dd0ef1afcf2d32b8c48bed74de7de..a187f4b120ea19b868e6e25b1e3a18a3332f888f 100644 (file)
@@ -163,6 +163,13 @@ xfs_bmap_broot_space_calc(
        struct xfs_mount        *mp,
        unsigned int            nrecs)
 {
+       /*
+        * If the bmbt root block is empty, we should be converting the fork
+        * to extents format.  Hence, the size is zero.
+        */
+       if (nrecs == 0)
+               return 0;
+
        return xfs_bmbt_block_len(mp) + \
               (nrecs * (sizeof(struct xfs_bmbt_key) + sizeof(xfs_bmbt_ptr_t)));
 }
index 58135d238754ed84382eef53b73b3e5a2c8b32be..1f348ffa69c042be6adcdbed5966f98f3f82bb8d 100644 (file)
@@ -506,10 +506,8 @@ xfs_iroot_realloc(
        cur_max = xfs_bmbt_maxrecs(mp, old_size, 0);
        new_max = cur_max + rec_diff;
        ASSERT(new_max >= 0);
-       if (new_max > 0)
-               new_size = xfs_bmap_broot_space_calc(mp, new_max);
-       else
-               new_size = 0;
+
+       new_size = xfs_bmap_broot_space_calc(mp, new_max);
        if (new_size == 0) {
                xfs_iroot_free(ip, whichfork);
                return;