]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_repair: refactor generate_rtinfo
authorChristoph Hellwig <hch@lst.de>
Tue, 30 Jul 2024 20:58:38 +0000 (13:58 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 1 Aug 2024 00:07:33 +0000 (17:07 -0700)
Move the allocation of the computed values into generate_rtinfo, and thus
make the variables holding them private in rt.c, and clean up a few
formatting nits.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
[djwong: move functions to fix build errors]
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
repair/globals.c
repair/globals.h
repair/phase5.c
repair/phase6.c
repair/rt.c
repair/rt.h

index ad01fcc23e39ad11c06bf157fe259fc3e8daa4e8..2b8e5ff649a73b42c0f2e413500792d410750bf2 100644 (file)
@@ -93,11 +93,6 @@ int          chunks_pblock;  /* # of 64-ino chunks per allocation */
 int            max_symlink_blocks;
 int64_t                fs_max_file_offset;
 
-/* realtime info */
-
-union xfs_rtword_raw   *btmcompute;
-union xfs_suminfo_raw  *sumcompute;
-
 /* inode tree records have full or partial backptr fields ? */
 
 int    full_ino_ex_data;       /*
index 9a5d444a8e7564fccf63bd4a949f3fc8d98dc120..d2222c1d07776fa9ea85c1c1c517fbe09350862b 100644 (file)
@@ -134,11 +134,6 @@ extern int         chunks_pblock;  /* # of 64-ino chunks per allocation */
 extern int             max_symlink_blocks;
 extern int64_t         fs_max_file_offset;
 
-/* realtime info */
-
-extern union xfs_rtword_raw            *btmcompute;
-extern union xfs_suminfo_raw           *sumcompute;
-
 /* inode tree records have full or partial backptr fields ? */
 
 extern int             full_ino_ex_data;/*
index 7d416502fd780967c674f76616d7561a4e20c116..63b9fc49eb709304124a35b8d9ba7086fdef690f 100644 (file)
@@ -627,8 +627,7 @@ void
 check_rtmetadata(
        struct xfs_mount        *mp)
 {
-       rtinit(mp);
-       generate_rtinfo(mp, btmcompute, sumcompute);
+       generate_rtinfo(mp);
        check_rtbitmap(mp);
        check_rtsummary(mp);
 }
index e0fd9b970130bffee4af048d16c3060133ea8b1d..779ea1ec5498cc38bd64d35b84e53893d53200ca 100644 (file)
@@ -19,6 +19,7 @@
 #include "progress.h"
 #include "versions.h"
 #include "repair/pptr.h"
+#include "repair/rt.h"
 
 static xfs_ino_t               orphanage_ino;
 
@@ -539,63 +540,6 @@ mk_rbmino(
        libxfs_irele(ip);
 }
 
-static void
-fill_rbmino(
-       struct xfs_mount        *mp)
-{
-       struct xfs_trans        *tp;
-       struct xfs_inode        *ip;
-       int                     error;
-
-       error = -libxfs_trans_alloc_empty(mp, &tp);
-       if (error)
-               do_error(
-_("couldn't allocate empty transaction, error %d\n"), error);
-       error = -libxfs_iget(mp, tp, mp->m_sb.sb_rbmino, 0, &ip);
-       if (error)
-               do_error(
-_("couldn't iget realtime bitmap inode, error %d\n"), error);
-       libxfs_trans_cancel(tp);
-
-       error = -libxfs_rtfile_initialize_blocks(ip, 0, mp->m_sb.sb_rbmblocks,
-                       btmcompute);
-       if (error)
-               do_error(
-_("couldn't re-initialize realtime bitmap inode, error %d\n"), error);
-       libxfs_irele(ip);
-}
-
-static void
-fill_rsumino(
-       struct xfs_mount        *mp)
-{
-       struct xfs_trans        *tp;
-       struct xfs_inode        *ip;
-       int                     error;
-
-       error = -libxfs_trans_alloc_empty(mp, &tp);
-       if (error)
-               do_error(
-_("couldn't allocate empty transaction, error %d\n"), error);
-       error = -libxfs_iget(mp, tp, mp->m_sb.sb_rsumino, 0, &ip);
-       if (error) {
-               do_error(
-_("couldn't iget realtime summary inode, error - %d\n"), error);
-       }
-       libxfs_trans_cancel(tp);
-
-       mp->m_rsumip = ip;
-       error = -libxfs_rtfile_initialize_blocks(ip, 0,
-                       mp->m_rsumsize >> mp->m_sb.sb_blocklog,
-                       sumcompute);
-       mp->m_rsumip = NULL;
-       if (error)
-               do_error(
-_("couldn't re-initialize realtime summary inode, error %d\n"), error);
-
-       libxfs_irele(ip);
-}
-
 static void
 mk_rsumino(
        struct xfs_mount        *mp)
@@ -3332,8 +3276,8 @@ phase6(xfs_mount_t *mp)
        if (!no_modify)  {
                do_log(
 _("        - resetting contents of realtime bitmap and summary inodes\n"));
-               fill_rbmino(mp);
-               fill_rsumino(mp);
+               fill_rtbitmap(mp);
+               fill_rtsummary(mp);
        }
 
        mark_standalone_inodes(mp);
index 4c81e2114c7735553a6491b085e1dc1595ffc1eb..15fa7de1f10bd26903122923db9849668fbdb774 100644 (file)
 #include "err_protos.h"
 #include "rt.h"
 
-void
-rtinit(xfs_mount_t *mp)
-{
-       unsigned long long      wordcnt;
-
-       if (mp->m_sb.sb_rblocks == 0)
-               return;
-
-       /*
-        * Allocate buffers for formatting the collected rt free space
-        * information.  The rtbitmap buffer must be large enough to compare
-        * against any unused bytes in the last block of the file.
-        */
-       wordcnt = libxfs_rtbitmap_wordcount(mp, mp->m_sb.sb_rextents);
-       btmcompute = calloc(wordcnt, sizeof(union xfs_rtword_raw));
-       if (!btmcompute)
-               do_error(
-       _("couldn't allocate memory for incore realtime bitmap.\n"));
-
-       wordcnt = libxfs_rtsummary_wordcount(mp, mp->m_rsumlevels,
-                       mp->m_sb.sb_rbmblocks);
-       sumcompute = calloc(wordcnt, sizeof(union xfs_suminfo_raw));
-       if (!sumcompute)
-               do_error(
-       _("couldn't allocate memory for incore realtime summary info.\n"));
-}
+/* Computed rt bitmap/summary data */
+static union xfs_rtword_raw    *btmcompute;
+static union xfs_suminfo_raw   *sumcompute;
 
 static inline void
 set_rtword(
@@ -65,58 +42,65 @@ inc_sumcount(
  * generate the real-time bitmap and summary info based on the
  * incore realtime extent map.
  */
-int
+void
 generate_rtinfo(
-       struct xfs_mount        *mp,
-       union xfs_rtword_raw    *words,
-       union xfs_suminfo_raw   *sumcompute)
+       struct xfs_mount        *mp)
 {
-       xfs_rtxnum_t    extno;
-       xfs_rtxnum_t    start_ext;
-       int             bitsperblock;
-       int             bmbno;
-       xfs_rtword_t    freebit;
-       xfs_rtword_t    bits;
-       int             start_bmbno;
-       int             i;
-       int             offs;
-       int             log;
-       int             len;
-       int             in_extent;
+       unsigned int            bitsperblock =
+               mp->m_blockwsize << XFS_NBWORDLOG;
+       xfs_rtxnum_t            extno = 0;
+       xfs_rtxnum_t            start_ext = 0;
+       int                     bmbno = 0;
+       int                     start_bmbno = 0;
+       bool                    in_extent = false;
+       union xfs_rtword_raw    *words;
 
-       ASSERT(mp->m_rbmip == NULL);
+       btmcompute = calloc(libxfs_rtbitmap_wordcount(mp, mp->m_sb.sb_rextents),
+                       sizeof(union xfs_rtword_raw));
+       if (!btmcompute)
+               do_error(
+_("couldn't allocate memory for incore realtime bitmap.\n"));
+       words = btmcompute;
+
+       sumcompute = calloc(libxfs_rtsummary_wordcount(mp, mp->m_rsumlevels,
+                       mp->m_sb.sb_rbmblocks), sizeof(union xfs_suminfo_raw));
+       if (!sumcompute)
+               do_error(
+_("couldn't allocate memory for incore realtime summary info.\n"));
 
-       bitsperblock = mp->m_blockwsize << XFS_NBWORDLOG;
-       extno = start_ext = 0;
-       bmbno = in_extent = start_bmbno = 0;
+       ASSERT(mp->m_rbmip == NULL);
 
        /*
-        * slower but simple, don't play around with trying to set
-        * things one word at a time, just set bit as required.
-        * Have to * track start and end (size) of each range of
-        * free extents to set the summary info properly.
+        * Slower but simple, don't play around with trying to set things one
+        * word at a time, just set bit as required.  Have to track start and
+        * end (size) of each range of free extents to set the summary info
+        * properly.
         */
        while (extno < mp->m_sb.sb_rextents)  {
-               freebit = 1;
+               xfs_rtword_t            freebit = 1;
+               xfs_rtword_t            bits = 0;
+               int                     i;
+
                set_rtword(mp, words, 0);
-               bits = 0;
                for (i = 0; i < sizeof(xfs_rtword_t) * NBBY &&
                                extno < mp->m_sb.sb_rextents; i++, extno++)  {
                        if (get_rtbmap(extno) == XR_E_FREE)  {
                                sb_frextents++;
                                bits |= freebit;
 
-                               if (in_extent == 0) {
+                               if (!in_extent) {
                                        start_ext = extno;
                                        start_bmbno = bmbno;
-                                       in_extent = 1;
+                                       in_extent = true;
                                }
-                       } else if (in_extent == 1) {
-                               len = (int) (extno - start_ext);
-                               log = libxfs_highbit64(len);
-                               offs = xfs_rtsumoffs(mp, log, start_bmbno);
+                       } else if (in_extent) {
+                               uint64_t        len = extno - start_ext;
+                               xfs_rtsumoff_t  offs;
+
+                               offs = xfs_rtsumoffs(mp, libxfs_highbit64(len),
+                                               start_bmbno);
                                inc_sumcount(mp, sumcompute, offs);
-                               in_extent = 0;
+                               in_extent = false;
                        }
 
                        freebit <<= 1;
@@ -127,10 +111,12 @@ generate_rtinfo(
                if (extno % bitsperblock == 0)
                        bmbno++;
        }
-       if (in_extent == 1) {
-               len = (int) (extno - start_ext);
-               log = libxfs_highbit64(len);
-               offs = xfs_rtsumoffs(mp, log, start_bmbno);
+
+       if (in_extent) {
+               uint64_t        len = extno - start_ext;
+               xfs_rtsumoff_t  offs;
+
+               offs = xfs_rtsumoffs(mp, libxfs_highbit64(len), start_bmbno);
                inc_sumcount(mp, sumcompute, offs);
        }
 
@@ -138,8 +124,6 @@ generate_rtinfo(
                do_warn(_("sb_frextents %" PRIu64 ", counted %" PRIu64 "\n"),
                                mp->m_sb.sb_frextents, sb_frextents);
        }
-
-       return(0);
 }
 
 static void
@@ -231,3 +215,60 @@ check_rtsummary(
        check_rtfile_contents(mp, "rtsummary", mp->m_sb.sb_rsumino, sumcompute,
                        XFS_B_TO_FSB(mp, mp->m_rsumsize));
 }
+
+void
+fill_rtbitmap(
+       struct xfs_mount        *mp)
+{
+       struct xfs_trans        *tp;
+       struct xfs_inode        *ip;
+       int                     error;
+
+       error = -libxfs_trans_alloc_empty(mp, &tp);
+       if (error)
+               do_error(
+_("couldn't allocate empty transaction, error %d\n"), error);
+       error = -libxfs_iget(mp, tp, mp->m_sb.sb_rbmino, 0, &ip);
+       if (error)
+               do_error(
+_("couldn't iget realtime bitmap inode, error %d\n"), error);
+       libxfs_trans_cancel(tp);
+
+       error = -libxfs_rtfile_initialize_blocks(ip, 0, mp->m_sb.sb_rbmblocks,
+                       btmcompute);
+       if (error)
+               do_error(
+_("couldn't re-initialize realtime bitmap inode, error %d\n"), error);
+       libxfs_irele(ip);
+}
+
+void
+fill_rtsummary(
+       struct xfs_mount        *mp)
+{
+       struct xfs_trans        *tp;
+       struct xfs_inode        *ip;
+       int                     error;
+
+       error = -libxfs_trans_alloc_empty(mp, &tp);
+       if (error)
+               do_error(
+_("couldn't allocate empty transaction, error %d\n"), error);
+       error = -libxfs_iget(mp, tp, mp->m_sb.sb_rsumino, 0, &ip);
+       if (error) {
+               do_error(
+_("couldn't iget realtime summary inode, error - %d\n"), error);
+       }
+       libxfs_trans_cancel(tp);
+
+       mp->m_rsumip = ip;
+       error = -libxfs_rtfile_initialize_blocks(ip, 0,
+                       mp->m_rsumsize >> mp->m_sb.sb_blocklog,
+                       sumcompute);
+       mp->m_rsumip = NULL;
+       if (error)
+               do_error(
+_("couldn't re-initialize realtime summary inode, error %d\n"), error);
+
+       libxfs_irele(ip);
+}
index 862695487bcd4c3aa97a2260edde187ef6bb2f88..f8caa5dc874ec29440786efbf6b3ac19a8c70fa2 100644 (file)
@@ -6,15 +6,11 @@
 #ifndef _XFS_REPAIR_RT_H_
 #define _XFS_REPAIR_RT_H_
 
-struct blkmap;
-
-void
-rtinit(xfs_mount_t             *mp);
-
-int generate_rtinfo(struct xfs_mount *mp, union xfs_rtword_raw *words,
-               union xfs_suminfo_raw *sumcompute);
-
+void generate_rtinfo(struct xfs_mount *mp);
 void check_rtbitmap(struct xfs_mount *mp);
 void check_rtsummary(struct xfs_mount *mp);
 
+void fill_rtbitmap(struct xfs_mount *mp);
+void fill_rtsummary(struct xfs_mount *mp);
+
 #endif /* _XFS_REPAIR_RT_H_ */