Skip to content

Commit

Permalink
btrfs: simplify extent type checks in run_delalloc_nocow
Browse files Browse the repository at this point in the history
There is no point in checking the type of the extent again just to set
the 'type' variable, when this check has already been performed before.
Instead, extend the original if branch with an 'else' clause. This
allows to remove one local variable and make it obvious how the code
flow differs for prealloc/regular extents.

Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Nikolay Borisov authored and David Sterba committed Sep 9, 2019
1 parent a6bd9cd commit bb55f62
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,6 @@ static noinline int run_delalloc_nocow(struct inode *inode,
u64 disk_bytenr = 0;
u64 num_bytes = 0;
u64 disk_num_bytes;
int type;
u64 ram_bytes;
int extent_type;
bool nocow = false;
Expand Down Expand Up @@ -1572,16 +1571,17 @@ static noinline int run_delalloc_nocow(struct inode *inode,
goto error;
}
free_extent_map(em);
}

if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
type = BTRFS_ORDERED_PREALLOC;
ret = btrfs_add_ordered_extent(inode, cur_offset,
disk_bytenr, num_bytes,
num_bytes,
BTRFS_ORDERED_PREALLOC);
} else {
type = BTRFS_ORDERED_NOCOW;
ret = btrfs_add_ordered_extent(inode, cur_offset,
disk_bytenr, num_bytes,
num_bytes,
BTRFS_ORDERED_NOCOW);
}

ret = btrfs_add_ordered_extent(inode, cur_offset, disk_bytenr,
num_bytes, num_bytes,type);
if (nocow)
btrfs_dec_nocow_writers(fs_info, disk_bytenr);
BUG_ON(ret); /* -ENOMEM */
Expand Down

0 comments on commit bb55f62

Please sign in to comment.