BFS: Fix missing trim of last range in a corner case.

The previous logic of _AddTrim plus _TrimNext meant that if a trim
range was specified in the final call to _TrimNext (i.e. with force=true),
but the trim buffer was already full at that point, that last range
would not actually be trimmed.

Now, _AddTrim returns true when the buffer is filled and trimming
should be done, rather than delaying it and requiring a second
add after trimming.

Change-Id: I4b782948e8dc9267c63e61bce0c078fd4e834177
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6070
Tested-by: Automation <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Augustin Cavalier
2023-02-17 20:21:24 +00:00
committed by waddlesplash
parent ba9ce9c13b
commit 050515f6ae
@@ -1335,14 +1335,15 @@ bool
BlockAllocator::_AddTrim(fs_trim_data& trimData, uint32 maxRanges,
uint64 offset, uint64 size)
{
if (trimData.range_count < maxRanges && size > 0) {
trimData.ranges[trimData.range_count].offset = offset;
trimData.ranges[trimData.range_count].size = size;
trimData.range_count++;
return true;
}
ASSERT(trimData.range_count < maxRanges);
if (size == 0)
return false;
return false;
trimData.ranges[trimData.range_count].offset = offset;
trimData.ranges[trimData.range_count].size = size;
trimData.range_count++;
return (trimData.range_count == maxRanges);
}
@@ -1353,9 +1354,9 @@ BlockAllocator::_TrimNext(fs_trim_data& trimData, uint32 maxRanges,
PRINT(("_TrimNext(index %" B_PRIu32 ", offset %" B_PRIu64 ", size %"
B_PRIu64 ")\n", trimData.range_count, offset, size));
bool pushed = _AddTrim(trimData, maxRanges, offset, size);
const bool rangesFilled = _AddTrim(trimData, maxRanges, offset, size);
if (!pushed || force) {
if (rangesFilled || force) {
// Trim now
trimData.trimmed_size = 0;
#ifdef DEBUG_TRIM
@@ -1375,9 +1376,6 @@ BlockAllocator::_TrimNext(fs_trim_data& trimData, uint32 maxRanges,
trimData.range_count = 0;
}
if (!pushed)
_AddTrim(trimData, maxRanges, offset, size);
return B_OK;
}