Skip to contentSkip to conversation

btrfs-progs: check: Detect overlapping csum item

PATCH In review Qu Wenruo 2 participants 4 messages Mar 4, 2020 – May 25, 2020 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

cover btrfs-progs: check: Detect overlapping csum item

There is one report about tree-checker rejecting overlapping csum item.

I haven't yet seen another report, thus the problem doesn't look widespread, thus maybe some regression in older kernels.

At least let btrfs check to detect such problem.
If we had another report, I'll spending extra time for the repair functionality (it's not that simple, as it involves a lot of csum item operation, and unexpected overlapping range).

Qu Wenruo (2):
btrfs-progs: check: Detect overlap csum items
btrfs-progs: fsck-tests: Add test image for overlapping csum item

 check/main.c                                  |   9 +++++++++
 .../overlap_csum_item.img.xz                  | Bin 0 -> 2172 bytes
 .../fsck-tests/045-overlap-csum-item/test.sh  |  19 ++++++++++++++++++
 3 files changed, 28 insertions(+)
 create mode 100644 tests/fsck-tests/045-overlap-csum-item/overlap_csum_item.img.xz
 create mode 100755 tests/fsck-tests/045-overlap-csum-item/test.sh
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/2 btrfs-progs: check: Detect overlap csum items

There is a report about csum item overlap, which makes newer btrfs kernel to reject it due to tree-checker.

Now let btrfs-progs have the same ability to detect such problem.

---
 check/main.c | 9 +++++++++
 1 file changed, 9 insertions(+)
check/main.c +9 -0
index d02dd1636852..c526c72d158e 100644
@@ -5893,6 +5893,7 @@ static int check_csums(struct btrfs_root *root)
 	struct btrfs_path path;
 	struct extent_buffer *leaf;
 	struct btrfs_key key;
+	u64 last_data_end = 0;
 	u64 offset = 0, num_bytes = 0;
 	u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
 	int errors = 0;
@@ -5952,6 +5953,13 @@ static int check_csums(struct btrfs_root *root)
 			continue;
 		}
 
+		if (key.offset < last_data_end) {
+			error(
+	"csum overlap, current bytenr=%llu prev_end=%llu, eb=%llu slot=%u",
+				key.offset, last_data_end, leaf->start,
+				path.slots[0]);
+			errors++;
+		}
 		data_len = (btrfs_item_size_nr(leaf, path.slots[0]) /
 			      csum_size) * root->fs_info->sectorsize;
 		if (!verify_csum)
@@ -5982,6 +5990,7 @@ skip_csum_check:
 			num_bytes = 0;
 		}
 		num_bytes += data_len;
+		last_data_end = key.offset + data_len;
 		path.slots[0]++;
 	}
 
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH 2/2 btrfs-progs: fsck-tests: Add test image for overlapping csum item

In reply to Qu Wenruo

The image has a csum item overlap with next csum item, make sure btrfs check can detect it.

---
 .../overlap_csum_item.img.xz                  | Bin 0 -> 2172 bytes
 .../fsck-tests/045-overlap-csum-item/test.sh  |  19 ++++++++++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 tests/fsck-tests/045-overlap-csum-item/overlap_csum_item.img.xz
 create mode 100755 tests/fsck-tests/045-overlap-csum-item/test.sh
tests/fsck-tests/045-overlap-csum-item/overlap_csum_item.img.xz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..9bcf152c7c590d4dca915f5d1ecb15fb4a58af84
GIT binary patch
tests/fsck-tests/045-overlap-csum-item/test.sh new file +19 -0
new file mode 100755
index 000000000000..06649ed9331c
@@ -0,0 +1,19 @@
+#!/bin/bash
+#
+# Verify that check can detect overlapped csum items
+#
+# There is one report of overlap csum items, causing tree-checker to reject
+# the csum tree.
+#
+# Make sure btrfs check can at least detect such error
+
+source "$TEST_TOP/common"
+
+check_prereq btrfs
+
+check_image() {
+	run_mustfail "overlapping csum item not detected" \
+		"$TOP/btrfs" check "$1"
+}
+
+check_all_images
Signature · 1 line
2.25.1
#3 lore raw
In reply to Qu Wenruo
Quoted 1 line · Qu Wenruo

There is one report about tree-checker rejecting overlapping csum item.

Do you have link of the report?

I think the bug has been fixed by "btrfs: fix corrupt log due to concurrent fsync of inodes with shared extents".

Quoted 11 lines

I haven't yet seen another report, thus the problem doesn't look widespread, thus maybe some regression in older kernels.

At least let btrfs check to detect such problem.
If we had another report, I'll spending extra time for the repair functionality (it's not that simple, as it involves a lot of csum item operation, and unexpected overlapping range).

Qu Wenruo (2):
btrfs-progs: check: Detect overlap csum items
btrfs-progs: fsck-tests: Add test image for overlapping csum item

Added to devel.