xfs: refactor delalloc indlen reservation split into helper
The delayed allocation indirect reservation splitting code is not sufficient in some cases where a delalloc extent is split in two. In preparation for enhancements to this code, refactor the current indlen distribution algorithm into a new helper function. [dchinner: rename temp, temp2 variables] Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com>
This commit is contained in:
committed by
Dave Chinner
parent
b2706a05ba
commit
a9bd24ac2b
@@ -4720,6 +4720,47 @@ error0:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When a delalloc extent is split (e.g., due to a hole punch), the original
|
||||||
|
* indlen reservation must be shared across the two new extents that are left
|
||||||
|
* behind.
|
||||||
|
*
|
||||||
|
* Given the original reservation and the worst case indlen for the two new
|
||||||
|
* extents (as calculated by xfs_bmap_worst_indlen()), split the original
|
||||||
|
* reservation fairly across the two new extents.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
xfs_bmap_split_indlen(
|
||||||
|
xfs_filblks_t ores, /* original res. */
|
||||||
|
xfs_filblks_t *indlen1, /* ext1 worst indlen */
|
||||||
|
xfs_filblks_t *indlen2) /* ext2 worst indlen */
|
||||||
|
{
|
||||||
|
xfs_filblks_t len1 = *indlen1;
|
||||||
|
xfs_filblks_t len2 = *indlen2;
|
||||||
|
xfs_filblks_t nres = len1 + len2; /* new total res. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The only blocks available are those reserved for the original extent.
|
||||||
|
* Therefore, we have to skim blocks off each of the new reservations so
|
||||||
|
* long as the new total reservation is greater than the original.
|
||||||
|
*/
|
||||||
|
while (nres > ores) {
|
||||||
|
if (len1) {
|
||||||
|
len1--;
|
||||||
|
nres--;
|
||||||
|
}
|
||||||
|
if (nres == ores)
|
||||||
|
break;
|
||||||
|
if (len2) {
|
||||||
|
len2--;
|
||||||
|
nres--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*indlen1 = len1;
|
||||||
|
*indlen2 = len2;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called by xfs_bmapi to update file extent records and the btree
|
* Called by xfs_bmapi to update file extent records and the btree
|
||||||
* after removing space (or undoing a delayed allocation).
|
* after removing space (or undoing a delayed allocation).
|
||||||
@@ -4985,27 +5026,21 @@ xfs_bmap_del_extent(
|
|||||||
XFS_IFORK_NEXTENTS(ip, whichfork) + 1);
|
XFS_IFORK_NEXTENTS(ip, whichfork) + 1);
|
||||||
} else {
|
} else {
|
||||||
ASSERT(whichfork == XFS_DATA_FORK);
|
ASSERT(whichfork == XFS_DATA_FORK);
|
||||||
temp = xfs_bmap_worst_indlen(ip, temp);
|
|
||||||
xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
|
/*
|
||||||
temp2 = xfs_bmap_worst_indlen(ip, temp2);
|
* Distribute the original indlen reservation across the
|
||||||
new.br_startblock = nullstartblock((int)temp2);
|
* two new extents.
|
||||||
|
*/
|
||||||
|
temp = xfs_bmap_worst_indlen(ip, got.br_blockcount);
|
||||||
|
temp2 = xfs_bmap_worst_indlen(ip, new.br_blockcount);
|
||||||
|
xfs_bmap_split_indlen(da_old, &temp, &temp2);
|
||||||
da_new = temp + temp2;
|
da_new = temp + temp2;
|
||||||
while (da_new > da_old) {
|
|
||||||
if (temp) {
|
/*
|
||||||
temp--;
|
* Set the reservation for each extent.
|
||||||
da_new--;
|
*/
|
||||||
xfs_bmbt_set_startblock(ep,
|
xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
|
||||||
nullstartblock((int)temp));
|
new.br_startblock = nullstartblock((int)temp2);
|
||||||
}
|
|
||||||
if (da_new == da_old)
|
|
||||||
break;
|
|
||||||
if (temp2) {
|
|
||||||
temp2--;
|
|
||||||
da_new--;
|
|
||||||
new.br_startblock =
|
|
||||||
nullstartblock((int)temp2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
|
trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
|
||||||
xfs_iext_insert(ip, *idx + 1, 1, &new, state);
|
xfs_iext_insert(ip, *idx + 1, 1, &new, state);
|
||||||
|
|||||||
Reference in New Issue
Block a user