diff mbox series

[v3,10/54] btrfs: convert some BUG_ON()'s to ASSERT()'s in do_relocation

Message ID 416807404fa65b6f122249f7c9d76834248be5ee.1606938211.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series Cleanup error handling in relocation | expand

Commit Message

Josef Bacik Dec. 2, 2020, 7:50 p.m. UTC
A few of these are checking for correctness, and won't be triggered by
corrupted file systems, so convert them to ASSERT() instead of BUG_ON()
and add a comment explaining their existence.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

Comments

Qu Wenruo Dec. 3, 2020, 2:14 a.m. UTC | #1
On 2020/12/3 上午3:50, Josef Bacik wrote:
> A few of these are checking for correctness, and won't be triggered by
> corrupted file systems, so convert them to ASSERT() instead of BUG_ON()
> and add a comment explaining their existence.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>  fs/btrfs/relocation.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index ce935139d87b..d0ce771a2a8d 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -2183,7 +2183,11 @@ static int do_relocation(struct btrfs_trans_handle *trans,
>  	int slot;
>  	int ret = 0;
>  
> -	BUG_ON(lowest && node->eb);
> +	/*
> +	 * If we are lowest then this is the first time we're processing this
> +	 * block, and thus shouldn't have an eb associated with it yet.
> +	 */
> +	ASSERT(!lowest || !node->eb);
>  
>  	path->lowest_level = node->level + 1;
>  	rc->backref_cache.path[node->level] = node;
> @@ -2268,7 +2272,11 @@ static int do_relocation(struct btrfs_trans_handle *trans,
>  			free_extent_buffer(eb);
>  			if (ret < 0)
>  				goto next;
> -			BUG_ON(node->eb != eb);
> +			/*
> +			 * We've just cow'ed this block, it should have updated
> +			 * the correct backref node entry.
> +			 */
> +			ASSERT(node->eb == eb);
>  		} else {
>  			btrfs_set_node_blockptr(upper->eb, slot,
>  						node->eb->start);
> @@ -2304,7 +2312,12 @@ static int do_relocation(struct btrfs_trans_handle *trans,
>  	}
>  
>  	path->lowest_level = 0;
> -	BUG_ON(ret == -ENOSPC);
> +
> +	/*
> +	 * We should have allocated all of our space in the block rsv and thus
> +	 * shouldn't ENOSPC.
> +	 */
> +	ASSERT(ret != -ENOSPC);
>  	return ret;
>  }
>  
>
diff mbox series

Patch

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index ce935139d87b..d0ce771a2a8d 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2183,7 +2183,11 @@  static int do_relocation(struct btrfs_trans_handle *trans,
 	int slot;
 	int ret = 0;
 
-	BUG_ON(lowest && node->eb);
+	/*
+	 * If we are lowest then this is the first time we're processing this
+	 * block, and thus shouldn't have an eb associated with it yet.
+	 */
+	ASSERT(!lowest || !node->eb);
 
 	path->lowest_level = node->level + 1;
 	rc->backref_cache.path[node->level] = node;
@@ -2268,7 +2272,11 @@  static int do_relocation(struct btrfs_trans_handle *trans,
 			free_extent_buffer(eb);
 			if (ret < 0)
 				goto next;
-			BUG_ON(node->eb != eb);
+			/*
+			 * We've just cow'ed this block, it should have updated
+			 * the correct backref node entry.
+			 */
+			ASSERT(node->eb == eb);
 		} else {
 			btrfs_set_node_blockptr(upper->eb, slot,
 						node->eb->start);
@@ -2304,7 +2312,12 @@  static int do_relocation(struct btrfs_trans_handle *trans,
 	}
 
 	path->lowest_level = 0;
-	BUG_ON(ret == -ENOSPC);
+
+	/*
+	 * We should have allocated all of our space in the block rsv and thus
+	 * shouldn't ENOSPC.
+	 */
+	ASSERT(ret != -ENOSPC);
 	return ret;
 }