Commit cacb2cea authored by Johannes Thumshirn's avatar Johannes Thumshirn Committed by David Sterba

btrfs: zoned: check if bio spans across an ordered extent

To ensure that an ordered extent maps to a contiguous region on disk, we
need to maintain a "one bio == one ordered extent" rule.

Ensure that constructing bio does not span more than an ordered extent.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarNaohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent d22002fd
......@@ -3120,6 +3120,8 @@ void btrfs_split_delalloc_extent(struct inode *inode,
struct extent_state *orig, u64 split);
int btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio,
unsigned long bio_flags);
bool btrfs_bio_fits_in_ordered_extent(struct page *page, struct bio *bio,
unsigned int size);
void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end);
vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf);
int btrfs_readpage(struct file *file, struct page *page);
......
......@@ -3124,10 +3124,15 @@ static bool btrfs_bio_add_page(struct bio *bio, struct page *page,
if (btrfs_bio_fits_in_stripe(page, size, bio, bio_flags))
return false;
if (bio_op(bio) == REQ_OP_ZONE_APPEND)
if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
struct page *first_page = bio_first_bvec_all(bio)->bv_page;
if (!btrfs_bio_fits_in_ordered_extent(first_page, bio, size))
return false;
ret = bio_add_zone_append_page(bio, page, size, pg_offset);
else
} else {
ret = bio_add_page(bio, page, size, pg_offset);
}
return ret == size;
}
......
......@@ -2215,6 +2215,33 @@ static blk_status_t btrfs_submit_bio_start(struct inode *inode, struct bio *bio,
return btrfs_csum_one_bio(BTRFS_I(inode), bio, 0, 0);
}
bool btrfs_bio_fits_in_ordered_extent(struct page *page, struct bio *bio,
unsigned int size)
{
struct btrfs_inode *inode = BTRFS_I(page->mapping->host);
struct btrfs_fs_info *fs_info = inode->root->fs_info;
struct btrfs_ordered_extent *ordered;
u64 len = bio->bi_iter.bi_size + size;
bool ret = true;
ASSERT(btrfs_is_zoned(fs_info));
ASSERT(fs_info->max_zone_append_size > 0);
ASSERT(bio_op(bio) == REQ_OP_ZONE_APPEND);
/* Ordered extent not yet created, so we're good */
ordered = btrfs_lookup_ordered_extent(inode, page_offset(page));
if (!ordered)
return ret;
if ((bio->bi_iter.bi_sector << SECTOR_SHIFT) + len >
ordered->disk_bytenr + ordered->disk_num_bytes)
ret = false;
btrfs_put_ordered_extent(ordered);
return ret;
}
static blk_status_t extract_ordered_extent(struct btrfs_inode *inode,
struct bio *bio, loff_t file_offset)
{
......
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