@@ -52,19 +52,17 @@ xfs_bmap_compute_maxlevels(
52
52
xfs_mount_t * mp , /* file system mount structure */
53
53
int whichfork ) /* data or attr fork */
54
54
{
55
+ uint64_t maxblocks ; /* max blocks at this level */
56
+ xfs_extnum_t maxleafents ; /* max leaf entries possible */
55
57
int level ; /* btree level */
56
- uint maxblocks ; /* max blocks at this level */
57
- uint maxleafents ; /* max leaf entries possible */
58
58
int maxrootrecs ; /* max records in root block */
59
59
int minleafrecs ; /* min records in leaf block */
60
60
int minnoderecs ; /* min records in node block */
61
61
int sz ; /* root block size */
62
62
63
63
/*
64
- * The maximum number of extents in a file, hence the maximum number of
65
- * leaf entries, is controlled by the size of the on-disk extent count,
66
- * either a signed 32-bit number for the data fork, or a signed 16-bit
67
- * number for the attr fork.
64
+ * The maximum number of extents in a fork, hence the maximum number of
65
+ * leaf entries, is controlled by the size of the on-disk extent count.
68
66
*
69
67
* Note that we can no longer assume that if we are in ATTR1 that the
70
68
* fork offset of all the inodes will be
@@ -74,22 +72,22 @@ xfs_bmap_compute_maxlevels(
74
72
* ATTR2 we have to assume the worst case scenario of a minimum size
75
73
* available.
76
74
*/
77
- if (whichfork == XFS_DATA_FORK ) {
78
- maxleafents = MAXEXTNUM ;
75
+ maxleafents = xfs_iext_max_nextents (xfs_has_large_extent_counts (mp ),
76
+ whichfork );
77
+ if (whichfork == XFS_DATA_FORK )
79
78
sz = XFS_BMDR_SPACE_CALC (MINDBTPTRS );
80
- } else {
81
- maxleafents = MAXAEXTNUM ;
79
+ else
82
80
sz = XFS_BMDR_SPACE_CALC (MINABTPTRS );
83
- }
81
+
84
82
maxrootrecs = xfs_bmdr_maxrecs (sz , 0 );
85
83
minleafrecs = mp -> m_bmap_dmnr [0 ];
86
84
minnoderecs = mp -> m_bmap_dmnr [1 ];
87
- maxblocks = (maxleafents + minleafrecs - 1 ) / minleafrecs ;
85
+ maxblocks = howmany_64 (maxleafents , minleafrecs ) ;
88
86
for (level = 1 ; maxblocks > 1 ; level ++ ) {
89
87
if (maxblocks <= maxrootrecs )
90
88
maxblocks = 1 ;
91
89
else
92
- maxblocks = (maxblocks + minnoderecs - 1 ) / minnoderecs ;
90
+ maxblocks = howmany_64 (maxblocks , minnoderecs ) ;
93
91
}
94
92
mp -> m_bm_maxlevels [whichfork ] = level ;
95
93
ASSERT (mp -> m_bm_maxlevels [whichfork ] <= xfs_bmbt_maxlevels_ondisk ());
@@ -468,7 +466,7 @@ xfs_bmap_check_leaf_extents(
468
466
if (bp_release )
469
467
xfs_trans_brelse (NULL , bp );
470
468
error_norelse :
471
- xfs_warn (mp , "%s: BAD after btree leaves for %d extents" ,
469
+ xfs_warn (mp , "%s: BAD after btree leaves for %llu extents" ,
472
470
__func__ , i );
473
471
xfs_err (mp , "%s: CORRUPTED BTREE OR SOMETHING" , __func__ );
474
472
xfs_force_shutdown (mp , SHUTDOWN_CORRUPT_INCORE );
@@ -1452,7 +1450,7 @@ xfs_bmap_add_extent_delay_real(
1452
1450
LEFT .br_startoff + LEFT .br_blockcount == new -> br_startoff &&
1453
1451
LEFT .br_startblock + LEFT .br_blockcount == new -> br_startblock &&
1454
1452
LEFT .br_state == new -> br_state &&
1455
- LEFT .br_blockcount + new -> br_blockcount <= MAXEXTLEN )
1453
+ LEFT .br_blockcount + new -> br_blockcount <= XFS_MAX_BMBT_EXTLEN )
1456
1454
state |= BMAP_LEFT_CONTIG ;
1457
1455
1458
1456
/*
@@ -1470,13 +1468,13 @@ xfs_bmap_add_extent_delay_real(
1470
1468
new_endoff == RIGHT .br_startoff &&
1471
1469
new -> br_startblock + new -> br_blockcount == RIGHT .br_startblock &&
1472
1470
new -> br_state == RIGHT .br_state &&
1473
- new -> br_blockcount + RIGHT .br_blockcount <= MAXEXTLEN &&
1471
+ new -> br_blockcount + RIGHT .br_blockcount <= XFS_MAX_BMBT_EXTLEN &&
1474
1472
((state & (BMAP_LEFT_CONTIG | BMAP_LEFT_FILLING |
1475
1473
BMAP_RIGHT_FILLING )) !=
1476
1474
(BMAP_LEFT_CONTIG | BMAP_LEFT_FILLING |
1477
1475
BMAP_RIGHT_FILLING ) ||
1478
1476
LEFT .br_blockcount + new -> br_blockcount + RIGHT .br_blockcount
1479
- <= MAXEXTLEN ))
1477
+ <= XFS_MAX_BMBT_EXTLEN ))
1480
1478
state |= BMAP_RIGHT_CONTIG ;
1481
1479
1482
1480
error = 0 ;
@@ -2000,7 +1998,7 @@ xfs_bmap_add_extent_unwritten_real(
2000
1998
LEFT .br_startoff + LEFT .br_blockcount == new -> br_startoff &&
2001
1999
LEFT .br_startblock + LEFT .br_blockcount == new -> br_startblock &&
2002
2000
LEFT .br_state == new -> br_state &&
2003
- LEFT .br_blockcount + new -> br_blockcount <= MAXEXTLEN )
2001
+ LEFT .br_blockcount + new -> br_blockcount <= XFS_MAX_BMBT_EXTLEN )
2004
2002
state |= BMAP_LEFT_CONTIG ;
2005
2003
2006
2004
/*
@@ -2018,13 +2016,13 @@ xfs_bmap_add_extent_unwritten_real(
2018
2016
new_endoff == RIGHT .br_startoff &&
2019
2017
new -> br_startblock + new -> br_blockcount == RIGHT .br_startblock &&
2020
2018
new -> br_state == RIGHT .br_state &&
2021
- new -> br_blockcount + RIGHT .br_blockcount <= MAXEXTLEN &&
2019
+ new -> br_blockcount + RIGHT .br_blockcount <= XFS_MAX_BMBT_EXTLEN &&
2022
2020
((state & (BMAP_LEFT_CONTIG | BMAP_LEFT_FILLING |
2023
2021
BMAP_RIGHT_FILLING )) !=
2024
2022
(BMAP_LEFT_CONTIG | BMAP_LEFT_FILLING |
2025
2023
BMAP_RIGHT_FILLING ) ||
2026
2024
LEFT .br_blockcount + new -> br_blockcount + RIGHT .br_blockcount
2027
- <= MAXEXTLEN ))
2025
+ <= XFS_MAX_BMBT_EXTLEN ))
2028
2026
state |= BMAP_RIGHT_CONTIG ;
2029
2027
2030
2028
/*
@@ -2510,15 +2508,15 @@ xfs_bmap_add_extent_hole_delay(
2510
2508
*/
2511
2509
if ((state & BMAP_LEFT_VALID ) && (state & BMAP_LEFT_DELAY ) &&
2512
2510
left .br_startoff + left .br_blockcount == new -> br_startoff &&
2513
- left .br_blockcount + new -> br_blockcount <= MAXEXTLEN )
2511
+ left .br_blockcount + new -> br_blockcount <= XFS_MAX_BMBT_EXTLEN )
2514
2512
state |= BMAP_LEFT_CONTIG ;
2515
2513
2516
2514
if ((state & BMAP_RIGHT_VALID ) && (state & BMAP_RIGHT_DELAY ) &&
2517
2515
new -> br_startoff + new -> br_blockcount == right .br_startoff &&
2518
- new -> br_blockcount + right .br_blockcount <= MAXEXTLEN &&
2516
+ new -> br_blockcount + right .br_blockcount <= XFS_MAX_BMBT_EXTLEN &&
2519
2517
(!(state & BMAP_LEFT_CONTIG ) ||
2520
2518
(left .br_blockcount + new -> br_blockcount +
2521
- right .br_blockcount <= MAXEXTLEN )))
2519
+ right .br_blockcount <= XFS_MAX_BMBT_EXTLEN )))
2522
2520
state |= BMAP_RIGHT_CONTIG ;
2523
2521
2524
2522
/*
@@ -2661,17 +2659,17 @@ xfs_bmap_add_extent_hole_real(
2661
2659
left .br_startoff + left .br_blockcount == new -> br_startoff &&
2662
2660
left .br_startblock + left .br_blockcount == new -> br_startblock &&
2663
2661
left .br_state == new -> br_state &&
2664
- left .br_blockcount + new -> br_blockcount <= MAXEXTLEN )
2662
+ left .br_blockcount + new -> br_blockcount <= XFS_MAX_BMBT_EXTLEN )
2665
2663
state |= BMAP_LEFT_CONTIG ;
2666
2664
2667
2665
if ((state & BMAP_RIGHT_VALID ) && !(state & BMAP_RIGHT_DELAY ) &&
2668
2666
new -> br_startoff + new -> br_blockcount == right .br_startoff &&
2669
2667
new -> br_startblock + new -> br_blockcount == right .br_startblock &&
2670
2668
new -> br_state == right .br_state &&
2671
- new -> br_blockcount + right .br_blockcount <= MAXEXTLEN &&
2669
+ new -> br_blockcount + right .br_blockcount <= XFS_MAX_BMBT_EXTLEN &&
2672
2670
(!(state & BMAP_LEFT_CONTIG ) ||
2673
2671
left .br_blockcount + new -> br_blockcount +
2674
- right .br_blockcount <= MAXEXTLEN ))
2672
+ right .br_blockcount <= XFS_MAX_BMBT_EXTLEN ))
2675
2673
state |= BMAP_RIGHT_CONTIG ;
2676
2674
2677
2675
error = 0 ;
@@ -2906,15 +2904,15 @@ xfs_bmap_extsize_align(
2906
2904
2907
2905
/*
2908
2906
* For large extent hint sizes, the aligned extent might be larger than
2909
- * MAXEXTLEN . In that case, reduce the size by an extsz so that it pulls
2910
- * the length back under MAXEXTLEN . The outer allocation loops handle
2911
- * short allocation just fine, so it is safe to do this. We only want to
2912
- * do it when we are forced to, though, because it means more allocation
2913
- * operations are required.
2907
+ * XFS_BMBT_MAX_EXTLEN . In that case, reduce the size by an extsz so
2908
+ * that it pulls the length back under XFS_BMBT_MAX_EXTLEN . The outer
2909
+ * allocation loops handle short allocation just fine, so it is safe to
2910
+ * do this. We only want to do it when we are forced to, though, because
2911
+ * it means more allocation operations are required.
2914
2912
*/
2915
- while (align_alen > MAXEXTLEN )
2913
+ while (align_alen > XFS_MAX_BMBT_EXTLEN )
2916
2914
align_alen -= extsz ;
2917
- ASSERT (align_alen <= MAXEXTLEN );
2915
+ ASSERT (align_alen <= XFS_MAX_BMBT_EXTLEN );
2918
2916
2919
2917
/*
2920
2918
* If the previous block overlaps with this proposed allocation
@@ -3004,9 +3002,9 @@ xfs_bmap_extsize_align(
3004
3002
return - EINVAL ;
3005
3003
} else {
3006
3004
ASSERT (orig_off >= align_off );
3007
- /* see MAXEXTLEN handling above */
3005
+ /* see XFS_BMBT_MAX_EXTLEN handling above */
3008
3006
ASSERT (orig_end <= align_off + align_alen ||
3009
- align_alen + extsz > MAXEXTLEN );
3007
+ align_alen + extsz > XFS_MAX_BMBT_EXTLEN );
3010
3008
}
3011
3009
3012
3010
#ifdef DEBUG
@@ -3971,7 +3969,7 @@ xfs_bmapi_reserve_delalloc(
3971
3969
* Cap the alloc length. Keep track of prealloc so we know whether to
3972
3970
* tag the inode before we return.
3973
3971
*/
3974
- alen = XFS_FILBLKS_MIN (len + prealloc , MAXEXTLEN );
3972
+ alen = XFS_FILBLKS_MIN (len + prealloc , XFS_MAX_BMBT_EXTLEN );
3975
3973
if (!eof )
3976
3974
alen = XFS_FILBLKS_MIN (alen , got -> br_startoff - aoff );
3977
3975
if (prealloc && alen >= len )
@@ -4104,7 +4102,7 @@ xfs_bmapi_allocate(
4104
4102
if (!xfs_iext_peek_prev_extent (ifp , & bma -> icur , & bma -> prev ))
4105
4103
bma -> prev .br_startoff = NULLFILEOFF ;
4106
4104
} else {
4107
- bma -> length = XFS_FILBLKS_MIN (bma -> length , MAXEXTLEN );
4105
+ bma -> length = XFS_FILBLKS_MIN (bma -> length , XFS_MAX_BMBT_EXTLEN );
4108
4106
if (!bma -> eof )
4109
4107
bma -> length = XFS_FILBLKS_MIN (bma -> length ,
4110
4108
bma -> got .br_startoff - bma -> offset );
@@ -4424,8 +4422,8 @@ xfs_bmapi_write(
4424
4422
* xfs_extlen_t and therefore 32 bits. Hence we have to
4425
4423
* check for 32-bit overflows and handle them here.
4426
4424
*/
4427
- if (len > (xfs_filblks_t )MAXEXTLEN )
4428
- bma .length = MAXEXTLEN ;
4425
+ if (len > (xfs_filblks_t )XFS_MAX_BMBT_EXTLEN )
4426
+ bma .length = XFS_MAX_BMBT_EXTLEN ;
4429
4427
else
4430
4428
bma .length = len ;
4431
4429
@@ -4526,14 +4524,16 @@ xfs_bmapi_convert_delalloc(
4526
4524
return error ;
4527
4525
4528
4526
xfs_ilock (ip , XFS_ILOCK_EXCL );
4527
+ xfs_trans_ijoin (tp , ip , 0 );
4529
4528
4530
4529
error = xfs_iext_count_may_overflow (ip , whichfork ,
4531
4530
XFS_IEXT_ADD_NOSPLIT_CNT );
4531
+ if (error == - EFBIG )
4532
+ error = xfs_iext_count_upgrade (tp , ip ,
4533
+ XFS_IEXT_ADD_NOSPLIT_CNT );
4532
4534
if (error )
4533
4535
goto out_trans_cancel ;
4534
4536
4535
- xfs_trans_ijoin (tp , ip , 0 );
4536
-
4537
4537
if (!xfs_iext_lookup_extent (ip , ifp , offset_fsb , & bma .icur , & bma .got ) ||
4538
4538
bma .got .br_startoff > offset_fsb ) {
4539
4539
/*
@@ -4560,7 +4560,8 @@ xfs_bmapi_convert_delalloc(
4560
4560
bma .ip = ip ;
4561
4561
bma .wasdel = true;
4562
4562
bma .offset = bma .got .br_startoff ;
4563
- bma .length = max_t (xfs_filblks_t , bma .got .br_blockcount , MAXEXTLEN );
4563
+ bma .length = max_t (xfs_filblks_t , bma .got .br_blockcount ,
4564
+ XFS_MAX_BMBT_EXTLEN );
4564
4565
bma .minleft = xfs_bmapi_minleft (tp , ip , whichfork );
4565
4566
4566
4567
/*
@@ -4641,7 +4642,7 @@ xfs_bmapi_remap(
4641
4642
4642
4643
ifp = XFS_IFORK_PTR (ip , whichfork );
4643
4644
ASSERT (len > 0 );
4644
- ASSERT (len <= (xfs_filblks_t )MAXEXTLEN );
4645
+ ASSERT (len <= (xfs_filblks_t )XFS_MAX_BMBT_EXTLEN );
4645
4646
ASSERT (xfs_isilocked (ip , XFS_ILOCK_EXCL ));
4646
4647
ASSERT (!(flags & ~(XFS_BMAPI_ATTRFORK | XFS_BMAPI_PREALLOC |
4647
4648
XFS_BMAPI_NORMAP )));
@@ -5148,26 +5149,6 @@ xfs_bmap_del_extent_real(
5148
5149
* Deleting the middle of the extent.
5149
5150
*/
5150
5151
5151
- /*
5152
- * For directories, -ENOSPC is returned since a directory entry
5153
- * remove operation must not fail due to low extent count
5154
- * availability. -ENOSPC will be handled by higher layers of XFS
5155
- * by letting the corresponding empty Data/Free blocks to linger
5156
- * until a future remove operation. Dabtree blocks would be
5157
- * swapped with the last block in the leaf space and then the
5158
- * new last block will be unmapped.
5159
- *
5160
- * The above logic also applies to the source directory entry of
5161
- * a rename operation.
5162
- */
5163
- error = xfs_iext_count_may_overflow (ip , whichfork , 1 );
5164
- if (error ) {
5165
- ASSERT (S_ISDIR (VFS_I (ip )-> i_mode ) &&
5166
- whichfork == XFS_DATA_FORK );
5167
- error = - ENOSPC ;
5168
- goto done ;
5169
- }
5170
-
5171
5152
old = got ;
5172
5153
5173
5154
got .br_blockcount = del -> br_startoff - got .br_startoff ;
@@ -5641,7 +5622,7 @@ xfs_bmse_can_merge(
5641
5622
if ((left -> br_startoff + left -> br_blockcount != startoff ) ||
5642
5623
(left -> br_startblock + left -> br_blockcount != got -> br_startblock ) ||
5643
5624
(left -> br_state != got -> br_state ) ||
5644
- (left -> br_blockcount + got -> br_blockcount > MAXEXTLEN ))
5625
+ (left -> br_blockcount + got -> br_blockcount > XFS_MAX_BMBT_EXTLEN ))
5645
5626
return false;
5646
5627
5647
5628
return true;
0 commit comments