]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: tidy up xfs_bmap_broot_realloc a bit
authorDarrick J. Wong <djwong@kernel.org>
Mon, 24 Feb 2025 18:21:45 +0000 (10:21 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 25 Feb 2025 17:15:57 +0000 (09:15 -0800)
Source kernel commit: c914081775e2e39e4afa9b4bb9e5c98202110f51

Hoist out the code that migrates broot pointers during a resize
operation to avoid code duplication and streamline the caller.  Also
use the correct bmbt pointer type for the sizeof operation.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libxfs/xfs_bmap_btree.c

index baae9ab91fa9086b6efdaf6faa2691fa71ca9397..40e0cb3016fc5e680b95ad7c277b7da2ff245192 100644 (file)
@@ -515,6 +515,22 @@ xfs_bmbt_keys_contiguous(
                                 be64_to_cpu(key2->bmbt.br_startoff));
 }
 
+static inline void
+xfs_bmbt_move_ptrs(
+       struct xfs_mount        *mp,
+       struct xfs_btree_block  *broot,
+       short                   old_size,
+       size_t                  new_size,
+       unsigned int            numrecs)
+{
+       void                    *dptr;
+       void                    *sptr;
+
+       sptr = xfs_bmap_broot_ptr_addr(mp, broot, 1, old_size);
+       dptr = xfs_bmap_broot_ptr_addr(mp, broot, 1, new_size);
+       memmove(dptr, sptr, numrecs * sizeof(xfs_bmbt_ptr_t));
+}
+
 /*
  * Reallocate the space for if_broot based on the number of records.  Move the
  * records and pointers in if_broot to fit the new size.  When shrinking this
@@ -540,8 +556,7 @@ xfs_bmap_broot_realloc(
 {
        struct xfs_mount        *mp = ip->i_mount;
        struct xfs_ifork        *ifp = xfs_ifork_ptr(ip, whichfork);
-       char                    *np;
-       char                    *op;
+       struct xfs_btree_block  *broot;
        unsigned int            new_size;
        unsigned int            old_size = ifp->if_broot_bytes;
 
@@ -576,15 +591,11 @@ xfs_bmap_broot_realloc(
                 * they are kept butted up against the btree block header.
                 */
                old_numrecs = xfs_bmbt_maxrecs(mp, old_size, false);
-               xfs_broot_realloc(ifp, new_size);
-               op = (char *)xfs_bmap_broot_ptr_addr(mp, ifp->if_broot, 1,
-                                                    old_size);
-               np = (char *)xfs_bmap_broot_ptr_addr(mp, ifp->if_broot, 1,
-                                                    (int)new_size);
-               ASSERT(xfs_bmap_bmdr_space(ifp->if_broot) <=
+               broot = xfs_broot_realloc(ifp, new_size);
+               ASSERT(xfs_bmap_bmdr_space(broot) <=
                        xfs_inode_fork_size(ip, whichfork));
-               memmove(np, op, old_numrecs * (uint)sizeof(xfs_fsblock_t));
-               return ifp->if_broot;
+               xfs_bmbt_move_ptrs(mp, broot, old_size, new_size, old_numrecs);
+               return broot;
        }
 
        /*
@@ -598,15 +609,11 @@ xfs_bmap_broot_realloc(
         * not butted up against the btree block header, then reallocating
         * broot.
         */
-       op = (char *)xfs_bmap_broot_ptr_addr(mp, ifp->if_broot, 1, old_size);
-       np = (char *)xfs_bmap_broot_ptr_addr(mp, ifp->if_broot, 1,
-                                            (int)new_size);
-       memmove(np, op, new_numrecs * (uint)sizeof(xfs_fsblock_t));
-
-       xfs_broot_realloc(ifp, new_size);
-       ASSERT(xfs_bmap_bmdr_space(ifp->if_broot) <=
+       xfs_bmbt_move_ptrs(mp, ifp->if_broot, old_size, new_size, new_numrecs);
+       broot = xfs_broot_realloc(ifp, new_size);
+       ASSERT(xfs_bmap_bmdr_space(broot) <=
               xfs_inode_fork_size(ip, whichfork));
-       return ifp->if_broot;
+       return broot;
 }
 
 static struct xfs_btree_block *