public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 3/5] btrfs-progs: check/lowmem: Detect invalid EXTENT_ITEM and EXTENT_DATA generation
Date: Tue, 31 Dec 2019 15:12:18 +0800	[thread overview]
Message-ID: <20191231071220.32935-4-wqu@suse.com> (raw)
In-Reply-To: <20191231071220.32935-1-wqu@suse.com>

Since older `btrfs check --init-extent-tree` could cause invalid
EXTENT_ITEM generation for data extents, add such check to lowmem mode
check.

Also add such generation check to file extents too.

For the repair part, I don't have any good idea yet. So affected user
may depend on --init-extent-tree again.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/mode-lowmem.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index f53a0c39..aad30c28 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -2041,6 +2041,8 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path,
 	u64 csum_found;		/* In byte size, sectorsize aligned */
 	u64 search_start;	/* Logical range start we search for csum */
 	u64 search_len;		/* Logical range len we search for csum */
+	u64 gen;
+	u64 super_gen = btrfs_super_generation(root->fs_info->super_copy);
 	unsigned int extent_type;
 	unsigned int is_hole;
 	int slot = path->slots[0];
@@ -2067,6 +2069,7 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path,
 		return check_file_extent_inline(root, path, size, end);
 
 	/* Check REG_EXTENT/PREALLOC_EXTENT */
+	gen = btrfs_file_extent_generation(node, fi);
 	disk_bytenr = btrfs_file_extent_disk_bytenr(node, fi);
 	disk_num_bytes = btrfs_file_extent_disk_num_bytes(node, fi);
 	extent_num_bytes = btrfs_file_extent_num_bytes(node, fi);
@@ -2074,6 +2077,13 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path,
 	compressed = btrfs_file_extent_compression(node, fi);
 	is_hole = (disk_bytenr == 0) && (disk_num_bytes == 0);
 
+	if (gen > super_gen + 1) {
+		error(
+		"vainlid file extent generation, have %llu expect (0, %llu]",
+			gen, super_gen + 1);
+		err |= INVALID_GENERATION;
+	}
+
 	/*
 	 * Check EXTENT_DATA csum
 	 *
@@ -4152,8 +4162,10 @@ static int check_extent_item(struct btrfs_fs_info *fs_info,
 	u64 parent;
 	u64 num_bytes;
 	u64 root_objectid;
+	u64 gen;
 	u64 owner;
 	u64 owner_offset;
+	u64 super_gen = btrfs_super_generation(fs_info->super_copy);
 	int metadata = 0;
 	int level;
 	struct btrfs_key key;
@@ -4183,6 +4195,13 @@ static int check_extent_item(struct btrfs_fs_info *fs_info,
 
 	ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item);
 	flags = btrfs_extent_flags(eb, ei);
+	gen = btrfs_extent_generation(eb, ei);
+	if (gen > super_gen + 1) {
+		error(
+		"invalid generation for extent %llu, have %llu expect (0, %llu]",
+			key.objectid, gen, super_gen + 1);
+		err |= INVALID_GENERATION;
+	}
 
 	if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK)
 		metadata = 1;
-- 
2.24.1


  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 ` Qu Wenruo [this message]
2019-12-31  7:12 ` [PATCH 4/5] btrfs-progs: check/original: Detect invalid extent generation Qu Wenruo
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-4-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