]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_repair: refactor realtime inode check
authorDarrick J. Wong <djwong@kernel.org>
Fri, 9 Aug 2024 12:18:17 +0000 (14:18 +0200)
committerChristoph Hellwig <hch@lst.de>
Mon, 12 Aug 2024 11:53:50 +0000 (13:53 +0200)
Refactor the realtime bitmap and summary checks into a helper function.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
repair/dinode.c

index 5ca4c4bebe1b57b6bb8b492d2046b40f0bd066fd..087cc8691f3b37211316bb0cee401c5182a4cdc8 100644 (file)
@@ -1784,6 +1784,39 @@ check_dinode_mode_format(
        return 0;       /* invalid modes are checked elsewhere */
 }
 
+static int
+process_check_rt_inode(
+       struct xfs_mount        *mp,
+       struct xfs_dinode       *dinoc,
+       xfs_ino_t               lino,
+       int                     *type,
+       int                     *dirty,
+       int                     expected_type,
+       const char              *tag)
+{
+       xfs_extnum_t            dnextents = xfs_dfork_data_extents(dinoc);
+
+       if (*type != expected_type) {
+               do_warn(
+_("%s inode %" PRIu64 " has bad type 0x%x, "),
+                       tag, lino, dinode_fmt(dinoc));
+               if (!no_modify)  {
+                       do_warn(_("resetting to regular file\n"));
+                       change_dinode_fmt(dinoc, S_IFREG);
+                       *dirty = 1;
+               } else  {
+                       do_warn(_("would reset to regular file\n"));
+               }
+       }
+       if (mp->m_sb.sb_rblocks == 0 && dnextents != 0)  {
+               do_warn(
+_("bad # of extents (%" PRIu64 ") for %s inode %" PRIu64 "\n"),
+                       dnextents, tag, lino);
+               return 1;
+       }
+       return 0;
+}
+
 /*
  * If inode is a superblock inode, does type check to make sure is it valid.
  * Returns 0 if it's valid, non-zero if it needs to be cleared.
@@ -1797,8 +1830,6 @@ process_check_metadata_inodes(
        int                     *type,
        int                     *dirty)
 {
-       xfs_extnum_t            dnextents;
-
        if (lino == mp->m_sb.sb_rootino) {
                if (*type != XR_INO_DIR)  {
                        do_warn(_("root inode %" PRIu64 " has bad type 0x%x\n"),
@@ -1840,52 +1871,12 @@ process_check_metadata_inodes(
                }
                return 0;
        }
-
-       dnextents = xfs_dfork_data_extents(dinoc);
-       if (lino == mp->m_sb.sb_rsumino ||
-           is_rtsummary_inode(lino)) {
-               if (*type != XR_INO_RTSUM) {
-                       do_warn(
-_("realtime summary inode %" PRIu64 " has bad type 0x%x, "),
-                               lino, dinode_fmt(dinoc));
-                       if (!no_modify)  {
-                               do_warn(_("resetting to regular file\n"));
-                               change_dinode_fmt(dinoc, S_IFREG);
-                               *dirty = 1;
-                       } else  {
-                               do_warn(_("would reset to regular file\n"));
-                       }
-               }
-               if (mp->m_sb.sb_rblocks == 0 && dnextents != 0)  {
-                       do_warn(
-_("bad # of extents (%" PRIu64 ") for realtime summary inode %" PRIu64 "\n"),
-                               dnextents, lino);
-                       return 1;
-               }
-               return 0;
-       }
-       if (lino == mp->m_sb.sb_rbmino ||
-           is_rtbitmap_inode(lino)) {
-               if (*type != XR_INO_RTBITMAP) {
-                       do_warn(
-_("realtime bitmap inode %" PRIu64 " has bad type 0x%x, "),
-                               lino, dinode_fmt(dinoc));
-                       if (!no_modify)  {
-                               do_warn(_("resetting to regular file\n"));
-                               change_dinode_fmt(dinoc, S_IFREG);
-                               *dirty = 1;
-                       } else  {
-                               do_warn(_("would reset to regular file\n"));
-                       }
-               }
-               if (mp->m_sb.sb_rblocks == 0 && dnextents != 0)  {
-                       do_warn(
-_("bad # of extents (%" PRIu64 ") for realtime bitmap inode %" PRIu64 "\n"),
-                               dnextents, lino);
-                       return 1;
-               }
-               return 0;
-       }
+       if (lino == mp->m_sb.sb_rsumino || is_rtsummary_inode(lino))
+               return process_check_rt_inode(mp, dinoc, lino, type, dirty,
+                               XR_INO_RTSUM, _("realtime summary"));
+       if (lino == mp->m_sb.sb_rbmino || is_rtbitmap_inode(lino))
+               return process_check_rt_inode(mp, dinoc, lino, type, dirty,
+                               XR_INO_RTBITMAP, _("realtime bitmap"));
        return 0;
 }