diff mbox series

[v2,1/5] btrfs: Always output error message when key/level verification fails

Message ID 20190117101528.8675-2-wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: Enhancement to tree block validation | expand

Commit Message

Qu Wenruo Jan. 17, 2019, 10:15 a.m. UTC
We have internal report of strange transaction abort due to EUCLEAN
without any error message.

Since error message inside verify_level_key() is only enabled for
CONFIG_BTRFS_DEBUG, the error message won't output for most distro.

This patch will make the error message mandatory, so when problem
happens we know what's causing the problem.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/disk-io.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Johannes Thumshirn Jan. 17, 2019, 1:14 p.m. UTC | #1
On 17/01/2019 11:15, Qu Wenruo wrote:
> @@ -449,9 +449,10 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,
>  		btrfs_item_key_to_cpu(eb, &found_key, 0);
>  	ret = btrfs_comp_cpu_keys(first_key, &found_key);
>  
> -#ifdef CONFIG_BTRFS_DEBUG
>  	if (ret) {
> +#ifdef CONFIG_BTRFS_DEBUG
>  		WARN_ON(1);
> +#endif
>  		btrfs_err(fs_info,
>  "tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu,%u,%llu) has=(%llu,%u,%llu)",
>  			  eb->start, parent_transid, first_key->objectid,
> @@ -459,7 +460,6 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,
>  			  found_key.objectid, found_key.type,
>  			  found_key.offset);
>  	}
> -#endif
>  	return ret;
>  }


Hmm I think the resulting code looks a bit odd now, doesn't it?
if (ret) {
#ifdef CONFIG_BTRFS_DEBUG
		WARN_ON(1);
#endif

	btrfs_err(fs_info,


Why not something like:
if (ret) {
	if (IS_ENABLED(CONFIG_BTRFS_DEBUG))
		WARN_ON(1);
	
	btrfs_err(fs_info,

Or even hide the if (IS_ENABLED(CONFIG_BTRFS_DEBUG)) WARN_ON(1); in a macro
#define BTRFS_DEBUG_WARN_ON(x) do { 		\
	if (IS_ENABLED(CONFIG_BTRFS_DEBUG)) 	\
		WARN_ON((x));			\
} while(0)
Qu Wenruo Jan. 17, 2019, 1:25 p.m. UTC | #2
On 2019/1/17 下午9:14, Johannes Thumshirn wrote:
> On 17/01/2019 11:15, Qu Wenruo wrote:
>> @@ -449,9 +449,10 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,
>>  		btrfs_item_key_to_cpu(eb, &found_key, 0);
>>  	ret = btrfs_comp_cpu_keys(first_key, &found_key);
>>  
>> -#ifdef CONFIG_BTRFS_DEBUG
>>  	if (ret) {
>> +#ifdef CONFIG_BTRFS_DEBUG
>>  		WARN_ON(1);
>> +#endif
>>  		btrfs_err(fs_info,
>>  "tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu,%u,%llu) has=(%llu,%u,%llu)",
>>  			  eb->start, parent_transid, first_key->objectid,
>> @@ -459,7 +460,6 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,
>>  			  found_key.objectid, found_key.type,
>>  			  found_key.offset);
>>  	}
>> -#endif
>>  	return ret;
>>  }
> 
> 
> Hmm I think the resulting code looks a bit odd now, doesn't it?
> if (ret) {
> #ifdef CONFIG_BTRFS_DEBUG
> 		WARN_ON(1);
> #endif
> 
> 	btrfs_err(fs_info,
> 
> 
> Why not something like:
> if (ret) {
> 	if (IS_ENABLED(CONFIG_BTRFS_DEBUG))
> 		WARN_ON(1);

Didn't know that macro, and indeed it looks much better.

> 	
> 	btrfs_err(fs_info,
> 
> Or even hide the if (IS_ENABLED(CONFIG_BTRFS_DEBUG)) WARN_ON(1); in a macro
> #define BTRFS_DEBUG_WARN_ON(x) do { 		\
> 	if (IS_ENABLED(CONFIG_BTRFS_DEBUG)) 	\
> 		WARN_ON((x));			\
> } while(0)

Although I'd say such WARN_ON() for DEBUG build will finally get moved
to any build.

Thanks,
Qu
>
diff mbox series

Patch

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 8da2f380d3c0..659bab9de03b 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -425,10 +425,10 @@  static int verify_level_key(struct btrfs_fs_info *fs_info,
 	if (found_level != level) {
 #ifdef CONFIG_BTRFS_DEBUG
 		WARN_ON(1);
+#endif
 		btrfs_err(fs_info,
 "tree level mismatch detected, bytenr=%llu level expected=%u has=%u",
 			  eb->start, level, found_level);
-#endif
 		return -EIO;
 	}
 
@@ -449,9 +449,10 @@  static int verify_level_key(struct btrfs_fs_info *fs_info,
 		btrfs_item_key_to_cpu(eb, &found_key, 0);
 	ret = btrfs_comp_cpu_keys(first_key, &found_key);
 
-#ifdef CONFIG_BTRFS_DEBUG
 	if (ret) {
+#ifdef CONFIG_BTRFS_DEBUG
 		WARN_ON(1);
+#endif
 		btrfs_err(fs_info,
 "tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu,%u,%llu) has=(%llu,%u,%llu)",
 			  eb->start, parent_transid, first_key->objectid,
@@ -459,7 +460,6 @@  static int verify_level_key(struct btrfs_fs_info *fs_info,
 			  found_key.objectid, found_key.type,
 			  found_key.offset);
 	}
-#endif
 	return ret;
 }