aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2011-12-18 15:00:07 -0500
committerBen Myers <bpm@sgi.com>2012-01-17 16:02:28 -0500
commit8096b1ebb59b94b3bc6abb6b7d121419e83447ba (patch)
tree3d01d19459cbb973dc8698b7fa44e1bee260303d /fs/xfs
parent3d2b3129c2c48cf0153e0f2058cf87e4b45ca3ac (diff)
xfs: remove the if_ext_max field in struct xfs_ifork
We spent a lot of effort to maintain this field, but it always equals to the fork size divided by the constant size of an extent. The prime use of it is to assert that the two stay in sync. Just divide the fork size by the extent size in the few places that we actually use it and remove the overhead of maintaining it. Also introduce a few helpers to consolidate the places where we actually care about the value. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Ben Myers <bpm@sgi.com>
Diffstat (limited to 'fs/xfs')
-rw-r--r--fs/xfs/xfs_attr_leaf.c9
-rw-r--r--fs/xfs/xfs_bmap.c101
-rw-r--r--fs/xfs/xfs_dfrag.c43
-rw-r--r--fs/xfs/xfs_iget.c2
-rw-r--r--fs/xfs/xfs_inode.c30
-rw-r--r--fs/xfs/xfs_inode.h4
-rw-r--r--fs/xfs/xfs_inode_item.c2
-rw-r--r--fs/xfs/xfs_trace.h5
8 files changed, 81 insertions, 115 deletions
diff --git a/fs/xfs/xfs_attr_leaf.c b/fs/xfs/xfs_attr_leaf.c
index c1b55e596551..d25eafd4d28d 100644
--- a/fs/xfs/xfs_attr_leaf.c
+++ b/fs/xfs/xfs_attr_leaf.c
@@ -271,10 +271,6 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
271 dp = args->dp; 271 dp = args->dp;
272 mp = dp->i_mount; 272 mp = dp->i_mount;
273 dp->i_d.di_forkoff = forkoff; 273 dp->i_d.di_forkoff = forkoff;
274 dp->i_df.if_ext_max =
275 XFS_IFORK_DSIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
276 dp->i_afp->if_ext_max =
277 XFS_IFORK_ASIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
278 274
279 ifp = dp->i_afp; 275 ifp = dp->i_afp;
280 ASSERT(ifp->if_flags & XFS_IFINLINE); 276 ASSERT(ifp->if_flags & XFS_IFINLINE);
@@ -326,7 +322,6 @@ xfs_attr_fork_reset(
326 ASSERT(ip->i_d.di_anextents == 0); 322 ASSERT(ip->i_d.di_anextents == 0);
327 ASSERT(ip->i_afp == NULL); 323 ASSERT(ip->i_afp == NULL);
328 324
329 ip->i_df.if_ext_max = XFS_IFORK_DSIZE(ip) / sizeof(xfs_bmbt_rec_t);
330 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); 325 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
331} 326}
332 327
@@ -389,10 +384,6 @@ xfs_attr_shortform_remove(xfs_da_args_t *args)
389 (args->op_flags & XFS_DA_OP_ADDNAME) || 384 (args->op_flags & XFS_DA_OP_ADDNAME) ||
390 !(mp->m_flags & XFS_MOUNT_ATTR2) || 385 !(mp->m_flags & XFS_MOUNT_ATTR2) ||
391 dp->i_d.di_format == XFS_DINODE_FMT_BTREE); 386 dp->i_d.di_format == XFS_DINODE_FMT_BTREE);
392 dp->i_afp->if_ext_max =
393 XFS_IFORK_ASIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
394 dp->i_df.if_ext_max =
395 XFS_IFORK_DSIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
396 xfs_trans_log_inode(args->trans, dp, 387 xfs_trans_log_inode(args->trans, dp,
397 XFS_ILOG_CORE | XFS_ILOG_ADATA); 388 XFS_ILOG_CORE | XFS_ILOG_ADATA);
398 } 389 }
diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
index d0ab78837057..7a888ca2f7f6 100644
--- a/fs/xfs/xfs_bmap.c
+++ b/fs/xfs/xfs_bmap.c
@@ -249,7 +249,27 @@ xfs_bmbt_lookup_ge(
249} 249}
250 250
251/* 251/*
252* Update the record referred to by cur to the value given 252 * Check if the inode needs to be converted to btree format.
253 */
254static inline bool xfs_bmap_needs_btree(struct xfs_inode *ip, int whichfork)
255{
256 return XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_EXTENTS &&
257 XFS_IFORK_NEXTENTS(ip, whichfork) >
258 XFS_IFORK_MAXEXT(ip, whichfork);
259}
260
261/*
262 * Check if the inode should be converted to extent format.
263 */
264static inline bool xfs_bmap_wants_extents(struct xfs_inode *ip, int whichfork)
265{
266 return XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE &&
267 XFS_IFORK_NEXTENTS(ip, whichfork) <=
268 XFS_IFORK_MAXEXT(ip, whichfork);
269}
270
271/*
272 * Update the record referred to by cur to the value given
253 * by [off, bno, len, state]. 273 * by [off, bno, len, state].
254 * This either works (return 0) or gets an EFSCORRUPTED error. 274 * This either works (return 0) or gets an EFSCORRUPTED error.
255 */ 275 */
@@ -683,8 +703,8 @@ xfs_bmap_add_extent_delay_real(
683 goto done; 703 goto done;
684 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 704 XFS_WANT_CORRUPTED_GOTO(i == 1, done);
685 } 705 }
686 if (bma->ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS && 706
687 bma->ip->i_d.di_nextents > bma->ip->i_df.if_ext_max) { 707 if (xfs_bmap_needs_btree(bma->ip, XFS_DATA_FORK)) {
688 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip, 708 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
689 bma->firstblock, bma->flist, 709 bma->firstblock, bma->flist,
690 &bma->cur, 1, &tmp_rval, XFS_DATA_FORK); 710 &bma->cur, 1, &tmp_rval, XFS_DATA_FORK);
@@ -767,8 +787,8 @@ xfs_bmap_add_extent_delay_real(
767 goto done; 787 goto done;
768 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 788 XFS_WANT_CORRUPTED_GOTO(i == 1, done);
769 } 789 }
770 if (bma->ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS && 790
771 bma->ip->i_d.di_nextents > bma->ip->i_df.if_ext_max) { 791 if (xfs_bmap_needs_btree(bma->ip, XFS_DATA_FORK)) {
772 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip, 792 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
773 bma->firstblock, bma->flist, &bma->cur, 1, 793 bma->firstblock, bma->flist, &bma->cur, 1,
774 &tmp_rval, XFS_DATA_FORK); 794 &tmp_rval, XFS_DATA_FORK);
@@ -836,8 +856,8 @@ xfs_bmap_add_extent_delay_real(
836 goto done; 856 goto done;
837 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 857 XFS_WANT_CORRUPTED_GOTO(i == 1, done);
838 } 858 }
839 if (bma->ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS && 859
840 bma->ip->i_d.di_nextents > bma->ip->i_df.if_ext_max) { 860 if (xfs_bmap_needs_btree(bma->ip, XFS_DATA_FORK)) {
841 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip, 861 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
842 bma->firstblock, bma->flist, &bma->cur, 862 bma->firstblock, bma->flist, &bma->cur,
843 1, &tmp_rval, XFS_DATA_FORK); 863 1, &tmp_rval, XFS_DATA_FORK);
@@ -884,8 +904,7 @@ xfs_bmap_add_extent_delay_real(
884 } 904 }
885 905
886 /* convert to a btree if necessary */ 906 /* convert to a btree if necessary */
887 if (XFS_IFORK_FORMAT(bma->ip, XFS_DATA_FORK) == XFS_DINODE_FMT_EXTENTS && 907 if (xfs_bmap_needs_btree(bma->ip, XFS_DATA_FORK)) {
888 XFS_IFORK_NEXTENTS(bma->ip, XFS_DATA_FORK) > ifp->if_ext_max) {
889 int tmp_logflags; /* partial log flag return val */ 908 int tmp_logflags; /* partial log flag return val */
890 909
891 ASSERT(bma->cur == NULL); 910 ASSERT(bma->cur == NULL);
@@ -1421,8 +1440,7 @@ xfs_bmap_add_extent_unwritten_real(
1421 } 1440 }
1422 1441
1423 /* convert to a btree if necessary */ 1442 /* convert to a btree if necessary */
1424 if (XFS_IFORK_FORMAT(ip, XFS_DATA_FORK) == XFS_DINODE_FMT_EXTENTS && 1443 if (xfs_bmap_needs_btree(ip, XFS_DATA_FORK)) {
1425 XFS_IFORK_NEXTENTS(ip, XFS_DATA_FORK) > ifp->if_ext_max) {
1426 int tmp_logflags; /* partial log flag return val */ 1444 int tmp_logflags; /* partial log flag return val */
1427 1445
1428 ASSERT(cur == NULL); 1446 ASSERT(cur == NULL);
@@ -1812,8 +1830,7 @@ xfs_bmap_add_extent_hole_real(
1812 } 1830 }
1813 1831
1814 /* convert to a btree if necessary */ 1832 /* convert to a btree if necessary */
1815 if (XFS_IFORK_FORMAT(bma->ip, whichfork) == XFS_DINODE_FMT_EXTENTS && 1833 if (xfs_bmap_needs_btree(bma->ip, whichfork)) {
1816 XFS_IFORK_NEXTENTS(bma->ip, whichfork) > ifp->if_ext_max) {
1817 int tmp_logflags; /* partial log flag return val */ 1834 int tmp_logflags; /* partial log flag return val */
1818 1835
1819 ASSERT(bma->cur == NULL); 1836 ASSERT(bma->cur == NULL);
@@ -3037,8 +3054,7 @@ xfs_bmap_extents_to_btree(
3037 3054
3038 ifp = XFS_IFORK_PTR(ip, whichfork); 3055 ifp = XFS_IFORK_PTR(ip, whichfork);
3039 ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_EXTENTS); 3056 ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_EXTENTS);
3040 ASSERT(ifp->if_ext_max == 3057
3041 XFS_IFORK_SIZE(ip, whichfork) / (uint)sizeof(xfs_bmbt_rec_t));
3042 /* 3058 /*
3043 * Make space in the inode incore. 3059 * Make space in the inode incore.
3044 */ 3060 */
@@ -3184,13 +3200,8 @@ xfs_bmap_forkoff_reset(
3184 ip->i_d.di_format != XFS_DINODE_FMT_BTREE) { 3200 ip->i_d.di_format != XFS_DINODE_FMT_BTREE) {
3185 uint dfl_forkoff = xfs_default_attroffset(ip) >> 3; 3201 uint dfl_forkoff = xfs_default_attroffset(ip) >> 3;
3186 3202
3187 if (dfl_forkoff > ip->i_d.di_forkoff) { 3203 if (dfl_forkoff > ip->i_d.di_forkoff)
3188 ip->i_d.di_forkoff = dfl_forkoff; 3204 ip->i_d.di_forkoff = dfl_forkoff;
3189 ip->i_df.if_ext_max =
3190 XFS_IFORK_DSIZE(ip) / sizeof(xfs_bmbt_rec_t);
3191 ip->i_afp->if_ext_max =
3192 XFS_IFORK_ASIZE(ip) / sizeof(xfs_bmbt_rec_t);
3193 }
3194 } 3205 }
3195} 3206}
3196 3207
@@ -3430,8 +3441,6 @@ xfs_bmap_add_attrfork(
3430 int error; /* error return value */ 3441 int error; /* error return value */
3431 3442
3432 ASSERT(XFS_IFORK_Q(ip) == 0); 3443 ASSERT(XFS_IFORK_Q(ip) == 0);
3433 ASSERT(ip->i_df.if_ext_max ==
3434 XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t));
3435 3444
3436 mp = ip->i_mount; 3445 mp = ip->i_mount;
3437 ASSERT(!XFS_NOT_DQATTACHED(mp, ip)); 3446 ASSERT(!XFS_NOT_DQATTACHED(mp, ip));
@@ -3486,12 +3495,9 @@ xfs_bmap_add_attrfork(
3486 error = XFS_ERROR(EINVAL); 3495 error = XFS_ERROR(EINVAL);
3487 goto error1; 3496 goto error1;
3488 } 3497 }
3489 ip->i_df.if_ext_max = 3498
3490 XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t);
3491 ASSERT(ip->i_afp == NULL); 3499 ASSERT(ip->i_afp == NULL);
3492 ip->i_afp = kmem_zone_zalloc(xfs_ifork_zone, KM_SLEEP); 3500 ip->i_afp = kmem_zone_zalloc(xfs_ifork_zone, KM_SLEEP);
3493 ip->i_afp->if_ext_max =
3494 XFS_IFORK_ASIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t);
3495 ip->i_afp->if_flags = XFS_IFEXTENTS; 3501 ip->i_afp->if_flags = XFS_IFEXTENTS;
3496 logflags = 0; 3502 logflags = 0;
3497 xfs_bmap_init(&flist, &firstblock); 3503 xfs_bmap_init(&flist, &firstblock);
@@ -3535,20 +3541,17 @@ xfs_bmap_add_attrfork(
3535 } else 3541 } else
3536 spin_unlock(&mp->m_sb_lock); 3542 spin_unlock(&mp->m_sb_lock);
3537 } 3543 }
3538 if ((error = xfs_bmap_finish(&tp, &flist, &committed))) 3544
3545 error = xfs_bmap_finish(&tp, &flist, &committed);
3546 if (error)
3539 goto error2; 3547 goto error2;
3540 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES); 3548 return xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
3541 ASSERT(ip->i_df.if_ext_max ==
3542 XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t));
3543 return error;
3544error2: 3549error2:
3545 xfs_bmap_cancel(&flist); 3550 xfs_bmap_cancel(&flist);
3546error1: 3551error1:
3547 xfs_iunlock(ip, XFS_ILOCK_EXCL); 3552 xfs_iunlock(ip, XFS_ILOCK_EXCL);
3548error0: 3553error0:
3549 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT); 3554 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
3550 ASSERT(ip->i_df.if_ext_max ==
3551 XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t));
3552 return error; 3555 return error;
3553} 3556}
3554 3557
@@ -4379,8 +4382,6 @@ xfs_bmapi_read(
4379 XFS_STATS_INC(xs_blk_mapr); 4382 XFS_STATS_INC(xs_blk_mapr);
4380 4383
4381 ifp = XFS_IFORK_PTR(ip, whichfork); 4384 ifp = XFS_IFORK_PTR(ip, whichfork);
4382 ASSERT(ifp->if_ext_max ==
4383 XFS_IFORK_SIZE(ip, whichfork) / (uint)sizeof(xfs_bmbt_rec_t));
4384 4385
4385 if (!(ifp->if_flags & XFS_IFEXTENTS)) { 4386 if (!(ifp->if_flags & XFS_IFEXTENTS)) {
4386 error = xfs_iread_extents(NULL, ip, whichfork); 4387 error = xfs_iread_extents(NULL, ip, whichfork);
@@ -4871,8 +4872,6 @@ xfs_bmapi_write(
4871 return XFS_ERROR(EIO); 4872 return XFS_ERROR(EIO);
4872 4873
4873 ifp = XFS_IFORK_PTR(ip, whichfork); 4874 ifp = XFS_IFORK_PTR(ip, whichfork);
4874 ASSERT(ifp->if_ext_max ==
4875 XFS_IFORK_SIZE(ip, whichfork) / (uint)sizeof(xfs_bmbt_rec_t));
4876 4875
4877 XFS_STATS_INC(xs_blk_mapw); 4876 XFS_STATS_INC(xs_blk_mapw);
4878 4877
@@ -4981,8 +4980,7 @@ xfs_bmapi_write(
4981 /* 4980 /*
4982 * Transform from btree to extents, give it cur. 4981 * Transform from btree to extents, give it cur.
4983 */ 4982 */
4984 if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE && 4983 if (xfs_bmap_wants_extents(ip, whichfork)) {
4985 XFS_IFORK_NEXTENTS(ip, whichfork) <= ifp->if_ext_max) {
4986 int tmp_logflags = 0; 4984 int tmp_logflags = 0;
4987 4985
4988 ASSERT(bma.cur); 4986 ASSERT(bma.cur);
@@ -4992,10 +4990,10 @@ xfs_bmapi_write(
4992 if (error) 4990 if (error)
4993 goto error0; 4991 goto error0;
4994 } 4992 }
4995 ASSERT(ifp->if_ext_max == 4993
4996 XFS_IFORK_SIZE(ip, whichfork) / (uint)sizeof(xfs_bmbt_rec_t));
4997 ASSERT(XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE || 4994 ASSERT(XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE ||
4998 XFS_IFORK_NEXTENTS(ip, whichfork) > ifp->if_ext_max); 4995 XFS_IFORK_NEXTENTS(ip, whichfork) >
4996 XFS_IFORK_MAXEXT(ip, whichfork));
4999 error = 0; 4997 error = 0;
5000error0: 4998error0:
5001 /* 4999 /*
@@ -5095,8 +5093,7 @@ xfs_bunmapi(
5095 5093
5096 ASSERT(len > 0); 5094 ASSERT(len > 0);
5097 ASSERT(nexts >= 0); 5095 ASSERT(nexts >= 0);
5098 ASSERT(ifp->if_ext_max == 5096
5099 XFS_IFORK_SIZE(ip, whichfork) / (uint)sizeof(xfs_bmbt_rec_t));
5100 if (!(ifp->if_flags & XFS_IFEXTENTS) && 5097 if (!(ifp->if_flags & XFS_IFEXTENTS) &&
5101 (error = xfs_iread_extents(tp, ip, whichfork))) 5098 (error = xfs_iread_extents(tp, ip, whichfork)))
5102 return error; 5099 return error;
@@ -5322,7 +5319,8 @@ xfs_bunmapi(
5322 */ 5319 */
5323 if (!wasdel && xfs_trans_get_block_res(tp) == 0 && 5320 if (!wasdel && xfs_trans_get_block_res(tp) == 0 &&
5324 XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_EXTENTS && 5321 XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_EXTENTS &&
5325 XFS_IFORK_NEXTENTS(ip, whichfork) >= ifp->if_ext_max && 5322 XFS_IFORK_NEXTENTS(ip, whichfork) >= /* Note the >= */
5323 XFS_IFORK_MAXEXT(ip, whichfork) &&
5326 del.br_startoff > got.br_startoff && 5324 del.br_startoff > got.br_startoff &&
5327 del.br_startoff + del.br_blockcount < 5325 del.br_startoff + del.br_blockcount <
5328 got.br_startoff + got.br_blockcount) { 5326 got.br_startoff + got.br_blockcount) {
@@ -5353,13 +5351,11 @@ nodelete:
5353 } 5351 }
5354 } 5352 }
5355 *done = bno == (xfs_fileoff_t)-1 || bno < start || lastx < 0; 5353 *done = bno == (xfs_fileoff_t)-1 || bno < start || lastx < 0;
5356 ASSERT(ifp->if_ext_max == 5354
5357 XFS_IFORK_SIZE(ip, whichfork) / (uint)sizeof(xfs_bmbt_rec_t));
5358 /* 5355 /*
5359 * Convert to a btree if necessary. 5356 * Convert to a btree if necessary.
5360 */ 5357 */
5361 if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_EXTENTS && 5358 if (xfs_bmap_needs_btree(ip, whichfork)) {
5362 XFS_IFORK_NEXTENTS(ip, whichfork) > ifp->if_ext_max) {
5363 ASSERT(cur == NULL); 5359 ASSERT(cur == NULL);
5364 error = xfs_bmap_extents_to_btree(tp, ip, firstblock, flist, 5360 error = xfs_bmap_extents_to_btree(tp, ip, firstblock, flist,
5365 &cur, 0, &tmp_logflags, whichfork); 5361 &cur, 0, &tmp_logflags, whichfork);
@@ -5370,8 +5366,7 @@ nodelete:
5370 /* 5366 /*
5371 * transform from btree to extents, give it cur 5367 * transform from btree to extents, give it cur
5372 */ 5368 */
5373 else if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE && 5369 else if (xfs_bmap_wants_extents(ip, whichfork)) {
5374 XFS_IFORK_NEXTENTS(ip, whichfork) <= ifp->if_ext_max) {
5375 ASSERT(cur != NULL); 5370 ASSERT(cur != NULL);
5376 error = xfs_bmap_btree_to_extents(tp, ip, cur, &tmp_logflags, 5371 error = xfs_bmap_btree_to_extents(tp, ip, cur, &tmp_logflags,
5377 whichfork); 5372 whichfork);
@@ -5382,8 +5377,6 @@ nodelete:
5382 /* 5377 /*
5383 * transform from extents to local? 5378 * transform from extents to local?
5384 */ 5379 */
5385 ASSERT(ifp->if_ext_max ==
5386 XFS_IFORK_SIZE(ip, whichfork) / (uint)sizeof(xfs_bmbt_rec_t));
5387 error = 0; 5380 error = 0;
5388error0: 5381error0:
5389 /* 5382 /*
diff --git a/fs/xfs/xfs_dfrag.c b/fs/xfs/xfs_dfrag.c
index 654dc6f05bac..dd974a55c77d 100644
--- a/fs/xfs/xfs_dfrag.c
+++ b/fs/xfs/xfs_dfrag.c
@@ -163,12 +163,14 @@ xfs_swap_extents_check_format(
163 163
164 /* Check temp in extent form to max in target */ 164 /* Check temp in extent form to max in target */
165 if (tip->i_d.di_format == XFS_DINODE_FMT_EXTENTS && 165 if (tip->i_d.di_format == XFS_DINODE_FMT_EXTENTS &&
166 XFS_IFORK_NEXTENTS(tip, XFS_DATA_FORK) > ip->i_df.if_ext_max) 166 XFS_IFORK_NEXTENTS(tip, XFS_DATA_FORK) >
167 XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK))
167 return EINVAL; 168 return EINVAL;
168 169
169 /* Check target in extent form to max in temp */ 170 /* Check target in extent form to max in temp */
170 if (ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS && 171 if (ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS &&
171 XFS_IFORK_NEXTENTS(ip, XFS_DATA_FORK) > tip->i_df.if_ext_max) 172 XFS_IFORK_NEXTENTS(ip, XFS_DATA_FORK) >
173 XFS_IFORK_MAXEXT(tip, XFS_DATA_FORK))
172 return EINVAL; 174 return EINVAL;
173 175
174 /* 176 /*
@@ -180,18 +182,25 @@ xfs_swap_extents_check_format(
180 * (a common defrag case) which will occur when the temp inode is in 182 * (a common defrag case) which will occur when the temp inode is in
181 * extent format... 183 * extent format...
182 */ 184 */
183 if (tip->i_d.di_format == XFS_DINODE_FMT_BTREE && 185 if (tip->i_d.di_format == XFS_DINODE_FMT_BTREE) {
184 ((XFS_IFORK_BOFF(ip) && 186 if (XFS_IFORK_BOFF(ip) &&
185 tip->i_df.if_broot_bytes > XFS_IFORK_BOFF(ip)) || 187 tip->i_df.if_broot_bytes > XFS_IFORK_BOFF(ip))
186 XFS_IFORK_NEXTENTS(tip, XFS_DATA_FORK) <= ip->i_df.if_ext_max)) 188 return EINVAL;
187 return EINVAL; 189 if (XFS_IFORK_NEXTENTS(tip, XFS_DATA_FORK) <=
190 XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK))
191 return EINVAL;
192 }
188 193
189 /* Reciprocal target->temp btree format checks */ 194 /* Reciprocal target->temp btree format checks */
190 if (ip->i_d.di_format == XFS_DINODE_FMT_BTREE && 195 if (ip->i_d.di_format == XFS_DINODE_FMT_BTREE) {
191 ((XFS_IFORK_BOFF(tip) && 196 if (XFS_IFORK_BOFF(tip) &&
192 ip->i_df.if_broot_bytes > XFS_IFORK_BOFF(tip)) || 197 ip->i_df.if_broot_bytes > XFS_IFORK_BOFF(tip))
193 XFS_IFORK_NEXTENTS(ip, XFS_DATA_FORK) <= tip->i_df.if_ext_max)) 198 return EINVAL;
194 return EINVAL; 199
200 if (XFS_IFORK_NEXTENTS(ip, XFS_DATA_FORK) <=
201 XFS_IFORK_MAXEXT(tip, XFS_DATA_FORK))
202 return EINVAL;
203 }
195 204
196 return 0; 205 return 0;
197} 206}
@@ -349,16 +358,6 @@ xfs_swap_extents(
349 *tifp = *tempifp; /* struct copy */ 358 *tifp = *tempifp; /* struct copy */
350 359
351 /* 360 /*
352 * Fix the in-memory data fork values that are dependent on the fork
353 * offset in the inode. We can't assume they remain the same as attr2
354 * has dynamic fork offsets.
355 */
356 ifp->if_ext_max = XFS_IFORK_SIZE(ip, XFS_DATA_FORK) /
357 (uint)sizeof(xfs_bmbt_rec_t);
358 tifp->if_ext_max = XFS_IFORK_SIZE(tip, XFS_DATA_FORK) /
359 (uint)sizeof(xfs_bmbt_rec_t);
360
361 /*
362 * Fix the on-disk inode values 361 * Fix the on-disk inode values
363 */ 362 */
364 tmp = (__uint64_t)ip->i_d.di_nblocks; 363 tmp = (__uint64_t)ip->i_d.di_nblocks;
diff --git a/fs/xfs/xfs_iget.c b/fs/xfs/xfs_iget.c
index 3960a066d7ff..f180ce896cd7 100644
--- a/fs/xfs/xfs_iget.c
+++ b/fs/xfs/xfs_iget.c
@@ -450,8 +450,6 @@ again:
450 450
451 *ipp = ip; 451 *ipp = ip;
452 452
453 ASSERT(ip->i_df.if_ext_max ==
454 XFS_IFORK_DSIZE(ip) / sizeof(xfs_bmbt_rec_t));
455 /* 453 /*
456 * If we have a real type for an on-disk inode, we can set ops(&unlock) 454 * If we have a real type for an on-disk inode, we can set ops(&unlock)
457 * now. If it's a new inode being created, xfs_ialloc will handle it. 455 * now. If it's a new inode being created, xfs_ialloc will handle it.
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index ccd619a993f6..96b29e3286db 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -299,11 +299,8 @@ xfs_iformat(
299{ 299{
300 xfs_attr_shortform_t *atp; 300 xfs_attr_shortform_t *atp;
301 int size; 301 int size;
302 int error; 302 int error = 0;
303 xfs_fsize_t di_size; 303 xfs_fsize_t di_size;
304 ip->i_df.if_ext_max =
305 XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t);
306 error = 0;
307 304
308 if (unlikely(be32_to_cpu(dip->di_nextents) + 305 if (unlikely(be32_to_cpu(dip->di_nextents) +
309 be16_to_cpu(dip->di_anextents) > 306 be16_to_cpu(dip->di_anextents) >
@@ -409,10 +406,10 @@ xfs_iformat(
409 } 406 }
410 if (!XFS_DFORK_Q(dip)) 407 if (!XFS_DFORK_Q(dip))
411 return 0; 408 return 0;
409
412 ASSERT(ip->i_afp == NULL); 410 ASSERT(ip->i_afp == NULL);
413 ip->i_afp = kmem_zone_zalloc(xfs_ifork_zone, KM_SLEEP | KM_NOFS); 411 ip->i_afp = kmem_zone_zalloc(xfs_ifork_zone, KM_SLEEP | KM_NOFS);
414 ip->i_afp->if_ext_max = 412
415 XFS_IFORK_ASIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t);
416 switch (dip->di_aformat) { 413 switch (dip->di_aformat) {
417 case XFS_DINODE_FMT_LOCAL: 414 case XFS_DINODE_FMT_LOCAL:
418 atp = (xfs_attr_shortform_t *)XFS_DFORK_APTR(dip); 415 atp = (xfs_attr_shortform_t *)XFS_DFORK_APTR(dip);
@@ -604,10 +601,11 @@ xfs_iformat_btree(
604 * or the number of extents is greater than the number of 601 * or the number of extents is greater than the number of
605 * blocks. 602 * blocks.
606 */ 603 */
607 if (unlikely(XFS_IFORK_NEXTENTS(ip, whichfork) <= ifp->if_ext_max 604 if (unlikely(XFS_IFORK_NEXTENTS(ip, whichfork) <=
608 || XFS_BMDR_SPACE_CALC(nrecs) > 605 XFS_IFORK_MAXEXT(ip, whichfork) ||
609 XFS_DFORK_SIZE(dip, ip->i_mount, whichfork) 606 XFS_BMDR_SPACE_CALC(nrecs) >
610 || XFS_IFORK_NEXTENTS(ip, whichfork) > ip->i_d.di_nblocks)) { 607 XFS_DFORK_SIZE(dip, ip->i_mount, whichfork) ||
608 XFS_IFORK_NEXTENTS(ip, whichfork) > ip->i_d.di_nblocks)) {
611 xfs_warn(ip->i_mount, "corrupt inode %Lu (btree).", 609 xfs_warn(ip->i_mount, "corrupt inode %Lu (btree).",
612 (unsigned long long) ip->i_ino); 610 (unsigned long long) ip->i_ino);
613 XFS_CORRUPTION_ERROR("xfs_iformat_btree", XFS_ERRLEVEL_LOW, 611 XFS_CORRUPTION_ERROR("xfs_iformat_btree", XFS_ERRLEVEL_LOW,
@@ -835,12 +833,6 @@ xfs_iread(
835 * with the uninitialized part of it. 833 * with the uninitialized part of it.
836 */ 834 */
837 ip->i_d.di_mode = 0; 835 ip->i_d.di_mode = 0;
838 /*
839 * Initialize the per-fork minima and maxima for a new
840 * inode here. xfs_iformat will do it for old inodes.
841 */
842 ip->i_df.if_ext_max =
843 XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t);
844 } 836 }
845 837
846 /* 838 /*
@@ -1740,8 +1732,6 @@ xfs_ifree(
1740 ip->i_d.di_flags = 0; 1732 ip->i_d.di_flags = 0;
1741 ip->i_d.di_dmevmask = 0; 1733 ip->i_d.di_dmevmask = 0;
1742 ip->i_d.di_forkoff = 0; /* mark the attr fork not in use */ 1734 ip->i_d.di_forkoff = 0; /* mark the attr fork not in use */
1743 ip->i_df.if_ext_max =
1744 XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t);
1745 ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS; 1735 ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
1746 ip->i_d.di_aformat = XFS_DINODE_FMT_EXTENTS; 1736 ip->i_d.di_aformat = XFS_DINODE_FMT_EXTENTS;
1747 /* 1737 /*
@@ -2408,7 +2398,7 @@ xfs_iflush(
2408 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)); 2398 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED));
2409 ASSERT(!completion_done(&ip->i_flush)); 2399 ASSERT(!completion_done(&ip->i_flush));
2410 ASSERT(ip->i_d.di_format != XFS_DINODE_FMT_BTREE || 2400 ASSERT(ip->i_d.di_format != XFS_DINODE_FMT_BTREE ||
2411 ip->i_d.di_nextents > ip->i_df.if_ext_max); 2401 ip->i_d.di_nextents > XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK));
2412 2402
2413 iip = ip->i_itemp; 2403 iip = ip->i_itemp;
2414 mp = ip->i_mount; 2404 mp = ip->i_mount;
@@ -2524,7 +2514,7 @@ xfs_iflush_int(
2524 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)); 2514 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED));
2525 ASSERT(!completion_done(&ip->i_flush)); 2515 ASSERT(!completion_done(&ip->i_flush));
2526 ASSERT(ip->i_d.di_format != XFS_DINODE_FMT_BTREE || 2516 ASSERT(ip->i_d.di_format != XFS_DINODE_FMT_BTREE ||
2527 ip->i_d.di_nextents > ip->i_df.if_ext_max); 2517 ip->i_d.di_nextents > XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK));
2528 2518
2529 iip = ip->i_itemp; 2519 iip = ip->i_itemp;
2530 mp = ip->i_mount; 2520 mp = ip->i_mount;
diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h
index c1574721a191..47497e11c111 100644
--- a/fs/xfs/xfs_inode.h
+++ b/fs/xfs/xfs_inode.h
@@ -66,7 +66,6 @@ typedef struct xfs_ifork {
66 struct xfs_btree_block *if_broot; /* file's incore btree root */ 66 struct xfs_btree_block *if_broot; /* file's incore btree root */
67 short if_broot_bytes; /* bytes allocated for root */ 67 short if_broot_bytes; /* bytes allocated for root */
68 unsigned char if_flags; /* per-fork flags */ 68 unsigned char if_flags; /* per-fork flags */
69 unsigned char if_ext_max; /* max # of extent records */
70 union { 69 union {
71 xfs_bmbt_rec_host_t *if_extents;/* linear map file exts */ 70 xfs_bmbt_rec_host_t *if_extents;/* linear map file exts */
72 xfs_ext_irec_t *if_ext_irec; /* irec map file exts */ 71 xfs_ext_irec_t *if_ext_irec; /* irec map file exts */
@@ -206,7 +205,8 @@ typedef struct xfs_icdinode {
206 ((w) == XFS_DATA_FORK ? \ 205 ((w) == XFS_DATA_FORK ? \
207 ((ip)->i_d.di_nextents = (n)) : \ 206 ((ip)->i_d.di_nextents = (n)) : \
208 ((ip)->i_d.di_anextents = (n))) 207 ((ip)->i_d.di_anextents = (n)))
209 208#define XFS_IFORK_MAXEXT(ip, w) \
209 (XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t))
210 210
211 211
212#ifdef __KERNEL__ 212#ifdef __KERNEL__
diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c
index cfd6c7f8cc3c..2b6b4fcef49e 100644
--- a/fs/xfs/xfs_inode_item.c
+++ b/fs/xfs/xfs_inode_item.c
@@ -79,8 +79,6 @@ xfs_inode_item_size(
79 break; 79 break;
80 80
81 case XFS_DINODE_FMT_BTREE: 81 case XFS_DINODE_FMT_BTREE:
82 ASSERT(ip->i_df.if_ext_max ==
83 XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t));
84 iip->ili_format.ilf_fields &= 82 iip->ili_format.ilf_fields &=
85 ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT | 83 ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT |
86 XFS_ILOG_DEV | XFS_ILOG_UUID); 84 XFS_ILOG_DEV | XFS_ILOG_UUID);
diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h
index 297f9fa6fb64..81efa0416173 100644
--- a/fs/xfs/xfs_trace.h
+++ b/fs/xfs/xfs_trace.h
@@ -1568,7 +1568,6 @@ DECLARE_EVENT_CLASS(xfs_swap_extent_class,
1568 __field(xfs_ino_t, ino) 1568 __field(xfs_ino_t, ino)
1569 __field(int, format) 1569 __field(int, format)
1570 __field(int, nex) 1570 __field(int, nex)
1571 __field(int, max_nex)
1572 __field(int, broot_size) 1571 __field(int, broot_size)
1573 __field(int, fork_off) 1572 __field(int, fork_off)
1574 ), 1573 ),
@@ -1578,18 +1577,16 @@ DECLARE_EVENT_CLASS(xfs_swap_extent_class,
1578 __entry->ino = ip->i_ino; 1577 __entry->ino = ip->i_ino;
1579 __entry->format = ip->i_d.di_format; 1578 __entry->format = ip->i_d.di_format;
1580 __entry->nex = ip->i_d.di_nextents; 1579 __entry->nex = ip->i_d.di_nextents;
1581 __entry->max_nex = ip->i_df.if_ext_max;
1582 __entry->broot_size = ip->i_df.if_broot_bytes; 1580 __entry->broot_size = ip->i_df.if_broot_bytes;
1583 __entry->fork_off = XFS_IFORK_BOFF(ip); 1581 __entry->fork_off = XFS_IFORK_BOFF(ip);
1584 ), 1582 ),
1585 TP_printk("dev %d:%d ino 0x%llx (%s), %s format, num_extents %d, " 1583 TP_printk("dev %d:%d ino 0x%llx (%s), %s format, num_extents %d, "
1586 "Max in-fork extents %d, broot size %d, fork offset %d", 1584 "broot size %d, fork offset %d",
1587 MAJOR(__entry->dev), MINOR(__entry->dev), 1585 MAJOR(__entry->dev), MINOR(__entry->dev),
1588 __entry->ino, 1586 __entry->ino,
1589 __print_symbolic(__entry->which, XFS_SWAPEXT_INODES), 1587 __print_symbolic(__entry->which, XFS_SWAPEXT_INODES),
1590 __print_symbolic(__entry->format, XFS_INODE_FORMAT_STR), 1588 __print_symbolic(__entry->format, XFS_INODE_FORMAT_STR),
1591 __entry->nex, 1589 __entry->nex,
1592 __entry->max_nex,
1593 __entry->broot_size, 1590 __entry->broot_size,
1594 __entry->fork_off) 1591 __entry->fork_off)
1595) 1592)