Commit 43004b2a authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: add a block to inode count converter

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: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
parent 7280feda
...@@ -1083,6 +1083,8 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev) ...@@ -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))) ((i) & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp)))
#define XFS_OFFBNO_TO_AGINO(mp,b,o) \ #define XFS_OFFBNO_TO_AGINO(mp,b,o) \
((xfs_agino_t)(((b) << XFS_INO_OFFSET_BITS(mp)) | (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 ((xfs_ino_t)((1ULL << 56) - 1ULL))
#define XFS_MAXINUMBER_32 ((xfs_ino_t)((1ULL << 32) - 1ULL)) #define XFS_MAXINUMBER_32 ((xfs_ino_t)((1ULL << 32) - 1ULL))
......
...@@ -300,7 +300,7 @@ xfs_ialloc_inode_init( ...@@ -300,7 +300,7 @@ xfs_ialloc_inode_init(
* blocks size. * blocks size.
*/ */
blks_per_cluster = xfs_icluster_size_fsb(mp); 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; nbufs = length / blks_per_cluster;
/* /*
...@@ -312,7 +312,7 @@ xfs_ialloc_inode_init( ...@@ -312,7 +312,7 @@ xfs_ialloc_inode_init(
* *
* For v3 inodes, we also need to write the inode number into the inode, * 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 * 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 * across multiple filesystem blocks (such as a cluster) and so cannot
* be used in the cluster buffer loop below. * be used in the cluster buffer loop below.
* *
...@@ -324,8 +324,7 @@ xfs_ialloc_inode_init( ...@@ -324,8 +324,7 @@ xfs_ialloc_inode_init(
*/ */
if (xfs_sb_version_hascrc(&mp->m_sb)) { if (xfs_sb_version_hascrc(&mp->m_sb)) {
version = 3; version = 3;
ino = XFS_AGINO_TO_INO(mp, agno, ino = XFS_AGINO_TO_INO(mp, agno, XFS_AGB_TO_AGINO(mp, agbno));
XFS_OFFBNO_TO_AGINO(mp, agbno, 0));
/* /*
* log the initialisation that is about to take place as an * log the initialisation that is about to take place as an
...@@ -445,7 +444,7 @@ xfs_align_sparse_ino( ...@@ -445,7 +444,7 @@ xfs_align_sparse_ino(
return; return;
/* calculate the inode offset and align startino */ /* calculate the inode offset and align startino */
offset = mod << mp->m_sb.sb_inopblog; offset = XFS_AGB_TO_AGINO(mp, mod);
*startino -= offset; *startino -= offset;
/* /*
...@@ -797,7 +796,7 @@ xfs_ialloc_ag_alloc( ...@@ -797,7 +796,7 @@ xfs_ialloc_ag_alloc(
if (error) if (error)
return 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); ASSERT(newlen <= XFS_INODES_PER_CHUNK);
allocmask = (1 << (newlen / XFS_INODES_PER_HOLEMASK_BIT)) - 1; allocmask = (1 << (newlen / XFS_INODES_PER_HOLEMASK_BIT)) - 1;
} }
...@@ -825,7 +824,7 @@ xfs_ialloc_ag_alloc( ...@@ -825,7 +824,7 @@ xfs_ialloc_ag_alloc(
/* /*
* Convert the results. * 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)) { if (xfs_inobt_issparse(~allocmask)) {
/* /*
...@@ -2724,8 +2723,8 @@ xfs_ialloc_has_inodes_at_extent( ...@@ -2724,8 +2723,8 @@ xfs_ialloc_has_inodes_at_extent(
xfs_agino_t low; xfs_agino_t low;
xfs_agino_t high; xfs_agino_t high;
low = XFS_OFFBNO_TO_AGINO(cur->bc_mp, bno, 0); low = XFS_AGB_TO_AGINO(cur->bc_mp, bno);
high = XFS_OFFBNO_TO_AGINO(cur->bc_mp, bno + len, 0) - 1; high = XFS_AGB_TO_AGINO(cur->bc_mp, bno + len) - 1;
return xfs_ialloc_has_inode_record(cur, low, high, exists); return xfs_ialloc_has_inode_record(cur, low, high, exists);
} }
......
...@@ -89,14 +89,14 @@ xfs_agino_range( ...@@ -89,14 +89,14 @@ xfs_agino_range(
*/ */
bno = round_up(XFS_AGFL_BLOCK(mp) + 1, bno = round_up(XFS_AGFL_BLOCK(mp) + 1,
xfs_ialloc_cluster_alignment(mp)); 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 * Calculate the last inode, which will be at the end of the
* last (aligned) cluster that can be allocated in the AG. * last (aligned) cluster that can be allocated in the AG.
*/ */
bno = round_down(eoag, xfs_ialloc_cluster_alignment(mp)); 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;
} }
/* /*
......
...@@ -200,7 +200,7 @@ xchk_iallocbt_check_freemask( ...@@ -200,7 +200,7 @@ xchk_iallocbt_check_freemask(
/* Make sure the freemask matches the inode records. */ /* Make sure the freemask matches the inode records. */
blks_per_cluster = xfs_icluster_size_fsb(mp); blks_per_cluster = xfs_icluster_size_fsb(mp);
nr_inodes = XFS_OFFBNO_TO_AGINO(mp, blks_per_cluster, 0); nr_inodes = XFS_FSB_TO_INO(mp, blks_per_cluster);
for (agino = irec->ir_startino; for (agino = irec->ir_startino;
agino < irec->ir_startino + XFS_INODES_PER_CHUNK; agino < irec->ir_startino + XFS_INODES_PER_CHUNK;
......
...@@ -252,7 +252,7 @@ xfs_growfs_data( ...@@ -252,7 +252,7 @@ xfs_growfs_data(
if (mp->m_sb.sb_imax_pct) { if (mp->m_sb.sb_imax_pct) {
uint64_t icount = mp->m_sb.sb_dblocks * mp->m_sb.sb_imax_pct; uint64_t icount = mp->m_sb.sb_dblocks * mp->m_sb.sb_imax_pct;
do_div(icount, 100); do_div(icount, 100);
mp->m_maxicount = icount << mp->m_sb.sb_inopblog; mp->m_maxicount = XFS_FSB_TO_INO(mp, icount);
} else } else
mp->m_maxicount = 0; mp->m_maxicount = 0;
......
...@@ -2200,7 +2200,7 @@ xfs_ifree_cluster( ...@@ -2200,7 +2200,7 @@ xfs_ifree_cluster(
inum = xic->first_ino; inum = xic->first_ino;
pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, inum)); pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, inum));
blks_per_cluster = xfs_icluster_size_fsb(mp); 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 = mp->m_ialloc_blks / blks_per_cluster; nbufs = mp->m_ialloc_blks / blks_per_cluster;
for (j = 0; j < nbufs; j++, inum += inodes_per_cluster) { for (j = 0; j < nbufs; j++, inum += inodes_per_cluster) {
......
...@@ -173,7 +173,7 @@ xfs_bulkstat_ichunk_ra( ...@@ -173,7 +173,7 @@ xfs_bulkstat_ichunk_ra(
agbno = XFS_AGINO_TO_AGBNO(mp, irec->ir_startino); agbno = XFS_AGINO_TO_AGBNO(mp, irec->ir_startino);
blks_per_cluster = xfs_icluster_size_fsb(mp); 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);
blk_start_plug(&plug); blk_start_plug(&plug);
for (i = 0; i < XFS_INODES_PER_CHUNK; for (i = 0; i < XFS_INODES_PER_CHUNK;
......
...@@ -608,7 +608,7 @@ xfs_set_inode_alloc( ...@@ -608,7 +608,7 @@ xfs_set_inode_alloc(
} }
/* Get the last possible inode in the filesystem */ /* Get the last possible inode in the filesystem */
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); ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
/* /*
...@@ -1150,7 +1150,7 @@ xfs_fs_statfs( ...@@ -1150,7 +1150,7 @@ xfs_fs_statfs(
statp->f_bfree = fdblocks - mp->m_alloc_set_aside; statp->f_bfree = fdblocks - mp->m_alloc_set_aside;
statp->f_bavail = statp->f_bfree; statp->f_bavail = statp->f_bfree;
fakeinos = statp->f_bfree << sbp->sb_inopblog; fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER); statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
if (mp->m_maxicount) if (mp->m_maxicount)
statp->f_files = min_t(typeof(statp->f_files), statp->f_files = min_t(typeof(statp->f_files),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment