All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/4] btrfs-progs: check/original: detect and report mixed inline and regular data extents
Date: Tue,  4 May 2021 14:25:23 +0800	[thread overview]
Message-ID: <20210504062525.152540-3-wqu@suse.com> (raw)
In-Reply-To: <20210504062525.152540-1-wqu@suse.com>

When a btrfs filesystem has mixed inline and regular data extents, btrfs
check original mode won't detect it as an error.

Considering how much effort we have done just to avoid such cases, we
really want btrfs check to detect such problem.

This error detection is even more important for the incoming btrfs
subpage support, as subpage data rw support can cause such problem much
easier.

So this patch will just add such ability to original mode.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/main.c          | 5 +++++
 check/mode-original.h | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/check/main.c b/check/main.c
index 1e65f8da4c6c..7837c3647f6f 100644
--- a/check/main.c
+++ b/check/main.c
@@ -621,6 +621,8 @@ static void print_inode_error(struct btrfs_root *root, struct inode_record *rec)
 			rec->imode & ~07777);
 	if (errors & I_ERR_INVALID_GEN)
 		fprintf(stderr, ", invalid inode generation or transid");
+	if (errors & I_ERR_MIXED_EXTENTS)
+		fprintf(stderr, ", mixed regular and inline extents");
 	fprintf(stderr, "\n");
 
 	/* Print the holes if needed */
@@ -1583,6 +1585,7 @@ static int process_file_extent(struct btrfs_root *root,
 	if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
 		struct btrfs_item *item = btrfs_item_nr(slot);
 
+		rec->found_inline_extent = 1;
 		num_bytes = btrfs_file_extent_ram_bytes(eb, fi);
 		if (num_bytes == 0)
 			rec->errors |= I_ERR_BAD_FILE_EXTENT;
@@ -1602,6 +1605,8 @@ static int process_file_extent(struct btrfs_root *root,
 		num_bytes = (num_bytes + mask) & ~mask;
 	} else if (extent_type == BTRFS_FILE_EXTENT_REG ||
 		   extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
+		if (rec->found_inline_extent)
+			rec->errors |= I_ERR_MIXED_EXTENTS;
 		num_bytes = btrfs_file_extent_num_bytes(eb, fi);
 		disk_bytenr = btrfs_file_extent_disk_bytenr(eb, fi);
 		extent_offset = btrfs_file_extent_offset(eb, fi);
diff --git a/check/mode-original.h b/check/mode-original.h
index b075a95c9757..f7efc06ec7c7 100644
--- a/check/mode-original.h
+++ b/check/mode-original.h
@@ -186,6 +186,7 @@ struct unaligned_extent_rec_t {
 #define I_ERR_MISMATCH_DIR_HASH		(1 << 18)
 #define I_ERR_INVALID_IMODE		(1 << 19)
 #define I_ERR_INVALID_GEN		(1 << 20)
+#define I_ERR_MIXED_EXTENTS		(1 << 21)
 
 struct inode_record {
 	struct list_head backrefs;
@@ -197,6 +198,7 @@ struct inode_record {
 	unsigned int found_csum_item:1;
 	unsigned int some_csum_missing:1;
 	unsigned int nodatasum:1;
+	unsigned int found_inline_extent:1;
 	int errors;
 
 	struct list_head unaligned_extent_recs;
-- 
2.31.1


  parent reply	other threads:[~2021-05-04  6:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04  6:25 [PATCH 0/4] btrfs-progs: check: add the ability to detect and report mixed inline and regular data extents Qu Wenruo
2021-05-04  6:25 ` [PATCH 1/4] btrfs-progs: check/original: add the "0x" prefix for hex error number Qu Wenruo
2021-05-04  6:25 ` Qu Wenruo [this message]
2021-05-04  6:25 ` [PATCH 3/4] btrfs-progs: check/lowmem: detect and report mixed inline and regular extents properly Qu Wenruo
2021-05-04  6:25 ` [PATCH 4/4] btrfs-progs: fsck-tests: add test image for mixed inline and regular data extents Qu Wenruo
2021-05-04 13:30 ` [PATCH 0/4] btrfs-progs: check: add the ability to detect and report " Su Yue
2021-05-06 13:02 ` Qu Wenruo

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=20210504062525.152540-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.