btrfs: Remove force argument from run_delalloc_nocow()
PATCH v2 1/1 btrfs: Remove force argument from run_delalloc_nocow()
force_nocow can be calculated by btrfs_inode and does not need to be passed as an argument.
This simplifies run_delalloc_nocow() call from btrfs_run_delalloc_range() since the decision whether the extent is cow'd or not can be derived from need_force_cow(). Since BTRFS_INODE_NODATACOW and BTRFS_INODE_PREALLOC flags are checked in need_force_cow(), there is no need to check it again.
Change since v1:
- Kept need_force_cow() as it is
--- fs/btrfs/inode.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
fs/btrfs/inode.c +4 -8
@@ -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,struct page *locked_page,const u64 start,const u64 end, -int *page_started,int force, +int *page_started,unsigned long *nr_written) {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);bool nocow = false;u64 disk_bytenr =0 ; +bool force = inode->flags &BTRFS_INODE_NODATACOW ; path =btrfs_alloc_path ();if (!path) {
@@ -1891,17 +1892,12 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page struct writeback_control *wbc) {int ret; -int force_cow =need_force_cow (inode, start, end);const bool zoned =btrfs_is_zoned (inode->root->fs_info); -if (inode->flags &BTRFS_INODE_NODATACOW && !force_cow) { +if (!need_force_cow (inode, start, end)) {ASSERT (!zoned); ret =run_delalloc_nocow (inode, locked_page, start, end, - page_started,1 , 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); + page_started, nr_written); }else if (!inode_can_compress (inode) || !inode_need_compress (inode, start, end)) {if (zoned)
Signature · 5 lines
2.30.1 -- Goldwyn
Quoted 64 lines · Goldwyn Rodrigues
force_nocowcan be calculated bybtrfs_inodeand does not need to be passed as an argument.This simplifies
run_delalloc_nocow()call frombtrfs_run_delalloc_range()since the decision whether the extent is cow'd or not can be derived fromneed_force_cow(). SinceBTRFS_INODE_NODATACOWandBTRFS_INODE_PREALLOCflags are checked inneed_force_cow(), there is no need to check it again.Signed-off-by Goldwyn Rodrigues <[email protected]>Change since v1:
- Keptneed_force_cow()as it is--- fs/btrfs/inode.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)fs/btrfs/inode.c +4
-9@@ -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,struct page *locked_page,const u64 start,const u64 end, -int *page_started,int force, +int *page_started,unsigned long *nr_written) {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);bool nocow = false;u64 disk_bytenr =0 ; +bool force = inode->flags &BTRFS_INODE_NODATACOW ; path =btrfs_alloc_path ();if (!path) {@@ -1891,17 +1892,12 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page struct writeback_control *wbc) {int ret; -int force_cow =need_force_cow (inode, start, end);const bool zoned =btrfs_is_zoned (inode->root->fs_info); -if (inode->flags &BTRFS_INODE_NODATACOW && !force_cow) { +if (!need_force_cow (inode, start, end)) {ASSERT (!zoned); ret =run_delalloc_nocow (inode, locked_page, start, end, - page_started,1 , 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); + page_started, nr_written); }else if (!inode_can_compress (inode) || !inode_need_compress (inode, start, end)) {if (zoned) --2.30.1
Quoted 2 lines
--
Goldwyn
Not super familiar with the btrfs inode implementation - but from what I know of it and what I can read here it looks good to me.
-Amy IP
Quoted 9 lines · Goldwyn Rodrigues
force_nocowcan be calculated bybtrfs_inodeand does not need to be passed as an argument.This simplifies
run_delalloc_nocow()call frombtrfs_run_delalloc_range()since the decision whether the extent is cow'd or not can be derived fromneed_force_cow(). SinceBTRFS_INODE_NODATACOWandBTRFS_INODE_PREALLOCflags are checked inneed_force_cow(), there is no need to check it again.
Quoted 4 lines
Signed-off-by Goldwyn Rodrigues <[email protected]>Change since v1:
- Keptneed_force_cow()as it is
Added to misc-next, thanks.
Quoted 26 lines
--- fs/btrfs/inode.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)fs/btrfs/inode.c +2
-1@@ -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,struct page *locked_page,const u64 start,const u64 end, -int *page_started,int force, +int *page_started,unsigned long *nr_written) {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);bool nocow = false;u64 disk_bytenr =0 ; +bool force = inode->flags &BTRFS_INODE_NODATACOW ; path =btrfs_alloc_path ();if (!path) {
fs/btrfs/inode.c int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page · line 1897
Quoted 8 lines
fs/btrfs/inode.c +1
-2@@ -1891,17 +1892,12 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page struct writeback_control *wbc) {int ret; -int force_cow =need_force_cow (inode, start, end);const bool zoned =btrfs_is_zoned (inode->root->fs_info); -if (inode->flags &BTRFS_INODE_NODATACOW && !force_cow) { +if (!need_force_cow (inode, start, end)) {
We may want to reverse the logic and naming so it says 'need_force_nocow', right now it's "we don't need to force COW, so let's do NOCOW", because COW is the default and the condition should pick the exceptional case.
Quoted 17 lines
fs/btrfs/inode.c +1
-5ASSERT (!zoned); ret =run_delalloc_nocow (inode, locked_page, start, end, - page_started,1 , 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); + page_started, nr_written); }else if (!inode_can_compress (inode) || !inode_need_compress (inode, start, end)) {if (zoned)Signature · 5 lines
2.30.1 -- Goldwyn
Quoted 49 lines · David Sterba
Quoted 9 lines · Goldwyn Rodrigues
force_nocowcan be calculated bybtrfs_inodeand does not need to be passed as an argument.This simplifies
run_delalloc_nocow()call frombtrfs_run_delalloc_range()since the decision whether the extent is cow'd or not can be derived fromneed_force_cow(). SinceBTRFS_INODE_NODATACOWandBTRFS_INODE_PREALLOCflags are checked inneed_force_cow(), there is no need to check it again.Quoted 4 lines
Signed-off-by Goldwyn Rodrigues <[email protected]>Change since v1:
- Keptneed_force_cow()as it isAdded to misc-next, thanks.
Quoted 32 lines
--- fs/btrfs/inode.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)fs/btrfs/inode.c +2
-2@@ -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,struct page *locked_page,const u64 start,const u64 end, -int *page_started,int force, +int *page_started,unsigned long *nr_written) {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);bool nocow = false;u64 disk_bytenr =0 ; +bool force = inode->flags &BTRFS_INODE_NODATACOW ; path =btrfs_alloc_path ();if (!path) {@@ -1891,17 +1892,12 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page struct writeback_control *wbc) {int ret; -int force_cow =need_force_cow (inode, start, end);const bool zoned =btrfs_is_zoned (inode->root->fs_info);
Quoted 7 lines
fs/btrfs/inode.c int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page · line 1897
Quoted 2 lines
fs/btrfs/inode.c +1
-1-if (inode->flags &BTRFS_INODE_NODATACOW && !force_cow) { +if (!need_force_cow (inode, start, end)) {We may want to reverse the logic and naming so it says '
need_force_nocow', right now it's "we don't need to force COW, so let's do NOCOW", because COW is the default and the condition should pick the exceptional case.
Calling it need_force_nocow() or should_nocow() will result in the same concept as previous patch where EXTENT_DEFRAG range would need to be checked before checking inode flags BTRFS_INODE_NODATACOW and BTRFS_INODE_PREALLOC. That's because EXTENT_DEFRAG in range should result in a COW sequence immaterial of what CoW sequence the inode flags say. Isn't it?
Maybe something like this would keep inode flags checks earlier than test_range_bit():
static inline bool should_nocow(struct btrfs_inode *inode, u64 start, u64 end)
{
if (inode->flags & (BTRFS_INODE_NODATACOW | BTRFS_INODE_PREALLOC)) {
if (inode->defrag_bytes &&
test_range_bit(&inode->io_tree, start, end, EXTENT_DEFRAG, 0, NULL))
return false;
return true;
}
return false;
}Quoted 12 lines
Quoted 12 lines
fs/btrfs/inode.c +1
-5ASSERT (!zoned); ret =run_delalloc_nocow (inode, locked_page, start, end, - page_started,1 , 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); + page_started, nr_written); }else if (!inode_can_compress (inode) || !inode_need_compress (inode, start, end)) {if (zoned)
Signature · 1 line
Goldwyn