Commit 8f4af4b8 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David Sterba

btrfs: sink parameter len to btrfs_split_ordered_extent

btrfs_split_ordered_extent is only ever asked to split out the beginning
of an ordered_extent (i.e. post == 0).  Change it to only take a len to
split out, and switch it to allocate the new extent for the beginning,
as that helps with callers that want to keep a pointer to the
ordered_extent that it is stealing from.
Reviewed-by: default avatarNaohiro Aota <naohiro.aota@wdc.com>
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 11d33ab6
...@@ -2646,17 +2646,11 @@ blk_status_t btrfs_extract_ordered_extent(struct btrfs_bio *bbio) ...@@ -2646,17 +2646,11 @@ blk_status_t btrfs_extract_ordered_extent(struct btrfs_bio *bbio)
goto out; goto out;
} }
/* The bio must be entirely covered by the ordered extent. */
if (WARN_ON_ONCE(len > ordered_len)) {
ret = -EINVAL;
goto out;
}
/* No need to split if the ordered extent covers the entire bio. */ /* No need to split if the ordered extent covers the entire bio. */
if (ordered->disk_num_bytes == len) if (ordered->disk_num_bytes == len)
goto out; goto out;
ret = btrfs_split_ordered_extent(ordered, len, 0); 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_zoned_em(inode, bbio->file_offset, ordered_len, len, 0);
......
...@@ -1138,17 +1138,22 @@ static int clone_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pos, ...@@ -1138,17 +1138,22 @@ static int clone_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pos,
ordered->compress_type); ordered->compress_type);
} }
int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre, /* Split out a new ordered extent for this first @len bytes of @ordered. */
u64 post) int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 len)
{ {
struct inode *inode = ordered->inode; struct inode *inode = ordered->inode;
struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree; struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree;
struct rb_node *node;
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
int ret = 0; struct rb_node *node;
trace_btrfs_ordered_extent_split(BTRFS_I(inode), ordered); trace_btrfs_ordered_extent_split(BTRFS_I(inode), ordered);
/*
* The entire bio must be covered by the ordered extent, but we can't
* reduce the original extent to a zero length either.
*/
if (WARN_ON_ONCE(len >= ordered->num_bytes))
return -EINVAL;
/* We cannot split once ordered extent is past end_bio. */ /* We cannot split once ordered extent is past end_bio. */
if (WARN_ON_ONCE(ordered->bytes_left != ordered->disk_num_bytes)) if (WARN_ON_ONCE(ordered->bytes_left != ordered->disk_num_bytes))
return -EINVAL; return -EINVAL;
...@@ -1167,11 +1172,11 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre, ...@@ -1167,11 +1172,11 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre,
if (tree->last == node) if (tree->last == node)
tree->last = NULL; tree->last = NULL;
ordered->file_offset += pre; ordered->file_offset += len;
ordered->disk_bytenr += pre; ordered->disk_bytenr += len;
ordered->num_bytes -= (pre + post); ordered->num_bytes -= len;
ordered->disk_num_bytes -= (pre + post); ordered->disk_num_bytes -= len;
ordered->bytes_left -= (pre + post); ordered->bytes_left -= len;
/* Re-insert the node */ /* Re-insert the node */
node = tree_insert(&tree->tree, ordered->file_offset, &ordered->rb_node); node = tree_insert(&tree->tree, ordered->file_offset, &ordered->rb_node);
...@@ -1182,13 +1187,7 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre, ...@@ -1182,13 +1187,7 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre,
spin_unlock_irq(&tree->lock); spin_unlock_irq(&tree->lock);
if (pre) return clone_ordered_extent(ordered, 0, len);
ret = clone_ordered_extent(ordered, 0, pre);
if (ret == 0 && post)
ret = clone_ordered_extent(ordered, pre + ordered->disk_num_bytes,
post);
return ret;
} }
int __init ordered_data_init(void) int __init ordered_data_init(void)
......
...@@ -212,8 +212,7 @@ void btrfs_lock_and_flush_ordered_range(struct btrfs_inode *inode, u64 start, ...@@ -212,8 +212,7 @@ void btrfs_lock_and_flush_ordered_range(struct btrfs_inode *inode, u64 start,
struct extent_state **cached_state); struct extent_state **cached_state);
bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end, bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end,
struct extent_state **cached_state); struct extent_state **cached_state);
int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre, int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 len);
u64 post);
int __init ordered_data_init(void); int __init ordered_data_init(void);
void __cold ordered_data_exit(void); void __cold ordered_data_exit(void);
......
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