]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_repair: refactor realtime inode check
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:22:23 +0000 (14:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 9 Jul 2024 22:37:20 +0000 (15:37 -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 63b5a49e5e80e74dcda0baa180d64008ab989d90..8d7962720639d27ca33a4dd0496e74262c49f9fd 100644 (file)
@@ -1747,6 +1747,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.
@@ -1760,8 +1793,6 @@ process_check_sb_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"),
@@ -1803,49 +1834,12 @@ process_check_sb_inodes(
                }
                return 0;
        }
-       dnextents = xfs_dfork_data_extents(dinoc);
-       if (lino == mp->m_sb.sb_rsumino) {
-               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) {
-               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)
+               return process_check_rt_inode(mp, dinoc, lino, type, dirty,
+                               XR_INO_RTSUM, _("realtime summary"));
+       if (lino == mp->m_sb.sb_rbmino)
+               return process_check_rt_inode(mp, dinoc, lino, type, dirty,
+                               XR_INO_RTBITMAP, _("realtime bitmap"));
        return 0;
 }