]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_repair: refactor metadata inode tagging
authorDarrick J. Wong <djwong@kernel.org>
Fri, 15 Jul 2022 21:22:04 +0000 (14:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 22 Nov 2023 23:03:31 +0000 (15:03 -0800)
Refactor tagging of metadata inodes into a single helper function
instead of open-coding a if-else statement.

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

index e46ae9ae46f71146e5fa361124d2a45347149f25..9f10fde09a1bfd439ae65c7a61ef23c220f2baf3 100644 (file)
@@ -136,6 +136,31 @@ process_sf_dir2_fixoff(
        }
 }
 
+static bool
+is_meta_ino(
+       struct xfs_mount        *mp,
+       xfs_ino_t               dirino,
+       xfs_ino_t               lino,
+       char                    **junkreason)
+{
+       char                    *reason = NULL;
+
+       if (lino == mp->m_sb.sb_rbmino)
+               reason = _("realtime bitmap");
+       else if (lino == mp->m_sb.sb_rsumino)
+               reason = _("realtime summary");
+       else if (lino == mp->m_sb.sb_uquotino)
+               reason = _("user quota");
+       else if (lino == mp->m_sb.sb_gquotino)
+               reason = _("group quota");
+       else if (lino == mp->m_sb.sb_pquotino)
+               reason = _("project quota");
+
+       if (reason)
+               *junkreason = reason;
+       return reason != NULL;
+}
+
 /*
  * this routine performs inode discovery and tries to fix things
  * in place.  available redundancy -- inode data size should match
@@ -227,21 +252,12 @@ process_sf_dir2(
                } else if (!libxfs_verify_dir_ino(mp, lino)) {
                        junkit = 1;
                        junkreason = _("invalid");
-               } else if (lino == mp->m_sb.sb_rbmino)  {
-                       junkit = 1;
-                       junkreason = _("realtime bitmap");
-               } else if (lino == mp->m_sb.sb_rsumino)  {
-                       junkit = 1;
-                       junkreason = _("realtime summary");
-               } else if (lino == mp->m_sb.sb_uquotino)  {
-                       junkit = 1;
-                       junkreason = _("user quota");
-               } else if (lino == mp->m_sb.sb_gquotino)  {
-                       junkit = 1;
-                       junkreason = _("group quota");
-               } else if (lino == mp->m_sb.sb_pquotino)  {
+               } else if (is_meta_ino(mp, ino, lino, &junkreason)) {
+                       /*
+                        * Directories that are not in the metadir tree should
+                        * not be linking to metadata files.
+                        */
                        junkit = 1;
-                       junkreason = _("project quota");
                } else if ((irec_p = find_inode_rec(mp,
                                        XFS_INO_TO_AGNO(mp, lino),
                                        XFS_INO_TO_AGINO(mp, lino))) != NULL) {
@@ -698,16 +714,12 @@ process_dir2_data(
                         * directory since it's still structurally intact.
                         */
                        clearreason = _("invalid");
-               } else if (ent_ino == mp->m_sb.sb_rbmino) {
-                       clearreason = _("realtime bitmap");
-               } else if (ent_ino == mp->m_sb.sb_rsumino) {
-                       clearreason = _("realtime summary");
-               } else if (ent_ino == mp->m_sb.sb_uquotino) {
-                       clearreason = _("user quota");
-               } else if (ent_ino == mp->m_sb.sb_gquotino) {
-                       clearreason = _("group quota");
-               } else if (ent_ino == mp->m_sb.sb_pquotino) {
-                       clearreason = _("project quota");
+               } else if (is_meta_ino(mp, ino, ent_ino, &clearreason)) {
+                       /*
+                        * Directories that are not in the metadir tree should
+                        * not be linking to metadata files.
+                        */
+                       clearino = 1;
                } else {
                        irec_p = find_inode_rec(mp,
                                                XFS_INO_TO_AGNO(mp, ent_ino),