]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_repair: refactor realtime inode check
authorDarrick J. Wong <djwong@kernel.org>
Tue, 15 Oct 2024 19:44:39 +0000 (12:44 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 1 Nov 2024 20:44:58 +0000 (13:44 -0700)
Refactor the realtime bitmap and summary checks into a helper function.

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

index 47d6459709d762bfa9fdb99f2d31c594aaeee017..bf09a0ca3a7e93e853b2e04cd35fe37ba98b826a 100644 (file)
@@ -1792,6 +1792,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.
@@ -1805,8 +1838,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"),
@@ -1848,52 +1879,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;
 }