btrfs: add a find_contiguous_extent_bit helper and use it for safe isize
Filipe noticed a race where we would sometimes get the wrong answer for
the i_disk_size for !NO_HOLES with my patch. That is because I expected
that find_first_extent_bit() would find the contiguous range, since I'm
only ever setting EXTENT_DIRTY. However the way set_extent_bit() works
is it'll temporarily split the range, loop around and set our bits, and
then merge the state. When it loops it drops the tree->lock, so there
is a window where we can have two adjacent states instead of one large
state. Fix this by walking forward until we find a non-contiguous
state, and set our end_ret to the end of our logically contiguous area.
This fixes the problem without relying on specific behavior from
set_extent_bit().
Fixes: 79ceff7f6e5d ("btrfs: introduce per-inode file extent tree")
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
3 files changed