From: "Dāvis Mosāns" <davispuh@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com,
linux-kernel@vger.kernel.org, ce3g8jdj@umail.furryterror.org,
"Dāvis Mosāns" <davispuh@gmail.com>
Subject: [PATCH] btrfs: Allow read-only mount with corrupted extent tree
Date: Sun, 21 Mar 2021 23:49:39 +0200 [thread overview]
Message-ID: <20210321214939.6984-1-davispuh@gmail.com> (raw)
In-Reply-To: <20210317012054.238334-1-davispuh@gmail.com>
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
next prev parent reply other threads:[~2021-03-21 21:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Dāvis Mosāns [this message]
2021-04-21 16:00 ` [PATCH] " 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210321214939.6984-1-davispuh@gmail.com \
--to=davispuh@gmail.com \
--cc=ce3g8jdj@umail.furryterror.org \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).