Commit da12fe54 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: Refactor btrfs_merge_bio_hook

This function really checks whether adding more data to the bio will
straddle a stripe/chunk. So first let's give it a more appropraite name
- btrfs_bio_fits_in_stripe. Secondly, the offset parameter was never
used to just remove it. Thirdly, pages are submitted to either btree or
data inodes so it's guaranteed that tree->ops is set so replace the
check with an ASSERT. Finally, document the parameters of the function.
No functional changes.
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 2ab4fd31
...@@ -332,7 +332,8 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start, ...@@ -332,7 +332,8 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start,
page = compressed_pages[pg_index]; page = compressed_pages[pg_index];
page->mapping = inode->i_mapping; page->mapping = inode->i_mapping;
if (bio->bi_iter.bi_size) if (bio->bi_iter.bi_size)
submit = btrfs_merge_bio_hook(page, 0, PAGE_SIZE, bio, 0); submit = btrfs_bio_fits_in_stripe(page, PAGE_SIZE, bio,
0);
page->mapping = NULL; page->mapping = NULL;
if (submit || bio_add_page(bio, page, PAGE_SIZE, 0) < if (submit || bio_add_page(bio, page, PAGE_SIZE, 0) <
...@@ -610,7 +611,7 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, ...@@ -610,7 +611,7 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
page->index = em_start >> PAGE_SHIFT; page->index = em_start >> PAGE_SHIFT;
if (comp_bio->bi_iter.bi_size) if (comp_bio->bi_iter.bi_size)
submit = btrfs_merge_bio_hook(page, 0, PAGE_SIZE, submit = btrfs_bio_fits_in_stripe(page, PAGE_SIZE,
comp_bio, 0); comp_bio, 0);
page->mapping = NULL; page->mapping = NULL;
......
...@@ -3191,8 +3191,7 @@ void btrfs_merge_delalloc_extent(struct inode *inode, struct extent_state *new, ...@@ -3191,8 +3191,7 @@ void btrfs_merge_delalloc_extent(struct inode *inode, struct extent_state *new,
struct extent_state *other); struct extent_state *other);
void btrfs_split_delalloc_extent(struct inode *inode, void btrfs_split_delalloc_extent(struct inode *inode,
struct extent_state *orig, u64 split); struct extent_state *orig, u64 split);
int btrfs_merge_bio_hook(struct page *page, unsigned long offset, int btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio,
size_t size, struct bio *bio,
unsigned long bio_flags); unsigned long bio_flags);
void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end); void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end);
vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf); vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf);
......
...@@ -2759,8 +2759,8 @@ static int submit_extent_page(unsigned int opf, struct extent_io_tree *tree, ...@@ -2759,8 +2759,8 @@ static int submit_extent_page(unsigned int opf, struct extent_io_tree *tree,
else else
contig = bio_end_sector(bio) == sector; contig = bio_end_sector(bio) == sector;
if (tree->ops && btrfs_merge_bio_hook(page, offset, page_size, ASSERT(tree->ops);
bio, bio_flags)) if (btrfs_bio_fits_in_stripe(page, page_size, bio, bio_flags))
can_merge = false; can_merge = false;
if (prev_bio_flags != bio_flags || !contig || !can_merge || if (prev_bio_flags != bio_flags || !contig || !can_merge ||
......
...@@ -1870,15 +1870,20 @@ void btrfs_clear_delalloc_extent(struct inode *vfs_inode, ...@@ -1870,15 +1870,20 @@ void btrfs_clear_delalloc_extent(struct inode *vfs_inode,
} }
/* /*
* Merge bio hook, this must check the chunk tree to make sure we don't create * btrfs_bio_fits_in_stripe - Checks whether the size of the given bio will fit
* bios that span stripes or chunks * in a chunk's stripe. This function ensures that bios do not span a
* stripe/chunk
* *
* return 1 if page cannot be merged to bio * @page - The page we are about to add to the bio
* return 0 if page can be merged to bio * @size - size we want to add to the bio
* @bio - bio we want to ensure is smaller than a stripe
* @bio_flags - flags of the bio
*
* return 1 if page cannot be added to the bio
* return 0 if page can be added to the bio
* return error otherwise * return error otherwise
*/ */
int btrfs_merge_bio_hook(struct page *page, unsigned long offset, int btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio,
size_t size, struct bio *bio,
unsigned long bio_flags) unsigned long bio_flags)
{ {
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
......
...@@ -6136,8 +6136,10 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, ...@@ -6136,8 +6136,10 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
*length = em->len - offset; *length = em->len - offset;
} }
/* This is for when we're called from btrfs_merge_bio_hook() and all /*
it cares about is the length */ * This is for when we're called from btrfs_bio_fits_in_stripe and all
* it cares about is the length
*/
if (!bbio_ret) if (!bbio_ret)
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment