aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2018-12-12 11:46:24 -0500
committerDarrick J. Wong <darrick.wong@oracle.com>2018-12-12 11:47:16 -0500
commit43004b2a8da2652b5ec526269a8acfba7d3d219c (patch)
tree197c76e61334c576f18530dd05a86958aac4101e
parent7280fedaf3a0f9097c0621c7d5b35849954d7f54 (diff)
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: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Brian Foster <bfoster@redhat.com>
-rw-r--r--fs/xfs/libxfs/xfs_format.h2
-rw-r--r--fs/xfs/libxfs/xfs_ialloc.c17
-rw-r--r--fs/xfs/libxfs/xfs_types.c4
-rw-r--r--fs/xfs/scrub/ialloc.c2
-rw-r--r--fs/xfs/xfs_fsops.c2
-rw-r--r--fs/xfs/xfs_inode.c2
-rw-r--r--fs/xfs/xfs_itable.c2
-rw-r--r--fs/xfs/xfs_super.c4
8 files changed, 18 insertions, 17 deletions
diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 9995d5ae380b..b15412e4c535 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -1083,6 +1083,8 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
1083 ((i) & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp))) 1083 ((i) & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp)))
1084#define XFS_OFFBNO_TO_AGINO(mp,b,o) \ 1084#define XFS_OFFBNO_TO_AGINO(mp,b,o) \
1085 ((xfs_agino_t)(((b) << XFS_INO_OFFSET_BITS(mp)) | (o))) 1085 ((xfs_agino_t)(((b) << XFS_INO_OFFSET_BITS(mp)) | (o)))
1086#define XFS_FSB_TO_INO(mp, b) ((xfs_ino_t)((b) << XFS_INO_OFFSET_BITS(mp)))
1087#define XFS_AGB_TO_AGINO(mp, b) ((xfs_agino_t)((b) << XFS_INO_OFFSET_BITS(mp)))
1086 1088
1087#define XFS_MAXINUMBER ((xfs_ino_t)((1ULL << 56) - 1ULL)) 1089#define XFS_MAXINUMBER ((xfs_ino_t)((1ULL << 56) - 1ULL))
1088#define XFS_MAXINUMBER_32 ((xfs_ino_t)((1ULL << 32) - 1ULL)) 1090#define XFS_MAXINUMBER_32 ((xfs_ino_t)((1ULL << 32) - 1ULL))
diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index fcf0d17405d8..3ac4a836428d 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -300,7 +300,7 @@ xfs_ialloc_inode_init(
300 * blocks size. 300 * blocks size.
301 */ 301 */
302 blks_per_cluster = xfs_icluster_size_fsb(mp); 302 blks_per_cluster = xfs_icluster_size_fsb(mp);
303 inodes_per_cluster = blks_per_cluster << mp->m_sb.sb_inopblog; 303 inodes_per_cluster = XFS_FSB_TO_INO(mp, blks_per_cluster);
304 nbufs = length / blks_per_cluster; 304 nbufs = length / blks_per_cluster;
305 305
306 /* 306 /*
@@ -312,7 +312,7 @@ xfs_ialloc_inode_init(
312 * 312 *
313 * For v3 inodes, we also need to write the inode number into the inode, 313 * For v3 inodes, we also need to write the inode number into the inode,
314 * so calculate the first inode number of the chunk here as 314 * so calculate the first inode number of the chunk here as
315 * XFS_OFFBNO_TO_AGINO() only works within a filesystem block, not 315 * XFS_AGB_TO_AGINO() only works within a filesystem block, not
316 * across multiple filesystem blocks (such as a cluster) and so cannot 316 * across multiple filesystem blocks (such as a cluster) and so cannot
317 * be used in the cluster buffer loop below. 317 * be used in the cluster buffer loop below.
318 * 318 *
@@ -324,8 +324,7 @@ xfs_ialloc_inode_init(
324 */ 324 */
325 if (xfs_sb_version_hascrc(&mp->m_sb)) { 325 if (xfs_sb_version_hascrc(&mp->m_sb)) {
326 version = 3; 326 version = 3;
327 ino = XFS_AGINO_TO_INO(mp, agno, 327 ino = XFS_AGINO_TO_INO(mp, agno, XFS_AGB_TO_AGINO(mp, agbno));
328 XFS_OFFBNO_TO_AGINO(mp, agbno, 0));
329 328
330 /* 329 /*
331 * log the initialisation that is about to take place as an 330 * log the initialisation that is about to take place as an
@@ -445,7 +444,7 @@ xfs_align_sparse_ino(
445 return; 444 return;
446 445
447 /* calculate the inode offset and align startino */ 446 /* calculate the inode offset and align startino */
448 offset = mod << mp->m_sb.sb_inopblog; 447 offset = XFS_AGB_TO_AGINO(mp, mod);
449 *startino -= offset; 448 *startino -= offset;
450 449
451 /* 450 /*
@@ -797,7 +796,7 @@ sparse_alloc:
797 if (error) 796 if (error)
798 return error; 797 return error;
799 798
800 newlen = args.len << args.mp->m_sb.sb_inopblog; 799 newlen = XFS_AGB_TO_AGINO(args.mp, args.len);
801 ASSERT(newlen <= XFS_INODES_PER_CHUNK); 800 ASSERT(newlen <= XFS_INODES_PER_CHUNK);
802 allocmask = (1 << (newlen / XFS_INODES_PER_HOLEMASK_BIT)) - 1; 801 allocmask = (1 << (newlen / XFS_INODES_PER_HOLEMASK_BIT)) - 1;
803 } 802 }
@@ -825,7 +824,7 @@ sparse_alloc:
825 /* 824 /*
826 * Convert the results. 825 * Convert the results.
827 */ 826 */
828 newino = XFS_OFFBNO_TO_AGINO(args.mp, args.agbno, 0); 827 newino = XFS_AGB_TO_AGINO(args.mp, args.agbno);
829 828
830 if (xfs_inobt_issparse(~allocmask)) { 829 if (xfs_inobt_issparse(~allocmask)) {
831 /* 830 /*
@@ -2724,8 +2723,8 @@ xfs_ialloc_has_inodes_at_extent(
2724 xfs_agino_t low; 2723 xfs_agino_t low;
2725 xfs_agino_t high; 2724 xfs_agino_t high;
2726 2725
2727 low = XFS_OFFBNO_TO_AGINO(cur->bc_mp, bno, 0); 2726 low = XFS_AGB_TO_AGINO(cur->bc_mp, bno);
2728 high = XFS_OFFBNO_TO_AGINO(cur->bc_mp, bno + len, 0) - 1; 2727 high = XFS_AGB_TO_AGINO(cur->bc_mp, bno + len) - 1;
2729 2728
2730 return xfs_ialloc_has_inode_record(cur, low, high, exists); 2729 return xfs_ialloc_has_inode_record(cur, low, high, exists);
2731} 2730}
diff --git a/fs/xfs/libxfs/xfs_types.c b/fs/xfs/libxfs/xfs_types.c
index 33a5ca346baf..895c232d63b7 100644
--- a/fs/xfs/libxfs/xfs_types.c
+++ b/fs/xfs/libxfs/xfs_types.c
@@ -89,14 +89,14 @@ xfs_agino_range(
89 */ 89 */
90 bno = round_up(XFS_AGFL_BLOCK(mp) + 1, 90 bno = round_up(XFS_AGFL_BLOCK(mp) + 1,
91 xfs_ialloc_cluster_alignment(mp)); 91 xfs_ialloc_cluster_alignment(mp));
92 *first = XFS_OFFBNO_TO_AGINO(mp, bno, 0); 92 *first = XFS_AGB_TO_AGINO(mp, bno);
93 93
94 /* 94 /*
95 * Calculate the last inode, which will be at the end of the 95 * Calculate the last inode, which will be at the end of the
96 * last (aligned) cluster that can be allocated in the AG. 96 * last (aligned) cluster that can be allocated in the AG.
97 */ 97 */
98 bno = round_down(eoag, xfs_ialloc_cluster_alignment(mp)); 98 bno = round_down(eoag, xfs_ialloc_cluster_alignment(mp));
99 *last = XFS_OFFBNO_TO_AGINO(mp, bno, 0) - 1; 99 *last = XFS_AGB_TO_AGINO(mp, bno) - 1;
100} 100}
101 101
102/* 102/*
diff --git a/fs/xfs/scrub/ialloc.c b/fs/xfs/scrub/ialloc.c
index 72f45b298fa5..426eb1a5503c 100644
--- a/fs/xfs/scrub/ialloc.c
+++ b/fs/xfs/scrub/ialloc.c
@@ -200,7 +200,7 @@ xchk_iallocbt_check_freemask(
200 200
201 /* Make sure the freemask matches the inode records. */ 201 /* Make sure the freemask matches the inode records. */
202 blks_per_cluster = xfs_icluster_size_fsb(mp); 202 blks_per_cluster = xfs_icluster_size_fsb(mp);
203 nr_inodes = XFS_OFFBNO_TO_AGINO(mp, blks_per_cluster, 0); 203 nr_inodes = XFS_FSB_TO_INO(mp, blks_per_cluster);
204 204
205 for (agino = irec->ir_startino; 205 for (agino = irec->ir_startino;
206 agino < irec->ir_startino + XFS_INODES_PER_CHUNK; 206 agino < irec->ir_startino + XFS_INODES_PER_CHUNK;
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index 093c2b8d7e20..ec2e63a7963b 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -252,7 +252,7 @@ xfs_growfs_data(
252 if (mp->m_sb.sb_imax_pct) { 252 if (mp->m_sb.sb_imax_pct) {
253 uint64_t icount = mp->m_sb.sb_dblocks * mp->m_sb.sb_imax_pct; 253 uint64_t icount = mp->m_sb.sb_dblocks * mp->m_sb.sb_imax_pct;
254 do_div(icount, 100); 254 do_div(icount, 100);
255 mp->m_maxicount = icount << mp->m_sb.sb_inopblog; 255 mp->m_maxicount = XFS_FSB_TO_INO(mp, icount);
256 } else 256 } else
257 mp->m_maxicount = 0; 257 mp->m_maxicount = 0;
258 258
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index f21756751540..801eb891d0fd 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -2200,7 +2200,7 @@ xfs_ifree_cluster(
2200 inum = xic->first_ino; 2200 inum = xic->first_ino;
2201 pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, inum)); 2201 pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, inum));
2202 blks_per_cluster = xfs_icluster_size_fsb(mp); 2202 blks_per_cluster = xfs_icluster_size_fsb(mp);
2203 inodes_per_cluster = blks_per_cluster << mp->m_sb.sb_inopblog; 2203 inodes_per_cluster = XFS_FSB_TO_INO(mp, blks_per_cluster);
2204 nbufs = mp->m_ialloc_blks / blks_per_cluster; 2204 nbufs = mp->m_ialloc_blks / blks_per_cluster;
2205 2205
2206 for (j = 0; j < nbufs; j++, inum += inodes_per_cluster) { 2206 for (j = 0; j < nbufs; j++, inum += inodes_per_cluster) {
diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
index e9508ba01ed1..18d8d3b812a7 100644
--- a/fs/xfs/xfs_itable.c
+++ b/fs/xfs/xfs_itable.c
@@ -173,7 +173,7 @@ xfs_bulkstat_ichunk_ra(
173 173
174 agbno = XFS_AGINO_TO_AGBNO(mp, irec->ir_startino); 174 agbno = XFS_AGINO_TO_AGBNO(mp, irec->ir_startino);
175 blks_per_cluster = xfs_icluster_size_fsb(mp); 175 blks_per_cluster = xfs_icluster_size_fsb(mp);
176 inodes_per_cluster = blks_per_cluster << mp->m_sb.sb_inopblog; 176 inodes_per_cluster = XFS_FSB_TO_INO(mp, blks_per_cluster);
177 177
178 blk_start_plug(&plug); 178 blk_start_plug(&plug);
179 for (i = 0; i < XFS_INODES_PER_CHUNK; 179 for (i = 0; i < XFS_INODES_PER_CHUNK;
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index a2e944b80d2a..c9097cb0b955 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -608,7 +608,7 @@ xfs_set_inode_alloc(
608 } 608 }
609 609
610 /* Get the last possible inode in the filesystem */ 610 /* Get the last possible inode in the filesystem */
611 agino = XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks - 1, 0); 611 agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
612 ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino); 612 ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
613 613
614 /* 614 /*
@@ -1150,7 +1150,7 @@ xfs_fs_statfs(
1150 statp->f_bfree = fdblocks - mp->m_alloc_set_aside; 1150 statp->f_bfree = fdblocks - mp->m_alloc_set_aside;
1151 statp->f_bavail = statp->f_bfree; 1151 statp->f_bavail = statp->f_bfree;
1152 1152
1153 fakeinos = statp->f_bfree << sbp->sb_inopblog; 1153 fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
1154 statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER); 1154 statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
1155 if (mp->m_maxicount) 1155 if (mp->m_maxicount)
1156 statp->f_files = min_t(typeof(statp->f_files), 1156 statp->f_files = min_t(typeof(statp->f_files),