linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] btrfs: rescue: allow ibadroots to skip bad extent tree when reading block group items
@ 2021-07-19  5:43 Qu Wenruo
  2021-07-19  5:52 ` Su Yue
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Qu Wenruo @ 2021-07-19  5:43 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Zhenyu Wu

When extent tree gets corrupted, normally it's not extent tree root, but
one toasted tree leaf/node.

In that case, rescue=ibadroots mount option won't help as it can only
handle the extent tree root corruption.

This patch will enhance the behavior by:

- Allow fill_dummy_bgs() to ignore -EEXIST error

  This means we may have some block group items read from disk, but
  then hit some error halfway.

- Fallback to fill_dummy_bgs() if any error gets hit in
  btrfs_read_block_groups()

  Of course, this still needs rescue=ibadroots mount option.

With that, rescue=ibadroots can handle extent tree corruption more
gracefully and allow a better recover chance.

Reported-by: Zhenyu Wu <wuzy001@gmail.com>
Link: https://www.spinics.net/lists/linux-btrfs/msg114424.html
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
Changelog:
v2:
- Don't try to fill with dummy block groups when we hit ENOMEM
v3:
- Remove a dead condition
  The empty fs_info->extent_root case has already been handled.
v4:
- Skip to next block group if we hit EEXIST when inserting the block
  group cache
---
 fs/btrfs/block-group.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 5bd76a45037e..758ba856f8c6 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2105,11 +2105,22 @@ static int fill_dummy_bgs(struct btrfs_fs_info *fs_info)
 		bg->used = em->len;
 		bg->flags = map->type;
 		ret = btrfs_add_block_group_cache(fs_info, bg);
+		/*
+		 * We may have some valid block group cache added already, in
+		 * that case we skip to next bg.
+		 */
+		if (ret == -EEXIST) {
+			ret = 0;
+			btrfs_put_block_group(bg);
+			continue;
+		}
+
 		if (ret) {
 			btrfs_remove_free_space_cache(bg);
 			btrfs_put_block_group(bg);
 			break;
 		}
+
 		btrfs_update_space_info(fs_info, bg->flags, em->len, em->len,
 					0, 0, &space_info);
 		bg->space_info = space_info;
@@ -2212,6 +2223,14 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
 	ret = check_chunk_block_group_mappings(info);
 error:
 	btrfs_free_path(path);
+	/*
+	 * We hit some error reading the extent tree, and have rescue=ibadroots
+	 * mount option.
+	 * Try to fill using dummy block groups so that the user can continue
+	 * to mount and grab their data.
+	 */
+	if (ret && btrfs_test_opt(info, IGNOREBADROOTS))
+		ret = fill_dummy_bgs(info);
 	return ret;
 }
 
-- 
2.32.0


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

* Re: [PATCH v4] btrfs: rescue: allow ibadroots to skip bad extent tree when reading block group items
  2021-07-19  5:43 [PATCH v4] btrfs: rescue: allow ibadroots to skip bad extent tree when reading block group items Qu Wenruo
@ 2021-07-19  5:52 ` Su Yue
  2021-07-19  8:19 ` Anand Jain
  2021-07-21 17:33 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Su Yue @ 2021-07-19  5:52 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, Zhenyu Wu


On Mon 19 Jul 2021 at 13:43, Qu Wenruo <wqu@suse.com> wrote:

> When extent tree gets corrupted, normally it's not extent tree 
> root, but
> one toasted tree leaf/node.
>
> In that case, rescue=ibadroots mount option won't help as it can 
> only
> handle the extent tree root corruption.
>
> This patch will enhance the behavior by:
>
> - Allow fill_dummy_bgs() to ignore -EEXIST error
>
>   This means we may have some block group items read from disk, 
>   but
>   then hit some error halfway.
>
> - Fallback to fill_dummy_bgs() if any error gets hit in
>   btrfs_read_block_groups()
>
>   Of course, this still needs rescue=ibadroots mount option.
>
> With that, rescue=ibadroots can handle extent tree corruption 
> more
> gracefully and allow a better recover chance.
>
> Reported-by: Zhenyu Wu <wuzy001@gmail.com>
> Link: https://www.spinics.net/lists/linux-btrfs/msg114424.html
> Signed-off-by: Qu Wenruo <wqu@suse.com>
>

LGTM.

Reviewed-by: Su Yue <l@damenly.su>

--
Su
> ---
> Changelog:
> v2:
> - Don't try to fill with dummy block groups when we hit ENOMEM
> v3:
> - Remove a dead condition
>   The empty fs_info->extent_root case has already been handled.
> v4:
> - Skip to next block group if we hit EEXIST when inserting the 
> block
>   group cache
> ---
>  fs/btrfs/block-group.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index 5bd76a45037e..758ba856f8c6 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -2105,11 +2105,22 @@ static int fill_dummy_bgs(struct 
> btrfs_fs_info *fs_info)
>  		bg->used = em->len;
>  		bg->flags = map->type;
>  		ret = btrfs_add_block_group_cache(fs_info, bg);
> +		/*
> +		 * We may have some valid block group cache added already, 
> in
> +		 * that case we skip to next bg.
> +		 */
> +		if (ret == -EEXIST) {
> +			ret = 0;
> +			btrfs_put_block_group(bg);
> +			continue;
> +		}
> +
>  		if (ret) {
>  			btrfs_remove_free_space_cache(bg);
>  			btrfs_put_block_group(bg);
>  			break;
>  		}
> +
>  		btrfs_update_space_info(fs_info, bg->flags, em->len, 
>  em->len,
>  					0, 0, &space_info);
>  		bg->space_info = space_info;
> @@ -2212,6 +2223,14 @@ int btrfs_read_block_groups(struct 
> btrfs_fs_info *info)
>  	ret = check_chunk_block_group_mappings(info);
>  error:
>  	btrfs_free_path(path);
> +	/*
> +	 * We hit some error reading the extent tree, and have 
> rescue=ibadroots
> +	 * mount option.
> +	 * Try to fill using dummy block groups so that the user can 
> continue
> +	 * to mount and grab their data.
> +	 */
> +	if (ret && btrfs_test_opt(info, IGNOREBADROOTS))
> +		ret = fill_dummy_bgs(info);
>  	return ret;
>  }

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

* Re: [PATCH v4] btrfs: rescue: allow ibadroots to skip bad extent tree when reading block group items
  2021-07-19  5:43 [PATCH v4] btrfs: rescue: allow ibadroots to skip bad extent tree when reading block group items Qu Wenruo
  2021-07-19  5:52 ` Su Yue
@ 2021-07-19  8:19 ` Anand Jain
  2021-07-21 17:33 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Anand Jain @ 2021-07-19  8:19 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs; +Cc: Zhenyu Wu

On 19/07/2021 13:43, Qu Wenruo wrote:
> When extent tree gets corrupted, normally it's not extent tree root, but
> one toasted tree leaf/node.
> 
> In that case, rescue=ibadroots mount option won't help as it can only
> handle the extent tree root corruption.
> 
> This patch will enhance the behavior by:
> 
> - Allow fill_dummy_bgs() to ignore -EEXIST error
> 
>    This means we may have some block group items read from disk, but
>    then hit some error halfway.
> 
> - Fallback to fill_dummy_bgs() if any error gets hit in
>    btrfs_read_block_groups()
> 
>    Of course, this still needs rescue=ibadroots mount option.
> 
> With that, rescue=ibadroots can handle extent tree corruption more
> gracefully and allow a better recover chance.
> 
> Reported-by: Zhenyu Wu <wuzy001@gmail.com>
> Link: https://www.spinics.net/lists/linux-btrfs/msg114424.html
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> Changelog:
> v2:
> - Don't try to fill with dummy block groups when we hit ENOMEM
> v3:
> - Remove a dead condition
>    The empty fs_info->extent_root case has already been handled.
> v4:
> - Skip to next block group if we hit EEXIST when inserting the block
>    group cache
> ---
>   fs/btrfs/block-group.c | 19 +++++++++++++++++++
>   1 file changed, 19 insertions(+)
> 
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index 5bd76a45037e..758ba856f8c6 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -2105,11 +2105,22 @@ static int fill_dummy_bgs(struct btrfs_fs_info *fs_info)
>   		bg->used = em->len;
>   		bg->flags = map->type;
>   		ret = btrfs_add_block_group_cache(fs_info, bg);
> +		/*
> +		 * We may have some valid block group cache added already, in
> +		 * that case we skip to next bg.
> +		 */
> +		if (ret == -EEXIST) {
> +			ret = 0;
> +			btrfs_put_block_group(bg);
> +			continue;

Looks good.

Reviewed-by: Anand Jain <anand.jain@oracle.com>

Thanks.


> +		}
> +
>   		if (ret) {
>   			btrfs_remove_free_space_cache(bg);
>   			btrfs_put_block_group(bg);
>   			break;
>   		}
> +
>   		btrfs_update_space_info(fs_info, bg->flags, em->len, em->len,
>   					0, 0, &space_info);
>   		bg->space_info = space_info;
> @@ -2212,6 +2223,14 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
>   	ret = check_chunk_block_group_mappings(info);
>   error:
>   	btrfs_free_path(path);
> +	/*
> +	 * We hit some error reading the extent tree, and have rescue=ibadroots
> +	 * mount option.
> +	 * Try to fill using dummy block groups so that the user can continue
> +	 * to mount and grab their data.
> +	 */
> +	if (ret && btrfs_test_opt(info, IGNOREBADROOTS))
> +		ret = fill_dummy_bgs(info);
>   	return ret;
>   }
>   
> 


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

* Re: [PATCH v4] btrfs: rescue: allow ibadroots to skip bad extent tree when reading block group items
  2021-07-19  5:43 [PATCH v4] btrfs: rescue: allow ibadroots to skip bad extent tree when reading block group items Qu Wenruo
  2021-07-19  5:52 ` Su Yue
  2021-07-19  8:19 ` Anand Jain
@ 2021-07-21 17:33 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2021-07-21 17:33 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, Zhenyu Wu

On Mon, Jul 19, 2021 at 01:43:04PM +0800, Qu Wenruo wrote:
> When extent tree gets corrupted, normally it's not extent tree root, but
> one toasted tree leaf/node.
> 
> In that case, rescue=ibadroots mount option won't help as it can only
> handle the extent tree root corruption.
> 
> This patch will enhance the behavior by:
> 
> - Allow fill_dummy_bgs() to ignore -EEXIST error
> 
>   This means we may have some block group items read from disk, but
>   then hit some error halfway.
> 
> - Fallback to fill_dummy_bgs() if any error gets hit in
>   btrfs_read_block_groups()
> 
>   Of course, this still needs rescue=ibadroots mount option.
> 
> With that, rescue=ibadroots can handle extent tree corruption more
> gracefully and allow a better recover chance.
> 
> Reported-by: Zhenyu Wu <wuzy001@gmail.com>
> Link: https://www.spinics.net/lists/linux-btrfs/msg114424.html
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> Changelog:
> v2:
> - Don't try to fill with dummy block groups when we hit ENOMEM
> v3:
> - Remove a dead condition
>   The empty fs_info->extent_root case has already been handled.
> v4:
> - Skip to next block group if we hit EEXIST when inserting the block
>   group cache

Added to misc-next, thanks.

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

end of thread, other threads:[~2021-07-21 17:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-19  5:43 [PATCH v4] btrfs: rescue: allow ibadroots to skip bad extent tree when reading block group items Qu Wenruo
2021-07-19  5:52 ` Su Yue
2021-07-19  8:19 ` Anand Jain
2021-07-21 17:33 ` 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).