mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 02:39:48 +00:00
btrfs: remove force argument from run_delalloc_nocow()
force_cow can be calculated from inode and does not need to be passed as an argument. This simplifies run_delalloc_nocow() call from btrfs_run_delalloc_range() A new function, should_nocow() checks if the range should be NOCOWed or not. The function returns true iff either BTRFS_INODE_NODATA or BTRFS_INODE_PREALLOC, but is not a defrag extent. Tested-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
d6ade6894e
commit
6e65ae7629
1 changed files with 13 additions and 24 deletions
|
@ -1516,7 +1516,7 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page,
|
||||||
static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
|
static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
|
||||||
struct page *locked_page,
|
struct page *locked_page,
|
||||||
const u64 start, const u64 end,
|
const u64 start, const u64 end,
|
||||||
int *page_started, int force,
|
int *page_started,
|
||||||
unsigned long *nr_written)
|
unsigned long *nr_written)
|
||||||
{
|
{
|
||||||
struct btrfs_fs_info *fs_info = inode->root->fs_info;
|
struct btrfs_fs_info *fs_info = inode->root->fs_info;
|
||||||
|
@ -1530,6 +1530,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
|
||||||
u64 ino = btrfs_ino(inode);
|
u64 ino = btrfs_ino(inode);
|
||||||
bool nocow = false;
|
bool nocow = false;
|
||||||
u64 disk_bytenr = 0;
|
u64 disk_bytenr = 0;
|
||||||
|
const bool force = inode->flags & BTRFS_INODE_NODATACOW;
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
path = btrfs_alloc_path();
|
||||||
if (!path) {
|
if (!path) {
|
||||||
|
@ -1863,23 +1864,16 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int need_force_cow(struct btrfs_inode *inode, u64 start, u64 end)
|
static bool should_nocow(struct btrfs_inode *inode, u64 start, u64 end)
|
||||||
{
|
{
|
||||||
|
if (inode->flags & (BTRFS_INODE_NODATACOW | BTRFS_INODE_PREALLOC)) {
|
||||||
if (!(inode->flags & BTRFS_INODE_NODATACOW) &&
|
if (inode->defrag_bytes &&
|
||||||
!(inode->flags & BTRFS_INODE_PREALLOC))
|
test_range_bit(&inode->io_tree, start, end, EXTENT_DEFRAG,
|
||||||
return 0;
|
0, NULL))
|
||||||
|
return false;
|
||||||
/*
|
return true;
|
||||||
* @defrag_bytes is a hint value, no spinlock held here,
|
}
|
||||||
* if is not zero, it means the file is defragging.
|
return false;
|
||||||
* Force cow if given extent needs to be defragged.
|
|
||||||
*/
|
|
||||||
if (inode->defrag_bytes &&
|
|
||||||
test_range_bit(&inode->io_tree, start, end, EXTENT_DEFRAG, 0, NULL))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1891,17 +1885,12 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page
|
||||||
struct writeback_control *wbc)
|
struct writeback_control *wbc)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int force_cow = need_force_cow(inode, start, end);
|
|
||||||
const bool zoned = btrfs_is_zoned(inode->root->fs_info);
|
const bool zoned = btrfs_is_zoned(inode->root->fs_info);
|
||||||
|
|
||||||
if (inode->flags & BTRFS_INODE_NODATACOW && !force_cow) {
|
if (should_nocow(inode, start, end)) {
|
||||||
ASSERT(!zoned);
|
ASSERT(!zoned);
|
||||||
ret = run_delalloc_nocow(inode, locked_page, start, end,
|
ret = run_delalloc_nocow(inode, locked_page, start, end,
|
||||||
page_started, 1, nr_written);
|
page_started, nr_written);
|
||||||
} else if (inode->flags & BTRFS_INODE_PREALLOC && !force_cow) {
|
|
||||||
ASSERT(!zoned);
|
|
||||||
ret = run_delalloc_nocow(inode, locked_page, start, end,
|
|
||||||
page_started, 0, nr_written);
|
|
||||||
} else if (!inode_can_compress(inode) ||
|
} else if (!inode_can_compress(inode) ||
|
||||||
!inode_need_compress(inode, start, end)) {
|
!inode_need_compress(inode, start, end)) {
|
||||||
if (zoned)
|
if (zoned)
|
||||||
|
|
Loading…
Reference in a new issue