[PATCH 11/12] xfs_repair: use precomputed inode geometry values

Darrick J. Wong
2019-08-20T20:32:29Z

From: Darrick J. Wong <darrick.wong@oracle.com>

Use the precomputed inode geometry values instead of open-coding them.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
repair/dino_chunks.c | 22 +++++++++++-----------
repair/dinode.c | 13 ++++---------
repair/globals.c | 1 -
repair/globals.h | 1 -
repair/prefetch.c | 21 ++++++++-------------
repair/xfs_repair.c | 2 --
6 files changed, 23 insertions(+), 37 deletions(-)

diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c
index 323a355e..00b67468 100644
--- a/repair/dino_chunks.c
+++ b/repair/dino_chunks.c
@@ -608,7 +608,6 @@ process_inode_chunk(
xfs_ino_t ino;
int dirty = 0;
int isa_dir = 0;
- int blks_per_cluster;
int cluster_count;
int bp_index;
int cluster_offset;
@@ -620,10 +619,7 @@ process_inode_chunk(
*bogus = 0;
ASSERT(igeo->ialloc_blks > 0);

- blks_per_cluster = M_IGEO(mp)->inode_cluster_size >> mp->m_sb.sb_blocklog;
- if (blks_per_cluster == 0)
- blks_per_cluster = 1;
- cluster_count = XFS_INODES_PER_CHUNK / inodes_per_cluster;
+ cluster_count = XFS_INODES_PER_CHUNK / M_IGEO(mp)->inodes_per_cluster;
if (cluster_count == 0)
cluster_count = 1;

@@ -662,13 +658,16 @@ process_inode_chunk(

bplist[bp_index] = libxfs_readbuf(mp->m_dev,
XFS_AGB_TO_DADDR(mp, agno, agbno),
- XFS_FSB_TO_BB(mp, blks_per_cluster), 0,
+ XFS_FSB_TO_BB(mp,
+ M_IGEO(mp)->blocks_per_cluster),
+ 0,
&xfs_inode_buf_ops);
if (!bplist[bp_index]) {
do_warn(_("cannot read inode %" PRIu64 ", disk block %" PRId64 ", cnt %d\n"),
XFS_AGINO_TO_INO(mp, agno, first_irec->ino_startnum),
XFS_AGB_TO_DADDR(mp, agno, agbno),
- XFS_FSB_TO_BB(mp, blks_per_cluster));
+ XFS_FSB_TO_BB(mp,
+ M_IGEO(mp)->blocks_per_cluster));
while (bp_index > 0) {
bp_index--;
libxfs_putbuf(bplist[bp_index]);
@@ -684,8 +683,9 @@ process_inode_chunk(
bplist[bp_index]->b_ops = &xfs_inode_buf_ops;

next_readbuf:
- irec_offset += mp->m_sb.sb_inopblock * blks_per_cluster;
- agbno += blks_per_cluster;
+ irec_offset += mp->m_sb.sb_inopblock *
+ M_IGEO(mp)->blocks_per_cluster;
+ agbno += M_IGEO(mp)->blocks_per_cluster;
}
agbno = XFS_AGINO_TO_AGBNO(mp, first_irec->ino_startnum);

@@ -745,7 +745,7 @@ process_inode_chunk(
ASSERT(ino_rec->ino_startnum == agino + 1);
irec_offset = 0;
}
- if (cluster_offset == inodes_per_cluster) {
+ if (cluster_offset == M_IGEO(mp)->inodes_per_cluster) {
bp_index++;
cluster_offset = 0;
}
@@ -964,7 +964,7 @@ process_inode_chunk(
ASSERT(ino_rec->ino_startnum == agino + 1);
irec_offset = 0;
}
- if (cluster_offset == inodes_per_cluster) {
+ if (cluster_offset == M_IGEO(mp)->inodes_per_cluster) {
bp_index++;
cluster_offset = 0;
}
diff --git a/repair/dinode.c b/repair/dinode.c
index f5e88cc3..8af2cb25 100644
--- a/repair/dinode.c
+++ b/repair/dinode.c
@@ -755,8 +755,6 @@ get_agino_buf(
struct xfs_dinode **dipp)
{
struct xfs_buf *bp;
- int cluster_size;
- int ino_per_cluster;
xfs_agino_t cluster_agino;
xfs_daddr_t cluster_daddr;
xfs_daddr_t cluster_blks;
@@ -768,18 +766,15 @@ get_agino_buf(
* we must find the buffer for its cluster, add the appropriate
* offset, and return that.
*/
- cluster_size = igeo->inode_cluster_size;
- ino_per_cluster = cluster_size / mp->m_sb.sb_inodesize;
- cluster_agino = agino & ~(ino_per_cluster - 1);
- cluster_blks = XFS_FSB_TO_DADDR(mp, max(1,
- igeo->inode_cluster_size >> mp->m_sb.sb_blocklog));
+ cluster_agino = agino & ~(igeo->inodes_per_cluster - 1);
+ cluster_blks = XFS_FSB_TO_DADDR(mp, igeo->blocks_per_cluster);
cluster_daddr = XFS_AGB_TO_DADDR(mp, agno,
XFS_AGINO_TO_AGBNO(mp, cluster_agino));

#ifdef XR_INODE_TRACE
printf("cluster_size %d ipc %d clusagino %d daddr %lld sectors %lld\n",
- cluster_size, ino_per_cluster, cluster_agino, cluster_daddr,
- cluster_blks);
+ M_IGEO(mp)->inode_cluster_size, M_IGEO(mp)->inodes_per_cluster,
+ cluster_agino, cluster_daddr, cluster_blks);
#endif

bp = libxfs_readbuf(mp->m_dev, cluster_daddr, cluster_blks,
diff --git a/repair/globals.c b/repair/globals.c
index ae9d55b4..dcd79ea4 100644
--- a/repair/globals.c
+++ b/repair/globals.c
@@ -81,7 +81,6 @@ xfs_agblock_t inobt_root;
/* configuration vars -- fs geometry dependent */

int inodes_per_block;
-int inodes_per_cluster;
unsigned int glob_agcount;
int chunks_pblock; /* # of 64-ino chunks per allocation */
int max_symlink_blocks;
diff --git a/repair/globals.h b/repair/globals.h
index 05121d4f..008bdd90 100644
--- a/repair/globals.h
+++ b/repair/globals.h
@@ -122,7 +122,6 @@ extern xfs_agblock_t inobt_root;
/* configuration vars -- fs geometry dependent */

extern int inodes_per_block;
-extern int inodes_per_cluster;
extern unsigned int glob_agcount;
extern int chunks_pblock; /* # of 64-ino chunks per allocation */
extern int max_symlink_blocks;
diff --git a/repair/prefetch.c b/repair/prefetch.c
index 2fecfd68..5a725a51 100644
--- a/repair/prefetch.c
+++ b/repair/prefetch.c
@@ -710,17 +710,12 @@ pf_queuing_worker(
int num_inos;
ino_tree_node_t *irec;
ino_tree_node_t *cur_irec;
- int blks_per_cluster;
xfs_agblock_t bno;
int i;
int err;
uint64_t sparse;
struct xfs_ino_geometry *igeo = M_IGEO(mp);

- blks_per_cluster = igeo->inode_cluster_size >> mp->m_sb.sb_blocklog;
- if (blks_per_cluster == 0)
- blks_per_cluster = 1;
-
for (i = 0; i < PF_THREAD_COUNT; i++) {
err = pthread_create(&args->io_threads[i], NULL,
pf_io_worker, args);
@@ -786,21 +781,22 @@ pf_queuing_worker(
struct xfs_buf_map map;

map.bm_bn = XFS_AGB_TO_DADDR(mp, args->agno, bno);
- map.bm_len = XFS_FSB_TO_BB(mp, blks_per_cluster);
+ map.bm_len = XFS_FSB_TO_BB(mp,
+ M_IGEO(mp)->blocks_per_cluster);

/*
* Queue I/O for each non-sparse cluster. We can check
* sparse state in cluster sized chunks as cluster size
* is the min. granularity of sparse irec regions.
*/
- if ((sparse & ((1ULL << inodes_per_cluster) - 1)) == 0)
+ if ((sparse & ((1ULL << M_IGEO(mp)->inodes_per_cluster) - 1)) == 0)
pf_queue_io(args, &map, 1,
(cur_irec->ino_isa_dir != 0) ?
B_DIR_INODE : B_INODE);

- bno += blks_per_cluster;
- num_inos += inodes_per_cluster;
- sparse >>= inodes_per_cluster;
+ bno += igeo->blocks_per_cluster;
+ num_inos += igeo->inodes_per_cluster;
+ sparse >>= igeo->inodes_per_cluster;
} while (num_inos < igeo->ialloc_inos);
}

@@ -903,9 +899,8 @@ start_inode_prefetch(

max_queue = libxfs_bcache->c_maxcount / thread_count / 8;
if (igeo->inode_cluster_size > mp->m_sb.sb_blocksize)
- max_queue = max_queue *
- (igeo->inode_cluster_size >> mp->m_sb.sb_blocklog) /
- igeo->ialloc_blks;
+ max_queue = max_queue * igeo->blocks_per_cluster /
+ igeo->ialloc_blks;

sem_init(&args->ra_count, 0, max_queue);

diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
index 9f4f2611..c7f3bfbc 100644
--- a/repair/xfs_repair.c
+++ b/repair/xfs_repair.c
@@ -762,8 +762,6 @@ main(int argc, char **argv)

chunks_pblock = mp->m_sb.sb_inopblock / XFS_INODES_PER_CHUNK;
max_symlink_blocks = libxfs_symlink_blocks(mp, XFS_SYMLINK_MAXLEN);
- inodes_per_cluster = max(mp->m_sb.sb_inopblock,
- igeo->inode_cluster_size >> mp->m_sb.sb_inodelog);

/*
* Automatic striding for high agcount filesystems.