Skip to content

Commit

Permalink
btrfs: allow btrfs_bio_fits_in_stripe() to accept bio without any page
Browse files Browse the repository at this point in the history
Function btrfs_bio_fits_in_stripe() now requires a bio with at least one
page added.  Or btrfs_get_chunk_map() will fail with -ENOENT.

But in fact this requirement is not needed at all, as we can just pass
sectorsize for btrfs_get_chunk_map().

This tiny behavior change is important for later subpage refactoring on
submit_extent_page().

As for 64K page size, we can have a page range with pgoff=0 and size=64K.
If the logical bytenr is just 16K before the stripe boundary, we have to
split the page range into two bios.

This means, we must check page range against stripe boundary, even adding
the range to an empty bio.

This tiny refactoring is for the incoming changes, but on its own,
regular sectorsize == PAGE_SIZE is not affected anyway.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Qu Wenruo authored and David Sterba committed Jun 21, 2021
1 parent 43c0d1a commit 1a0b5c4
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2193,25 +2193,22 @@ int btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio,
struct inode *inode = page->mapping->host;
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
u64 logical = bio->bi_iter.bi_sector << 9;
u32 bio_len = bio->bi_iter.bi_size;
struct extent_map *em;
u64 length = 0;
u64 map_length;
int ret = 0;
struct btrfs_io_geometry geom;

if (bio_flags & EXTENT_BIO_COMPRESSED)
return 0;

length = bio->bi_iter.bi_size;
map_length = length;
em = btrfs_get_chunk_map(fs_info, logical, map_length);
em = btrfs_get_chunk_map(fs_info, logical, fs_info->sectorsize);
if (IS_ERR(em))
return PTR_ERR(em);
ret = btrfs_get_io_geometry(fs_info, em, btrfs_op(bio), logical, &geom);
if (ret < 0)
goto out;

if (geom.len < length + size)
if (geom.len < bio_len + size)
ret = 1;
out:
free_extent_map(em);
Expand Down

0 comments on commit 1a0b5c4

Please sign in to comment.