From d343adda47305bb77a60f2ffe1c8738ca887aeb4 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 11 Jul 2024 14:21:43 +0200 Subject: [PATCH] repair: factor out a xfs_rootrec_inodes_inuse helper 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 --- repair/incore.h | 13 +++++++++++++ repair/phase2.c | 5 +---- repair/phase5.c | 5 +---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/repair/incore.h b/repair/incore.h index 645cc5317..07716fc4c 100644 --- a/repair/incore.h +++ b/repair/incore.h @@ -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 */ diff --git a/repair/phase2.c b/repair/phase2.c index c3e462ae1..4cdd14d2d 100644 --- a/repair/phase2.c +++ b/repair/phase2.c @@ -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 */ diff --git a/repair/phase5.c b/repair/phase5.c index 51efcd6ca..b9caea2b7 100644 --- a/repair/phase5.c +++ b/repair/phase5.c @@ -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)); -- 2.50.1