From: Darrick J. Wong Date: Wed, 27 Feb 2019 23:13:44 +0000 (-0600) Subject: xfs: add a block to inode count converter X-Git-Tag: v5.0.0-rc1~63 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7516da71dcb2efc0b37b3f865ef74961917cfee2;p=thirdparty%2Fxfsprogs-dev.git xfs: add a block to inode count converter Source kernel commit: 43004b2a8da2652b5ec526269a8acfba7d3d219c Add new helpers to convert units of fs blocks into inodes, and AG blocks into AG inodes, respectively. Convert all the open-coded conversions and XFS_OFFBNO_TO_AGINO(, , 0) calls to use them, as appropriate. The OFFBNO_TO_AGINO macro is retained for xfs_repair. Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster Signed-off-by: Eric Sandeen --- diff --git a/db/check.c b/db/check.c index 442600be2..d9fda4e0a 100644 --- a/db/check.c +++ b/db/check.c @@ -4399,7 +4399,7 @@ scanfunc_ino( blks_per_buf = xfs_icluster_size_fsb(mp); else blks_per_buf = mp->m_ialloc_blks; - inodes_per_buf = min(blks_per_buf << mp->m_sb.sb_inopblog, + inodes_per_buf = min(XFS_FSB_TO_INO(mp, blks_per_buf), XFS_INODES_PER_CHUNK); if (be32_to_cpu(block->bb_magic) != XFS_IBT_MAGIC && @@ -4542,7 +4542,7 @@ scanfunc_fino( blks_per_buf = xfs_icluster_size_fsb(mp); else blks_per_buf = mp->m_ialloc_blks; - inodes_per_buf = min(blks_per_buf << mp->m_sb.sb_inopblog, + inodes_per_buf = min(XFS_FSB_TO_INO(mp, blks_per_buf), XFS_INODES_PER_CHUNK); if (be32_to_cpu(block->bb_magic) != XFS_FIBT_MAGIC && diff --git a/db/convert.c b/db/convert.c index 32ded0675..01a088231 100644 --- a/db/convert.c +++ b/db/convert.c @@ -201,7 +201,7 @@ convert_f(int argc, char **argv) break; case CT_AGINO: v = (v >> mp->m_sb.sb_inodelog) % - (mp->m_sb.sb_agblocks << mp->m_sb.sb_inopblog); + XFS_AGB_TO_AGINO(mp, mp->m_sb.sb_agblocks); break; case CT_AGNUMBER: v = xfs_daddr_to_agno(mp, v >> BBSHIFT); @@ -223,7 +223,7 @@ convert_f(int argc, char **argv) case CT_INO: v = XFS_AGINO_TO_INO(mp, xfs_daddr_to_agno(mp, v >> BBSHIFT), (v >> mp->m_sb.sb_inodelog) % - (mp->m_sb.sb_agblocks << mp->m_sb.sb_inopblog)); + XFS_AGB_TO_AGINO(mp, mp->m_sb.sb_agblocks)); break; case CT_INOIDX: v = (v >> mp->m_sb.sb_inodelog) & (mp->m_sb.sb_inopblock - 1); diff --git a/db/frag.c b/db/frag.c index 5f33cb73b..27b67b1b9 100644 --- a/db/frag.c +++ b/db/frag.c @@ -477,7 +477,7 @@ scanfunc_ino( blks_per_buf = xfs_icluster_size_fsb(mp); else blks_per_buf = mp->m_ialloc_blks; - inodes_per_buf = min(blks_per_buf << mp->m_sb.sb_inopblog, + inodes_per_buf = min(XFS_FSB_TO_INO(mp, blks_per_buf), XFS_INODES_PER_CHUNK); if (level == 0) { diff --git a/db/io.c b/db/io.c index 0486ae2e7..6b66472ed 100644 --- a/db/io.c +++ b/db/io.c @@ -596,7 +596,7 @@ set_iocur_type( */ ino = XFS_AGINO_TO_INO(mp, xfs_daddr_to_agno(mp, b), ((b << BBSHIFT) >> mp->m_sb.sb_inodelog) % - (mp->m_sb.sb_agblocks << mp->m_sb.sb_inopblog)); + XFS_AGB_TO_AGINO(mp, mp->m_sb.sb_agblocks)); set_cur_inode(ino); return; } diff --git a/db/metadump.c b/db/metadump.c index 4a801106f..1d4379819 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -2423,7 +2423,7 @@ copy_inode_chunk( blks_per_buf = xfs_icluster_size_fsb(mp); else blks_per_buf = mp->m_ialloc_blks; - inodes_per_buf = min(blks_per_buf << mp->m_sb.sb_inopblog, + inodes_per_buf = min(XFS_FSB_TO_INO(mp, blks_per_buf), XFS_INODES_PER_CHUNK); /* diff --git a/libxfs/init.c b/libxfs/init.c index 626add9f1..cd93658c9 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -495,7 +495,7 @@ libxfs_initialize_perag( * If we mount with the inode64 option, or no inode overflows * the legacy 32-bit address space clear the inode32 option. */ - agino = XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks - 1, 0); + agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1); ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino); if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && ino > XFS_MAXINUMBER_32) @@ -662,8 +662,9 @@ libxfs_mount( * units we allocate inodes in. */ mp->m_maxicount = (sbp->sb_dblocks * sbp->sb_imax_pct) / 100; - mp->m_maxicount = ((mp->m_maxicount / mp->m_ialloc_blks) * - mp->m_ialloc_blks) << sbp->sb_inopblog; + mp->m_maxicount = XFS_FSB_TO_INO(mp, + (mp->m_maxicount / mp->m_ialloc_blks) * + mp->m_ialloc_blks); } else mp->m_maxicount = 0; diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 0d3422167..f56b24464 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -1083,6 +1083,8 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev) ((i) & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp))) #define XFS_OFFBNO_TO_AGINO(mp,b,o) \ ((xfs_agino_t)(((b) << XFS_INO_OFFSET_BITS(mp)) | (o))) +#define XFS_FSB_TO_INO(mp, b) ((xfs_ino_t)((b) << XFS_INO_OFFSET_BITS(mp))) +#define XFS_AGB_TO_AGINO(mp, b) ((xfs_agino_t)((b) << XFS_INO_OFFSET_BITS(mp))) #define XFS_MAXINUMBER ((xfs_ino_t)((1ULL << 56) - 1ULL)) #define XFS_MAXINUMBER_32 ((xfs_ino_t)((1ULL << 32) - 1ULL)) diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index cccfb363a..aa9432c21 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -294,7 +294,7 @@ xfs_ialloc_inode_init( * blocks size. */ blks_per_cluster = xfs_icluster_size_fsb(mp); - inodes_per_cluster = blks_per_cluster << mp->m_sb.sb_inopblog; + inodes_per_cluster = XFS_FSB_TO_INO(mp, blks_per_cluster); nbufs = length / blks_per_cluster; /* @@ -306,7 +306,7 @@ xfs_ialloc_inode_init( * * For v3 inodes, we also need to write the inode number into the inode, * so calculate the first inode number of the chunk here as - * XFS_OFFBNO_TO_AGINO() only works within a filesystem block, not + * XFS_AGB_TO_AGINO() only works within a filesystem block, not * across multiple filesystem blocks (such as a cluster) and so cannot * be used in the cluster buffer loop below. * @@ -318,8 +318,7 @@ xfs_ialloc_inode_init( */ if (xfs_sb_version_hascrc(&mp->m_sb)) { version = 3; - ino = XFS_AGINO_TO_INO(mp, agno, - XFS_OFFBNO_TO_AGINO(mp, agbno, 0)); + ino = XFS_AGINO_TO_INO(mp, agno, XFS_AGB_TO_AGINO(mp, agbno)); /* * log the initialisation that is about to take place as an @@ -439,7 +438,7 @@ xfs_align_sparse_ino( return; /* calculate the inode offset and align startino */ - offset = mod << mp->m_sb.sb_inopblog; + offset = XFS_AGB_TO_AGINO(mp, mod); *startino -= offset; /* @@ -791,7 +790,7 @@ sparse_alloc: if (error) return error; - newlen = args.len << args.mp->m_sb.sb_inopblog; + newlen = XFS_AGB_TO_AGINO(args.mp, args.len); ASSERT(newlen <= XFS_INODES_PER_CHUNK); allocmask = (1 << (newlen / XFS_INODES_PER_HOLEMASK_BIT)) - 1; } @@ -819,7 +818,7 @@ sparse_alloc: /* * Convert the results. */ - newino = XFS_OFFBNO_TO_AGINO(args.mp, args.agbno, 0); + newino = XFS_AGB_TO_AGINO(args.mp, args.agbno); if (xfs_inobt_issparse(~allocmask)) { /* @@ -2718,8 +2717,8 @@ xfs_ialloc_has_inodes_at_extent( xfs_agino_t low; xfs_agino_t high; - low = XFS_OFFBNO_TO_AGINO(cur->bc_mp, bno, 0); - high = XFS_OFFBNO_TO_AGINO(cur->bc_mp, bno + len, 0) - 1; + low = XFS_AGB_TO_AGINO(cur->bc_mp, bno); + high = XFS_AGB_TO_AGINO(cur->bc_mp, bno + len) - 1; return xfs_ialloc_has_inode_record(cur, low, high, exists); } diff --git a/libxfs/xfs_types.c b/libxfs/xfs_types.c index 544e868d4..2bfda2aa8 100644 --- a/libxfs/xfs_types.c +++ b/libxfs/xfs_types.c @@ -89,14 +89,14 @@ xfs_agino_range( */ bno = round_up(XFS_AGFL_BLOCK(mp) + 1, xfs_ialloc_cluster_alignment(mp)); - *first = XFS_OFFBNO_TO_AGINO(mp, bno, 0); + *first = XFS_AGB_TO_AGINO(mp, bno); /* * Calculate the last inode, which will be at the end of the * last (aligned) cluster that can be allocated in the AG. */ bno = round_down(eoag, xfs_ialloc_cluster_alignment(mp)); - *last = XFS_OFFBNO_TO_AGINO(mp, bno, 0) - 1; + *last = XFS_AGB_TO_AGINO(mp, bno) - 1; } /* diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c index b4ede4618..3b1890b18 100644 --- a/repair/dino_chunks.c +++ b/repair/dino_chunks.c @@ -166,7 +166,7 @@ verify_inode_chunk(xfs_mount_t *mp, pthread_mutex_unlock(&ag_locks[agno].lock); - start_agino = XFS_OFFBNO_TO_AGINO(mp, agbno, 0); + start_agino = XFS_AGB_TO_AGINO(mp, agbno); *start_ino = XFS_AGINO_TO_INO(mp, agno, start_agino); /* @@ -227,14 +227,14 @@ verify_inode_chunk(xfs_mount_t *mp, * ok, put the record into the tree, if no conflict. */ if (find_uncertain_inode_rec(agno, - XFS_OFFBNO_TO_AGINO(mp, start_agbno, 0))) + XFS_AGB_TO_AGINO(mp, start_agbno))) return(0); - start_agino = XFS_OFFBNO_TO_AGINO(mp, start_agbno, 0); + start_agino = XFS_AGB_TO_AGINO(mp, start_agbno); *start_ino = XFS_AGINO_TO_INO(mp, agno, start_agino); irec_p = set_inode_free_alloc(mp, agno, - XFS_OFFBNO_TO_AGINO(mp, start_agbno, 0)); + XFS_AGB_TO_AGINO(mp, start_agbno)); for (i = 1; i < XFS_INODES_PER_CHUNK; i++) set_inode_free(irec_p, i); @@ -271,7 +271,7 @@ verify_inode_chunk(xfs_mount_t *mp, */ irec_before_p = irec_after_p = NULL; - find_inode_rec_range(mp, agno, XFS_OFFBNO_TO_AGINO(mp, start_agbno, 0), + find_inode_rec_range(mp, agno, XFS_AGB_TO_AGINO(mp, start_agbno), XFS_OFFBNO_TO_AGINO(mp, end_agbno, mp->m_sb.sb_inopblock - 1), &irec_before_p, &irec_after_p); @@ -446,7 +446,7 @@ verify_inode_chunk(xfs_mount_t *mp, * ok because we'll override the free setting later if the * contents of the inode indicate it's in use. */ - start_agino = XFS_OFFBNO_TO_AGINO(mp, chunk_start_agbno, 0); + start_agino = XFS_AGB_TO_AGINO(mp, chunk_start_agbno); *start_ino = XFS_AGINO_TO_INO(mp, agno, start_agino); ASSERT(find_inode_rec(mp, agno, start_agino) == NULL); diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index 41ab3017b..2d333d504 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -435,16 +435,15 @@ calc_mkfs(xfs_mount_t *mp) * ditto the location of the first inode chunks in the fs ('/') */ if (xfs_sb_version_hasdalign(&mp->m_sb) && do_inoalign) { - first_prealloc_ino = XFS_OFFBNO_TO_AGINO(mp, roundup(fino_bno, - mp->m_sb.sb_unit), 0); + first_prealloc_ino = XFS_AGB_TO_AGINO(mp, roundup(fino_bno, + mp->m_sb.sb_unit)); } else if (xfs_sb_version_hasalign(&mp->m_sb) && mp->m_sb.sb_inoalignmt > 1) { - first_prealloc_ino = XFS_OFFBNO_TO_AGINO(mp, + first_prealloc_ino = XFS_AGB_TO_AGINO(mp, roundup(fino_bno, - mp->m_sb.sb_inoalignmt), - 0); + mp->m_sb.sb_inoalignmt)); } else { - first_prealloc_ino = XFS_OFFBNO_TO_AGINO(mp, fino_bno, 0); + first_prealloc_ino = XFS_AGB_TO_AGINO(mp, fino_bno); } ASSERT(mp->m_ialloc_blks > 0); @@ -452,7 +451,7 @@ calc_mkfs(xfs_mount_t *mp) if (mp->m_ialloc_blks > 1) last_prealloc_ino = first_prealloc_ino + XFS_INODES_PER_CHUNK; else - last_prealloc_ino = XFS_OFFBNO_TO_AGINO(mp, fino_bno + 1, 0); + last_prealloc_ino = XFS_AGB_TO_AGINO(mp, fino_bno + 1); /* * now the first 3 inodes in the system