From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/2] btrfs: Validate btrfs_super_block::log_root_transid
Date: Thu, 4 Oct 2018 13:49:50 +0800 [thread overview]
Message-ID: <20181004054950.11651-3-wqu@suse.com> (raw)
In-Reply-To: <20181004054950.11651-1-wqu@suse.com>
So we can detect log root related problem early and report the error
more meaningfully other than hitting it log root read time.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/disk-io.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 5124c15705ce..34c68401c6bc 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2408,6 +2408,7 @@ static int validate_super(struct btrfs_fs_info *fs_info,
{
u64 nodesize = btrfs_super_nodesize(sb);
u64 sectorsize = btrfs_super_sectorsize(sb);
+ u64 generation;
int ret = 0;
if (btrfs_super_magic(sb) != BTRFS_MAGIC) {
@@ -2534,21 +2535,36 @@ static int validate_super(struct btrfs_fs_info *fs_info,
ret = -EINVAL;
}
+ generation = btrfs_super_generation(sb);
/*
* The generation is a global counter, we'll trust it more than the others
* but it's still possible that it's the one that's wrong.
*/
- if (btrfs_super_generation(sb) < btrfs_super_chunk_root_generation(sb))
+ if (generation < btrfs_super_chunk_root_generation(sb))
btrfs_warn(fs_info,
"suspicious: generation < chunk_root_generation: %llu < %llu",
- btrfs_super_generation(sb),
- btrfs_super_chunk_root_generation(sb));
- if (btrfs_super_generation(sb) < btrfs_super_cache_generation(sb)
+ generation, btrfs_super_chunk_root_generation(sb));
+ if (generation < btrfs_super_cache_generation(sb)
&& btrfs_super_cache_generation(sb) != (u64)-1)
btrfs_warn(fs_info,
"suspicious: generation < cache_generation: %llu < %llu",
- btrfs_super_generation(sb),
- btrfs_super_cache_generation(sb));
+ generation, btrfs_super_cache_generation(sb));
+
+ /*
+ * Check log root transid against super block generation.
+ *
+ * Older kernel doesn't populate log_root_transid, only need to check
+ * it when it's not zero.
+ * Since replaying suspicious log tree can cause serious problem, refuse
+ * to mount if it doesn't match.
+ */
+ if (btrfs_super_log_root_transid(sb) &&
+ btrfs_super_log_root_transid(sb) != generation + 1) {
+ btrfs_err(fs_info,
+ "bad log tree, log_root_transid != generation + 1: %llu != %llu + 1",
+ btrfs_super_log_root_transid(sb), generation);
+ ret = -EINVAL;
+ }
return ret;
}
--
2.19.0
next prev parent reply other threads:[~2018-10-04 5:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-04 5:49 [PATCH 0/2] btrfs: btrfs_super_block::log_root_transid related enhancement Qu Wenruo
2018-10-04 5:49 ` [PATCH 1/2] btrfs: Populate btrfs_super_block::log_root_transid Qu Wenruo
2018-10-04 8:07 ` Anand Jain
2018-10-04 8:28 ` Qu Wenruo
2018-10-11 12:31 ` David Sterba
2018-10-11 12:45 ` Qu Wenruo
2018-10-11 13:11 ` Nikolay Borisov
2018-10-11 13:13 ` Qu Wenruo
2018-10-04 5:49 ` Qu Wenruo [this message]
2018-10-04 6:57 ` [PATCH 2/2] btrfs: Validate btrfs_super_block::log_root_transid Nikolay Borisov
2018-10-04 7:30 ` Qu Wenruo
2018-10-11 12:19 ` David Sterba
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=20181004054950.11651-3-wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@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).