Skip to contentSkip to conversation

btrfs-progs: misc-tests: Primary Superblock corruption and recovery using backup Superblock.

PATCH Superseded Lakshmipathi.G 2 participants 3 messages Feb 14, 2017 – Mar 13, 2017 1 message not in the archive Btrfs file system

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: misc-tests: Primary Superblock corruption and recovery using backup Superblock.

---
 .../019-fix-corrupted-superblock/test.sh           | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100755 tests/misc-tests/019-fix-corrupted-superblock/test.sh
tests/misc-tests/019-fix-corrupted-superblock/test.sh new file +37 -0
new file mode 100755
index 0000000..806c775
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# Corrupt primary superblock and restore it using backup superblock.
+#
+
+source $TOP/tests/common
+
+check_prereq btrfs-select-super
+
+setup_root_helper
+prepare_test_dev 512M
+
+superblock_offset=65536
+
+test_superblock_restore()
+{
+	run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV
+
+	# Corrupt superblock checksum
+        dd if=/dev/zero of=$TEST_DEV seek=$superblock_offset bs=1 \
+        count=4  conv=notrunc &> /dev/null
+	run_check_stdout $SUDO_HELPER mount $TEST_DEV $TEST_MNT | \
+	grep -q 'wrong fs type'
+        if [ $? -ne 0 ]; then
+		_fail "Failed to corrupt superblock."
+        fi 
+
+	# Copy backup superblock to primary
+	run_check $TOP/btrfs-select-super -s 1 $TEST_DEV
+	run_check $SUDO_HELPER mount $TEST_DEV $TEST_MNT
+        if [ $? -ne 0 ]; then
+		_fail "Failed to fix superblock."
+        fi 
+	run_check_umount_test_dev
+}
+
+test_superblock_restore
Signature · 1 line
2.7.4

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 13 lines · Qu Wenruo

tests/misc-tests/019-fix-corrupted-superblock/test.sh line 23

Quoted 7 lines
tests/misc-tests/019-fix-corrupted-superblock/test.sh new file +5 -0
+	# Corrupt superblock checksum
+        dd if=/dev/zero of=$TEST_DEV seek=$superblock_offset bs=1 \
+        count=4  conv=notrunc &> /dev/null
+	run_check_stdout $SUDO_HELPER mount $TEST_DEV $TEST_MNT | \
+	grep -q 'wrong fs type'

What about using btrfs check instead of trying to mount it?

This could emit the need to use $SUDO_HELPER, and could catch super error more accurate.

Quoted 8 lines

tests/misc-tests/019-fix-corrupted-superblock/test.sh line 30

Quoted 7 lines
tests/misc-tests/019-fix-corrupted-superblock/test.sh new file +7 -0
+        if [ $? -ne 0 ]; then
+		_fail "Failed to corrupt superblock."
+        fi
+
+	# Copy backup superblock to primary
+	run_check $TOP/btrfs-select-super -s 1 $TEST_DEV
+	run_check $SUDO_HELPER mount $TEST_DEV $TEST_MNT

Same here.

I started with 'btrfs check' and 'btrfs check --repair' but it seems like --repair don't fix the corruption. So just moved away from using it.

After you mentioned, now I see 'btrfs check' will be helpful. Will make these changes.

Cheers.
Lakshmipathi.G

#3 lore raw
Quoted 22 lines · Lakshmipathi.G
Quoted 13 lines · Qu Wenruo

tests/misc-tests/019-fix-corrupted-superblock/test.sh line 23

Quoted 7 lines
tests/misc-tests/019-fix-corrupted-superblock/test.sh new file +5 -0
+	# Corrupt superblock checksum
+        dd if=/dev/zero of=$TEST_DEV seek=$superblock_offset bs=1 \
+        count=4  conv=notrunc &> /dev/null
+	run_check_stdout $SUDO_HELPER mount $TEST_DEV $TEST_MNT | \
+	grep -q 'wrong fs type'

What about using btrfs check instead of trying to mount it?

This could emit the need to use $SUDO_HELPER, and could catch super error more accurate.

Quoted 8 lines

tests/misc-tests/019-fix-corrupted-superblock/test.sh line 30

Quoted 7 lines
tests/misc-tests/019-fix-corrupted-superblock/test.sh new file +7 -0
+        if [ $? -ne 0 ]; then
+		_fail "Failed to corrupt superblock."
+        fi
+
+	# Copy backup superblock to primary
+	run_check $TOP/btrfs-select-super -s 1 $TEST_DEV
+	run_check $SUDO_HELPER mount $TEST_DEV $TEST_MNT

Same here.

Quoted 2 lines

I started with 'btrfs check' and 'btrfs check --repair' but it seems like --repair don't fix the corruption. So just moved away from using it.

Check --repair will not fix the superblock checksum as it's not clear whether the rest of the superblock is ok or not.