Skip to content

Commit 0daaeca

Browse files
Brian Fosterdjwong
authored andcommitted
xfs: fix indlen accounting error on partial delalloc conversion
The delalloc -> real block conversion path uses an incorrect calculation in the case where the middle part of a delalloc extent is being converted. This is documented as a rare situation because XFS generally attempts to maximize contiguity by converting as much of a delalloc extent as possible. If this situation does occur, the indlen reservation for the two new delalloc extents left behind by the conversion of the middle range is calculated and compared with the original reservation. If more blocks are required, the delta is allocated from the global block pool. This delta value can be characterized as the difference between the new total requirement (temp + temp2) and the currently available reservation minus those blocks that have already been allocated (startblockval(PREV.br_startblock) - allocated). The problem is that the current code does not account for previously allocated blocks correctly. It subtracts the current allocation count from the (new - old) delta rather than the old indlen reservation. This means that more indlen blocks than have been allocated end up stashed in the remaining extents and free space accounting is broken as a result. Fix up the calculation to subtract the allocated block count from the original extent indlen and thus correctly allocate the reservation delta based on the difference between the new total requirement and the unused blocks from the original reservation. Also remove a bogus assert that contradicts the fact that the new indlen reservation can be larger than the original indlen reservation. Signed-off-by: Brian Foster <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 2ea659a commit 0daaeca

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,8 +2065,10 @@ xfs_bmap_add_extent_delay_real(
20652065
}
20662066
temp = xfs_bmap_worst_indlen(bma->ip, temp);
20672067
temp2 = xfs_bmap_worst_indlen(bma->ip, temp2);
2068-
diff = (int)(temp + temp2 - startblockval(PREV.br_startblock) -
2069-
(bma->cur ? bma->cur->bc_private.b.allocated : 0));
2068+
diff = (int)(temp + temp2 -
2069+
(startblockval(PREV.br_startblock) -
2070+
(bma->cur ?
2071+
bma->cur->bc_private.b.allocated : 0)));
20702072
if (diff > 0) {
20712073
error = xfs_mod_fdblocks(bma->ip->i_mount,
20722074
-((int64_t)diff), false);
@@ -2123,7 +2125,6 @@ xfs_bmap_add_extent_delay_real(
21232125
temp = da_new;
21242126
if (bma->cur)
21252127
temp += bma->cur->bc_private.b.allocated;
2126-
ASSERT(temp <= da_old);
21272128
if (temp < da_old)
21282129
xfs_mod_fdblocks(bma->ip->i_mount,
21292130
(int64_t)(da_old - temp), false);

0 commit comments

Comments
 (0)