]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
repair: refactor check_rtfile_contents
authorChristoph Hellwig <hch@lst.de>
Thu, 18 Jul 2024 11:45:32 +0000 (13:45 +0200)
committerChristoph Hellwig <hch@lst.de>
Thu, 18 Jul 2024 13:13:57 +0000 (15:13 +0200)
Use a single conditional for all the bitmap vs summary information
instead of passing various arguments.

Signed-off-by: Christoph Hellwig <hch@lst.de>
repair/rt.c

index 736a7247b9e6b61292bbf38728371fa03f3a3fb6..4a39d4b1d98df314bdbe9f88f19cf7543634b272 100644 (file)
@@ -193,18 +193,33 @@ check_rtwords(
 static void
 check_rtfile_contents(
        struct xfs_mount        *mp,
-       const char              *filename,
-       xfs_ino_t               ino,
-       void                    *buf,
-       xfs_fileoff_t           filelen,
-       const struct xfs_buf_ops *buf_ops)
+       bool                    is_bitmap)
 {
-       struct xfs_bmbt_irec    map;
-       struct xfs_buf          *bp;
+       const struct xfs_buf_ops *buf_ops = NULL;
+       const char              *filename;
+       xfs_ino_t               ino;
+       void                    *buf;
+       xfs_fileoff_t           filelen;
        struct xfs_inode        *ip;
        xfs_fileoff_t           bno = 0;
        int                     error;
 
+       if (is_bitmap) {
+               if (xfs_has_rtgroups(mp))
+                       buf_ops = &xfs_rtbitmap_buf_ops;
+               filename = "rtbitmap";
+               ino = mp->m_sb.sb_rbmino;
+               buf = btmcompute;
+               filelen = mp->m_sb.sb_rbmblocks;
+       } else {
+               if (xfs_has_rtgroups(mp))
+                       buf_ops = &xfs_rtsummary_buf_ops;
+               filename = "rtsummary";
+               ino = mp->m_sb.sb_rsumino;
+               buf = sumcompute;
+               filelen = XFS_B_TO_FSB(mp, mp->m_rsumsize);
+       }
+
        error = -libxfs_iget(mp, NULL, ino, 0, &ip);
        if (error) {
                do_warn(_("unable to open %s file, err %d\n"), filename, error);
@@ -219,8 +234,10 @@ check_rtfile_contents(
        }
 
        while (bno < filelen)  {
-               xfs_daddr_t     daddr;
-               int             nmap = 1;
+               unsigned int            offset = 0;
+               int                     nmap = 1;
+               struct xfs_bmbt_irec    map;
+               struct xfs_buf          *bp;
 
                error = -libxfs_bmapi_read(ip, bno, 1, &map, &nmap, 0);
                if (error) {
@@ -235,8 +252,8 @@ check_rtfile_contents(
                        break;
                }
 
-               daddr = XFS_FSB_TO_DADDR(mp, map.br_startblock);
-               error = -libxfs_buf_read_uncached(mp->m_dev, daddr,
+               error = -libxfs_buf_read_uncached(mp->m_dev,
+                               XFS_FSB_TO_DADDR(mp, map.br_startblock),
                                XFS_FSB_TO_BB(mp, map.br_blockcount),
                                0, &bp, buf_ops);
                if (error) {
@@ -245,13 +262,8 @@ check_rtfile_contents(
                        break;
                }
 
-               if (buf_ops == &xfs_rtbitmap_buf_ops) {
-                       struct xfs_rtalloc_args         args = {
-                               .mp                     = mp,
-                       };
+               if (xfs_has_rtgroups(mp)) {
                        struct xfs_rtbuf_blkinfo        *hdr = bp->b_addr;
-                       union xfs_rtword_raw            *incore = buf;
-                       union xfs_rtword_raw            *ondisk;
 
                        if (hdr->rt_owner != cpu_to_be64(ino)) {
                                do_warn(
@@ -259,34 +271,13 @@ check_rtfile_contents(
                                        filename, (unsigned long long)bno);
                        }
 
-                       args.rbmbp = bp;
-                       ondisk = xfs_rbmblock_wordptr(&args, 0);
-                       check_rtwords(mp, filename, bno, ondisk, incore);
-                       buf += mp->m_blockwsize << XFS_WORDLOG;
-               } else if (buf_ops == &xfs_rtsummary_buf_ops) {
-                       struct xfs_rtalloc_args         args = {
-                               .mp                     = mp,
-                       };
-                       struct xfs_rtbuf_blkinfo        *hdr = bp->b_addr;
-                       union xfs_suminfo_raw           *incore = buf;
-                       union xfs_suminfo_raw           *ondisk;
-
-                       if (hdr->rt_owner != cpu_to_be64(ino)) {
-                               do_warn(
- _("corrupt owner in %s at dblock 0x%llx\n"),
-                                       filename, (unsigned long long)bno);
-                       }
-
-                       args.sumbp = bp;
-                       ondisk = xfs_rsumblock_infoptr(&args, 0);
-                       check_rtwords(mp, filename, bno, ondisk, incore);
-                       buf += mp->m_blockwsize << XFS_WORDLOG;
-               } else {
-                       check_rtwords(mp, filename, bno, bp->b_addr, buf);
-                       buf += XFS_FSB_TO_B(mp, map.br_blockcount);
+                       offset = sizeof(*hdr);
                }
 
-               bno += map.br_blockcount;
+               check_rtwords(mp, filename, bno, bp->b_addr + offset, buf);
+
+               buf += mp->m_blockwsize << XFS_WORDLOG;
+               bno++;
                libxfs_buf_relse(bp);
        }
 
@@ -297,30 +288,18 @@ void
 check_rtbitmap(
        struct xfs_mount        *mp)
 {
-       const struct xfs_buf_ops *buf_ops = NULL;
-
        if (need_rbmino)
                return;
-       if (xfs_has_rtgroups(mp))
-               buf_ops = &xfs_rtbitmap_buf_ops;
-
-       check_rtfile_contents(mp, "rtbitmap", mp->m_sb.sb_rbmino, btmcompute,
-                       mp->m_sb.sb_rbmblocks, buf_ops);
+       check_rtfile_contents(mp, true);
 }
 
 void
 check_rtsummary(
        struct xfs_mount        *mp)
 {
-       const struct xfs_buf_ops *buf_ops = NULL;
-
        if (need_rsumino)
                return;
-       if (xfs_has_rtgroups(mp))
-               buf_ops = &xfs_rtsummary_buf_ops;
-
-       check_rtfile_contents(mp, "rtsummary", mp->m_sb.sb_rsumino, sumcompute,
-                       XFS_B_TO_FSB(mp, mp->m_rsumsize), buf_ops);
+       check_rtfile_contents(mp, false);
 }
 
 void