btrfs: use ASSERT to report logical error in cow_file_range()
PATCH 1/1 btrfs: use ASSERT to report logical error in cow_file_range()
Use ASSERT to report logical error in cow_file_range(), also move it a bit closer to when the num_bytes is derived.
--- fs/btrfs/inode.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/btrfs/inode.c +2 -3
@@ -976,6 +976,8 @@ static noinline int cow_file_range(struct inode *inode, num_bytes =ALIGN (end - start +1 , blocksize); num_bytes =max (blocksize, num_bytes); +ASSERT (!(num_bytes > +btrfs_super_total_bytes (fs_info->super_copy)));inode_should_defrag (BTRFS_I (inode), start, end, num_bytes,SZ_64K );
@@ -1006,9 +1008,6 @@ static noinline int cow_file_range(struct inode *inode, } } -BUG_ON (num_bytes > -btrfs_super_total_bytes (fs_info->super_copy)); - alloc_hint =get_extent_allocation_hint (inode, start, num_bytes);btrfs_drop_extent_cache (BTRFS_I (inode), start, start + num_bytes -1 ,0 );
Signature · 1 line
2.15.0
Quoted 13 lines · Anand Jain
Use ASSERT to report logical error in
cow_file_range(), also move it a bit closer to when thenum_bytesis derived.Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/inode.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)fs/btrfs/inode.c +0
-0
fs/btrfs/inode.c static noinline int cow_file_range(struct inode *inode, · line 980
Quoted 5 lines
fs/btrfs/inode.c +2
-0@@ -976,6 +976,8 @@ static noinline int cow_file_range(struct inode *inode, num_bytes =ALIGN (end - start +1 , blocksize); num_bytes =max (blocksize, num_bytes); +ASSERT (!(num_bytes > +btrfs_super_total_bytes (fs_info->super_copy)));
The gist of the assert is to see if the range we want to cow is not larger than the actual filesystem size. So just write it like:
ASSERT(numbytes <= btrfs_super_total_bytes(fs_info->super_copy))
It's a lot easier to grok.
Quoted 14 lines
fs/btrfs/inode.c +0
-3inode_should_defrag (BTRFS_I (inode), start, end, num_bytes,SZ_64K );@@ -1006,9 +1008,6 @@ static noinline int cow_file_range(struct inode *inode, } } -BUG_ON (num_bytes > -btrfs_super_total_bytes (fs_info->super_copy)); - alloc_hint =get_extent_allocation_hint (inode, start, num_bytes);btrfs_drop_extent_cache (BTRFS_I (inode), start, start + num_bytes -1 ,0 );
PATCH v2 1/1 btrfs: use ASSERT to report logical error in cow_file_range()
Use ASSERT to report logical error in cow_file_range(), also move it a bit closer to when the num_bytes is derived.
---v1->v2:
ASSERT logic changed. Thanks Nikolay.
fs/btrfs/inode.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/inode.c +1 -3
@@ -976,6 +976,7 @@ static noinline int cow_file_range(struct inode *inode, num_bytes =ALIGN (end - start +1 , blocksize); num_bytes =max (blocksize, num_bytes); +ASSERT (num_bytes <=btrfs_super_total_bytes (fs_info->super_copy));inode_should_defrag (BTRFS_I (inode), start, end, num_bytes,SZ_64K );
@@ -1006,9 +1007,6 @@ static noinline int cow_file_range(struct inode *inode, } } -BUG_ON (num_bytes > -btrfs_super_total_bytes (fs_info->super_copy)); - alloc_hint =get_extent_allocation_hint (inode, start, num_bytes);btrfs_drop_extent_cache (BTRFS_I (inode), start, start + num_bytes -1 ,0 );
Signature · 1 line
2.15.0
Quoted 4 lines · Anand Jain
Use ASSERT to report logical error in
cow_file_range(), also move it a bit closer to when thenum_bytesis derived.Signed-off-by Anand Jain <[email protected]>
Quoted 30 lines
---
v1->v2:
ASSERT logic changed. Thanks Nikolay.fs/btrfs/inode.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)fs/btrfs/inode.c +1
-3@@ -976,6 +976,7 @@ static noinline int cow_file_range(struct inode *inode, num_bytes =ALIGN (end - start +1 , blocksize); num_bytes =max (blocksize, num_bytes); +ASSERT (num_bytes <=btrfs_super_total_bytes (fs_info->super_copy));inode_should_defrag (BTRFS_I (inode), start, end, num_bytes,SZ_64K );@@ -1006,9 +1007,6 @@ static noinline int cow_file_range(struct inode *inode, } } -BUG_ON (num_bytes > -btrfs_super_total_bytes (fs_info->super_copy)); - alloc_hint =get_extent_allocation_hint (inode, start, num_bytes);btrfs_drop_extent_cache (BTRFS_I (inode), start, start + num_bytes -1 ,0 );
Quoted 16 lines · Anand Jain
Use ASSERT to report logical error in
cow_file_range(), also move it a bit closer to when thenum_bytesis derived.Signed-off-by Anand Jain <[email protected]>---
v1->v2:
ASSERT logic changed. Thanks Nikolay.fs/btrfs/inode.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)fs/btrfs/inode.c +0
-0
fs/btrfs/inode.c static noinline int cow_file_range(struct inode *inode, · line 979
Quoted 4 lines
fs/btrfs/inode.c +1
-0@@ -976,6 +976,7 @@ static noinline int cow_file_range(struct inode *inode, num_bytes =ALIGN (end - start +1 , blocksize); num_bytes =max (blocksize, num_bytes); +ASSERT (num_bytes <=btrfs_super_total_bytes (fs_info->super_copy));
I was looking how if this assert is valid and theoretically possible. Yes it seems so, extent start of range could be (u64)-1 in some cases and this must not enter cow_file_range. So the assert is the right way to check the parameter mismatch.