aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorEric Sandeen <sandeen@sandeen.net>2017-01-09 10:38:36 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-01-12 05:39:39 -0500
commitf380ee72a7a498c934afe3aa67a50242b935f540 (patch)
tree23140340a4458debfddad4051a53f30ec98c2114 /fs
parent3978c5bb004312fd267aed7279fe64b119e126b0 (diff)
xfs: provide helper for counting extents from if_bytes
commit 5d829300bee000980a09ac2ccb761cb25867b67c upstream. The open-coded pattern: ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t) is all over the xfs code; provide a new helper xfs_iext_count(ifp) to count the number of inline extents in an inode fork. [dchinner: pick up several missed conversions] Signed-off-by: Eric Sandeen <sandeen@redhat.com> Reviewed-by: Brian Foster <bfoster@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com> Cc: Christoph Hellwig <hch@lst.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/xfs/libxfs/xfs_bmap.c49
-rw-r--r--fs/xfs/libxfs/xfs_inode_fork.c31
-rw-r--r--fs/xfs/libxfs/xfs_inode_fork.h1
-rw-r--r--fs/xfs/xfs_bmap_util.c34
-rw-r--r--fs/xfs/xfs_inode_item.c4
-rw-r--r--fs/xfs/xfs_ioctl.c6
-rw-r--r--fs/xfs/xfs_qm.c2
-rw-r--r--fs/xfs/xfs_reflink.c4
8 files changed, 64 insertions, 67 deletions
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 71dd6d783710..5c3c4dd14735 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -515,7 +515,7 @@ xfs_bmap_trace_exlist(
515 state |= BMAP_ATTRFORK; 515 state |= BMAP_ATTRFORK;
516 516
517 ifp = XFS_IFORK_PTR(ip, whichfork); 517 ifp = XFS_IFORK_PTR(ip, whichfork);
518 ASSERT(cnt == (ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t))); 518 ASSERT(cnt == xfs_iext_count(ifp));
519 for (idx = 0; idx < cnt; idx++) 519 for (idx = 0; idx < cnt; idx++)
520 trace_xfs_extlist(ip, idx, whichfork, caller_ip); 520 trace_xfs_extlist(ip, idx, whichfork, caller_ip);
521} 521}
@@ -811,7 +811,7 @@ try_another_ag:
811 XFS_BTREE_LONG_PTRS); 811 XFS_BTREE_LONG_PTRS);
812 812
813 arp = XFS_BMBT_REC_ADDR(mp, ablock, 1); 813 arp = XFS_BMBT_REC_ADDR(mp, ablock, 1);
814 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 814 nextents = xfs_iext_count(ifp);
815 for (cnt = i = 0; i < nextents; i++) { 815 for (cnt = i = 0; i < nextents; i++) {
816 ep = xfs_iext_get_ext(ifp, i); 816 ep = xfs_iext_get_ext(ifp, i);
817 if (!isnullstartblock(xfs_bmbt_get_startblock(ep))) { 817 if (!isnullstartblock(xfs_bmbt_get_startblock(ep))) {
@@ -1296,7 +1296,7 @@ xfs_bmap_read_extents(
1296 /* 1296 /*
1297 * Here with bp and block set to the leftmost leaf node in the tree. 1297 * Here with bp and block set to the leftmost leaf node in the tree.
1298 */ 1298 */
1299 room = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 1299 room = xfs_iext_count(ifp);
1300 i = 0; 1300 i = 0;
1301 /* 1301 /*
1302 * Loop over all leaf nodes. Copy information to the extent records. 1302 * Loop over all leaf nodes. Copy information to the extent records.
@@ -1361,7 +1361,7 @@ xfs_bmap_read_extents(
1361 return error; 1361 return error;
1362 block = XFS_BUF_TO_BLOCK(bp); 1362 block = XFS_BUF_TO_BLOCK(bp);
1363 } 1363 }
1364 ASSERT(i == (ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t))); 1364 ASSERT(i == xfs_iext_count(ifp));
1365 ASSERT(i == XFS_IFORK_NEXTENTS(ip, whichfork)); 1365 ASSERT(i == XFS_IFORK_NEXTENTS(ip, whichfork));
1366 XFS_BMAP_TRACE_EXLIST(ip, i, whichfork); 1366 XFS_BMAP_TRACE_EXLIST(ip, i, whichfork);
1367 return 0; 1367 return 0;
@@ -1404,7 +1404,7 @@ xfs_bmap_search_multi_extents(
1404 if (lastx > 0) { 1404 if (lastx > 0) {
1405 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, lastx - 1), prevp); 1405 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, lastx - 1), prevp);
1406 } 1406 }
1407 if (lastx < (ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t))) { 1407 if (lastx < xfs_iext_count(ifp)) {
1408 xfs_bmbt_get_all(ep, gotp); 1408 xfs_bmbt_get_all(ep, gotp);
1409 *eofp = 0; 1409 *eofp = 0;
1410 } else { 1410 } else {
@@ -1497,7 +1497,7 @@ xfs_bmap_first_unused(
1497 (error = xfs_iread_extents(tp, ip, whichfork))) 1497 (error = xfs_iread_extents(tp, ip, whichfork)))
1498 return error; 1498 return error;
1499 lowest = *first_unused; 1499 lowest = *first_unused;
1500 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 1500 nextents = xfs_iext_count(ifp);
1501 for (idx = 0, lastaddr = 0, max = lowest; idx < nextents; idx++) { 1501 for (idx = 0, lastaddr = 0, max = lowest; idx < nextents; idx++) {
1502 xfs_bmbt_rec_host_t *ep = xfs_iext_get_ext(ifp, idx); 1502 xfs_bmbt_rec_host_t *ep = xfs_iext_get_ext(ifp, idx);
1503 off = xfs_bmbt_get_startoff(ep); 1503 off = xfs_bmbt_get_startoff(ep);
@@ -1582,7 +1582,7 @@ xfs_bmap_last_extent(
1582 return error; 1582 return error;
1583 } 1583 }
1584 1584
1585 nextents = ifp->if_bytes / sizeof(xfs_bmbt_rec_t); 1585 nextents = xfs_iext_count(ifp);
1586 if (nextents == 0) { 1586 if (nextents == 0) {
1587 *is_empty = 1; 1587 *is_empty = 1;
1588 return 0; 1588 return 0;
@@ -1735,7 +1735,7 @@ xfs_bmap_add_extent_delay_real(
1735 &bma->ip->i_d.di_nextents); 1735 &bma->ip->i_d.di_nextents);
1736 1736
1737 ASSERT(bma->idx >= 0); 1737 ASSERT(bma->idx >= 0);
1738 ASSERT(bma->idx <= ifp->if_bytes / sizeof(struct xfs_bmbt_rec)); 1738 ASSERT(bma->idx <= xfs_iext_count(ifp));
1739 ASSERT(!isnullstartblock(new->br_startblock)); 1739 ASSERT(!isnullstartblock(new->br_startblock));
1740 ASSERT(!bma->cur || 1740 ASSERT(!bma->cur ||
1741 (bma->cur->bc_private.b.flags & XFS_BTCUR_BPRV_WASDEL)); 1741 (bma->cur->bc_private.b.flags & XFS_BTCUR_BPRV_WASDEL));
@@ -1794,7 +1794,7 @@ xfs_bmap_add_extent_delay_real(
1794 * Don't set contiguous if the combined extent would be too large. 1794 * Don't set contiguous if the combined extent would be too large.
1795 * Also check for all-three-contiguous being too large. 1795 * Also check for all-three-contiguous being too large.
1796 */ 1796 */
1797 if (bma->idx < ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t) - 1) { 1797 if (bma->idx < xfs_iext_count(ifp) - 1) {
1798 state |= BMAP_RIGHT_VALID; 1798 state |= BMAP_RIGHT_VALID;
1799 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, bma->idx + 1), &RIGHT); 1799 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, bma->idx + 1), &RIGHT);
1800 1800
@@ -2300,7 +2300,7 @@ xfs_bmap_add_extent_unwritten_real(
2300 ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK); 2300 ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK);
2301 2301
2302 ASSERT(*idx >= 0); 2302 ASSERT(*idx >= 0);
2303 ASSERT(*idx <= ifp->if_bytes / sizeof(struct xfs_bmbt_rec)); 2303 ASSERT(*idx <= xfs_iext_count(ifp));
2304 ASSERT(!isnullstartblock(new->br_startblock)); 2304 ASSERT(!isnullstartblock(new->br_startblock));
2305 2305
2306 XFS_STATS_INC(mp, xs_add_exlist); 2306 XFS_STATS_INC(mp, xs_add_exlist);
@@ -2356,7 +2356,7 @@ xfs_bmap_add_extent_unwritten_real(
2356 * Don't set contiguous if the combined extent would be too large. 2356 * Don't set contiguous if the combined extent would be too large.
2357 * Also check for all-three-contiguous being too large. 2357 * Also check for all-three-contiguous being too large.
2358 */ 2358 */
2359 if (*idx < ip->i_df.if_bytes / (uint)sizeof(xfs_bmbt_rec_t) - 1) { 2359 if (*idx < xfs_iext_count(&ip->i_df) - 1) {
2360 state |= BMAP_RIGHT_VALID; 2360 state |= BMAP_RIGHT_VALID;
2361 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *idx + 1), &RIGHT); 2361 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *idx + 1), &RIGHT);
2362 if (isnullstartblock(RIGHT.br_startblock)) 2362 if (isnullstartblock(RIGHT.br_startblock))
@@ -2836,7 +2836,7 @@ xfs_bmap_add_extent_hole_delay(
2836 * Check and set flags if the current (right) segment exists. 2836 * Check and set flags if the current (right) segment exists.
2837 * If it doesn't exist, we're converting the hole at end-of-file. 2837 * If it doesn't exist, we're converting the hole at end-of-file.
2838 */ 2838 */
2839 if (*idx < ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t)) { 2839 if (*idx < xfs_iext_count(ifp)) {
2840 state |= BMAP_RIGHT_VALID; 2840 state |= BMAP_RIGHT_VALID;
2841 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *idx), &right); 2841 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *idx), &right);
2842 2842
@@ -2966,7 +2966,7 @@ xfs_bmap_add_extent_hole_real(
2966 ifp = XFS_IFORK_PTR(bma->ip, whichfork); 2966 ifp = XFS_IFORK_PTR(bma->ip, whichfork);
2967 2967
2968 ASSERT(bma->idx >= 0); 2968 ASSERT(bma->idx >= 0);
2969 ASSERT(bma->idx <= ifp->if_bytes / sizeof(struct xfs_bmbt_rec)); 2969 ASSERT(bma->idx <= xfs_iext_count(ifp));
2970 ASSERT(!isnullstartblock(new->br_startblock)); 2970 ASSERT(!isnullstartblock(new->br_startblock));
2971 ASSERT(!bma->cur || 2971 ASSERT(!bma->cur ||
2972 !(bma->cur->bc_private.b.flags & XFS_BTCUR_BPRV_WASDEL)); 2972 !(bma->cur->bc_private.b.flags & XFS_BTCUR_BPRV_WASDEL));
@@ -2992,7 +2992,7 @@ xfs_bmap_add_extent_hole_real(
2992 * Check and set flags if this segment has a current value. 2992 * Check and set flags if this segment has a current value.
2993 * Not true if we're inserting into the "hole" at eof. 2993 * Not true if we're inserting into the "hole" at eof.
2994 */ 2994 */
2995 if (bma->idx < ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t)) { 2995 if (bma->idx < xfs_iext_count(ifp)) {
2996 state |= BMAP_RIGHT_VALID; 2996 state |= BMAP_RIGHT_VALID;
2997 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, bma->idx), &right); 2997 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, bma->idx), &right);
2998 if (isnullstartblock(right.br_startblock)) 2998 if (isnullstartblock(right.br_startblock))
@@ -4221,7 +4221,7 @@ xfs_bmapi_read(
4221 break; 4221 break;
4222 4222
4223 /* Else go on to the next record. */ 4223 /* Else go on to the next record. */
4224 if (++lastx < ifp->if_bytes / sizeof(xfs_bmbt_rec_t)) 4224 if (++lastx < xfs_iext_count(ifp))
4225 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, lastx), &got); 4225 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, lastx), &got);
4226 else 4226 else
4227 eof = 1; 4227 eof = 1;
@@ -4733,7 +4733,7 @@ xfs_bmapi_write(
4733 4733
4734 /* Else go on to the next record. */ 4734 /* Else go on to the next record. */
4735 bma.prev = bma.got; 4735 bma.prev = bma.got;
4736 if (++bma.idx < ifp->if_bytes / sizeof(xfs_bmbt_rec_t)) { 4736 if (++bma.idx < xfs_iext_count(ifp)) {
4737 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, bma.idx), 4737 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, bma.idx),
4738 &bma.got); 4738 &bma.got);
4739 } else 4739 } else
@@ -4885,7 +4885,7 @@ xfs_bmap_del_extent_delay(
4885 da_new = 0; 4885 da_new = 0;
4886 4886
4887 ASSERT(*idx >= 0); 4887 ASSERT(*idx >= 0);
4888 ASSERT(*idx < ifp->if_bytes / sizeof(struct xfs_bmbt_rec)); 4888 ASSERT(*idx <= xfs_iext_count(ifp));
4889 ASSERT(del->br_blockcount > 0); 4889 ASSERT(del->br_blockcount > 0);
4890 ASSERT(got->br_startoff <= del->br_startoff); 4890 ASSERT(got->br_startoff <= del->br_startoff);
4891 ASSERT(got_endoff >= del_endoff); 4891 ASSERT(got_endoff >= del_endoff);
@@ -5016,7 +5016,7 @@ xfs_bmap_del_extent_cow(
5016 got_endoff = got->br_startoff + got->br_blockcount; 5016 got_endoff = got->br_startoff + got->br_blockcount;
5017 5017
5018 ASSERT(*idx >= 0); 5018 ASSERT(*idx >= 0);
5019 ASSERT(*idx < ifp->if_bytes / sizeof(struct xfs_bmbt_rec)); 5019 ASSERT(*idx <= xfs_iext_count(ifp));
5020 ASSERT(del->br_blockcount > 0); 5020 ASSERT(del->br_blockcount > 0);
5021 ASSERT(got->br_startoff <= del->br_startoff); 5021 ASSERT(got->br_startoff <= del->br_startoff);
5022 ASSERT(got_endoff >= del_endoff); 5022 ASSERT(got_endoff >= del_endoff);
@@ -5122,8 +5122,7 @@ xfs_bmap_del_extent(
5122 state |= BMAP_COWFORK; 5122 state |= BMAP_COWFORK;
5123 5123
5124 ifp = XFS_IFORK_PTR(ip, whichfork); 5124 ifp = XFS_IFORK_PTR(ip, whichfork);
5125 ASSERT((*idx >= 0) && (*idx < ifp->if_bytes / 5125 ASSERT((*idx >= 0) && (*idx < xfs_iext_count(ifp)));
5126 (uint)sizeof(xfs_bmbt_rec_t)));
5127 ASSERT(del->br_blockcount > 0); 5126 ASSERT(del->br_blockcount > 0);
5128 ep = xfs_iext_get_ext(ifp, *idx); 5127 ep = xfs_iext_get_ext(ifp, *idx);
5129 xfs_bmbt_get_all(ep, &got); 5128 xfs_bmbt_get_all(ep, &got);
@@ -5448,7 +5447,6 @@ __xfs_bunmapi(
5448 int logflags; /* transaction logging flags */ 5447 int logflags; /* transaction logging flags */
5449 xfs_extlen_t mod; /* rt extent offset */ 5448 xfs_extlen_t mod; /* rt extent offset */
5450 xfs_mount_t *mp; /* mount structure */ 5449 xfs_mount_t *mp; /* mount structure */
5451 xfs_extnum_t nextents; /* number of file extents */
5452 xfs_bmbt_irec_t prev; /* previous extent record */ 5450 xfs_bmbt_irec_t prev; /* previous extent record */
5453 xfs_fileoff_t start; /* first file offset deleted */ 5451 xfs_fileoff_t start; /* first file offset deleted */
5454 int tmp_logflags; /* partial logging flags */ 5452 int tmp_logflags; /* partial logging flags */
@@ -5480,8 +5478,7 @@ __xfs_bunmapi(
5480 if (!(ifp->if_flags & XFS_IFEXTENTS) && 5478 if (!(ifp->if_flags & XFS_IFEXTENTS) &&
5481 (error = xfs_iread_extents(tp, ip, whichfork))) 5479 (error = xfs_iread_extents(tp, ip, whichfork)))
5482 return error; 5480 return error;
5483 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 5481 if (xfs_iext_count(ifp) == 0) {
5484 if (nextents == 0) {
5485 *rlen = 0; 5482 *rlen = 0;
5486 return 0; 5483 return 0;
5487 } 5484 }
@@ -5966,7 +5963,7 @@ xfs_bmse_shift_one(
5966 5963
5967 mp = ip->i_mount; 5964 mp = ip->i_mount;
5968 ifp = XFS_IFORK_PTR(ip, whichfork); 5965 ifp = XFS_IFORK_PTR(ip, whichfork);
5969 total_extents = ifp->if_bytes / sizeof(xfs_bmbt_rec_t); 5966 total_extents = xfs_iext_count(ifp);
5970 5967
5971 xfs_bmbt_get_all(gotp, &got); 5968 xfs_bmbt_get_all(gotp, &got);
5972 5969
@@ -6143,7 +6140,7 @@ xfs_bmap_shift_extents(
6143 * are collapsing out, so we cannot use the count of real extents here. 6140 * are collapsing out, so we cannot use the count of real extents here.
6144 * Instead we have to calculate it from the incore fork. 6141 * Instead we have to calculate it from the incore fork.
6145 */ 6142 */
6146 total_extents = ifp->if_bytes / sizeof(xfs_bmbt_rec_t); 6143 total_extents = xfs_iext_count(ifp);
6147 if (total_extents == 0) { 6144 if (total_extents == 0) {
6148 *done = 1; 6145 *done = 1;
6149 goto del_cursor; 6146 goto del_cursor;
@@ -6203,7 +6200,7 @@ xfs_bmap_shift_extents(
6203 * count can change. Update the total and grade the next record. 6200 * count can change. Update the total and grade the next record.
6204 */ 6201 */
6205 if (direction == SHIFT_LEFT) { 6202 if (direction == SHIFT_LEFT) {
6206 total_extents = ifp->if_bytes / sizeof(xfs_bmbt_rec_t); 6203 total_extents = xfs_iext_count(ifp);
6207 stop_extent = total_extents; 6204 stop_extent = total_extents;
6208 } 6205 }
6209 6206
diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c
index 5dd56d3dbb3a..5fbe24c31679 100644
--- a/fs/xfs/libxfs/xfs_inode_fork.c
+++ b/fs/xfs/libxfs/xfs_inode_fork.c
@@ -775,6 +775,13 @@ xfs_idestroy_fork(
775 } 775 }
776} 776}
777 777
778/* Count number of incore extents based on if_bytes */
779xfs_extnum_t
780xfs_iext_count(struct xfs_ifork *ifp)
781{
782 return ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t);
783}
784
778/* 785/*
779 * Convert in-core extents to on-disk form 786 * Convert in-core extents to on-disk form
780 * 787 *
@@ -803,7 +810,7 @@ xfs_iextents_copy(
803 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)); 810 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED));
804 ASSERT(ifp->if_bytes > 0); 811 ASSERT(ifp->if_bytes > 0);
805 812
806 nrecs = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 813 nrecs = xfs_iext_count(ifp);
807 XFS_BMAP_TRACE_EXLIST(ip, nrecs, whichfork); 814 XFS_BMAP_TRACE_EXLIST(ip, nrecs, whichfork);
808 ASSERT(nrecs > 0); 815 ASSERT(nrecs > 0);
809 816
@@ -941,7 +948,7 @@ xfs_iext_get_ext(
941 xfs_extnum_t idx) /* index of target extent */ 948 xfs_extnum_t idx) /* index of target extent */
942{ 949{
943 ASSERT(idx >= 0); 950 ASSERT(idx >= 0);
944 ASSERT(idx < ifp->if_bytes / sizeof(xfs_bmbt_rec_t)); 951 ASSERT(idx < xfs_iext_count(ifp));
945 952
946 if ((ifp->if_flags & XFS_IFEXTIREC) && (idx == 0)) { 953 if ((ifp->if_flags & XFS_IFEXTIREC) && (idx == 0)) {
947 return ifp->if_u1.if_ext_irec->er_extbuf; 954 return ifp->if_u1.if_ext_irec->er_extbuf;
@@ -1017,7 +1024,7 @@ xfs_iext_add(
1017 int new_size; /* size of extents after adding */ 1024 int new_size; /* size of extents after adding */
1018 xfs_extnum_t nextents; /* number of extents in file */ 1025 xfs_extnum_t nextents; /* number of extents in file */
1019 1026
1020 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 1027 nextents = xfs_iext_count(ifp);
1021 ASSERT((idx >= 0) && (idx <= nextents)); 1028 ASSERT((idx >= 0) && (idx <= nextents));
1022 byte_diff = ext_diff * sizeof(xfs_bmbt_rec_t); 1029 byte_diff = ext_diff * sizeof(xfs_bmbt_rec_t);
1023 new_size = ifp->if_bytes + byte_diff; 1030 new_size = ifp->if_bytes + byte_diff;
@@ -1241,7 +1248,7 @@ xfs_iext_remove(
1241 trace_xfs_iext_remove(ip, idx, state, _RET_IP_); 1248 trace_xfs_iext_remove(ip, idx, state, _RET_IP_);
1242 1249
1243 ASSERT(ext_diff > 0); 1250 ASSERT(ext_diff > 0);
1244 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 1251 nextents = xfs_iext_count(ifp);
1245 new_size = (nextents - ext_diff) * sizeof(xfs_bmbt_rec_t); 1252 new_size = (nextents - ext_diff) * sizeof(xfs_bmbt_rec_t);
1246 1253
1247 if (new_size == 0) { 1254 if (new_size == 0) {
@@ -1270,7 +1277,7 @@ xfs_iext_remove_inline(
1270 1277
1271 ASSERT(!(ifp->if_flags & XFS_IFEXTIREC)); 1278 ASSERT(!(ifp->if_flags & XFS_IFEXTIREC));
1272 ASSERT(idx < XFS_INLINE_EXTS); 1279 ASSERT(idx < XFS_INLINE_EXTS);
1273 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 1280 nextents = xfs_iext_count(ifp);
1274 ASSERT(((nextents - ext_diff) > 0) && 1281 ASSERT(((nextents - ext_diff) > 0) &&
1275 (nextents - ext_diff) < XFS_INLINE_EXTS); 1282 (nextents - ext_diff) < XFS_INLINE_EXTS);
1276 1283
@@ -1309,7 +1316,7 @@ xfs_iext_remove_direct(
1309 ASSERT(!(ifp->if_flags & XFS_IFEXTIREC)); 1316 ASSERT(!(ifp->if_flags & XFS_IFEXTIREC));
1310 new_size = ifp->if_bytes - 1317 new_size = ifp->if_bytes -
1311 (ext_diff * sizeof(xfs_bmbt_rec_t)); 1318 (ext_diff * sizeof(xfs_bmbt_rec_t));
1312 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 1319 nextents = xfs_iext_count(ifp);
1313 1320
1314 if (new_size == 0) { 1321 if (new_size == 0) {
1315 xfs_iext_destroy(ifp); 1322 xfs_iext_destroy(ifp);
@@ -1546,7 +1553,7 @@ xfs_iext_indirect_to_direct(
1546 int size; /* size of file extents */ 1553 int size; /* size of file extents */
1547 1554
1548 ASSERT(ifp->if_flags & XFS_IFEXTIREC); 1555 ASSERT(ifp->if_flags & XFS_IFEXTIREC);
1549 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 1556 nextents = xfs_iext_count(ifp);
1550 ASSERT(nextents <= XFS_LINEAR_EXTS); 1557 ASSERT(nextents <= XFS_LINEAR_EXTS);
1551 size = nextents * sizeof(xfs_bmbt_rec_t); 1558 size = nextents * sizeof(xfs_bmbt_rec_t);
1552 1559
@@ -1620,7 +1627,7 @@ xfs_iext_bno_to_ext(
1620 xfs_extnum_t nextents; /* number of file extents */ 1627 xfs_extnum_t nextents; /* number of file extents */
1621 xfs_fileoff_t startoff = 0; /* start offset of extent */ 1628 xfs_fileoff_t startoff = 0; /* start offset of extent */
1622 1629
1623 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 1630 nextents = xfs_iext_count(ifp);
1624 if (nextents == 0) { 1631 if (nextents == 0) {
1625 *idxp = 0; 1632 *idxp = 0;
1626 return NULL; 1633 return NULL;
@@ -1733,8 +1740,8 @@ xfs_iext_idx_to_irec(
1733 1740
1734 ASSERT(ifp->if_flags & XFS_IFEXTIREC); 1741 ASSERT(ifp->if_flags & XFS_IFEXTIREC);
1735 ASSERT(page_idx >= 0); 1742 ASSERT(page_idx >= 0);
1736 ASSERT(page_idx <= ifp->if_bytes / sizeof(xfs_bmbt_rec_t)); 1743 ASSERT(page_idx <= xfs_iext_count(ifp));
1737 ASSERT(page_idx < ifp->if_bytes / sizeof(xfs_bmbt_rec_t) || realloc); 1744 ASSERT(page_idx < xfs_iext_count(ifp) || realloc);
1738 1745
1739 nlists = ifp->if_real_bytes / XFS_IEXT_BUFSZ; 1746 nlists = ifp->if_real_bytes / XFS_IEXT_BUFSZ;
1740 erp_idx = 0; 1747 erp_idx = 0;
@@ -1782,7 +1789,7 @@ xfs_iext_irec_init(
1782 xfs_extnum_t nextents; /* number of extents in file */ 1789 xfs_extnum_t nextents; /* number of extents in file */
1783 1790
1784 ASSERT(!(ifp->if_flags & XFS_IFEXTIREC)); 1791 ASSERT(!(ifp->if_flags & XFS_IFEXTIREC));
1785 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 1792 nextents = xfs_iext_count(ifp);
1786 ASSERT(nextents <= XFS_LINEAR_EXTS); 1793 ASSERT(nextents <= XFS_LINEAR_EXTS);
1787 1794
1788 erp = kmem_alloc(sizeof(xfs_ext_irec_t), KM_NOFS); 1795 erp = kmem_alloc(sizeof(xfs_ext_irec_t), KM_NOFS);
@@ -1906,7 +1913,7 @@ xfs_iext_irec_compact(
1906 1913
1907 ASSERT(ifp->if_flags & XFS_IFEXTIREC); 1914 ASSERT(ifp->if_flags & XFS_IFEXTIREC);
1908 nlists = ifp->if_real_bytes / XFS_IEXT_BUFSZ; 1915 nlists = ifp->if_real_bytes / XFS_IEXT_BUFSZ;
1909 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 1916 nextents = xfs_iext_count(ifp);
1910 1917
1911 if (nextents == 0) { 1918 if (nextents == 0) {
1912 xfs_iext_destroy(ifp); 1919 xfs_iext_destroy(ifp);
diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h
index c9476f50e32d..8bf112e29aa1 100644
--- a/fs/xfs/libxfs/xfs_inode_fork.h
+++ b/fs/xfs/libxfs/xfs_inode_fork.h
@@ -152,6 +152,7 @@ void xfs_init_local_fork(struct xfs_inode *, int, const void *, int);
152 152
153struct xfs_bmbt_rec_host * 153struct xfs_bmbt_rec_host *
154 xfs_iext_get_ext(struct xfs_ifork *, xfs_extnum_t); 154 xfs_iext_get_ext(struct xfs_ifork *, xfs_extnum_t);
155xfs_extnum_t xfs_iext_count(struct xfs_ifork *);
155void xfs_iext_insert(struct xfs_inode *, xfs_extnum_t, xfs_extnum_t, 156void xfs_iext_insert(struct xfs_inode *, xfs_extnum_t, xfs_extnum_t,
156 struct xfs_bmbt_irec *, int); 157 struct xfs_bmbt_irec *, int);
157void xfs_iext_add(struct xfs_ifork *, xfs_extnum_t, int); 158void xfs_iext_add(struct xfs_ifork *, xfs_extnum_t, int);
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 47074e0c33f3..0670a8bd5818 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -359,9 +359,7 @@ xfs_bmap_count_blocks(
359 mp = ip->i_mount; 359 mp = ip->i_mount;
360 ifp = XFS_IFORK_PTR(ip, whichfork); 360 ifp = XFS_IFORK_PTR(ip, whichfork);
361 if ( XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_EXTENTS ) { 361 if ( XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_EXTENTS ) {
362 xfs_bmap_count_leaves(ifp, 0, 362 xfs_bmap_count_leaves(ifp, 0, xfs_iext_count(ifp), count);
363 ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t),
364 count);
365 return 0; 363 return 0;
366 } 364 }
367 365
@@ -426,7 +424,7 @@ xfs_getbmapx_fix_eof_hole(
426 ifp = XFS_IFORK_PTR(ip, whichfork); 424 ifp = XFS_IFORK_PTR(ip, whichfork);
427 if (!moretocome && 425 if (!moretocome &&
428 xfs_iext_bno_to_ext(ifp, fileblock, &lastx) && 426 xfs_iext_bno_to_ext(ifp, fileblock, &lastx) &&
429 (lastx == (ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t))-1)) 427 (lastx == xfs_iext_count(ifp) - 1))
430 out->bmv_oflags |= BMV_OF_LAST; 428 out->bmv_oflags |= BMV_OF_LAST;
431 } 429 }
432 430
@@ -1878,15 +1876,13 @@ xfs_swap_extent_forks(
1878 1876
1879 switch (ip->i_d.di_format) { 1877 switch (ip->i_d.di_format) {
1880 case XFS_DINODE_FMT_EXTENTS: 1878 case XFS_DINODE_FMT_EXTENTS:
1881 /* If the extents fit in the inode, fix the 1879 /*
1882 * pointer. Otherwise it's already NULL or 1880 * If the extents fit in the inode, fix the pointer. Otherwise
1883 * pointing to the extent. 1881 * it's already NULL or pointing to the extent.
1884 */ 1882 */
1885 nextents = ip->i_df.if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 1883 nextents = xfs_iext_count(&ip->i_df);
1886 if (nextents <= XFS_INLINE_EXTS) { 1884 if (nextents <= XFS_INLINE_EXTS)
1887 ifp->if_u1.if_extents = 1885 ifp->if_u1.if_extents = ifp->if_u2.if_inline_ext;
1888 ifp->if_u2.if_inline_ext;
1889 }
1890 (*src_log_flags) |= XFS_ILOG_DEXT; 1886 (*src_log_flags) |= XFS_ILOG_DEXT;
1891 break; 1887 break;
1892 case XFS_DINODE_FMT_BTREE: 1888 case XFS_DINODE_FMT_BTREE:
@@ -1898,15 +1894,13 @@ xfs_swap_extent_forks(
1898 1894
1899 switch (tip->i_d.di_format) { 1895 switch (tip->i_d.di_format) {
1900 case XFS_DINODE_FMT_EXTENTS: 1896 case XFS_DINODE_FMT_EXTENTS:
1901 /* If the extents fit in the inode, fix the 1897 /*
1902 * pointer. Otherwise it's already NULL or 1898 * If the extents fit in the inode, fix the pointer. Otherwise
1903 * pointing to the extent. 1899 * it's already NULL or pointing to the extent.
1904 */ 1900 */
1905 nextents = tip->i_df.if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 1901 nextents = xfs_iext_count(&tip->i_df);
1906 if (nextents <= XFS_INLINE_EXTS) { 1902 if (nextents <= XFS_INLINE_EXTS)
1907 tifp->if_u1.if_extents = 1903 tifp->if_u1.if_extents = tifp->if_u2.if_inline_ext;
1908 tifp->if_u2.if_inline_ext;
1909 }
1910 (*target_log_flags) |= XFS_ILOG_DEXT; 1904 (*target_log_flags) |= XFS_ILOG_DEXT;
1911 break; 1905 break;
1912 case XFS_DINODE_FMT_BTREE: 1906 case XFS_DINODE_FMT_BTREE:
diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c
index 9610e9c00952..d90e7811ccdd 100644
--- a/fs/xfs/xfs_inode_item.c
+++ b/fs/xfs/xfs_inode_item.c
@@ -164,7 +164,7 @@ xfs_inode_item_format_data_fork(
164 struct xfs_bmbt_rec *p; 164 struct xfs_bmbt_rec *p;
165 165
166 ASSERT(ip->i_df.if_u1.if_extents != NULL); 166 ASSERT(ip->i_df.if_u1.if_extents != NULL);
167 ASSERT(ip->i_df.if_bytes / sizeof(xfs_bmbt_rec_t) > 0); 167 ASSERT(xfs_iext_count(&ip->i_df) > 0);
168 168
169 p = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_IEXT); 169 p = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_IEXT);
170 data_bytes = xfs_iextents_copy(ip, p, XFS_DATA_FORK); 170 data_bytes = xfs_iextents_copy(ip, p, XFS_DATA_FORK);
@@ -261,7 +261,7 @@ xfs_inode_item_format_attr_fork(
261 ip->i_afp->if_bytes > 0) { 261 ip->i_afp->if_bytes > 0) {
262 struct xfs_bmbt_rec *p; 262 struct xfs_bmbt_rec *p;
263 263
264 ASSERT(ip->i_afp->if_bytes / sizeof(xfs_bmbt_rec_t) == 264 ASSERT(xfs_iext_count(ip->i_afp) ==
265 ip->i_d.di_anextents); 265 ip->i_d.di_anextents);
266 ASSERT(ip->i_afp->if_u1.if_extents != NULL); 266 ASSERT(ip->i_afp->if_u1.if_extents != NULL);
267 267
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index c245bed3249b..a39197501a7c 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -910,16 +910,14 @@ xfs_ioc_fsgetxattr(
910 if (attr) { 910 if (attr) {
911 if (ip->i_afp) { 911 if (ip->i_afp) {
912 if (ip->i_afp->if_flags & XFS_IFEXTENTS) 912 if (ip->i_afp->if_flags & XFS_IFEXTENTS)
913 fa.fsx_nextents = ip->i_afp->if_bytes / 913 fa.fsx_nextents = xfs_iext_count(ip->i_afp);
914 sizeof(xfs_bmbt_rec_t);
915 else 914 else
916 fa.fsx_nextents = ip->i_d.di_anextents; 915 fa.fsx_nextents = ip->i_d.di_anextents;
917 } else 916 } else
918 fa.fsx_nextents = 0; 917 fa.fsx_nextents = 0;
919 } else { 918 } else {
920 if (ip->i_df.if_flags & XFS_IFEXTENTS) 919 if (ip->i_df.if_flags & XFS_IFEXTENTS)
921 fa.fsx_nextents = ip->i_df.if_bytes / 920 fa.fsx_nextents = xfs_iext_count(&ip->i_df);
922 sizeof(xfs_bmbt_rec_t);
923 else 921 else
924 fa.fsx_nextents = ip->i_d.di_nextents; 922 fa.fsx_nextents = ip->i_d.di_nextents;
925 } 923 }
diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c
index a60d9e2739d1..45e50ea90769 100644
--- a/fs/xfs/xfs_qm.c
+++ b/fs/xfs/xfs_qm.c
@@ -1135,7 +1135,7 @@ xfs_qm_get_rtblks(
1135 return error; 1135 return error;
1136 } 1136 }
1137 rtblks = 0; 1137 rtblks = 0;
1138 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 1138 nextents = xfs_iext_count(ifp);
1139 for (idx = 0; idx < nextents; idx++) 1139 for (idx = 0; idx < nextents; idx++)
1140 rtblks += xfs_bmbt_get_blockcount(xfs_iext_get_ext(ifp, idx)); 1140 rtblks += xfs_bmbt_get_blockcount(xfs_iext_get_ext(ifp, idx));
1141 *O_rtblks = (xfs_qcnt_t)rtblks; 1141 *O_rtblks = (xfs_qcnt_t)rtblks;
diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index c06904893202..0edf835af32d 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -486,7 +486,7 @@ xfs_reflink_trim_irec_to_next_cow(
486 /* This is the extent before; try sliding up one. */ 486 /* This is the extent before; try sliding up one. */
487 if (irec.br_startoff < offset_fsb) { 487 if (irec.br_startoff < offset_fsb) {
488 idx++; 488 idx++;
489 if (idx >= ifp->if_bytes / sizeof(xfs_bmbt_rec_t)) 489 if (idx >= xfs_iext_count(ifp))
490 return 0; 490 return 0;
491 gotp = xfs_iext_get_ext(ifp, idx); 491 gotp = xfs_iext_get_ext(ifp, idx);
492 xfs_bmbt_get_all(gotp, &irec); 492 xfs_bmbt_get_all(gotp, &irec);
@@ -566,7 +566,7 @@ xfs_reflink_cancel_cow_blocks(
566 xfs_bmap_del_extent_cow(ip, &idx, &got, &del); 566 xfs_bmap_del_extent_cow(ip, &idx, &got, &del);
567 } 567 }
568 568
569 if (++idx >= ifp->if_bytes / sizeof(struct xfs_bmbt_rec)) 569 if (++idx >= xfs_iext_count(ifp))
570 break; 570 break;
571 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx), &got); 571 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx), &got);
572 } 572 }