From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 4/5] btrfs-progs: check/original: Detect invalid extent generation
Date: Tue, 31 Dec 2019 15:12:19 +0800 [thread overview]
Message-ID: <20191231071220.32935-5-wqu@suse.com> (raw)
In-Reply-To: <20191231071220.32935-1-wqu@suse.com>
Much like what we have done in lowmem mode, also detect and report
invalid extent generation in original mode.
Unlike lowmem mode, we have extent_record::generation, which is the
higher number of generations in EXTENT_ITEM, EXTENT_DATA or tree block
header, so there is no need to check generations in different locations.
For repair, we still need to depend on --init-extent-tree, as directly
modifying extent items can easily cause conflicts with delayed refs,
thus it should be avoided.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
check/main.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/check/main.c b/check/main.c
index 88b174ab..a9a236a4 100644
--- a/check/main.c
+++ b/check/main.c
@@ -4021,10 +4021,13 @@ static void free_extent_record_cache(struct cache_tree *extent_cache)
static int maybe_free_extent_rec(struct cache_tree *extent_cache,
struct extent_record *rec)
{
+ u64 super_gen = btrfs_super_generation(global_info->super_copy);
+
if (rec->content_checked && rec->owner_ref_checked &&
rec->extent_item_refs == rec->refs && rec->refs > 0 &&
rec->num_duplicates == 0 && !all_backpointers_checked(rec, 0) &&
!rec->bad_full_backref && !rec->crossing_stripes &&
+ rec->generation <= super_gen + 1 &&
!rec->wrong_chunk_type) {
remove_cache_extent(extent_cache, &rec->cache);
free_all_extent_backrefs(rec);
@@ -7857,6 +7860,7 @@ static int check_extent_refs(struct btrfs_root *root,
{
struct extent_record *rec;
struct cache_extent *cache;
+ u64 super_gen = btrfs_super_generation(root->fs_info->super_copy);
int ret = 0;
int had_dups = 0;
int err = 0;
@@ -7939,6 +7943,13 @@ static int check_extent_refs(struct btrfs_root *root,
cur_err = 1;
}
+ if (rec->generation > super_gen + 1) {
+ error(
+ "invalid generation for extent %llu, have %llu expect (0, %llu]",
+ rec->start, rec->generation,
+ super_gen + 1);
+ cur_err = 1;
+ }
if (rec->refs != rec->extent_item_refs) {
fprintf(stderr, "ref mismatch on [%llu %llu] ",
(unsigned long long)rec->start,
--
2.24.1
next prev parent reply other threads:[~2019-12-31 7:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-31 7:12 [PATCH 0/5] btrfs-progs: Bad extent item generation related bug fixes Qu Wenruo
2019-12-31 7:12 ` [PATCH 1/5] btrfs-progs: check: Initialize extent_record::generation member Qu Wenruo
2019-12-31 7:12 ` [PATCH 2/5] btrfs-progs: check: Populate extent generation correctly for data extents Qu Wenruo
2019-12-31 7:12 ` [PATCH 3/5] btrfs-progs: check/lowmem: Detect invalid EXTENT_ITEM and EXTENT_DATA generation Qu Wenruo
2019-12-31 7:12 ` Qu Wenruo [this message]
2019-12-31 7:12 ` [PATCH 5/5] btrfs-progs: fsck-tests: Make sure btrfs check can detect bad extent item generation Qu Wenruo
2019-12-31 8:05 ` [PATCH 0/5] btrfs-progs: Bad extent item generation related bug fixes Su Yue
2020-01-02 18:36 ` 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=20191231071220.32935-5-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