Skip to contentSkip to conversation

btrfs: Extend btrfs/003 device removal test

PATCH In review Nikolay Borisov 2 participants 2 messages Mar 19, 2019 – Mar 23, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 btrfs: Extend btrfs/003 device removal test

When a device is deleted/removed from a btrfs filesystem the kernel ensures all superblocks on said device are zeroed out. Test for this behavior. Since btrfs inspect-internal dump-super always return success I cannot test for the return value of the command. Instead there are 2 cases to handle:

1. When the device is smaller than the requested super block copy, i.e. super block copy 2 resides at 256GB. In such cases btrfs command just returns blank screen

2. When the device is removed and a valid offset of the super block is queried btrfs command returns a textual error to stderr.

---
V2:
* properly assign the return value of the last command expression to ret

 tests/btrfs/003 | 8 ++++++++
 1 file changed, 8 insertions(+)
tests/btrfs/003 +8 -0
index 22aa57aad0b9..a805826ce891 100755
@@ -161,6 +161,14 @@ _test_remove()
 	dev_del=`echo ${SCRATCH_DEV_POOL} | awk '{print $NF}'`
 	$BTRFS_UTIL_PROG device delete $dev_del $SCRATCH_MNT || _fail "btrfs device delete failed"
 	$BTRFS_UTIL_PROG filesystem show $SCRATCH_DEV 2>&1 | grep $dev_del >> $seqres.full && _fail "btrfs still shows the deleted dev"
+	for i in {0..2}; do
+		local output=$($BTRFS_UTIL_PROG inspect-internal dump-super -s $i $dev_del 2>&1)
+		$BTRFS_UTIL_PROG inspect-internal dump-super -s $i $dev_del 2>&1 | grep -q "bad magic"
+		ret=$?
+		if [[ "$output" != "" && $ret -eq 1 ]]; then
+			_fail "Delete dev superblocks not scratched"
+		fi
+	done
 	_scratch_unmount
 }
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 6 lines · Nikolay Borisov

When a device is deleted/removed from a btrfs filesystem the kernel ensures all superblocks on said device are zeroed out. Test for this behavior. Since btrfs inspect-internal dump-super always return success I cannot test for the return value of the command. Instead there are 2 cases to handle:

Quoted 8 lines

1. When the device is smaller than the requested super block copy, i.e. super block copy 2 resides at 256GB. In such cases btrfs command just returns blank screen

2. When the device is removed and a valid offset of the super block is queried btrfs command returns a textual error to stderr.

I think this test deserves a new test itself, not being embedded in an existing test randomly.

Thanks,
Eryu

Quoted 29 lines

---
V2:
* properly assign the return value of the last command expression to ret

 tests/btrfs/003 | 8 ++++++++
 1 file changed, 8 insertions(+)
tests/btrfs/003 +8 -0
index 22aa57aad0b9..a805826ce891 100755
@@ -161,6 +161,14 @@ _test_remove()
 	dev_del=`echo ${SCRATCH_DEV_POOL} | awk '{print $NF}'`
 	$BTRFS_UTIL_PROG device delete $dev_del $SCRATCH_MNT || _fail "btrfs device delete failed"
 	$BTRFS_UTIL_PROG filesystem show $SCRATCH_DEV 2>&1 | grep $dev_del >> $seqres.full && _fail "btrfs still shows the deleted dev"
+	for i in {0..2}; do
+		local output=$($BTRFS_UTIL_PROG inspect-internal dump-super -s $i $dev_del 2>&1)
+		$BTRFS_UTIL_PROG inspect-internal dump-super -s $i $dev_del 2>&1 | grep -q "bad magic"
+		ret=$?
+		if [[ "$output" != "" && $ret -eq 1 ]]; then
+			_fail "Delete dev superblocks not scratched"
+		fi
+	done
 	_scratch_unmount
 }
 
Signature · 1 line
2.7.4