Commit 3daea5fd authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David Sterba

btrfs: merge the two calls to btrfs_add_ordered_extent in run_delalloc_nocow

Refactor run_delalloc_nocow a little bit so that there is only a single
call to btrfs_add_ordered_extent instead of two.
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent a39da514
...@@ -2140,6 +2140,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, ...@@ -2140,6 +2140,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
u64 ram_bytes; u64 ram_bytes;
u64 nocow_end; u64 nocow_end;
int extent_type; int extent_type;
bool is_prealloc;
nocow = false; nocow = false;
...@@ -2278,8 +2279,8 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, ...@@ -2278,8 +2279,8 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
} }
nocow_end = cur_offset + nocow_args.num_bytes - 1; nocow_end = cur_offset + nocow_args.num_bytes - 1;
is_prealloc = extent_type == BTRFS_FILE_EXTENT_PREALLOC;
if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) { if (is_prealloc) {
u64 orig_start = found_key.offset - nocow_args.extent_offset; u64 orig_start = found_key.offset - nocow_args.extent_offset;
struct extent_map *em; struct extent_map *em;
...@@ -2295,28 +2296,20 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, ...@@ -2295,28 +2296,20 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
goto error; goto error;
} }
free_extent_map(em); free_extent_map(em);
ret = btrfs_add_ordered_extent(inode, }
cur_offset, nocow_args.num_bytes,
nocow_args.num_bytes, ret = btrfs_add_ordered_extent(inode, cur_offset,
nocow_args.disk_bytenr, nocow_args.num_bytes, nocow_args.num_bytes,
nocow_args.num_bytes, 0, nocow_args.disk_bytenr, nocow_args.num_bytes, 0,
1 << BTRFS_ORDERED_PREALLOC, is_prealloc
? (1 << BTRFS_ORDERED_PREALLOC)
: (1 << BTRFS_ORDERED_NOCOW),
BTRFS_COMPRESS_NONE); BTRFS_COMPRESS_NONE);
if (ret) { if (ret) {
if (is_prealloc) {
btrfs_drop_extent_map_range(inode, cur_offset, btrfs_drop_extent_map_range(inode, cur_offset,
nocow_end, false); nocow_end, false);
goto error;
} }
} else {
ret = btrfs_add_ordered_extent(inode, cur_offset,
nocow_args.num_bytes,
nocow_args.num_bytes,
nocow_args.disk_bytenr,
nocow_args.num_bytes,
0,
1 << BTRFS_ORDERED_NOCOW,
BTRFS_COMPRESS_NONE);
if (ret)
goto error; goto error;
} }
......
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