linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] btrfs: Allow read-only mount with corrupted extent tree
@ 2021-03-17  1:20 Dāvis Mosāns
  2021-03-17  1:29 ` Dāvis Mosāns
  2021-03-21 21:49 ` [PATCH] " Dāvis Mosāns
  0 siblings, 2 replies; 12+ messages in thread
From: Dāvis Mosāns @ 2021-03-17  1:20 UTC (permalink / raw)
  To: linux-btrfs
  Cc: clm, josef, dsterba, linux-kernel, ce3g8jdj, Dāvis Mosāns

Currently if there's any corruption at all in extent tree
(eg. even single bit) then mounting will fail with:
"failed to read block groups: -5" (-EIO)
It happens because we immediately abort on first error when
searching in extent tree for block groups.

Now with this patch if `ignorebadroots` option is specified
then we handle such case and continue by removing already
created block groups and creating dummy block groups.

Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
---
 fs/btrfs/block-group.c | 14 ++++++++++++++
 fs/btrfs/disk-io.c     |  4 ++--
 fs/btrfs/disk-io.h     |  2 ++
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 48ebc106a606..827a977614b3 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2048,6 +2048,20 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
 	ret = check_chunk_block_group_mappings(info);
 error:
 	btrfs_free_path(path);
+
+	if (ret == -EIO && btrfs_test_opt(info, IGNOREBADROOTS)) {
+		btrfs_put_block_group_cache(info);
+		btrfs_stop_all_workers(info);
+		btrfs_free_block_groups(info);
+		ret = btrfs_init_workqueues(info, NULL);
+		if (ret)
+			return ret;
+		ret = btrfs_init_space_info(info);
+		if (ret)
+			return ret;
+		return fill_dummy_bgs(info);
+	}
+
 	return ret;
 }
 
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 07a2b4f69b10..dc744f76d075 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1955,7 +1955,7 @@ static int read_backup_root(struct btrfs_fs_info *fs_info, u8 priority)
 }
 
 /* helper to cleanup workers */
-static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
+void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
 {
 	btrfs_destroy_workqueue(fs_info->fixup_workers);
 	btrfs_destroy_workqueue(fs_info->delalloc_workers);
@@ -2122,7 +2122,7 @@ static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info)
 	mutex_init(&fs_info->qgroup_rescan_lock);
 }
 
-static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info,
+int btrfs_init_workqueues(struct btrfs_fs_info *fs_info,
 		struct btrfs_fs_devices *fs_devices)
 {
 	u32 max_active = fs_info->thread_pool_size;
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index e45057c0c016..f9bfcba86a04 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -137,6 +137,8 @@ int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid);
 int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid);
 int __init btrfs_end_io_wq_init(void);
 void __cold btrfs_end_io_wq_exit(void);
+void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info);
+int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, struct btrfs_fs_devices *fs_devices);
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 void btrfs_set_buffer_lockdep_class(u64 objectid,
-- 
2.30.2


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

* Re: [RFC] btrfs: Allow read-only mount with corrupted extent tree
  2021-03-17  1:20 [RFC] btrfs: Allow read-only mount with corrupted extent tree Dāvis Mosāns
@ 2021-03-17  1:29 ` Dāvis Mosāns
  2021-03-17 10:28   ` Qu Wenruo
  2021-03-21 21:49 ` [PATCH] " Dāvis Mosāns
  1 sibling, 1 reply; 12+ messages in thread
From: Dāvis Mosāns @ 2021-03-17  1:29 UTC (permalink / raw)
  To: Btrfs BTRFS; +Cc: clm, josef, dsterba, linux-kernel, Zygo Blaxell

trešd., 2021. g. 17. marts, plkst. 03:18 — lietotājs Dāvis Mosāns
(<davispuh@gmail.com>) rakstīja:
>
> Currently if there's any corruption at all in extent tree
> (eg. even single bit) then mounting will fail with:
> "failed to read block groups: -5" (-EIO)
> It happens because we immediately abort on first error when
> searching in extent tree for block groups.
>
> Now with this patch if `ignorebadroots` option is specified
> then we handle such case and continue by removing already
> created block groups and creating dummy block groups.
>
> Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
> ---
>  fs/btrfs/block-group.c | 14 ++++++++++++++
>  fs/btrfs/disk-io.c     |  4 ++--
>  fs/btrfs/disk-io.h     |  2 ++
>  3 files changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index 48ebc106a606..827a977614b3 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -2048,6 +2048,20 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
>         ret = check_chunk_block_group_mappings(info);
>  error:
>         btrfs_free_path(path);
> +
> +       if (ret == -EIO && btrfs_test_opt(info, IGNOREBADROOTS)) {
> +               btrfs_put_block_group_cache(info);
> +               btrfs_stop_all_workers(info);
> +               btrfs_free_block_groups(info);
> +               ret = btrfs_init_workqueues(info, NULL);
> +               if (ret)
> +                       return ret;
> +               ret = btrfs_init_space_info(info);
> +               if (ret)
> +                       return ret;
> +               return fill_dummy_bgs(info);

This isn't that nice, but I don't really know how to properly clean up
everything related to already created block groups so this was easiest
way. It seems to work fine.
But looks like need to do something about replay log aswell because if
it's not disabled then it fails with:

[ 1397.246869] BTRFS info (device sde): start tree-log replay
[ 1398.218685] BTRFS warning (device sde): sde checksum verify failed
on 21057127661568 wanted 0xd1506ed9 found 0x22ab750a level 0
[ 1398.218803] BTRFS warning (device sde): sde checksum verify failed
on 21057127661568 wanted 0xd1506ed9 found 0x7dd54bb9 level 0
[ 1398.218813] BTRFS: error (device sde) in __btrfs_free_extent:3054:
errno=-5 IO failure
[ 1398.218828] BTRFS: error (device sde) in
btrfs_run_delayed_refs:2124: errno=-5 IO failure
[ 1398.219002] BTRFS: error (device sde) in btrfs_replay_log:2254:
errno=-5 IO failure (Failed to recover log tree)
[ 1398.229048] BTRFS error (device sde): open_ctree failed

Ideally it should replay everything except extent refs.


I also noticed that after unmount there is:

[11000.562504] BTRFS warning (device sde): page private not zero on
page 21057098481664
[11000.562510] BTRFS warning (device sde): page private not zero on
page 21057098485760

not sure what it means.


Best regards,
Dāvis

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

* Re: [RFC] btrfs: Allow read-only mount with corrupted extent tree
  2021-03-17  1:29 ` Dāvis Mosāns
@ 2021-03-17 10:28   ` Qu Wenruo
  2021-03-17 21:03     ` Dāvis Mosāns
  0 siblings, 1 reply; 12+ messages in thread
From: Qu Wenruo @ 2021-03-17 10:28 UTC (permalink / raw)
  To: Dāvis Mosāns, Btrfs BTRFS
  Cc: clm, josef, dsterba, linux-kernel, Zygo Blaxell



On 2021/3/17 上午9:29, Dāvis Mosāns wrote:
> trešd., 2021. g. 17. marts, plkst. 03:18 — lietotājs Dāvis Mosāns
> (<davispuh@gmail.com>) rakstīja:
>>
>> Currently if there's any corruption at all in extent tree
>> (eg. even single bit) then mounting will fail with:
>> "failed to read block groups: -5" (-EIO)
>> It happens because we immediately abort on first error when
>> searching in extent tree for block groups.
>>
>> Now with this patch if `ignorebadroots` option is specified
>> then we handle such case and continue by removing already
>> created block groups and creating dummy block groups.
>>
>> Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
>> ---
>>   fs/btrfs/block-group.c | 14 ++++++++++++++
>>   fs/btrfs/disk-io.c     |  4 ++--
>>   fs/btrfs/disk-io.h     |  2 ++
>>   3 files changed, 18 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
>> index 48ebc106a606..827a977614b3 100644
>> --- a/fs/btrfs/block-group.c
>> +++ b/fs/btrfs/block-group.c
>> @@ -2048,6 +2048,20 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
>>          ret = check_chunk_block_group_mappings(info);
>>   error:
>>          btrfs_free_path(path);
>> +
>> +       if (ret == -EIO && btrfs_test_opt(info, IGNOREBADROOTS)) {
>> +               btrfs_put_block_group_cache(info);
>> +               btrfs_stop_all_workers(info);
>> +               btrfs_free_block_groups(info);
>> +               ret = btrfs_init_workqueues(info, NULL);
>> +               if (ret)
>> +                       return ret;
>> +               ret = btrfs_init_space_info(info);
>> +               if (ret)
>> +                       return ret;
>> +               return fill_dummy_bgs(info);

When we hit bad things in extent tree, we should ensure we're mounting
the fs RO, or we can't continue.

And we should also refuse to mount back to RW if we hit such case, so
that we don't need anything complex, just ignore the whole extent tree
and create the dummy block groups.

>
> This isn't that nice, but I don't really know how to properly clean up
> everything related to already created block groups so this was easiest
> way. It seems to work fine.
> But looks like need to do something about replay log aswell because if
> it's not disabled then it fails with:
>
> [ 1397.246869] BTRFS info (device sde): start tree-log replay
> [ 1398.218685] BTRFS warning (device sde): sde checksum verify failed
> on 21057127661568 wanted 0xd1506ed9 found 0x22ab750a level 0
> [ 1398.218803] BTRFS warning (device sde): sde checksum verify failed
> on 21057127661568 wanted 0xd1506ed9 found 0x7dd54bb9 level 0
> [ 1398.218813] BTRFS: error (device sde) in __btrfs_free_extent:3054:
> errno=-5 IO failure
> [ 1398.218828] BTRFS: error (device sde) in
> btrfs_run_delayed_refs:2124: errno=-5 IO failure
> [ 1398.219002] BTRFS: error (device sde) in btrfs_replay_log:2254:
> errno=-5 IO failure (Failed to recover log tree)
> [ 1398.229048] BTRFS error (device sde): open_ctree failed

This is because we shouldn't allow to do anything write to the fs if we
have anything wrong in extent tree.

Thanks,
Qu
>
> Ideally it should replay everything except extent refs. >
>
> I also noticed that after unmount there is:
>
> [11000.562504] BTRFS warning (device sde): page private not zero on
> page 21057098481664
> [11000.562510] BTRFS warning (device sde): page private not zero on
> page 21057098485760
>
> not sure what it means.
>
>
> Best regards,
> Dāvis
>

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

* Re: [RFC] btrfs: Allow read-only mount with corrupted extent tree
  2021-03-17 10:28   ` Qu Wenruo
@ 2021-03-17 21:03     ` Dāvis Mosāns
  2021-03-17 23:49       ` Qu Wenruo
  0 siblings, 1 reply; 12+ messages in thread
From: Dāvis Mosāns @ 2021-03-17 21:03 UTC (permalink / raw)
  To: Qu Wenruo
  Cc: Btrfs BTRFS, clm, Josef Bacik, dsterba, linux-kernel, Zygo Blaxell

trešd., 2021. g. 17. marts, plkst. 12:28 — lietotājs Qu Wenruo
(<quwenruo.btrfs@gmx.com>) rakstīja:
>
>
>
> On 2021/3/17 上午9:29, Dāvis Mosāns wrote:
> > trešd., 2021. g. 17. marts, plkst. 03:18 — lietotājs Dāvis Mosāns
> > (<davispuh@gmail.com>) rakstīja:
> >>
> >> Currently if there's any corruption at all in extent tree
> >> (eg. even single bit) then mounting will fail with:
> >> "failed to read block groups: -5" (-EIO)
> >> It happens because we immediately abort on first error when
> >> searching in extent tree for block groups.
> >>
> >> Now with this patch if `ignorebadroots` option is specified
> >> then we handle such case and continue by removing already
> >> created block groups and creating dummy block groups.
> >>
> >> Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
> >> ---
> >>   fs/btrfs/block-group.c | 14 ++++++++++++++
> >>   fs/btrfs/disk-io.c     |  4 ++--
> >>   fs/btrfs/disk-io.h     |  2 ++
> >>   3 files changed, 18 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> >> index 48ebc106a606..827a977614b3 100644
> >> --- a/fs/btrfs/block-group.c
> >> +++ b/fs/btrfs/block-group.c
> >> @@ -2048,6 +2048,20 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
> >>          ret = check_chunk_block_group_mappings(info);
> >>   error:
> >>          btrfs_free_path(path);
> >> +
> >> +       if (ret == -EIO && btrfs_test_opt(info, IGNOREBADROOTS)) {
> >> +               btrfs_put_block_group_cache(info);
> >> +               btrfs_stop_all_workers(info);
> >> +               btrfs_free_block_groups(info);
> >> +               ret = btrfs_init_workqueues(info, NULL);
> >> +               if (ret)
> >> +                       return ret;
> >> +               ret = btrfs_init_space_info(info);
> >> +               if (ret)
> >> +                       return ret;
> >> +               return fill_dummy_bgs(info);
>
> When we hit bad things in extent tree, we should ensure we're mounting
> the fs RO, or we can't continue.
>
> And we should also refuse to mount back to RW if we hit such case, so
> that we don't need anything complex, just ignore the whole extent tree
> and create the dummy block groups.
>

That's what we're doing here, `ignorebadroots` implies RO mount and
without specifying it doesn't mount at all.

> >
> > This isn't that nice, but I don't really know how to properly clean up
> > everything related to already created block groups so this was easiest
> > way. It seems to work fine.
> > But looks like need to do something about replay log aswell because if
> > it's not disabled then it fails with:
> >
> > [ 1397.246869] BTRFS info (device sde): start tree-log replay
> > [ 1398.218685] BTRFS warning (device sde): sde checksum verify failed
> > on 21057127661568 wanted 0xd1506ed9 found 0x22ab750a level 0
> > [ 1398.218803] BTRFS warning (device sde): sde checksum verify failed
> > on 21057127661568 wanted 0xd1506ed9 found 0x7dd54bb9 level 0
> > [ 1398.218813] BTRFS: error (device sde) in __btrfs_free_extent:3054:
> > errno=-5 IO failure
> > [ 1398.218828] BTRFS: error (device sde) in
> > btrfs_run_delayed_refs:2124: errno=-5 IO failure
> > [ 1398.219002] BTRFS: error (device sde) in btrfs_replay_log:2254:
> > errno=-5 IO failure (Failed to recover log tree)
> > [ 1398.229048] BTRFS error (device sde): open_ctree failed
>
> This is because we shouldn't allow to do anything write to the fs if we
> have anything wrong in extent tree.
>

This is happening when mounting read-only. My assumption is that it
only tries to replay in memory without writing anything to disk.

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

* Re: [RFC] btrfs: Allow read-only mount with corrupted extent tree
  2021-03-17 21:03     ` Dāvis Mosāns
@ 2021-03-17 23:49       ` Qu Wenruo
  2021-03-19 15:34         ` Dāvis Mosāns
  0 siblings, 1 reply; 12+ messages in thread
From: Qu Wenruo @ 2021-03-17 23:49 UTC (permalink / raw)
  To: Dāvis Mosāns
  Cc: Btrfs BTRFS, clm, Josef Bacik, dsterba, linux-kernel, Zygo Blaxell



On 2021/3/18 上午5:03, Dāvis Mosāns wrote:
> trešd., 2021. g. 17. marts, plkst. 12:28 — lietotājs Qu Wenruo
> (<quwenruo.btrfs@gmx.com>) rakstīja:
>>
>>
>>
>> On 2021/3/17 上午9:29, Dāvis Mosāns wrote:
>>> trešd., 2021. g. 17. marts, plkst. 03:18 — lietotājs Dāvis Mosāns
>>> (<davispuh@gmail.com>) rakstīja:
>>>>
>>>> Currently if there's any corruption at all in extent tree
>>>> (eg. even single bit) then mounting will fail with:
>>>> "failed to read block groups: -5" (-EIO)
>>>> It happens because we immediately abort on first error when
>>>> searching in extent tree for block groups.
>>>>
>>>> Now with this patch if `ignorebadroots` option is specified
>>>> then we handle such case and continue by removing already
>>>> created block groups and creating dummy block groups.
>>>>
>>>> Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
>>>> ---
>>>>    fs/btrfs/block-group.c | 14 ++++++++++++++
>>>>    fs/btrfs/disk-io.c     |  4 ++--
>>>>    fs/btrfs/disk-io.h     |  2 ++
>>>>    3 files changed, 18 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
>>>> index 48ebc106a606..827a977614b3 100644
>>>> --- a/fs/btrfs/block-group.c
>>>> +++ b/fs/btrfs/block-group.c
>>>> @@ -2048,6 +2048,20 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
>>>>           ret = check_chunk_block_group_mappings(info);
>>>>    error:
>>>>           btrfs_free_path(path);
>>>> +
>>>> +       if (ret == -EIO && btrfs_test_opt(info, IGNOREBADROOTS)) {
>>>> +               btrfs_put_block_group_cache(info);
>>>> +               btrfs_stop_all_workers(info);
>>>> +               btrfs_free_block_groups(info);
>>>> +               ret = btrfs_init_workqueues(info, NULL);
>>>> +               if (ret)
>>>> +                       return ret;
>>>> +               ret = btrfs_init_space_info(info);
>>>> +               if (ret)
>>>> +                       return ret;
>>>> +               return fill_dummy_bgs(info);
>>
>> When we hit bad things in extent tree, we should ensure we're mounting
>> the fs RO, or we can't continue.
>>
>> And we should also refuse to mount back to RW if we hit such case, so
>> that we don't need anything complex, just ignore the whole extent tree
>> and create the dummy block groups.
>>
>
> That's what we're doing here, `ignorebadroots` implies RO mount and
> without specifying it doesn't mount at all.
>
>>>
>>> This isn't that nice, but I don't really know how to properly clean up
>>> everything related to already created block groups so this was easiest
>>> way. It seems to work fine.
>>> But looks like need to do something about replay log aswell because if
>>> it's not disabled then it fails with:
>>>
>>> [ 1397.246869] BTRFS info (device sde): start tree-log replay
>>> [ 1398.218685] BTRFS warning (device sde): sde checksum verify failed
>>> on 21057127661568 wanted 0xd1506ed9 found 0x22ab750a level 0
>>> [ 1398.218803] BTRFS warning (device sde): sde checksum verify failed
>>> on 21057127661568 wanted 0xd1506ed9 found 0x7dd54bb9 level 0
>>> [ 1398.218813] BTRFS: error (device sde) in __btrfs_free_extent:3054:
>>> errno=-5 IO failure
>>> [ 1398.218828] BTRFS: error (device sde) in
>>> btrfs_run_delayed_refs:2124: errno=-5 IO failure
>>> [ 1398.219002] BTRFS: error (device sde) in btrfs_replay_log:2254:
>>> errno=-5 IO failure (Failed to recover log tree)
>>> [ 1398.229048] BTRFS error (device sde): open_ctree failed
>>
>> This is because we shouldn't allow to do anything write to the fs if we
>> have anything wrong in extent tree.
>>
>
> This is happening when mounting read-only. My assumption is that it
> only tries to replay in memory without writing anything to disk.
>

We lacks the check on log tree.

Normally for such forced RO mount, log replay is not allowed.

We should output a warning to prompt user to use nologreplay, and reject
the mount.

Thanks,
Qu

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

* Re: [RFC] btrfs: Allow read-only mount with corrupted extent tree
  2021-03-17 23:49       ` Qu Wenruo
@ 2021-03-19 15:34         ` Dāvis Mosāns
  2021-03-20  0:34           ` Qu Wenruo
  0 siblings, 1 reply; 12+ messages in thread
From: Dāvis Mosāns @ 2021-03-19 15:34 UTC (permalink / raw)
  To: Qu Wenruo
  Cc: Btrfs BTRFS, clm, Josef Bacik, dsterba, linux-kernel, Zygo Blaxell

ceturtd., 2021. g. 18. marts, plkst. 01:49 — lietotājs Qu Wenruo
(<quwenruo.btrfs@gmx.com>) rakstīja:
>
>
>
> On 2021/3/18 上午5:03, Dāvis Mosāns wrote:
> > trešd., 2021. g. 17. marts, plkst. 12:28 — lietotājs Qu Wenruo
> > (<quwenruo.btrfs@gmx.com>) rakstīja:
> >>
> >>
> >>
> >> On 2021/3/17 上午9:29, Dāvis Mosāns wrote:
> >>> trešd., 2021. g. 17. marts, plkst. 03:18 — lietotājs Dāvis Mosāns
> >>> (<davispuh@gmail.com>) rakstīja:
> >>>>
> >>>> Currently if there's any corruption at all in extent tree
> >>>> (eg. even single bit) then mounting will fail with:
> >>>> "failed to read block groups: -5" (-EIO)
> >>>> It happens because we immediately abort on first error when
> >>>> searching in extent tree for block groups.
> >>>>
> >>>> Now with this patch if `ignorebadroots` option is specified
> >>>> then we handle such case and continue by removing already
> >>>> created block groups and creating dummy block groups.
> >>>>
> >>>> Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
> >>>> ---
> >>>>    fs/btrfs/block-group.c | 14 ++++++++++++++
> >>>>    fs/btrfs/disk-io.c     |  4 ++--
> >>>>    fs/btrfs/disk-io.h     |  2 ++
> >>>>    3 files changed, 18 insertions(+), 2 deletions(-)
> >>>>
> >>>> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> >>>> index 48ebc106a606..827a977614b3 100644
> >>>> --- a/fs/btrfs/block-group.c
> >>>> +++ b/fs/btrfs/block-group.c
> >>>> @@ -2048,6 +2048,20 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
> >>>>           ret = check_chunk_block_group_mappings(info);
> >>>>    error:
> >>>>           btrfs_free_path(path);
> >>>> +
> >>>> +       if (ret == -EIO && btrfs_test_opt(info, IGNOREBADROOTS)) {
> >>>> +               btrfs_put_block_group_cache(info);
> >>>> +               btrfs_stop_all_workers(info);
> >>>> +               btrfs_free_block_groups(info);
> >>>> +               ret = btrfs_init_workqueues(info, NULL);
> >>>> +               if (ret)
> >>>> +                       return ret;
> >>>> +               ret = btrfs_init_space_info(info);
> >>>> +               if (ret)
> >>>> +                       return ret;
> >>>> +               return fill_dummy_bgs(info);
> >>
> >> When we hit bad things in extent tree, we should ensure we're mounting
> >> the fs RO, or we can't continue.
> >>
> >> And we should also refuse to mount back to RW if we hit such case, so
> >> that we don't need anything complex, just ignore the whole extent tree
> >> and create the dummy block groups.
> >>
> >
> > That's what we're doing here, `ignorebadroots` implies RO mount and
> > without specifying it doesn't mount at all.
> >
> >>>
> >>> This isn't that nice, but I don't really know how to properly clean up
> >>> everything related to already created block groups so this was easiest
> >>> way. It seems to work fine.
> >>> But looks like need to do something about replay log aswell because if
> >>> it's not disabled then it fails with:
> >>>
> >>> [ 1397.246869] BTRFS info (device sde): start tree-log replay
> >>> [ 1398.218685] BTRFS warning (device sde): sde checksum verify failed
> >>> on 21057127661568 wanted 0xd1506ed9 found 0x22ab750a level 0
> >>> [ 1398.218803] BTRFS warning (device sde): sde checksum verify failed
> >>> on 21057127661568 wanted 0xd1506ed9 found 0x7dd54bb9 level 0
> >>> [ 1398.218813] BTRFS: error (device sde) in __btrfs_free_extent:3054:
> >>> errno=-5 IO failure
> >>> [ 1398.218828] BTRFS: error (device sde) in
> >>> btrfs_run_delayed_refs:2124: errno=-5 IO failure
> >>> [ 1398.219002] BTRFS: error (device sde) in btrfs_replay_log:2254:
> >>> errno=-5 IO failure (Failed to recover log tree)
> >>> [ 1398.229048] BTRFS error (device sde): open_ctree failed
> >>
> >> This is because we shouldn't allow to do anything write to the fs if we
> >> have anything wrong in extent tree.
> >>
> >
> > This is happening when mounting read-only. My assumption is that it
> > only tries to replay in memory without writing anything to disk.
> >
>
> We lacks the check on log tree.
>
> Normally for such forced RO mount, log replay is not allowed.
>
> We should output a warning to prompt user to use nologreplay, and reject
> the mount.
>

I'm not familiar with log replay but couldn't there be something
useful (ignoring ref counts) that would still be worth replaying in
memory?

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

* Re: [RFC] btrfs: Allow read-only mount with corrupted extent tree
  2021-03-19 15:34         ` Dāvis Mosāns
@ 2021-03-20  0:34           ` Qu Wenruo
  0 siblings, 0 replies; 12+ messages in thread
From: Qu Wenruo @ 2021-03-20  0:34 UTC (permalink / raw)
  To: Dāvis Mosāns
  Cc: Btrfs BTRFS, clm, Josef Bacik, dsterba, linux-kernel, Zygo Blaxell



On 2021/3/19 下午11:34, Dāvis Mosāns wrote:
> ceturtd., 2021. g. 18. marts, plkst. 01:49 — lietotājs Qu Wenruo
> (<quwenruo.btrfs@gmx.com>) rakstīja:
>>
>>
>>
>> On 2021/3/18 上午5:03, Dāvis Mosāns wrote:
>>> trešd., 2021. g. 17. marts, plkst. 12:28 — lietotājs Qu Wenruo
>>> (<quwenruo.btrfs@gmx.com>) rakstīja:
>>>>
>>>>
>>>>
>>>> On 2021/3/17 上午9:29, Dāvis Mosāns wrote:
>>>>> trešd., 2021. g. 17. marts, plkst. 03:18 — lietotājs Dāvis Mosāns
>>>>> (<davispuh@gmail.com>) rakstīja:
>>>>>>
>>>>>> Currently if there's any corruption at all in extent tree
>>>>>> (eg. even single bit) then mounting will fail with:
>>>>>> "failed to read block groups: -5" (-EIO)
>>>>>> It happens because we immediately abort on first error when
>>>>>> searching in extent tree for block groups.
>>>>>>
>>>>>> Now with this patch if `ignorebadroots` option is specified
>>>>>> then we handle such case and continue by removing already
>>>>>> created block groups and creating dummy block groups.
>>>>>>
>>>>>> Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
>>>>>> ---
>>>>>>     fs/btrfs/block-group.c | 14 ++++++++++++++
>>>>>>     fs/btrfs/disk-io.c     |  4 ++--
>>>>>>     fs/btrfs/disk-io.h     |  2 ++
>>>>>>     3 files changed, 18 insertions(+), 2 deletions(-)
>>>>>>
>>>>>> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
>>>>>> index 48ebc106a606..827a977614b3 100644
>>>>>> --- a/fs/btrfs/block-group.c
>>>>>> +++ b/fs/btrfs/block-group.c
>>>>>> @@ -2048,6 +2048,20 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
>>>>>>            ret = check_chunk_block_group_mappings(info);
>>>>>>     error:
>>>>>>            btrfs_free_path(path);
>>>>>> +
>>>>>> +       if (ret == -EIO && btrfs_test_opt(info, IGNOREBADROOTS)) {
>>>>>> +               btrfs_put_block_group_cache(info);
>>>>>> +               btrfs_stop_all_workers(info);
>>>>>> +               btrfs_free_block_groups(info);
>>>>>> +               ret = btrfs_init_workqueues(info, NULL);
>>>>>> +               if (ret)
>>>>>> +                       return ret;
>>>>>> +               ret = btrfs_init_space_info(info);
>>>>>> +               if (ret)
>>>>>> +                       return ret;
>>>>>> +               return fill_dummy_bgs(info);
>>>>
>>>> When we hit bad things in extent tree, we should ensure we're mounting
>>>> the fs RO, or we can't continue.
>>>>
>>>> And we should also refuse to mount back to RW if we hit such case, so
>>>> that we don't need anything complex, just ignore the whole extent tree
>>>> and create the dummy block groups.
>>>>
>>>
>>> That's what we're doing here, `ignorebadroots` implies RO mount and
>>> without specifying it doesn't mount at all.
>>>
>>>>>
>>>>> This isn't that nice, but I don't really know how to properly clean up
>>>>> everything related to already created block groups so this was easiest
>>>>> way. It seems to work fine.
>>>>> But looks like need to do something about replay log aswell because if
>>>>> it's not disabled then it fails with:
>>>>>
>>>>> [ 1397.246869] BTRFS info (device sde): start tree-log replay
>>>>> [ 1398.218685] BTRFS warning (device sde): sde checksum verify failed
>>>>> on 21057127661568 wanted 0xd1506ed9 found 0x22ab750a level 0
>>>>> [ 1398.218803] BTRFS warning (device sde): sde checksum verify failed
>>>>> on 21057127661568 wanted 0xd1506ed9 found 0x7dd54bb9 level 0
>>>>> [ 1398.218813] BTRFS: error (device sde) in __btrfs_free_extent:3054:
>>>>> errno=-5 IO failure
>>>>> [ 1398.218828] BTRFS: error (device sde) in
>>>>> btrfs_run_delayed_refs:2124: errno=-5 IO failure
>>>>> [ 1398.219002] BTRFS: error (device sde) in btrfs_replay_log:2254:
>>>>> errno=-5 IO failure (Failed to recover log tree)
>>>>> [ 1398.229048] BTRFS error (device sde): open_ctree failed
>>>>
>>>> This is because we shouldn't allow to do anything write to the fs if we
>>>> have anything wrong in extent tree.
>>>>
>>>
>>> This is happening when mounting read-only. My assumption is that it
>>> only tries to replay in memory without writing anything to disk.
>>>
>>
>> We lacks the check on log tree.
>>
>> Normally for such forced RO mount, log replay is not allowed.
>>
>> We should output a warning to prompt user to use nologreplay, and reject
>> the mount.
>>
>
> I'm not familiar with log replay but couldn't there be something
> useful (ignoring ref counts) that would still be worth replaying in
> memory?
>
Log replay means metadata write.

Any write needs a valid extent tree to find out free space for new
metadata/data.

So no, we can't do anything but completely ignoring the log.

Thanks,
Qu

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

* [PATCH] btrfs: Allow read-only mount with corrupted extent tree
  2021-03-17  1:20 [RFC] btrfs: Allow read-only mount with corrupted extent tree Dāvis Mosāns
  2021-03-17  1:29 ` Dāvis Mosāns
@ 2021-03-21 21:49 ` Dāvis Mosāns
  2021-04-21 16:00   ` Dāvis Mosāns
  1 sibling, 1 reply; 12+ messages in thread
From: Dāvis Mosāns @ 2021-03-21 21:49 UTC (permalink / raw)
  To: linux-btrfs
  Cc: clm, josef, dsterba, linux-kernel, ce3g8jdj, Dāvis Mosāns

Currently if there's any corruption at all in extent tree
(eg. even single bit) then mounting will fail with:
"failed to read block groups: -5" (-EIO)
It happens because we immediately abort on first error when
searching in extent tree for block groups.

Now with this patch if `ignorebadroots` option is specified
then we handle such case and continue by removing already
created block groups and creating dummy block groups.

Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
---
 fs/btrfs/block-group.c | 20 ++++++++++++++++++++
 fs/btrfs/disk-io.c     |  4 ++--
 fs/btrfs/disk-io.h     |  2 ++
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 48ebc106a606..f485cf14c2f8 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2048,6 +2048,26 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
 	ret = check_chunk_block_group_mappings(info);
 error:
 	btrfs_free_path(path);
+
+	if (ret == -EIO && btrfs_test_opt(info, IGNOREBADROOTS)) {
+
+		if (btrfs_super_log_root(info->super_copy) != 0) {
+			btrfs_warn(info, "Ignoring tree-log replay due to extent tree corruption!");
+			btrfs_set_super_log_root(info->super_copy, 0);
+		}
+
+		btrfs_put_block_group_cache(info);
+		btrfs_stop_all_workers(info);
+		btrfs_free_block_groups(info);
+		ret = btrfs_init_workqueues(info, NULL);
+		if (ret)
+			return ret;
+		ret = btrfs_init_space_info(info);
+		if (ret)
+			return ret;
+		return fill_dummy_bgs(info);
+	}
+
 	return ret;
 }
 
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 07a2b4f69b10..dc744f76d075 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1955,7 +1955,7 @@ static int read_backup_root(struct btrfs_fs_info *fs_info, u8 priority)
 }
 
 /* helper to cleanup workers */
-static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
+void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
 {
 	btrfs_destroy_workqueue(fs_info->fixup_workers);
 	btrfs_destroy_workqueue(fs_info->delalloc_workers);
@@ -2122,7 +2122,7 @@ static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info)
 	mutex_init(&fs_info->qgroup_rescan_lock);
 }
 
-static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info,
+int btrfs_init_workqueues(struct btrfs_fs_info *fs_info,
 		struct btrfs_fs_devices *fs_devices)
 {
 	u32 max_active = fs_info->thread_pool_size;
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index e45057c0c016..f9bfcba86a04 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -137,6 +137,8 @@ int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid);
 int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid);
 int __init btrfs_end_io_wq_init(void);
 void __cold btrfs_end_io_wq_exit(void);
+void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info);
+int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, struct btrfs_fs_devices *fs_devices);
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 void btrfs_set_buffer_lockdep_class(u64 objectid,
-- 
2.30.2


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

* Re: [PATCH] btrfs: Allow read-only mount with corrupted extent tree
  2021-03-21 21:49 ` [PATCH] " Dāvis Mosāns
@ 2021-04-21 16:00   ` Dāvis Mosāns
  0 siblings, 0 replies; 12+ messages in thread
From: Dāvis Mosāns @ 2021-04-21 16:00 UTC (permalink / raw)
  To: Btrfs BTRFS; +Cc: clm, Josef Bacik, dsterba, linux-kernel, Zygo Blaxell

svētd., 2021. g. 21. marts, plkst. 23:46 — lietotājs Dāvis Mosāns
(<davispuh@gmail.com>) rakstīja:
>
> Currently if there's any corruption at all in extent tree
> (eg. even single bit) then mounting will fail with:
> "failed to read block groups: -5" (-EIO)
> It happens because we immediately abort on first error when
> searching in extent tree for block groups.
>
> Now with this patch if `ignorebadroots` option is specified
> then we handle such case and continue by removing already
> created block groups and creating dummy block groups.
>
> Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
> ---
>  fs/btrfs/block-group.c | 20 ++++++++++++++++++++
>  fs/btrfs/disk-io.c     |  4 ++--
>  fs/btrfs/disk-io.h     |  2 ++
>  3 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index 48ebc106a606..f485cf14c2f8 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -2048,6 +2048,26 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
>         ret = check_chunk_block_group_mappings(info);
>  error:
>         btrfs_free_path(path);
> +
> +       if (ret == -EIO && btrfs_test_opt(info, IGNOREBADROOTS)) {
> +
> +               if (btrfs_super_log_root(info->super_copy) != 0) {
> +                       btrfs_warn(info, "Ignoring tree-log replay due to extent tree corruption!");
> +                       btrfs_set_super_log_root(info->super_copy, 0);
> +               }
> +
> +               btrfs_put_block_group_cache(info);
> +               btrfs_stop_all_workers(info);
> +               btrfs_free_block_groups(info);
> +               ret = btrfs_init_workqueues(info, NULL);
> +               if (ret)
> +                       return ret;
> +               ret = btrfs_init_space_info(info);
> +               if (ret)
> +                       return ret;
> +               return fill_dummy_bgs(info);
> +       }
> +
>         return ret;
>  }
>
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 07a2b4f69b10..dc744f76d075 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -1955,7 +1955,7 @@ static int read_backup_root(struct btrfs_fs_info *fs_info, u8 priority)
>  }
>
>  /* helper to cleanup workers */
> -static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
> +void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
>  {
>         btrfs_destroy_workqueue(fs_info->fixup_workers);
>         btrfs_destroy_workqueue(fs_info->delalloc_workers);
> @@ -2122,7 +2122,7 @@ static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info)
>         mutex_init(&fs_info->qgroup_rescan_lock);
>  }
>
> -static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info,
> +int btrfs_init_workqueues(struct btrfs_fs_info *fs_info,
>                 struct btrfs_fs_devices *fs_devices)
>  {
>         u32 max_active = fs_info->thread_pool_size;
> diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
> index e45057c0c016..f9bfcba86a04 100644
> --- a/fs/btrfs/disk-io.h
> +++ b/fs/btrfs/disk-io.h
> @@ -137,6 +137,8 @@ int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid);
>  int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid);
>  int __init btrfs_end_io_wq_init(void);
>  void __cold btrfs_end_io_wq_exit(void);
> +void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info);
> +int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, struct btrfs_fs_devices *fs_devices);
>
>  #ifdef CONFIG_DEBUG_LOCK_ALLOC
>  void btrfs_set_buffer_lockdep_class(u64 objectid,
> --
> 2.30.2
>

Ping? Could anyone take a look?

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

* Re: [PATCH] btrfs: Allow read-only mount with corrupted extent tree
  2021-08-11 20:41 ` Josef Bacik
@ 2021-08-12 17:18   ` Dāvis Mosāns
  0 siblings, 0 replies; 12+ messages in thread
From: Dāvis Mosāns @ 2021-08-12 17:18 UTC (permalink / raw)
  To: Josef Bacik, Qu Wenruo
  Cc: Btrfs BTRFS, Chris Mason, David Sterba, linux-kernel

trešd., 2021. g. 11. aug., plkst. 23:41 — lietotājs Josef Bacik
(<josef@toxicpanda.com>) rakstīja:
>
> On 8/11/21 4:07 PM, Dāvis Mosāns wrote:
> > Currently if there's any corruption at all in extent tree
> > (eg. even single bit) then mounting will fail with:
> > "failed to read block groups: -5" (-EIO)
> > It happens because we immediately abort on first error when
> > searching in extent tree for block groups.
> >
> > Now with this patch if `ignorebadroots` option is specified
> > then we handle such case and continue by removing already
> > created block groups and creating dummy block groups.
> >
>
> Already done and queue'ed up for the next release
>
> btrfs: rescue: allow ibadroots to skip bad extent tree when reading block group
> items

Nice!
Originally I submitted this patch in March, but it went nowhere so resent.
Anyway I tested that other patch and it has limitation that it won't
handle log replay error so need to use both
rescue=ignorebadroots,nologreplay
But other than it seems to work fine.

Here's output when not using nologreplay

[ 1886.281376] BTRFS info (device sde): ignoring bad roots
[ 1886.281381] BTRFS info (device sde): disk space caching is enabled
[ 1886.281383] BTRFS info (device sde): has skinny extents
[ 1886.365608] BTRFS info (device sde): bdev /dev/sdq errs: wr 0, rd
0, flush 0, corrupt 473, gen 0
[ 1886.365618] BTRFS info (device sde): bdev /dev/sdi errs: wr 31626,
rd 18765, flush 178, corrupt 5841, gen 0
[ 1886.365623] BTRFS info (device sde): bdev /dev/sdo errs: wr 6867,
rd 2640, flush 178, corrupt 1066, gen 0
[ 1900.249267] BTRFS warning (device sde): checksum verify failed on
21057125941248 wanted 0x5a4526a7 found 0x25949991 level 0
[ 1902.323362] BTRFS error (device sde): parent transid verify failed
on 21057111523328 wanted 2262739 found 2262698
[ 1902.519338] BTRFS error (device sde): bad tree block start, want
21057108836352 have 524288
[ 1902.940022] BTRFS warning (device sde): checksum verify failed on
21057097302016 wanted 0x8b2501e9 found 0x5b8ab9a3 level 0
[ 1902.946715] BTRFS error (device sde): parent transid verify failed
on 21057097302016 wanted 2262739 found 2262696
[ 1902.950727] BTRFS info (device sde): start tree-log replay
[ 1911.289738] BTRFS warning (device sde): checksum verify failed on
21057127661568 wanted 0xd1506ed9 found 0x22ab750a level 0
[ 1911.293266] BTRFS warning (device sde): checksum verify failed on
21057107017728 wanted 0x9120eaee found 0x35b2df28 level 0
[ 1911.326093] BTRFS: error (device sde) in __btrfs_free_extent:3069:
errno=-5 IO failure
[ 1911.326101] BTRFS: error (device sde) in
btrfs_run_delayed_refs:2150: errno=-5 IO failure
[ 1911.326106] BTRFS warning (device sde): Skipping commit of aborted
transaction.
[ 1911.326108] BTRFS: error (device sde) in cleanup_transaction:1945:
errno=-5 IO failure
[ 1911.326190] BTRFS warning (device sde): checksum verify failed on
21057107017728 wanted 0x9120eaee found 0xd00e16cf level 0
[ 1911.326317] BTRFS warning (device sde): checksum verify failed on
21057107017728 wanted 0x9120eaee found 0xd00e16cf level 0
[ 1911.326922] BTRFS: error (device sde) in btrfs_replay_log:2417:
errno=-5 IO failure (Failed to recover log tree)
[ 1912.160913] BTRFS error (device sde): parent transid verify failed
on 21057111736320 wanted 2262739 found 2262698
[ 1914.666177] BTRFS error (device sde): open_ctree failed

Best regards,
Dāvis

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

* Re: [PATCH] btrfs: Allow read-only mount with corrupted extent tree
  2021-08-11 20:07 Dāvis Mosāns
@ 2021-08-11 20:41 ` Josef Bacik
  2021-08-12 17:18   ` Dāvis Mosāns
  0 siblings, 1 reply; 12+ messages in thread
From: Josef Bacik @ 2021-08-11 20:41 UTC (permalink / raw)
  To: Dāvis Mosāns, linux-btrfs
  Cc: Chris Mason, David Sterba, linux-kernel

On 8/11/21 4:07 PM, Dāvis Mosāns wrote:
> Currently if there's any corruption at all in extent tree
> (eg. even single bit) then mounting will fail with:
> "failed to read block groups: -5" (-EIO)
> It happens because we immediately abort on first error when
> searching in extent tree for block groups.
> 
> Now with this patch if `ignorebadroots` option is specified
> then we handle such case and continue by removing already
> created block groups and creating dummy block groups.
> 

Already done and queue'ed up for the next release

btrfs: rescue: allow ibadroots to skip bad extent tree when reading block group 
items

thanks,

Josef

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

* [PATCH] btrfs: Allow read-only mount with corrupted extent tree
@ 2021-08-11 20:07 Dāvis Mosāns
  2021-08-11 20:41 ` Josef Bacik
  0 siblings, 1 reply; 12+ messages in thread
From: Dāvis Mosāns @ 2021-08-11 20:07 UTC (permalink / raw)
  To: linux-btrfs
  Cc: Chris Mason, Josef Bacik, David Sterba, linux-kernel,
	Dāvis Mosāns

Currently if there's any corruption at all in extent tree
(eg. even single bit) then mounting will fail with:
"failed to read block groups: -5" (-EIO)
It happens because we immediately abort on first error when
searching in extent tree for block groups.

Now with this patch if `ignorebadroots` option is specified
then we handle such case and continue by removing already
created block groups and creating dummy block groups.

Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
---
 fs/btrfs/block-group.c | 20 ++++++++++++++++++++
 fs/btrfs/disk-io.c     |  4 ++--
 fs/btrfs/disk-io.h     |  2 ++
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 9e7d9d0c763d..80b9bb9afb8c 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2212,6 +2212,26 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
 	ret = check_chunk_block_group_mappings(info);
 error:
 	btrfs_free_path(path);
+
+	if (ret == -EIO && btrfs_test_opt(info, IGNOREBADROOTS)) {
+
+		if (btrfs_super_log_root(info->super_copy) != 0) {
+			btrfs_warn(info, "Ignoring tree-log replay due to extent tree corruption!");
+			btrfs_set_super_log_root(info->super_copy, 0);
+		}
+
+		btrfs_put_block_group_cache(info);
+		btrfs_stop_all_workers(info);
+		btrfs_free_block_groups(info);
+		ret = btrfs_init_workqueues(info, NULL);
+		if (ret)
+			return ret;
+		ret = btrfs_init_space_info(info);
+		if (ret)
+			return ret;
+		return fill_dummy_bgs(info);
+	}
+
 	return ret;
 }
 
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index a59ab7b9aea0..b1ad9c85d578 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2115,7 +2115,7 @@ static int read_backup_root(struct btrfs_fs_info *fs_info, u8 priority)
 }
 
 /* helper to cleanup workers */
-static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
+void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
 {
 	btrfs_destroy_workqueue(fs_info->fixup_workers);
 	btrfs_destroy_workqueue(fs_info->delalloc_workers);
@@ -2283,7 +2283,7 @@ static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info)
 	mutex_init(&fs_info->qgroup_rescan_lock);
 }
 
-static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info,
+int btrfs_init_workqueues(struct btrfs_fs_info *fs_info,
 		struct btrfs_fs_devices *fs_devices)
 {
 	u32 max_active = fs_info->thread_pool_size;
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index 0e7e9526b6a8..41348c8d3f9a 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -139,6 +139,8 @@ int btrfs_get_free_objectid(struct btrfs_root *root, u64 *objectid);
 int btrfs_init_root_free_objectid(struct btrfs_root *root);
 int __init btrfs_end_io_wq_init(void);
 void __cold btrfs_end_io_wq_exit(void);
+void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info);
+int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, struct btrfs_fs_devices *fs_devices);
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 void btrfs_set_buffer_lockdep_class(u64 objectid,
-- 
2.32.0


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

end of thread, other threads:[~2021-08-12 17:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17  1:20 [RFC] btrfs: Allow read-only mount with corrupted extent tree Dāvis Mosāns
2021-03-17  1:29 ` Dāvis Mosāns
2021-03-17 10:28   ` Qu Wenruo
2021-03-17 21:03     ` Dāvis Mosāns
2021-03-17 23:49       ` Qu Wenruo
2021-03-19 15:34         ` Dāvis Mosāns
2021-03-20  0:34           ` Qu Wenruo
2021-03-21 21:49 ` [PATCH] " Dāvis Mosāns
2021-04-21 16:00   ` Dāvis Mosāns
2021-08-11 20:07 Dāvis Mosāns
2021-08-11 20:41 ` Josef Bacik
2021-08-12 17:18   ` Dāvis Mosāns

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