]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
repair: factor out a xfs_rootrec_inodes_inuse helper
authorChristoph Hellwig <hch@lst.de>
Thu, 11 Jul 2024 12:21:43 +0000 (14:21 +0200)
committerChristoph Hellwig <hch@lst.de>
Tue, 30 Jul 2024 01:07:30 +0000 (18:07 -0700)
Ensure only one place needs to be found and modified when changing the
number of "static" sb rooted inodes, saving copious debug time when
doing so.

Signed-off-by: Christoph Hellwig <hch@lst.de>
repair/incore.h
repair/phase2.c
repair/phase5.c

index 645cc5317c8d61d1633be18fd4393c71c98134a3..07716fc4c01a05c853466243d51b62fdfa1b74b0 100644 (file)
@@ -687,4 +687,17 @@ inorec_set_freecount(
                rp->ir_u.f.ir_freecount = cpu_to_be32(freecount);
 }
 
+/*
+ * Number of inodes assumed to be always allocated because they are created
+ * by mkfs.
+ */
+static inline unsigned int
+xfs_rootrec_inodes_inuse(
+       struct xfs_mount        *mp)
+{
+       if (xfs_has_metadir(mp))
+               return 4; /* sb_rootino, sb_rbmino, sb_rsumino, sb_metadirino */
+       return 3; /* sb_rootino, sb_rbmino, sb_rsumino */
+}
+
 #endif /* XFS_REPAIR_INCORE_H */
index c3e462ae1ee2a4fd3b01706d4273dc803616017b..4cdd14d2d0b270693eeb412dc6e5432b601d4688 100644 (file)
@@ -700,7 +700,7 @@ phase2(
        struct xfs_mount        *mp,
        int                     scan_threads)
 {
-       int                     j, inuse = 3; /* root, rbm, rsum */
+       int                     inuse = xfs_rootrec_inodes_inuse(mp), j;
        ino_tree_node_t         *ino_rec;
 
        /* now we can start using the buffer cache routines */
@@ -741,9 +741,6 @@ phase2(
 
        print_final_rpt();
 
-       if (xfs_has_metadir(mp))
-               inuse++; /* root, metaroot, rbm, rsum */
-
        /*
         * make sure we know about the root inode chunk
         */
index 51efcd6ca123b72a6a9989d79cff22868964d1ef..b9caea2b71288970352b2149054ea29e2f8db228 100644 (file)
@@ -418,11 +418,8 @@ sync_sb(xfs_mount_t *mp)
 static void
 keep_fsinos(xfs_mount_t *mp)
 {
+       int                     inuse = xfs_rootrec_inodes_inuse(mp), i;
        ino_tree_node_t         *irec;
-       int                     i, inuse = 3; /* root, rbm, rsum */
-
-       if (xfs_has_metadir(mp))
-               inuse++; /* root, metaroot, rbm, rsum */
 
        irec = find_inode_rec(mp, XFS_INO_TO_AGNO(mp, mp->m_sb.sb_rootino),
                        XFS_INO_TO_AGINO(mp, mp->m_sb.sb_rootino));