Currently the first megabyte on a device housing a btrfs filesystem is
exempt from allocation and trimming. Currently this is not a problem
since 'start' is set to 1m at the beginning of btrfs_trim_free_extents
and find_first_clear_extent_bit always returns a range that is >= start.
However, in a follow up patch find_first_clear_extent_bit will be
changed such that it will return a range containing 'start' and this
range may very well be 0...>=1M so 'start'.

Future proof the sole user of find_first_clear_extent_bit by setting
'start' after the function is called. No functional changes.

Signed-off-by: Nikolay Borisov <nbori...@suse.com>
---
 fs/btrfs/extent-tree.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index d8c5febf7636..5a11e4988243 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -11183,6 +11183,10 @@ static int btrfs_trim_free_extents(struct btrfs_device 
*device, u64 *trimmed)
                 * to the caller to trim the value to the size of the device.
                 */
                end = min(end, device->total_bytes - 1);
+
+               /* Ensure we skip first mb in case we have a bootloader there */
+               start = max_t(u64, start, SZ_1M);
+
                len = end - start + 1;
 
                /* We didn't find any extents */
-- 
2.17.1

Reply via email to