Commit 11d33ab6 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David Sterba

btrfs: simplify splitting logic in btrfs_extract_ordered_extent

btrfs_extract_ordered_extent is always used to split an ordered_extent
and extent_map into two parts, so it doesn't need to deal with a three
way split.

Simplify it by only allowing for a single split point, and always split
out the beginning of the extent, as that is what we'll later need to
be able to hold on to a reference to the original ordered_extent that
the first part is split off for submission.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Tested-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent e44ca71c
...@@ -2632,39 +2632,36 @@ blk_status_t btrfs_extract_ordered_extent(struct btrfs_bio *bbio) ...@@ -2632,39 +2632,36 @@ blk_status_t btrfs_extract_ordered_extent(struct btrfs_bio *bbio)
u64 len = bbio->bio.bi_iter.bi_size; u64 len = bbio->bio.bi_iter.bi_size;
struct btrfs_inode *inode = bbio->inode; struct btrfs_inode *inode = bbio->inode;
struct btrfs_ordered_extent *ordered; struct btrfs_ordered_extent *ordered;
u64 file_len; u64 ordered_len;
u64 end = start + len;
u64 ordered_end;
u64 pre, post;
int ret = 0; int ret = 0;
ordered = btrfs_lookup_ordered_extent(inode, bbio->file_offset); ordered = btrfs_lookup_ordered_extent(inode, bbio->file_offset);
if (WARN_ON_ONCE(!ordered)) if (WARN_ON_ONCE(!ordered))
return BLK_STS_IOERR; return BLK_STS_IOERR;
ordered_len = ordered->num_bytes;
/* No need to split */ /* Must always be called for the beginning of an ordered extent. */
if (ordered->disk_num_bytes == len) if (WARN_ON_ONCE(start != ordered->disk_bytenr)) {
ret = -EINVAL;
goto out; goto out;
}
ordered_end = ordered->disk_bytenr + ordered->disk_num_bytes; /* The bio must be entirely covered by the ordered extent. */
/* bio must be in one ordered extent */ if (WARN_ON_ONCE(len > ordered_len)) {
if (WARN_ON_ONCE(start < ordered->disk_bytenr || end > ordered_end)) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
file_len = ordered->num_bytes; /* No need to split if the ordered extent covers the entire bio. */
pre = start - ordered->disk_bytenr; if (ordered->disk_num_bytes == len)
post = ordered_end - end; goto out;
ret = btrfs_split_ordered_extent(ordered, pre, post); ret = btrfs_split_ordered_extent(ordered, len, 0);
if (ret) if (ret)
goto out; goto out;
ret = split_zoned_em(inode, bbio->file_offset, file_len, pre, post); ret = split_zoned_em(inode, bbio->file_offset, ordered_len, len, 0);
out: out:
btrfs_put_ordered_extent(ordered); btrfs_put_ordered_extent(ordered);
return errno_to_blk_status(ret); return errno_to_blk_status(ret);
} }
......
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