All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: <calestyo@scientia.net>, <chris@colorremedies.com>, <dsterba@suse.cz>
Subject: [PATCH 4/9] btrfs-progs: lowmem check: Fix false alert in checking data extent pointing to prealloc extent
Date: Mon, 23 Jan 2017 17:13:53 +0800	[thread overview]
Message-ID: <20170123091359.21390-5-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <20170123091359.21390-1-quwenruo@cn.fujitsu.com>

Btrfs lowmem check can report false csum error like:
ERROR: root 5 EXTENT_DATA[257 0] datasum missing
ERROR: root 5 EXTENT_DATA[257 4096] prealloc shouldn't have datasum

This is because lowmem check code always compare the found csum size
with the whole extent which data extents points to.

Normally it's OK, but when prealloc extent is written, or reflink is
done, data extent can points to part of a larger extent, making the csum
check wrong.

The fix changes the csum check part to the data extent size, other than
the disk_bytenr/disk_num_bytes which points to a larger extent.

Reported-by: Chris Murphy <chris@colorremedies.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-check.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index f158daf9..fd176b76 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -4695,6 +4695,7 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey,
 	u64 disk_bytenr;
 	u64 disk_num_bytes;
 	u64 extent_num_bytes;
+	u64 extent_offset;
 	u64 found;
 	unsigned int extent_type;
 	unsigned int is_hole;
@@ -4731,17 +4732,28 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey,
 	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);
+	extent_offset = btrfs_file_extent_offset(node, fi);
 	is_hole = (disk_bytenr == 0) && (disk_num_bytes == 0);
 
-	/* Check EXTENT_DATA datasum */
-	ret = count_csum_range(root, disk_bytenr, disk_num_bytes, &found);
+	/*
+	 * Check EXTENT_DATA datasum
+	 *
+	 * We should only check the range we're referring to, as it's possible
+	 * that part of prealloc extent has been written, and has csum:
+	 *
+	 * |<------- Original large preallocate extent A -------->|
+	 * |<- Prealloc File Extent ->|<- Regular Extent ->|
+	 *	No csum				Has csum
+	 */
+	ret = count_csum_range(root, disk_bytenr + extent_offset,
+			       extent_num_bytes, &found);
 	if (found > 0 && nodatasum) {
 		err |= ODD_CSUM_ITEM;
 		error("root %llu EXTENT_DATA[%llu %llu] nodatasum shouldn't have datasum",
 		      root->objectid, fkey->objectid, fkey->offset);
 	} else if (extent_type == BTRFS_FILE_EXTENT_REG && !nodatasum &&
 		   !is_hole &&
-		   (ret < 0 || found == 0 || found < disk_num_bytes)) {
+		   (ret < 0 || found == 0 || found < extent_num_bytes)) {
 		err |= CSUM_ITEM_MISSING;
 		error("root %llu EXTENT_DATA[%llu %llu] datasum missing",
 		      root->objectid, fkey->objectid, fkey->offset);
-- 
2.11.0




  parent reply	other threads:[~2017-01-23  9:15 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-23  9:13 [PATCH 0/9] Lowmem mode fsck fixes with fsck-tests framework update Qu Wenruo
2017-01-23  9:13 ` [PATCH 1/9] btrfs-progs: lowmem check: Fix wrong block group check when search slot points to slot beyong leaf Qu Wenruo
2017-01-23  9:13 ` [PATCH 2/9] btrfs-progs: fsck-test: Add test image for lowmem mode block group false alert Qu Wenruo
2017-01-23  9:13 ` [PATCH 3/9] btrfs-progs: fsck: Output verbose error when fsck found a bug Qu Wenruo
2017-01-23  9:13 ` Qu Wenruo [this message]
2017-01-23  9:13 ` [PATCH 5/9] btrfs-progs: lowmem check: Fix extent item size false alert Qu Wenruo
2017-01-23  9:13 ` [PATCH 6/9] btrfs-progs: tests: Move fsck-tests/015 to fuzz tests Qu Wenruo
2017-01-23  9:13 ` [PATCH 7/9] btrfs-progs: fsck-tests: Make 013 compatible with lowmem mode Qu Wenruo
2017-01-23  9:13 ` [PATCH 8/8] btrfs-progs: fsck: Fix lowmem mode override to allow it skip repair work Qu Wenruo
2017-01-23  9:13 ` [PATCH 8/9] btrfs-progs: fsck-tests: Add new test case for partly written prealloc extent Qu Wenruo
2017-01-23  9:13 ` [PATCH 9/9] btrfs-progs: fsck: Fix lowmem mode override to allow it skip repair work Qu Wenruo
2017-01-24 16:54 ` [PATCH 0/9] Lowmem mode fsck fixes with fsck-tests framework update Christoph Anton Mitterer
2017-01-25  0:44   ` Qu Wenruo
2017-01-25  0:46     ` Christoph Anton Mitterer
2017-01-25  4:16       ` Qu Wenruo
2017-01-25  4:40         ` Christoph Anton Mitterer
2017-01-26  2:50         ` Christoph Anton Mitterer
2017-01-26  3:10           ` Qu Wenruo
2017-01-26  3:30             ` Christoph Anton Mitterer
2017-01-26 23:31             ` Christoph Anton Mitterer
2017-01-29  4:27               ` Qu Wenruo
2017-01-30  3:07                 ` Christoph Anton Mitterer
2017-02-01  1:06                   ` Qu Wenruo
2017-02-01 22:03                     ` Christoph Anton Mitterer
2017-02-02  0:25                       ` Qu Wenruo
2017-02-02  2:12                         ` Qu Wenruo
     [not found]                           ` <1486098502.7443.3.camel@lmu.de>
2017-02-03  6:20                             ` Qu Wenruo
2017-02-03 23:01                               ` Christoph Anton Mitterer
2017-02-06  1:25                                 ` 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=20170123091359.21390-5-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=calestyo@scientia.net \
    --cc=chris@colorremedies.com \
    --cc=dsterba@suse.cz \
    --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.