linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: use ASSERT to report logical error in cow_file_range()
@ 2018-02-15  4:30 Anand Jain
  2018-02-15  8:43 ` Nikolay Borisov
  0 siblings, 1 reply; 5+ messages in thread
From: Anand Jain @ 2018-02-15  4:30 UTC (permalink / raw)
  To: linux-btrfs

Use ASSERT to report logical error in cow_file_range(), also move
it a bit closer to when the num_bytes is derived.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/inode.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 4b156e191592..5648c4425f1e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -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);
-- 
2.15.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: use ASSERT to report logical error in cow_file_range()
  2018-02-15  4:30 [PATCH] btrfs: use ASSERT to report logical error in cow_file_range() Anand Jain
@ 2018-02-15  8:43 ` Nikolay Borisov
  2018-02-15 10:07   ` [PATCH v2] " Anand Jain
  0 siblings, 1 reply; 5+ messages in thread
From: Nikolay Borisov @ 2018-02-15  8:43 UTC (permalink / raw)
  To: Anand Jain, linux-btrfs



On 15.02.2018 06:30, Anand Jain wrote:
> Use ASSERT to report logical error in cow_file_range(), also move
> it a bit closer to when the num_bytes is derived.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  fs/btrfs/inode.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 4b156e191592..5648c4425f1e 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -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.

>  
>  	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);
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] btrfs: use ASSERT to report logical error in cow_file_range()
  2018-02-15  8:43 ` Nikolay Borisov
@ 2018-02-15 10:07   ` Anand Jain
  2018-02-15 10:09     ` Nikolay Borisov
  2018-02-19 15:19     ` David Sterba
  0 siblings, 2 replies; 5+ messages in thread
From: Anand Jain @ 2018-02-15 10:07 UTC (permalink / raw)
  To: linux-btrfs

Use ASSERT to report logical error in cow_file_range(), also move
it a bit closer to when the num_bytes is derived.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v1->v2:
   ASSERT logic changed. Thanks Nikolay.

 fs/btrfs/inode.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 4b156e191592..260fd8139951 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -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);
-- 
2.15.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] btrfs: use ASSERT to report logical error in cow_file_range()
  2018-02-15 10:07   ` [PATCH v2] " Anand Jain
@ 2018-02-15 10:09     ` Nikolay Borisov
  2018-02-19 15:19     ` David Sterba
  1 sibling, 0 replies; 5+ messages in thread
From: Nikolay Borisov @ 2018-02-15 10:09 UTC (permalink / raw)
  To: Anand Jain, linux-btrfs



On 15.02.2018 12:07, Anand Jain wrote:
> Use ASSERT to report logical error in cow_file_range(), also move
> it a bit closer to when the num_bytes is derived.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
> v1->v2:
>    ASSERT logic changed. Thanks Nikolay.
> 
>  fs/btrfs/inode.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 4b156e191592..260fd8139951 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -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);
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] btrfs: use ASSERT to report logical error in cow_file_range()
  2018-02-15 10:07   ` [PATCH v2] " Anand Jain
  2018-02-15 10:09     ` Nikolay Borisov
@ 2018-02-19 15:19     ` David Sterba
  1 sibling, 0 replies; 5+ messages in thread
From: David Sterba @ 2018-02-19 15:19 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Thu, Feb 15, 2018 at 06:07:59PM +0800, Anand Jain wrote:
> Use ASSERT to report logical error in cow_file_range(), also move
> it a bit closer to when the num_bytes is derived.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> v1->v2:
>    ASSERT logic changed. Thanks Nikolay.
> 
>  fs/btrfs/inode.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 4b156e191592..260fd8139951 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -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.

Reviewed-by: David Sterba <dsterba@suse.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-02-19 15:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-15  4:30 [PATCH] btrfs: use ASSERT to report logical error in cow_file_range() Anand Jain
2018-02-15  8:43 ` Nikolay Borisov
2018-02-15 10:07   ` [PATCH v2] " Anand Jain
2018-02-15 10:09     ` Nikolay Borisov
2018-02-19 15:19     ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).