All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/12] lowmem mode fixes
@ 2017-02-21  8:34 Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 01/12] btrfs-progs: lowmem check: Fix several bugs related to afterward search Qu Wenruo
                   ` (12 more replies)
  0 siblings, 13 replies; 15+ messages in thread
From: Qu Wenruo @ 2017-02-21  8:34 UTC (permalink / raw)
  To: linux-btrfs

Patches can be fetch from github:
https://github.com/adam900710/btrfs-progs/tree/lowmem_fixes

Thanks for reports from Chris Murphy and Christoph Anton Mitterer,
several new bugs are exposed for lowmem mode fsck.

Special thank to Christoph, who did rounds of test during the patch
development.

The following bugs are fixed in lowmem mode:

1) Block group used space false alert
   If a BLOCK_GROUP_ITEM or its first EXTENT/METADATA_ITEM is located at
   the first slot of a leaf, search_slot() used by lowmem mode can
   point to previous leaf, with path->slots[0] beyond valid leaf slots.

   This makes us to read out uninitialized data, and can abort block
   group used space check loop, causing a false alert.

   Fix it with a test case image inside fsck-tests/020/extent-ref-cases
   Also fix all possible backward search.
   Reported by Christoph.

2) Partly written prealloc extent false alert
   If a prealloc extent gets partily written, lowmem mode will report
   prealloc extent shouldn't have csum.

   Lowmem mode passed wrong variable to csum checking code, causing it
   to check the whole range of the prealloc extent, making the bug
   happens.

   Fix it with a test case inside fsck-tests/020/extent-ref-cases.
   Reported by Chirs Murphy And Christoph.

3) Extent item size false alert.
   Under certain case, btrfs lowmem mode check reports data backref
   lost.
   It's because newly introduced extent item size check aborts normal
   check routine.

   It can happen if a data/metadata extent item has no inline ref.

   Fix it, test case already submitted before and merged, but due to
   fsck-tests framework bugs, it never get called for lowmem mode.

4) Compressed inline data extent
   The extra check on inline data extent length doesn't take compression
   into consideration and will cause false alert without outputting any
   error message.

   Fix it and add correct error message output for it.
   Also fix all possible silent error.
   Reported by Christoph.

5) fsck-tests Lowmem mode override fixes
   Allow lowmem mode override to get called for all tests, and allow
   them all to pass lowmem mode except fsck-tests/006, which is a
   original repair mode bug.


changelog:
  v2:
    More generic forward search bug fix, not restricted to block group
    item.
    Compressed inline extent false alert fix.
    Lowmem fsck-test enhance, to allow it really work.
    Fix walk_down_tree_v2() to continue after non-fatal errors detected
  v3:
    Update the last patch to make it works better for incoming lowmem
    mode repair patchset.

Lu Fengqi (1):
  btrfs-progs: fsck: Fix lowmem mode override to allow it skip repair
    work

Qu Wenruo (10):
  btrfs-progs: lowmem check: Fix several bugs related to afterward
    search
  btrfs-progs: check: Output verbose error when fsck found a bug in any
    tree
  btrfs-progs: lowmem check: Fix false alert in checking data extent
    csums
  btrfs-progs: lowmem check: Fix extent item size false alert
  btrfs-progs: lowmem check: Fix false alert on inline compressed extent
  btrfs-progs: lowmem check: Fix silent error if first inode item
    missing
  btrfs-progs: tests: Move fsck-tests/015 to fuzz tests
  btrfs-progs: fsck-test: Add test image for lowmem mode block group
    false alert
  btrfs-progs: fsck-test: Make 013 compatible with lowmem mode
  btrfs-progs: fsck-test: Add new test case for file extent false alerts

Su Yue (1):
  btrfs-progs: cmds-check.c: walk_down_tree_v2 break cause of leaf
    process

 cmds-check.c                                       | 175 +++++++++++++++------
 tests/common                                       |   8 +-
 tests/common.local                                 |   2 +-
 tests/fsck-tests/013-extent-tree-rebuild/test.sh   |   2 +-
 .../block_group_item_false_alert.raw.xz            | Bin 0 -> 47792 bytes
 tests/fsck-tests/020-extent-ref-cases/test.sh      |  15 +-
 tests/fsck-tests/025-file-extents/test.sh          |  42 +++++
 .../images}/bko-97171-btrfs-image.raw.txt          |   0
 .../images}/bko-97171-btrfs-image.raw.xz           | Bin
 9 files changed, 190 insertions(+), 54 deletions(-)
 create mode 100644 tests/fsck-tests/020-extent-ref-cases/block_group_item_false_alert.raw.xz
 create mode 100755 tests/fsck-tests/025-file-extents/test.sh
 rename tests/{fsck-tests/015-check-bad-memory-access => fuzz-tests/images}/bko-97171-btrfs-image.raw.txt (100%)
 rename tests/{fsck-tests/015-check-bad-memory-access => fuzz-tests/images}/bko-97171-btrfs-image.raw.xz (100%)

-- 
2.11.1




^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v3 01/12] btrfs-progs: lowmem check: Fix several bugs related to afterward search
  2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
@ 2017-02-21  8:34 ` Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 02/12] btrfs-progs: check: Output verbose error when fsck found a bug in any tree Qu Wenruo
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Qu Wenruo @ 2017-02-21  8:34 UTC (permalink / raw)
  To: linux-btrfs

Since btrfs_search_slot() can points to the slot which is beyond the
leaves' capacity, we should pay extra attention when doing afterward
search.

While for lowmem check, several places uses afterward search:
1) Block group item used space check
2) Device item used space check
3) Data extent backref check.

In the following case for block group item check, btrfs lowmem mode
check will skip the block group and report false alert:

leaf 29405184 items 37 free space 1273 generation 11 owner 2
...
        item 36 key (77594624 EXTENT_ITEM 2097152)
                extent refs 1 gen 8 flags DATA
                extent data backref root 5 objectid 265 offset 0 count 1
leaf 29409280 items 43 free space 670 generation 11 owner 2
        item 0 key (96468992 EXTENT_ITEM 2097152)
                extent refs 1 gen 8 flags DATA
                extent data backref root 5 objectid 274 offset 0 count 1
        item 1 key (96468992 BLOCK_GROUP_ITEM 33554432)
                block group used 2265088 chunk_objectid 256 flags DATA

When checking block group item, we will search key(96468992 0 0) to
start from the first item in the block group.

While search_slot() will point to leaf 29405184, slot 37 which is beyond
leaf capacity.

And when reading key from slot 37, uninitialized data can be read out
and cause us to exit block group item check, leading to false alert.

Fix it by checking path.slot[0] before reading out the key.

Reported-by: Christoph Anton Mitterer <calestyo@scientia.net>
Reported-by: Chris Murphy <chris@colorremedies.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-check.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/cmds-check.c b/cmds-check.c
index 37e5ff18..699753fb 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -10591,6 +10591,8 @@ static int check_extent_data_backref(struct btrfs_fs_info *fs_info,
 		leaf = path.nodes[0];
 		slot = path.slots[0];
 
+		if (slot >= btrfs_header_nritems(leaf))
+			goto next;
 		btrfs_item_key_to_cpu(leaf, &key, slot);
 		if (key.objectid != objectid || key.type != BTRFS_EXTENT_DATA_KEY)
 			break;
@@ -10606,6 +10608,7 @@ static int check_extent_data_backref(struct btrfs_fs_info *fs_info,
 		    offset)
 			found_count++;
 
+next:
 		ret = btrfs_next_item(root, &path);
 		if (ret)
 			break;
@@ -10878,8 +10881,10 @@ static int check_dev_item(struct btrfs_fs_info *fs_info,
 
 	/* Iterate dev_extents to calculate the used space of a device */
 	while (1) {
-		btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]);
+		if (path.slots[0] >= btrfs_header_nritems(path.nodes[0]))
+			goto next;
 
+		btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]);
 		if (key.objectid > dev_id)
 			break;
 		if (key.type != BTRFS_DEV_EXTENT_KEY || key.objectid != dev_id)
@@ -10976,6 +10981,11 @@ static int check_block_group_item(struct btrfs_fs_info *fs_info,
 	/* Iterate extent tree to account used space */
 	while (1) {
 		leaf = path.nodes[0];
+
+		/* Search slot can point to the last item beyond leaf nritems */
+		if (path.slots[0] >= btrfs_header_nritems(leaf))
+			goto next;
+
 		btrfs_item_key_to_cpu(leaf, &extent_key, path.slots[0]);
 		if (extent_key.objectid >= bg_key.objectid + bg_key.offset)
 			break;
-- 
2.11.1




^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 02/12] btrfs-progs: check: Output verbose error when fsck found a bug in any tree
  2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 01/12] btrfs-progs: lowmem check: Fix several bugs related to afterward search Qu Wenruo
@ 2017-02-21  8:34 ` Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 03/12] btrfs-progs: lowmem check: Fix false alert in checking data extent csums Qu Wenruo
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Qu Wenruo @ 2017-02-21  8:34 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Christoph Anton Mitterer

Although we output error like "errors found in extent allocation tree or
chunk allocation", but we lacks such output for other trees, but leaving
the final "found error is %d" to catch the last return value(and
sometime it's cleared)

This patch adds extra error message for top level error path, and modify
the last "found error is %d" to "error(s) found" or "no error found".

Cc: Christoph Anton Mitterer <calestyo@scientia.net>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-check.c | 43 +++++++++++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 10 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index 699753fb..107359f8 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -12933,8 +12933,10 @@ int cmd_check(int argc, char **argv)
 
 	ret = repair_root_items(info);
 	err |= !!ret;
-	if (ret < 0)
+	if (ret < 0) {
+		error("failed to repair root items: %s", strerror(-ret));
 		goto close_out;
+	}
 	if (repair) {
 		fprintf(stderr, "Fixed %d roots.\n", ret);
 		ret = 0;
@@ -12957,8 +12959,13 @@ int cmd_check(int argc, char **argv)
 	}
 	ret = check_space_cache(root);
 	err |= !!ret;
-	if (ret)
+	if (ret) {
+		if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE))
+			error("errors found in free space tree");
+		else
+			error("errors found in free space cache");
 		goto out;
+	}
 
 	/*
 	 * We used to have to have these hole extents in between our real
@@ -12974,22 +12981,28 @@ int cmd_check(int argc, char **argv)
 	else
 		ret = check_fs_roots(root, &root_cache);
 	err |= !!ret;
-	if (ret)
+	if (ret) {
+		error("errors found in fs roots");
 		goto out;
+	}
 
 	fprintf(stderr, "checking csums\n");
 	ret = check_csums(root);
 	err |= !!ret;
-	if (ret)
+	if (ret) {
+		error("errors found in csum tree");
 		goto out;
+	}
 
 	fprintf(stderr, "checking root refs\n");
 	/* For low memory mode, check_fs_roots_v2 handles root refs */
 	if (check_mode != CHECK_MODE_LOWMEM) {
 		ret = check_root_refs(root, &root_cache);
 		err |= !!ret;
-		if (ret)
+		if (ret) {
+			error("errors found in root refs");
 			goto out;
+		}
 	}
 
 	while (repair && !list_empty(&root->fs_info->recow_ebs)) {
@@ -13000,8 +13013,10 @@ int cmd_check(int argc, char **argv)
 		list_del_init(&eb->recow);
 		ret = recow_extent_buffer(root, eb);
 		err |= !!ret;
-		if (ret)
+		if (ret) {
+			error("fails to fix transid errors");
 			break;
+		}
 	}
 
 	while (!list_empty(&delete_items)) {
@@ -13020,13 +13035,17 @@ int cmd_check(int argc, char **argv)
 		fprintf(stderr, "checking quota groups\n");
 		ret = qgroup_verify_all(info);
 		err |= !!ret;
-		if (ret)
+		if (ret) {
+			error("failed to check quota groups");
 			goto out;
+		}
 		report_qgroups(0);
 		ret = repair_qgroups(info, &qgroups_repaired);
 		err |= !!ret;
-		if (err)
+		if (err) {
+			error("failed to repair quota groups");
 			goto out;
+		}
 		ret = 0;
 	}
 
@@ -13047,8 +13066,12 @@ out:
 		       "backup data and re-format the FS. *\n\n");
 		err |= 1;
 	}
-	printf("found %llu bytes used err is %d\n",
-	       (unsigned long long)bytes_used, ret);
+	printf("found %llu bytes used, ",
+	       (unsigned long long)bytes_used);
+	if (err)
+		printf("error(s) found\n");
+	else
+		printf("no error found\n");
 	printf("total csum bytes: %llu\n",(unsigned long long)total_csum_bytes);
 	printf("total tree bytes: %llu\n",
 	       (unsigned long long)total_btree_bytes);
-- 
2.11.1




^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 03/12] btrfs-progs: lowmem check: Fix false alert in checking data extent csums
  2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 01/12] btrfs-progs: lowmem check: Fix several bugs related to afterward search Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 02/12] btrfs-progs: check: Output verbose error when fsck found a bug in any tree Qu Wenruo
@ 2017-02-21  8:34 ` Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 04/12] btrfs-progs: lowmem check: Fix extent item size false alert Qu Wenruo
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Qu Wenruo @ 2017-02-21  8:34 UTC (permalink / raw)
  To: linux-btrfs

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.

To fix it, the csum check part is modified to handle plain and
compressed extents in different ways:

1) Plain extent
   Only search csums for the range it refers to.
   So the search range is from (disk_bytenr + extent_offset) and search
   length is (extent_num_bytes)

2) Compressed extent
   Search the whole extent.
   Search range is from (disk_bytner) and search length is
   (disk_num_bytes)

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

diff --git a/cmds-check.c b/cmds-check.c
index 107359f8..e99e3c36 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -4703,9 +4703,13 @@ 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 found;
+	u64 extent_offset;
+	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 */
 	unsigned int extent_type;
 	unsigned int is_hole;
+	int compressed = 0;
 	int ret;
 	int err = 0;
 
@@ -4739,24 +4743,45 @@ 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);
+	compressed = btrfs_file_extent_compression(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);
-	if (found > 0 && nodatasum) {
+	/*
+	 * Check EXTENT_DATA datasum
+	 *
+	 * For plain(uncompressed) extent, 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
+	 *
+	 * For compressed extent, we should check the whole range.
+	 */
+	if (!compressed) {
+		search_start = disk_bytenr + extent_offset;
+		search_len = extent_num_bytes;
+	} else {
+		search_start = disk_bytenr;
+		search_len = disk_num_bytes;
+	}
+	ret = count_csum_range(root, search_start, search_len, &csum_found);
+	if (csum_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)) {
+		   !is_hole && (ret < 0 || csum_found < search_len)) {
 		err |= CSUM_ITEM_MISSING;
-		error("root %llu EXTENT_DATA[%llu %llu] datasum missing",
-		      root->objectid, fkey->objectid, fkey->offset);
-	} else if (extent_type == BTRFS_FILE_EXTENT_PREALLOC && found > 0) {
+		error("root %llu EXTENT_DATA[%llu %llu] datasum missing, have: %llu, expect: %llu",
+		      root->objectid, fkey->objectid, fkey->offset,
+		      csum_found, search_len);
+	} else if (extent_type == BTRFS_FILE_EXTENT_PREALLOC && csum_found > 0) {
 		err |= ODD_CSUM_ITEM;
-		error("root %llu EXTENT_DATA[%llu %llu] prealloc shouldn't have datasum",
-		      root->objectid, fkey->objectid, fkey->offset);
+		error("root %llu EXTENT_DATA[%llu %llu] prealloc shouldn't have datasum, but have: %llu",
+		      root->objectid, fkey->objectid, fkey->offset, csum_found);
 	}
 
 	/* Check EXTENT_DATA hole */
-- 
2.11.1




^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 04/12] btrfs-progs: lowmem check: Fix extent item size false alert
  2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
                   ` (2 preceding siblings ...)
  2017-02-21  8:34 ` [PATCH v3 03/12] btrfs-progs: lowmem check: Fix false alert in checking data extent csums Qu Wenruo
@ 2017-02-21  8:34 ` Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 05/12] btrfs-progs: lowmem check: Fix false alert on inline compressed extent Qu Wenruo
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Qu Wenruo @ 2017-02-21  8:34 UTC (permalink / raw)
  To: linux-btrfs

If one extent item has no inline ref, btrfs lowmem mode check can give
false alert without outputting any error message.

The problem is lowmem mode always assume that extent item has inline
refs, and when it encounters such case it flags the extent item has
wrong size, but doesn't output the error message.

Although we already have such image submitted, at the commit time due to
another bug in cmds-check return value, it doesn't detect it until that
bug is fixed.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-check.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index e99e3c36..eb146432 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -10761,13 +10761,20 @@ static int check_extent_item(struct btrfs_fs_info *fs_info,
 	}
 	end = (unsigned long)ei + item_size;
 
-	if (ptr >= end) {
+next:
+	/* Reached extent item end normally */
+	if (ptr == end)
+		goto out;
+
+	/* Beyond extent item end, wrong item size */
+	if (ptr > end) {
 		err |= ITEM_SIZE_MISMATCH;
+		error("extent item at bytenr %llu slot %d has wrong size",
+			eb->start, slot);
 		goto out;
 	}
 
 	/* Now check every backref in this extent item */
-next:
 	iref = (struct btrfs_extent_inline_ref *)ptr;
 	type = btrfs_extent_inline_ref_type(eb, iref);
 	offset = btrfs_extent_inline_ref_offset(eb, iref);
@@ -10804,8 +10811,7 @@ next:
 	}
 
 	ptr += btrfs_extent_inline_ref_size(type);
-	if (ptr < end)
-		goto next;
+	goto next;
 
 out:
 	return err;
-- 
2.11.1




^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 05/12] btrfs-progs: lowmem check: Fix false alert on inline compressed extent
  2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
                   ` (3 preceding siblings ...)
  2017-02-21  8:34 ` [PATCH v3 04/12] btrfs-progs: lowmem check: Fix extent item size false alert Qu Wenruo
@ 2017-02-21  8:34 ` Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 06/12] btrfs-progs: lowmem check: Fix silent error if first inode item missing Qu Wenruo
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Qu Wenruo @ 2017-02-21  8:34 UTC (permalink / raw)
  To: linux-btrfs

Old lowmem check doesn't check if the inline extent is compressed and
always check extent numbytes against inline item size.

And when it finds the extent numbytes mismatch with inline item size it
doesn't output any error message, just return error silently, making it
quite hard to debug.

Fix it by only checking extent numbytes against inline item size when
the extent is not compressed, and output error message.

Reported-by: Christoph Anton Mitterer <calestyo@scientia.net>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-check.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index eb146432..cf5a08ce 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -4715,17 +4715,28 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey,
 
 	fi = btrfs_item_ptr(node, slot, struct btrfs_file_extent_item);
 
+	/* Check inline extent */
 	extent_type = btrfs_file_extent_type(node, fi);
-	/* Skip if file extent is inline */
 	if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
 		struct btrfs_item *e = btrfs_item_nr(slot);
 		u32 item_inline_len;
 
 		item_inline_len = btrfs_file_extent_inline_item_len(node, e);
 		extent_num_bytes = btrfs_file_extent_inline_len(node, slot, fi);
-		if (extent_num_bytes == 0 ||
-		    extent_num_bytes != item_inline_len)
+		compressed = btrfs_file_extent_compression(node, fi);
+		if (extent_num_bytes == 0) {
+			error(
+		"root %llu EXTENT_DATA[%llu %llu] has empty inline extent",
+				root->objectid, fkey->objectid, fkey->offset);
 			err |= FILE_EXTENT_ERROR;
+		}
+		if (!compressed && extent_num_bytes != item_inline_len) {
+			error(
+		"root %llu EXTENT_DATA[%llu %llu] wrong inline size, have: %llu, expect: %u",
+				root->objectid, fkey->objectid, fkey->offset,
+				extent_num_bytes, item_inline_len);
+			err |= FILE_EXTENT_ERROR;
+		}
 		*size += extent_num_bytes;
 		return err;
 	}
-- 
2.11.1




^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 06/12] btrfs-progs: lowmem check: Fix silent error if first inode item missing
  2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
                   ` (4 preceding siblings ...)
  2017-02-21  8:34 ` [PATCH v3 05/12] btrfs-progs: lowmem check: Fix false alert on inline compressed extent Qu Wenruo
@ 2017-02-21  8:34 ` Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 07/12] btrfs-progs: tests: Move fsck-tests/015 to fuzz tests Qu Wenruo
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Qu Wenruo @ 2017-02-21  8:34 UTC (permalink / raw)
  To: linux-btrfs

If first inode item is missing, lowmem check will detect it but not
output any error message.

Add error message for it.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-check.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/cmds-check.c b/cmds-check.c
index cf5a08ce..7d273623 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -5001,6 +5001,8 @@ static int check_fs_first_inode(struct btrfs_root *root, unsigned int ext_ref)
 	if (ret > 0) {
 		ret = 0;
 		err |= INODE_ITEM_MISSING;
+		error("first inode item of root %llu is missing",
+		      root->objectid);
 	}
 
 	err |= check_inode_item(root, &path, ext_ref);
-- 
2.11.1




^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 07/12] btrfs-progs: tests: Move fsck-tests/015 to fuzz tests
  2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
                   ` (5 preceding siblings ...)
  2017-02-21  8:34 ` [PATCH v3 06/12] btrfs-progs: lowmem check: Fix silent error if first inode item missing Qu Wenruo
@ 2017-02-21  8:34 ` Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 08/12] btrfs-progs: fsck-test: Add test image for lowmem mode block group false alert Qu Wenruo
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Qu Wenruo @ 2017-02-21  8:34 UTC (permalink / raw)
  To: linux-btrfs

The test case fsck-tests/015-check-bad-memory-access can't be repair by
btrfs check, and it's a fortunate bug makes original mode to forget the
error code from extent tree, making original mode pass it.

So fuzz-tests is more suitable for it.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 .../images}/bko-97171-btrfs-image.raw.txt                   |   0
 .../images}/bko-97171-btrfs-image.raw.xz                    | Bin
 2 files changed, 0 insertions(+), 0 deletions(-)
 rename tests/{fsck-tests/015-check-bad-memory-access => fuzz-tests/images}/bko-97171-btrfs-image.raw.txt (100%)
 rename tests/{fsck-tests/015-check-bad-memory-access => fuzz-tests/images}/bko-97171-btrfs-image.raw.xz (100%)

diff --git a/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.txt b/tests/fuzz-tests/images/bko-97171-btrfs-image.raw.txt
similarity index 100%
rename from tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.txt
rename to tests/fuzz-tests/images/bko-97171-btrfs-image.raw.txt
diff --git a/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.xz b/tests/fuzz-tests/images/bko-97171-btrfs-image.raw.xz
similarity index 100%
rename from tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.xz
rename to tests/fuzz-tests/images/bko-97171-btrfs-image.raw.xz
-- 
2.11.1




^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v3 08/12] btrfs-progs: fsck-test: Add test image for lowmem mode block group false alert
  2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
                   ` (6 preceding siblings ...)
  2017-02-21  8:34 ` [PATCH v3 07/12] btrfs-progs: tests: Move fsck-tests/015 to fuzz tests Qu Wenruo
@ 2017-02-21  8:34 ` Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 09/12] btrfs-progs: fsck-test: Make 013 compatible with lowmem mode Qu Wenruo
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Qu Wenruo @ 2017-02-21  8:34 UTC (permalink / raw)
  To: linux-btrfs

Add a minimal image which can reproduce the block group used space
false alert for lowmem mode fsck.

Reported-by: Christoph Anton Mitterer <calestyo@scientia.net>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 .../block_group_item_false_alert.raw.xz                 | Bin 0 -> 47792 bytes
 tests/fsck-tests/020-extent-ref-cases/test.sh           |  15 +++++++++++----
 2 files changed, 11 insertions(+), 4 deletions(-)
 create mode 100644 tests/fsck-tests/020-extent-ref-cases/block_group_item_false_alert.raw.xz

diff --git a/tests/fsck-tests/020-extent-ref-cases/block_group_item_false_alert.raw.xz b/tests/fsck-tests/020-extent-ref-cases/block_group_item_false_alert.raw.xz
new file mode 100644
index 0000000000000000000000000000000000000000..559c3fa9e8491f3ce1f424d1baef29853e8fb889
GIT binary patch
literal 47792
zcmeHwWmukDmL={If(LhZcL)S`cXxMpcPD`W!5xAV+%>qnyL)h$?&&{0(>=H9R^2;Q
z-Ti*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0FaX2;@(joS3eVnuRbmc+J^=av=>L;}J{`!3bFi?+SLBeM0;K`^
z{8KYW!9TBf;U6dt{@q6#ncQL<{HtC;3k=i!ck`eBGd=b-F|^LsFho`(P<bZn4Hc9L
z<iwJ{I($b2pXyZdigvxdMbP{I(|GFt?CbsG#|;0rGdk|ojswCNAdLNaI1Ehi`kN+r
z0Sp#kumFSoCu6X{Zi9cnj^j7@4gmT9=>Gu=UjPpS3Soii=l^jL(r?7YZ>M{I{|=_#
zI2r(b0Q3RS|0mor1>};yGnd2$W%z#!uSq^m0o~iH;u|+ppTw{2)o1^fRd&AtqyInz
z{~M3S)rH#yL_|PD1Vluj6ZJ1|@%-n6K7hOe<P{*V0D1lEHW33D_QwfRe<SJqtG7n~
z#%~3HJ^=av=mVe+fc{^*<sGOHW@myds5-L)48~;p-)F!1U$Gz#kaqxi2atCFc?V$<
z=%dj)p&SmGOi7LOrB1k_aJj?&pD=F|XgmUL$zC!*t@xdi0bnq|V1KU00(cnUVStAL
zJS-@n)1;RS(DZ*N8UO|Z4EE>3C*Wa#hXEc2JhK7MY{07#@M`pyLMe(|@*mLvxFvyG
z61XM*V_X38&hLy1z+iyE{#+mdJPhzKz{3E=6;NEMt=H>$E`BE(08Ae+*q;lZfQJDd
z26z~dO9F~3ptu5xE1<a2IFADTlK+6N9e{@cJnYZsVgAnkAaMVCU{QU{a)CF<zkKfN
mXF=`|Mjk;xLvO+S|K$S;0&?rL4uOWr!wCMbe*mGO`M&@R<KJBX

literal 0
HcmV?d00001

diff --git a/tests/fsck-tests/020-extent-ref-cases/test.sh b/tests/fsck-tests/020-extent-ref-cases/test.sh
index c2b6a006..5dc5e55d 100755
--- a/tests/fsck-tests/020-extent-ref-cases/test.sh
+++ b/tests/fsck-tests/020-extent-ref-cases/test.sh
@@ -8,16 +8,23 @@
 # * shared_data_ref
 # * no_inline_ref (a extent item without inline ref)
 # * no_skinny_ref
+#
+# Special check for lowmem regression
+# * block_group_item_false_alert
+#   Containing a block group and its first extent at
+#   the beginning of leaf.
+#   Which caused false alert for lowmem mode.
 
 source $TOP/tests/common
 
 check_prereq btrfs
 
-for img in *.img
+for img in *.img *.raw.xz
 do
 	image=$(extract_image $img)
-	run_check_stdout $TOP/btrfs check "$image" 2>&1 |
-		grep -q "Errors found in extent allocation tree or chunk allocation" &&
-		_fail "unexpected error occurred when checking $img"
+
+	# Since the return value bug is already fixed, we don't need
+	# the old grep hack to detect bug.
+	run_check $TOP/btrfs check "$image"
 	rm -f "$image"
 done
-- 
2.11.1




^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 09/12] btrfs-progs: fsck-test: Make 013 compatible with lowmem mode
  2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
                   ` (7 preceding siblings ...)
  2017-02-21  8:34 ` [PATCH v3 08/12] btrfs-progs: fsck-test: Add test image for lowmem mode block group false alert Qu Wenruo
@ 2017-02-21  8:34 ` Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 10/12] btrfs-progs: fsck-test: Add new test case for file extent false alerts Qu Wenruo
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Qu Wenruo @ 2017-02-21  8:34 UTC (permalink / raw)
  To: linux-btrfs

fsck-tests/013-extent-tree-rebuild uses "--init-extent-tree", which
implies "--repair".

But the test script doesn't specify "--repair" for lowmem mode test to
detect it.

Add it so lowmem mode test can be happy with it.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 tests/fsck-tests/013-extent-tree-rebuild/test.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh
index 37bdcd9c..08c1e50e 100755
--- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh
+++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh
@@ -36,7 +36,7 @@ test_extent_tree_rebuild()
 
 	$SUDO_HELPER $TOP/btrfs check $TEST_DEV >& /dev/null && \
 			_fail "btrfs check should detect failure"
-	run_check $SUDO_HELPER $TOP/btrfs check --init-extent-tree $TEST_DEV
+	run_check $SUDO_HELPER $TOP/btrfs check --repair --init-extent-tree $TEST_DEV
 	run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV
 }
 
-- 
2.11.1




^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 10/12] btrfs-progs: fsck-test: Add new test case for file extent false alerts
  2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
                   ` (8 preceding siblings ...)
  2017-02-21  8:34 ` [PATCH v3 09/12] btrfs-progs: fsck-test: Make 013 compatible with lowmem mode Qu Wenruo
@ 2017-02-21  8:34 ` Qu Wenruo
  2017-03-01 16:27   ` David Sterba
  2017-02-21  8:34 ` [PATCH v3 11/12] btrfs-progs: fsck: Fix lowmem mode override to allow it skip repair work Qu Wenruo
                   ` (2 subsequent siblings)
  12 siblings, 1 reply; 15+ messages in thread
From: Qu Wenruo @ 2017-02-21  8:34 UTC (permalink / raw)
  To: linux-btrfs

Lowmem mode exposed several false alerts, all related to file extents
check.

1) Partly written prealloc extent
   Cause lowmem mode to report missing csum or prealloc extent should
   not have csum

2) Compressed inline extent
   Cause lowmem mode to find mismatch on inline len and item len.
   While no error message is output but exit silently.

Reported-by: Chris Murphy <chris@colorremedies.com>
Reported-by: Christoph Anton Mitterer <calestyo@scientia.net>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 tests/fsck-tests/025-file-extents/test.sh | 42 +++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100755 tests/fsck-tests/025-file-extents/test.sh

diff --git a/tests/fsck-tests/025-file-extents/test.sh b/tests/fsck-tests/025-file-extents/test.sh
new file mode 100755
index 00000000..cb64c500
--- /dev/null
+++ b/tests/fsck-tests/025-file-extents/test.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+# Confirm btrfs check can check file extents without causing false alert
+
+source $TOP/tests/common
+
+check_prereq btrfs
+check_prereq mkfs.btrfs
+check_global_prereq xfs_io
+check_global_prereq fallocate
+
+setup_root_helper
+prepare_test_dev 128M
+
+# Do some write into a large prealloc range
+# Lowmem mode can report missing csum due to wrong csum range
+test_paritical_write_into_prealloc()
+{
+	run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
+	run_check_mount_test_dev
+
+	run_check fallocate -l 128K "$TEST_MNT/file"
+	sync
+	run_check xfs_io -c "pwrite 0 64K" "$TEST_MNT/file"
+	run_check_umount_test_dev
+	run_check "$TOP/btrfs" check "$TEST_DEV"
+}
+
+# Inline compressed file extent
+# Lowmem mode can cause silent error without any error message
+# due to too restrict check on inline extent size
+test_compressed_inline_extent()
+{
+	run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
+	run_check_mount_test_dev -o compress=lzo,max_inline=2048
+
+	run_check xfs_io -f -c "pwrite 0 1K" "$TEST_MNT/file"
+	run_check_umount_test_dev
+	run_check "$TOP/btrfs" check "$TEST_DEV"
+}
+
+test_paritical_write_into_prealloc
+test_compressed_inline_extent
-- 
2.11.1




^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 11/12] btrfs-progs: fsck: Fix lowmem mode override to allow it skip repair work
  2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
                   ` (9 preceding siblings ...)
  2017-02-21  8:34 ` [PATCH v3 10/12] btrfs-progs: fsck-test: Add new test case for file extent false alerts Qu Wenruo
@ 2017-02-21  8:34 ` Qu Wenruo
  2017-02-21  8:34 ` [PATCH v3 12/12] btrfs-progs: cmds-check.c: walk_down_tree_v2 break cause of leaf process Qu Wenruo
  2017-03-01 16:30 ` [PATCH v3 00/12] lowmem mode fixes David Sterba
  12 siblings, 0 replies; 15+ messages in thread
From: Qu Wenruo @ 2017-02-21  8:34 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Lu Fengqi

From: Lu Fengqi <lufq.fnst@cn.fujitsu.com>

Current common.local doesn't handle lowmem mode well.
It passes "--mode=lowmem" alone with "--repair", making it unable to
check lowmem mode.

It's caused by the following bugs:

1) Wrong variable in test/common.local
   We should check TEST_ARGS_CHECK, not TEST_CHECK, which is not defined
   so we never return 1.

2) Wrong parameter passed to _cmd_spec() in test/common
   This prevents us from grepping the correct parameters.

Fix it.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
---
 tests/common       | 8 ++++----
 tests/common.local | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tests/common b/tests/common
index 51c2e267..7ad436e3 100644
--- a/tests/common
+++ b/tests/common
@@ -106,7 +106,7 @@ run_check()
 	ins=$(_get_spec_ins "$@")
 	spec=$(($ins-1))
 	cmd=$(eval echo "\${$spec}")
-	spec=$(_cmd_spec "$cmd")
+	spec=$(_cmd_spec "${@:$spec}")
 	set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}"
 	echo "############### $@" >> "$RESULTS" 2>&1
 	if [[ $TEST_LOG =~ tty ]]; then echo "CMD: $@" > /dev/tty; fi
@@ -128,7 +128,7 @@ run_check_stdout()
 	ins=$(_get_spec_ins "$@")
 	spec=$(($ins-1))
 	cmd=$(eval echo "\${$spec}")
-	spec=$(_cmd_spec "$cmd")
+	spec=$(_cmd_spec "${@:$spec}")
 	set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}"
 	echo "############### $@" >> "$RESULTS" 2>&1
 	if [[ $TEST_LOG =~ tty ]]; then echo "CMD(stdout): $@" > /dev/tty; fi
@@ -152,7 +152,7 @@ run_mayfail()
 	ins=$(_get_spec_ins "$@")
 	spec=$(($ins-1))
 	cmd=$(eval echo "\${$spec}")
-	spec=$(_cmd_spec "$cmd")
+	spec=$(_cmd_spec "${@:$spec}")
 	set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}"
 	echo "############### $@" >> "$RESULTS" 2>&1
 	if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mayfail): $@" > /dev/tty; fi
@@ -188,7 +188,7 @@ run_mustfail()
 	ins=$(_get_spec_ins "$@")
 	spec=$(($ins-1))
 	cmd=$(eval echo "\${$spec}")
-	spec=$(_cmd_spec "$cmd")
+	spec=$(_cmd_spec "${@:$spec}")
 	set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}"
 	echo "############### $@" >> "$RESULTS" 2>&1
 	if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mustfail): $@" > /dev/tty; fi
diff --git a/tests/common.local b/tests/common.local
index 9f567c27..4f56bb08 100644
--- a/tests/common.local
+++ b/tests/common.local
@@ -17,7 +17,7 @@ TEST_ARGS_CHECK=--mode=lowmem
 # break tests
 _skip_spec()
 {
-	if echo "$TEST_CHECK" | grep -q 'mode=lowmem' &&
+	if echo "$TEST_ARGS_CHECK" | grep -q 'mode=lowmem' &&
 	   echo "$@" | grep -q -- '--repair'; then
 		return 0
 	fi
-- 
2.11.1




^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 12/12] btrfs-progs: cmds-check.c: walk_down_tree_v2 break cause of leaf process
  2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
                   ` (10 preceding siblings ...)
  2017-02-21  8:34 ` [PATCH v3 11/12] btrfs-progs: fsck: Fix lowmem mode override to allow it skip repair work Qu Wenruo
@ 2017-02-21  8:34 ` Qu Wenruo
  2017-03-01 16:30 ` [PATCH v3 00/12] lowmem mode fixes David Sterba
  12 siblings, 0 replies; 15+ messages in thread
From: Qu Wenruo @ 2017-02-21  8:34 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Su Yue

From: Su Yue <suy.fnst@cn.fujitsu.com>

In lowmem mode, 'walk_down_tree_v2' returns negative values wheather
the error is fatal or not. It causes the loop where 'walk_down_tree_v2'
is to break even the error is tolerated and then subsequent nodes process
will be skipped.

Fix it by redefining meanings of values 'walk_down_tree_v2' returns.
Do a similar fix for 'process_one_leaf_v2'.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 cmds-check.c | 40 +++++++++++++++++++++++++---------------
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index 7d273623..9cc1932c 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -1868,6 +1868,11 @@ static int update_nodes_refs(struct btrfs_root *root, u64 bytenr,
 static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path,
 			    unsigned int ext_ref);
 
+/*
+ * Returns >0  Found error, not fatal, should continue process
+ * Returns <0  Fata error, must exit the whole check
+ * returns 0   No error is found
+ */
 static int process_one_leaf_v2(struct btrfs_root *root, struct btrfs_path *path,
 			       struct node_refs *nrefs, int *level, int ext_ref)
 {
@@ -1937,13 +1942,8 @@ again:
 	}
 out:
 	err &= ~LAST_ITEM;
-	/*
-	 * Convert any error bitmap to -EIO, as we should avoid
-	 * mixing positive and negative return value to represent
-	 * error
-	 */
 	if (err && !ret)
-		ret = -EIO;
+		ret = err;
 	return ret;
 }
 
@@ -2213,6 +2213,11 @@ out:
 static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path,
 			    unsigned int ext_ref);
 
+/*
+ * Returns >0  Found error, should continue
+ * Returns 0   No error is found
+ * Returns <0  Fatal error, must exit the whole check
+ */
 static int walk_down_tree_v2(struct btrfs_root *root, struct btrfs_path *path,
 			     int *level, struct node_refs *nrefs, int ext_ref)
 {
@@ -5028,8 +5033,9 @@ static int check_fs_root_v2(struct btrfs_root *root, unsigned int ext_ref)
 	struct btrfs_path path;
 	struct node_refs nrefs;
 	struct btrfs_root_item *root_item = &root->root_item;
-	int ret, wret;
+	int ret;
 	int level;
+	int err = 0;
 
 	/*
 	 * We need to manually check the first inode item(256)
@@ -5063,17 +5069,21 @@ static int check_fs_root_v2(struct btrfs_root *root, unsigned int ext_ref)
 	}
 
 	while (1) {
-		wret = walk_down_tree_v2(root, &path, &level, &nrefs, ext_ref);
-		if (wret < 0)
-			ret = wret;
-		if (wret != 0)
+		ret = walk_down_tree_v2(root, &path, &level, &nrefs, ext_ref);
+		err |= !!ret;
+
+		/* if ret is negative, walk shall stop */
+		if (ret < 0) {
+			ret = err;
 			break;
+		}
 
-		wret = walk_up_tree_v2(root, &path, &level);
-		if (wret < 0)
-			ret = wret;
-		if (wret != 0)
+		ret = walk_up_tree_v2(root, &path, &level);
+		if (ret != 0) {
+			/* Normal exit, reset ret to err */
+			ret = err;
 			break;
+		}
 	}
 
 out:
-- 
2.11.1




^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 10/12] btrfs-progs: fsck-test: Add new test case for file extent false alerts
  2017-02-21  8:34 ` [PATCH v3 10/12] btrfs-progs: fsck-test: Add new test case for file extent false alerts Qu Wenruo
@ 2017-03-01 16:27   ` David Sterba
  0 siblings, 0 replies; 15+ messages in thread
From: David Sterba @ 2017-03-01 16:27 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Tue, Feb 21, 2017 at 04:34:36PM +0800, Qu Wenruo wrote:
> +check_global_prereq xfs_io

> +	run_check xfs_io -c "pwrite 0 64K" "$TEST_MNT/file"

> +	run_check xfs_io -f -c "pwrite 0 1K" "$TEST_MNT/file"

I've converted this to dd as we don't want to depend on xfsprogs
installed for the tests.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 00/12] lowmem mode fixes
  2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
                   ` (11 preceding siblings ...)
  2017-02-21  8:34 ` [PATCH v3 12/12] btrfs-progs: cmds-check.c: walk_down_tree_v2 break cause of leaf process Qu Wenruo
@ 2017-03-01 16:30 ` David Sterba
  12 siblings, 0 replies; 15+ messages in thread
From: David Sterba @ 2017-03-01 16:30 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Tue, Feb 21, 2017 at 04:34:26PM +0800, Qu Wenruo wrote:
> Patches can be fetch from github:
> https://github.com/adam900710/btrfs-progs/tree/lowmem_fixes
> 
> Thanks for reports from Chris Murphy and Christoph Anton Mitterer,
> several new bugs are exposed for lowmem mode fsck.
> 
> Special thank to Christoph, who did rounds of test during the patch
> development.
> 
> The following bugs are fixed in lowmem mode:
> 
> 1) Block group used space false alert
>    If a BLOCK_GROUP_ITEM or its first EXTENT/METADATA_ITEM is located at
>    the first slot of a leaf, search_slot() used by lowmem mode can
>    point to previous leaf, with path->slots[0] beyond valid leaf slots.
> 
>    This makes us to read out uninitialized data, and can abort block
>    group used space check loop, causing a false alert.
> 
>    Fix it with a test case image inside fsck-tests/020/extent-ref-cases
>    Also fix all possible backward search.
>    Reported by Christoph.
> 
> 2) Partly written prealloc extent false alert
>    If a prealloc extent gets partily written, lowmem mode will report
>    prealloc extent shouldn't have csum.
> 
>    Lowmem mode passed wrong variable to csum checking code, causing it
>    to check the whole range of the prealloc extent, making the bug
>    happens.
> 
>    Fix it with a test case inside fsck-tests/020/extent-ref-cases.
>    Reported by Chirs Murphy And Christoph.
> 
> 3) Extent item size false alert.
>    Under certain case, btrfs lowmem mode check reports data backref
>    lost.
>    It's because newly introduced extent item size check aborts normal
>    check routine.
> 
>    It can happen if a data/metadata extent item has no inline ref.
> 
>    Fix it, test case already submitted before and merged, but due to
>    fsck-tests framework bugs, it never get called for lowmem mode.
> 
> 4) Compressed inline data extent
>    The extra check on inline data extent length doesn't take compression
>    into consideration and will cause false alert without outputting any
>    error message.
> 
>    Fix it and add correct error message output for it.
>    Also fix all possible silent error.
>    Reported by Christoph.
> 
> 5) fsck-tests Lowmem mode override fixes
>    Allow lowmem mode override to get called for all tests, and allow
>    them all to pass lowmem mode except fsck-tests/006, which is a
>    original repair mode bug.
> 
> 
> changelog:
>   v2:
>     More generic forward search bug fix, not restricted to block group
>     item.
>     Compressed inline extent false alert fix.
>     Lowmem fsck-test enhance, to allow it really work.
>     Fix walk_down_tree_v2() to continue after non-fatal errors detected
>   v3:
>     Update the last patch to make it works better for incoming lowmem
>     mode repair patchset.

Thanks for the fixes, applied with a few minor fixups in changelogs.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-03-01 16:43 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-21  8:34 [PATCH v3 00/12] lowmem mode fixes Qu Wenruo
2017-02-21  8:34 ` [PATCH v3 01/12] btrfs-progs: lowmem check: Fix several bugs related to afterward search Qu Wenruo
2017-02-21  8:34 ` [PATCH v3 02/12] btrfs-progs: check: Output verbose error when fsck found a bug in any tree Qu Wenruo
2017-02-21  8:34 ` [PATCH v3 03/12] btrfs-progs: lowmem check: Fix false alert in checking data extent csums Qu Wenruo
2017-02-21  8:34 ` [PATCH v3 04/12] btrfs-progs: lowmem check: Fix extent item size false alert Qu Wenruo
2017-02-21  8:34 ` [PATCH v3 05/12] btrfs-progs: lowmem check: Fix false alert on inline compressed extent Qu Wenruo
2017-02-21  8:34 ` [PATCH v3 06/12] btrfs-progs: lowmem check: Fix silent error if first inode item missing Qu Wenruo
2017-02-21  8:34 ` [PATCH v3 07/12] btrfs-progs: tests: Move fsck-tests/015 to fuzz tests Qu Wenruo
2017-02-21  8:34 ` [PATCH v3 08/12] btrfs-progs: fsck-test: Add test image for lowmem mode block group false alert Qu Wenruo
2017-02-21  8:34 ` [PATCH v3 09/12] btrfs-progs: fsck-test: Make 013 compatible with lowmem mode Qu Wenruo
2017-02-21  8:34 ` [PATCH v3 10/12] btrfs-progs: fsck-test: Add new test case for file extent false alerts Qu Wenruo
2017-03-01 16:27   ` David Sterba
2017-02-21  8:34 ` [PATCH v3 11/12] btrfs-progs: fsck: Fix lowmem mode override to allow it skip repair work Qu Wenruo
2017-02-21  8:34 ` [PATCH v3 12/12] btrfs-progs: cmds-check.c: walk_down_tree_v2 break cause of leaf process Qu Wenruo
2017-03-01 16:30 ` [PATCH v3 00/12] lowmem mode fixes David Sterba

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.