]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: move rtbitmap/summary initialization to libxfs xfs-rt-cleanups
authorChristoph Hellwig <hch@lst.de>
Sun, 14 Jul 2024 16:03:29 +0000 (18:03 +0200)
committerChristoph Hellwig <hch@lst.de>
Thu, 18 Jul 2024 06:40:32 +0000 (08:40 +0200)
Move the rtbitmap/summary block initialization to libxfs after
refactoring it a bit.

Signed-off-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_rtbitmap.c
fs/xfs/libxfs/xfs_rtbitmap.h
fs/xfs/xfs_rtalloc.c

index 9fb18172803370fe04c4a04346bc7a5b6142eaf0..cdd5cdd91fef592445feca764d0555e484af7f7e 100644 (file)
@@ -13,6 +13,8 @@
 #include "xfs_mount.h"
 #include "xfs_inode.h"
 #include "xfs_bmap.h"
+#include "xfs_bmap_btree.h"
+#include "xfs_trans_space.h"
 #include "xfs_trans.h"
 #include "xfs_rtalloc.h"
 #include "xfs_error.h"
@@ -1326,3 +1328,130 @@ xfs_rtbitmap_unlock_shared(
        if (rbmlock_flags & XFS_RBMLOCK_BITMAP)
                xfs_iunlock(mp->m_rbmip, XFS_ILOCK_SHARED);
 }
+
+static int
+xfs_rtfile_alloc_blocks(
+       struct xfs_inode        *ip,
+       xfs_fileoff_t           offset_fsb,
+       xfs_filblks_t           count_fsb,
+       struct xfs_bmbt_irec    *map)
+{
+       struct xfs_mount        *mp = ip->i_mount;
+       struct xfs_trans        *tp;
+       int                     nmap = 1;
+       int                     error;
+
+       error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtalloc,
+                       XFS_GROWFSRT_SPACE_RES(mp, count_fsb), 0, 0, &tp);
+       if (error)
+               return error;
+
+       xfs_ilock(ip, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+
+       error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK,
+                               XFS_IEXT_ADD_NOSPLIT_CNT);
+       if (error)
+               goto out_trans_cancel;
+
+       error = xfs_bmapi_write(tp, ip, offset_fsb, count_fsb,
+                       XFS_BMAPI_METADATA, 0, map, &nmap);
+       if (error)
+               goto out_trans_cancel;
+
+       return xfs_trans_commit(tp);
+
+out_trans_cancel:
+       xfs_trans_cancel(tp);
+       return error;
+}
+
+/* Get a buffer for the block. */
+static int
+xfs_rtfile_initialize_block(
+       struct xfs_inode        *ip,
+       xfs_fsblock_t           fsbno,
+       enum xfs_blft           buf_type)
+{
+       struct xfs_mount        *mp = ip->i_mount;
+       struct xfs_trans        *tp;
+       struct xfs_buf          *bp;
+       int                     error;
+
+       error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtzero, 0, 0, 0, &tp);
+       if (error)
+               return error;
+       xfs_ilock(ip, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+
+       error = xfs_trans_get_buf(tp, mp->m_ddev_targp,
+                       XFS_FSB_TO_DADDR(mp, fsbno), mp->m_bsize, 0, &bp);
+       if (error) {
+               xfs_trans_cancel(tp);
+               return error;
+       }
+
+       xfs_trans_buf_set_type(tp, bp, buf_type);
+       bp->b_ops = xfs_rtblock_ops(mp, buf_type == XFS_BLFT_RTSUMMARY_BUF);
+       memset(bp->b_addr, 0, mp->m_sb.sb_blocksize);
+
+       if (xfs_has_rtgroups(mp)) {
+               struct xfs_rtbuf_blkinfo        *hdr = bp->b_addr;
+
+               if (buf_type == XFS_BLFT_RTBITMAP_BUF)
+                       hdr->rt_magic = cpu_to_be32(XFS_RTBITMAP_MAGIC);
+               else
+                       hdr->rt_magic = cpu_to_be32(XFS_RTSUMMARY_MAGIC);
+               hdr->rt_owner = cpu_to_be64(ip->i_ino);
+               hdr->rt_blkno = cpu_to_be64(xfs_buf_daddr(bp));
+               uuid_copy(&hdr->rt_uuid, &mp->m_sb.sb_meta_uuid);
+       }
+
+       xfs_trans_log_buf(tp, bp, 0, mp->m_sb.sb_blocksize - 1);
+       return xfs_trans_commit(tp);
+}
+
+/*
+ * Allocate space to the bitmap or summary file, and zero it, for growfs.
+ */
+int
+xfs_rtfile_initialize_blocks(
+       struct xfs_inode        *ip,            /* inode (bitmap/summary) */
+       xfs_fileoff_t           offset_fsb,     /* offѕet to start from */
+       xfs_fileoff_t           end_fsb)        /* offѕet to allocate to */
+{
+       struct xfs_mount        *mp = ip->i_mount;
+       enum xfs_blft           buf_type;
+
+       if (ip == mp->m_rsumip)
+               buf_type = XFS_BLFT_RTSUMMARY_BUF;
+       else
+               buf_type = XFS_BLFT_RTBITMAP_BUF;
+
+       while (offset_fsb < end_fsb) {
+               struct xfs_bmbt_irec    map;
+               xfs_filblks_t           i;
+               int                     error;
+
+               error = xfs_rtfile_alloc_blocks(ip, offset_fsb,
+                               end_fsb - offset_fsb, &map);
+               if (error)
+                       return error;
+
+               /*
+                * Now we need to clear the allocated blocks.
+                *
+                * Do this one block per transaction, to keep it simple.
+                */
+               for (i = 0; i < map.br_blockcount; i++) {
+                       error = xfs_rtfile_initialize_block(ip,
+                                       map.br_startblock + i, buf_type);
+                       if (error)
+                               return error;
+               }
+
+               offset_fsb = map.br_startoff + map.br_blockcount;
+       }
+
+       return 0;
+}
index f5bb1ef7df7cce8885de5709b857bc3f05f8ec97..4c718ca19d41a7e131091e4e85c216f08a5d9f29 100644 (file)
@@ -400,6 +400,9 @@ xfs_filblks_t xfs_rtsummary_blockcount(struct xfs_mount *mp,
 unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp,
                unsigned int rsumlevels, xfs_extlen_t rbmblocks);
 
+int xfs_rtfile_initialize_blocks(struct xfs_inode *ip,
+               xfs_fileoff_t offset_fsb, xfs_fileoff_t end_fsb);
+
 void xfs_rtbitmap_lock(struct xfs_trans *tp, struct xfs_mount *mp);
 void xfs_rtbitmap_unlock(struct xfs_mount *mp);
 
index 92adc7df47e537fa445ab20a5af472212a569eae..b6bf112c4b3eec641d96e59c1c5d89bac783e0b1 100644 (file)
@@ -731,150 +731,6 @@ xfs_rtallocate_extent_size(
        return -ENOSPC;
 }
 
-/* Get a buffer for the block. */
-static int
-xfs_growfs_init_rtbuf(
-       struct xfs_trans        *tp,
-       struct xfs_inode        *ip,
-       xfs_fsblock_t           fsbno,
-       enum xfs_blft           buf_type)
-{
-       struct xfs_mount        *mp = tp->t_mountp;
-       struct xfs_buf          *bp;
-       xfs_daddr_t             d;
-       int                     error;
-
-       d = XFS_FSB_TO_DADDR(mp, fsbno);
-       error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0,
-                       &bp);
-       if (error)
-               return error;
-
-       xfs_trans_buf_set_type(tp, bp, buf_type);
-       bp->b_ops = xfs_rtblock_ops(mp, buf_type == XFS_BLFT_RTSUMMARY_BUF);
-       memset(bp->b_addr, 0, mp->m_sb.sb_blocksize);
-
-       if (xfs_has_rtgroups(mp)) {
-               struct xfs_rtbuf_blkinfo        *hdr = bp->b_addr;
-
-               if (buf_type == XFS_BLFT_RTBITMAP_BUF)
-                       hdr->rt_magic = cpu_to_be32(XFS_RTBITMAP_MAGIC);
-               else
-                       hdr->rt_magic = cpu_to_be32(XFS_RTSUMMARY_MAGIC);
-               hdr->rt_owner = cpu_to_be64(ip->i_ino);
-               hdr->rt_blkno = cpu_to_be64(d);
-               uuid_copy(&hdr->rt_uuid, &mp->m_sb.sb_meta_uuid);
-       }
-
-       xfs_trans_log_buf(tp, bp, 0, mp->m_sb.sb_blocksize - 1);
-       return 0;
-}
-
-/*
- * Allocate space to the bitmap or summary file, and zero it, for growfs.
- */
-STATIC int
-xfs_growfs_rt_alloc(
-       struct xfs_mount        *mp,            /* file system mount point */
-       xfs_extlen_t            oblocks,        /* old count of blocks */
-       xfs_extlen_t            nblocks,        /* new count of blocks */
-       struct xfs_inode        *ip)            /* inode (bitmap/summary) */
-{
-       xfs_fileoff_t           bno;            /* block number in file */
-       int                     error;          /* error return value */
-       xfs_fsblock_t           fsbno;          /* filesystem block for bno */
-       struct xfs_bmbt_irec    map;            /* block map output */
-       int                     nmap;           /* number of block maps */
-       int                     resblks;        /* space reservation */
-       enum xfs_blft           buf_type;
-       struct xfs_trans        *tp;
-
-       if (ip == mp->m_rsumip)
-               buf_type = XFS_BLFT_RTSUMMARY_BUF;
-       else
-               buf_type = XFS_BLFT_RTBITMAP_BUF;
-
-       /*
-        * Allocate space to the file, as necessary.
-        */
-       while (oblocks < nblocks) {
-               resblks = XFS_GROWFSRT_SPACE_RES(mp, nblocks - oblocks);
-               /*
-                * Reserve space & log for one extent added to the file.
-                */
-               error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtalloc, resblks,
-                               0, 0, &tp);
-               if (error)
-                       return error;
-               /*
-                * Lock the inode.
-                */
-               xfs_ilock(ip, XFS_ILOCK_EXCL);
-               xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-
-               error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK,
-                               XFS_IEXT_ADD_NOSPLIT_CNT);
-               if (error)
-                       goto out_trans_cancel;
-
-               /*
-                * Allocate blocks to the bitmap file.
-                */
-               nmap = 1;
-               error = xfs_bmapi_write(tp, ip, oblocks, nblocks - oblocks,
-                                       XFS_BMAPI_METADATA, 0, &map, &nmap);
-               if (error)
-                       goto out_trans_cancel;
-               /*
-                * Free any blocks freed up in the transaction, then commit.
-                */
-               error = xfs_trans_commit(tp);
-               if (error)
-                       return error;
-               /*
-                * Now we need to clear the allocated blocks.
-                * Do this one block per transaction, to keep it simple.
-                */
-               for (bno = map.br_startoff, fsbno = map.br_startblock;
-                    bno < map.br_startoff + map.br_blockcount;
-                    bno++, fsbno++) {
-                       /*
-                        * Reserve log for one block zeroing.
-                        */
-                       error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtzero,
-                                       0, 0, 0, &tp);
-                       if (error)
-                               return error;
-                       /*
-                        * Lock the bitmap inode.
-                        */
-                       xfs_ilock(ip, XFS_ILOCK_EXCL);
-                       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-
-                       error = xfs_growfs_init_rtbuf(tp, ip, fsbno, buf_type);
-                       if (error)
-                               goto out_trans_cancel;
-
-                       /*
-                        * Commit the transaction.
-                        */
-                       error = xfs_trans_commit(tp);
-                       if (error)
-                               return error;
-               }
-               /*
-                * Go on to the next extent, if any.
-                */
-               oblocks = map.br_startoff + map.br_blockcount;
-       }
-
-       return 0;
-
-out_trans_cancel:
-       xfs_trans_cancel(tp);
-       return error;
-}
-
 static void
 xfs_alloc_rsum_cache(
        xfs_mount_t     *mp,            /* file system mount structure */
@@ -1208,10 +1064,12 @@ xfs_growfs_rt(
        /*
         * Allocate space to the bitmap and summary files, as necessary.
         */
-       error = xfs_growfs_rt_alloc(mp, rbmblocks, nrbmblocks, mp->m_rbmip);
+       error = xfs_rtfile_initialize_blocks(mp->m_rbmip, rbmblocks,
+                       nrbmblocks);
        if (error)
                return error;
-       error = xfs_growfs_rt_alloc(mp, rsumblocks, nrsumblocks, mp->m_rsumip);
+       error = xfs_rtfile_initialize_blocks(mp->m_rsumip, rsumblocks,
+                       nrsumblocks);
        if (error)
                return error;