Skip to contentSkip to conversation

btrfs-progs: fsck-tests: missing csum test script

PATCH In review Lakshmipathi.G 2 participants 3 messages Jan 5, 2017 – Jan 25, 2017 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: fsck-tests: missing csum test script

---
 tests/fsck-tests/027-missing-data-csum/test.sh | 39 ++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100755 tests/fsck-tests/027-missing-data-csum/test.sh
tests/fsck-tests/027-missing-data-csum/test.sh new file +39 -0
new file mode 100755
index 0000000..6d1dc97
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+source $TOP/tests/common
+
+check_prereq btrfs-corrupt-block
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+prepare_test_dev 512M
+
+
+# simulate missing csum error and repair using init-csum option
+test_csum_corruption()
+{
+	run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV
+
+	run_check_mount_test_dev
+
+	export DATASET_SIZE=1
+	generate_dataset small
+
+	run_check_umount_test_dev
+
+	# find bytenr
+	bytenr=`$SUDO_HELPER $TOP/btrfs-debug-tree $TEST_DEV | \
+	grep "EXTENT_CSUM EXTENT_CSUM" | \
+	cut -f1 -d')' | awk '{print $6}'`
+
+	# corrupt csum bytenr
+	run_check $SUDO_HELPER $TOP/btrfs-corrupt-block -C $bytenr $TEST_DEV
+
+	$SUDO_HELPER $TOP/btrfs check $TEST_DEV >& /dev/null && \
+			_fail "btrfs check failed to detect missing csum."
+	run_check $SUDO_HELPER $TOP/btrfs check --repair --init-csum $TEST_DEV
+	run_check $SUDO_HELPER $TOP/btrfs check  $TEST_DEV
+}
+
+test_csum_corruption
Signature · 1 line
2.7.4
#1 lore raw

It's not clear from the test what's the purpose. There's one corrupted csum but the whole csum tree rebuild option is used. This is a pretty basic check that the --init-csum-tree works, so it should be mentioned somewhere in the test script.

Quoted 28 lines · Lakshmipathi.G
---
 tests/fsck-tests/027-missing-data-csum/test.sh | 39 ++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100755 tests/fsck-tests/027-missing-data-csum/test.sh
tests/fsck-tests/027-missing-data-csum/test.sh new file +16 -0
new file mode 100755
index 0000000..6d1dc97
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+source $TOP/tests/common
+
+check_prereq btrfs-corrupt-block
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+prepare_test_dev 512M
+
+
+# simulate missing csum error and repair using init-csum option
+test_csum_corruption()
+{
+	run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV

tests/fsck-tests/027-missing-data-csum/test.sh line 26

Quoted 10 lines
tests/fsck-tests/027-missing-data-csum/test.sh new file +10 -0
+
+	run_check_mount_test_dev
+
+	export DATASET_SIZE=1
+	generate_dataset small
+
+	run_check_umount_test_dev
+
+	# find bytenr
+	bytenr=`$SUDO_HELPER $TOP/btrfs-debug-tree $TEST_DEV | \

Please don't use btrfs-debug-tree, it's been obsoleted by the dump-tree subcommand. And you can use the '-t csum' option to dump just the csum tree.

tests/fsck-tests/027-missing-data-csum/test.sh line 28

Quoted 2 lines
tests/fsck-tests/027-missing-data-csum/test.sh new file +2 -0
+	grep "EXTENT_CSUM EXTENT_CSUM" | \
+	cut -f1 -d')' | awk '{print $6}'`

This can be simplified to one sed command.

tests/fsck-tests/027-missing-data-csum/test.sh line 34

Quoted 6 lines
tests/fsck-tests/027-missing-data-csum/test.sh new file +6 -0
+
+	# corrupt csum bytenr
+	run_check $SUDO_HELPER $TOP/btrfs-corrupt-block -C $bytenr $TEST_DEV
+
+	$SUDO_HELPER $TOP/btrfs check $TEST_DEV >& /dev/null && \
+			_fail "btrfs check failed to detect missing csum."

Here we want to capture the output from 'check' for analysis in case of problems.

Quoted 5 lines
tests/fsck-tests/027-missing-data-csum/test.sh new file +5 -0
+	run_check $SUDO_HELPER $TOP/btrfs check --repair --init-csum $TEST_DEV
+	run_check $SUDO_HELPER $TOP/btrfs check  $TEST_DEV
+}
+
+test_csum_corruption
#2 lore raw
Quoted 4 lines · David Sterba

It's not clear from the test what's the purpose. There's one corrupted csum but the whole csum tree rebuild option is used. This is a pretty basic check that the --init-csum-tree works, so it should be mentioned somewhere in the test script.

I'll rename directory to 027-verify-init-csum-tree instead of current one.

Is it possible, to fix only the corrupted csum instead of re-building the csum-tree?

Quoted 6 lines

Please don't use btrfs-debug-tree, it's been obsoleted by the dump-tree subcommand. And you can use the '-t csum' option to dump just the csum tree.

Quoted 7 lines

This can be simplified to one sed command.

Here we want to capture the output from 'check' for analysis in case of problems.

Will fix above three issues with next patch.