btrfs: simplify extent map splitting and rename split_zoned_em
split_zoned_em is only ever asked to split out the beginning of an extent map. Change it to only take a len to split out instead of a pre and post region. Also rename the function to split_extent_map as there is nothing zoned device specific about it. Reviewed-by: Josef Bacik <josef@toxicpanda.com> Tested-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
f0792b792d
commit
2e38a84bc6
@ -2512,37 +2512,31 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Split an extent_map at [start, start + len]
|
* Split off the first pre bytes from the extent_map at [start, start + len]
|
||||||
*
|
*
|
||||||
* This function is intended to be used only for extract_ordered_extent().
|
* This function is intended to be used only for extract_ordered_extent().
|
||||||
*/
|
*/
|
||||||
static int split_zoned_em(struct btrfs_inode *inode, u64 start, u64 len,
|
static int split_extent_map(struct btrfs_inode *inode, u64 start, u64 len, u64 pre)
|
||||||
u64 pre, u64 post)
|
|
||||||
{
|
{
|
||||||
struct extent_map_tree *em_tree = &inode->extent_tree;
|
struct extent_map_tree *em_tree = &inode->extent_tree;
|
||||||
struct extent_map *em;
|
struct extent_map *em;
|
||||||
struct extent_map *split_pre = NULL;
|
struct extent_map *split_pre = NULL;
|
||||||
struct extent_map *split_mid = NULL;
|
struct extent_map *split_mid = NULL;
|
||||||
struct extent_map *split_post = NULL;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
/* Sanity check */
|
ASSERT(pre != 0);
|
||||||
if (pre == 0 && post == 0)
|
ASSERT(pre < len);
|
||||||
return 0;
|
|
||||||
|
|
||||||
split_pre = alloc_extent_map();
|
split_pre = alloc_extent_map();
|
||||||
if (pre)
|
if (!split_pre)
|
||||||
split_mid = alloc_extent_map();
|
return -ENOMEM;
|
||||||
if (post)
|
split_mid = alloc_extent_map();
|
||||||
split_post = alloc_extent_map();
|
if (!split_mid) {
|
||||||
if (!split_pre || (pre && !split_mid) || (post && !split_post)) {
|
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto out;
|
goto out_free_pre;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(pre + post < len);
|
|
||||||
|
|
||||||
lock_extent(&inode->io_tree, start, start + len - 1, NULL);
|
lock_extent(&inode->io_tree, start, start + len - 1, NULL);
|
||||||
write_lock(&em_tree->lock);
|
write_lock(&em_tree->lock);
|
||||||
em = lookup_extent_mapping(em_tree, start, len);
|
em = lookup_extent_mapping(em_tree, start, len);
|
||||||
@ -2563,7 +2557,7 @@ static int split_zoned_em(struct btrfs_inode *inode, u64 start, u64 len,
|
|||||||
|
|
||||||
/* First, replace the em with a new extent_map starting from * em->start */
|
/* First, replace the em with a new extent_map starting from * em->start */
|
||||||
split_pre->start = em->start;
|
split_pre->start = em->start;
|
||||||
split_pre->len = (pre ? pre : em->len - post);
|
split_pre->len = pre;
|
||||||
split_pre->orig_start = split_pre->start;
|
split_pre->orig_start = split_pre->start;
|
||||||
split_pre->block_start = em->block_start;
|
split_pre->block_start = em->block_start;
|
||||||
split_pre->block_len = split_pre->len;
|
split_pre->block_len = split_pre->len;
|
||||||
@ -2577,38 +2571,21 @@ static int split_zoned_em(struct btrfs_inode *inode, u64 start, u64 len,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Now we only have an extent_map at:
|
* Now we only have an extent_map at:
|
||||||
* [em->start, em->start + pre] if pre != 0
|
* [em->start, em->start + pre]
|
||||||
* [em->start, em->start + em->len - post] if pre == 0
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (pre) {
|
/* Insert the middle extent_map. */
|
||||||
/* Insert the middle extent_map */
|
split_mid->start = em->start + pre;
|
||||||
split_mid->start = em->start + pre;
|
split_mid->len = em->len - pre;
|
||||||
split_mid->len = em->len - pre - post;
|
split_mid->orig_start = split_mid->start;
|
||||||
split_mid->orig_start = split_mid->start;
|
split_mid->block_start = em->block_start + pre;
|
||||||
split_mid->block_start = em->block_start + pre;
|
split_mid->block_len = split_mid->len;
|
||||||
split_mid->block_len = split_mid->len;
|
split_mid->orig_block_len = split_mid->block_len;
|
||||||
split_mid->orig_block_len = split_mid->block_len;
|
split_mid->ram_bytes = split_mid->len;
|
||||||
split_mid->ram_bytes = split_mid->len;
|
split_mid->flags = flags;
|
||||||
split_mid->flags = flags;
|
split_mid->compress_type = em->compress_type;
|
||||||
split_mid->compress_type = em->compress_type;
|
split_mid->generation = em->generation;
|
||||||
split_mid->generation = em->generation;
|
add_extent_mapping(em_tree, split_mid, 1);
|
||||||
add_extent_mapping(em_tree, split_mid, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (post) {
|
|
||||||
split_post->start = em->start + em->len - post;
|
|
||||||
split_post->len = post;
|
|
||||||
split_post->orig_start = split_post->start;
|
|
||||||
split_post->block_start = em->block_start + em->len - post;
|
|
||||||
split_post->block_len = split_post->len;
|
|
||||||
split_post->orig_block_len = split_post->block_len;
|
|
||||||
split_post->ram_bytes = split_post->len;
|
|
||||||
split_post->flags = flags;
|
|
||||||
split_post->compress_type = em->compress_type;
|
|
||||||
split_post->generation = em->generation;
|
|
||||||
add_extent_mapping(em_tree, split_post, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Once for us */
|
/* Once for us */
|
||||||
free_extent_map(em);
|
free_extent_map(em);
|
||||||
@ -2618,11 +2595,9 @@ static int split_zoned_em(struct btrfs_inode *inode, u64 start, u64 len,
|
|||||||
out_unlock:
|
out_unlock:
|
||||||
write_unlock(&em_tree->lock);
|
write_unlock(&em_tree->lock);
|
||||||
unlock_extent(&inode->io_tree, start, start + len - 1, NULL);
|
unlock_extent(&inode->io_tree, start, start + len - 1, NULL);
|
||||||
out:
|
|
||||||
free_extent_map(split_pre);
|
|
||||||
free_extent_map(split_mid);
|
free_extent_map(split_mid);
|
||||||
free_extent_map(split_post);
|
out_free_pre:
|
||||||
|
free_extent_map(split_pre);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2653,7 +2628,7 @@ blk_status_t btrfs_extract_ordered_extent(struct btrfs_bio *bbio)
|
|||||||
ret = btrfs_split_ordered_extent(ordered, len);
|
ret = btrfs_split_ordered_extent(ordered, len);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
ret = split_zoned_em(inode, bbio->file_offset, ordered_len, len, 0);
|
ret = split_extent_map(inode, bbio->file_offset, ordered_len, len);
|
||||||
out:
|
out:
|
||||||
btrfs_put_ordered_extent(ordered);
|
btrfs_put_ordered_extent(ordered);
|
||||||
return errno_to_blk_status(ret);
|
return errno_to_blk_status(ret);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user