fstests: btrfs: 159 superblock corruption test case
PATCH 1/1 fstests: btrfs: 159 superblock corruption test case
Verify if the superblock corruption is handled correctly.
--- tests/btrfs/159 | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/159.out | 35 +++++++++++++ tests/btrfs/group | 1 + 3 files changed, 178 insertions(+) create mode 100755 tests/btrfs/159 create mode 100644 tests/btrfs/159.out
tests/btrfs/159 new file +142 -0
@@ -0,0 +1,142 @@ +#! /bin/bash +# FS QA Test 159 +# +# Test if the superblock corruption is handled correctly. +# - Check and validate superblock csum in mount and scan context +# - Check and validate superblock for all disks in the fs +# - Make sure if the copies are really a copy of the primary superblock +# +#--------------------------------------------------------------------- +# Copyright (c) 2018 Oracle. All Rights Reserved. +# Author: Anand Jain <[email protected]> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#--------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" +status=1 # failure is the default! + +_cleanup() +{ + _scratch_dev_pool_put +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/module + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here + +_supported_fs btrfs +_supported_os Linux +_require_scratch_dev_pool 2 +_require_loadable_fs_module "btrfs" +_require_command "$WIPEFS_PROG" wipefs + +_scratch_dev_pool_get 2 + +MNT_OPT=$(echo $MOUNT_OPTIONS | cut -d" " -f2-) +DEV_GOOD=$(echo $SCRATCH_DEV_POOL | awk '{print $1}') +DEV_BAD=$(echo $SCRATCH_DEV_POOL | awk '{print $2}') + +wipe() +{ + $WIPEFS_PROG -a $DEV_GOOD > /dev/null 2>&1 + $WIPEFS_PROG -a $DEV_BAD > /dev/null 2>&1 +} + +# If copy1 fsid does not match with primary fail the scan thus the mount as well +check_copy1_fsid() +{ + local bytenr=67108864 + echo -e "\\ncheck_copy1_fsid\\n{" | tee -a $seqres.full + + wipe + $MKFS_BTRFS_PROG -fq $DEV_GOOD + $MKFS_BTRFS_PROG -fq $DEV_BAD + _reload_fs_module "btrfs" + + dd status=none of=$DEV_BAD if=$DEV_GOOD ibs=1 obs=1 skip=$bytenr seek=$bytenr count=4K|\ + tee -a $seqres.full + + _mount -o $MNT_OPT $DEV_BAD $SCRATCH_MNT 2>&1 | _filter_scratch_pool + + echo -e "good\\n}" | tee -a $seqres.full +} + +# As in Linux kernel 4.16 if the primary is corrupted mount will fail. +# Which might change in the long run. +check_primary() +{ + local bytenr=65536 + echo -e "\\ncheck_primary\\n{" | tee -a $seqres.full + + wipe + _scratch_pool_mkfs "-mraid1 -draid1" + _reload_fs_module "btrfs" + + #To corrupt a disk block, read in hex, write in dec + od -j$bytenr -N1 -An -x $DEV_BAD |\ + dd status=none of=$DEV_BAD ibs=1 obs=1 seek=$bytenr count=1|\ + tee -a $seqres.full + _mount -o $MNT_OPT,device=$DEV_GOOD $DEV_BAD $SCRATCH_MNT 2>&1 | _filter_scratch_pool + + echo -e "good\\n}" | tee -a $seqres.full +} + +# If copy1 or copy2 is corrupted we still should be able to mount +check_copy1() +{ + local bytenr=67108864 + echo -e "\\ncheck_copy1\\n{" | tee -a $seqres.full + + wipe + _scratch_pool_mkfs "-mraid1 -draid1" + _reload_fs_module "btrfs" + + #corrupt the disk block bytenr, read in hex, write in dec + od -j$bytenr -N1 -An -x $DEV_BAD |\ + dd status=none of=$DEV_BAD ibs=1 obs=1 seek=$bytenr count=1|\ + tee -a $seqres.full + _mount -o $MNT_OPT,device=$DEV_GOOD $DEV_BAD $SCRATCH_MNT 2>&1 | _filter_scratch_pool + + echo -e "good\\n}" | tee -a $seqres.full + + _scratch_unmount +} + +check_copy1_fsid + +check_primary +check_copy1 + +echo -e "\\nReverse the good and bad device" +# Generally devid 1 is used to read tree at the mount time, now reverse the +# devid on which the corrupt superblock will reside. +dev_tmp=$DEV_GOOD +DEV_GOOD=$DEV_BAD +DEV_BAD=$dev_tmp +check_primary +check_copy1 + +status=0 +exit
tests/btrfs/159.out new file +35 -0
@@ -0,0 +1,35 @@ +QA output created by 159 + +check_copy1_fsid +{ +mount: wrong fs type, bad option, bad superblock on SCRATCH_DEV, + missing codepage or helper program, or other error + + In some cases useful info is found in syslog - try + dmesg | tail or so. +good +} + +check_primary +{ +mount: mount SCRATCH_DEV on /scratch failed: Structure needs cleaning +good +} + +check_copy1 +{ +good +} + +Reverse the good and bad device + +check_primary +{ +mount: mount SCRATCH_DEV on /scratch failed: Structure needs cleaning +good +} + +check_copy1 +{ +good +}
tests/btrfs/group +1 -0
@@ -161,3 +161,4 @@ 156 auto quick trim 157 auto quick raid 158 auto quick raid scrub +159 auto quick
Signature · 1 line
2.7.0
Quoted 38 lines · Anand Jain
Verify if the superblock corruption is handled correctly.
Signed-off-by Anand Jain <[email protected]>--- tests/btrfs/159 | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/159.out | 35 +++++++++++++ tests/btrfs/group | 1 + 3 files changed, 178 insertions(+) create mode 100755 tests/btrfs/159 create mode 100644 tests/btrfs/159.outtests/btrfs/159 new file +21
-0@@ -0,0 +1,142 @@ +#! /bin/bash +# FS QA Test 159 +# +# Test if the superblock corruption is handled correctly. +# - Check and validate superblock csum in mount and scan context +# - Check and validate superblock for all disks in the fs +# - Make sure if the copies are really a copy of the primary superblock +# +#--------------------------------------------------------------------- +# Copyright (c) 2018 Oracle. All Rights Reserved. +# Author: Anand Jain <[email protected]> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +#
tests/btrfs/159 line 31
Quoted 10 lines
tests/btrfs/159 new file +10
-0+# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#--------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" +status=1 # failure is the default!
Please use './new btrfs' to generate new test template, which defines variables like 'tmp' and 'here', these variables may not be used in the test explicitly, but they could be used by some helper functions, especially the "$tmp" var. (Or please don't remove them from template :)
Quoted 16 lines
tests/btrfs/159 new file +16
-0+ +_cleanup() +{ + _scratch_dev_pool_put +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/module + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here
tests/btrfs/159 line 57
Quoted 10 lines
tests/btrfs/159 new file +10
-0+ +_supported_fs btrfs +_supported_os Linux +_require_scratch_dev_pool 2 +_require_loadable_fs_module "btrfs" +_require_command "$WIPEFS_PROG" wipefs + +_scratch_dev_pool_get 2 + +MNT_OPT=$(echo $MOUNT_OPTIONS | cut -d" " -f2-)
I'm not sure about the purpose of this MNT_OPT, and it could be empty and causes problems in test. Please see below.
Quoted 4 lines
tests/btrfs/159 new file +4
-0+DEV_GOOD=$(echo $SCRATCH_DEV_POOL | awk '{print $1}') +DEV_BAD=$(echo $SCRATCH_DEV_POOL | awk '{print $2}') + +wipe()
tests/btrfs/159 line 71
Quoted 10 lines
tests/btrfs/159 new file +10
-0+{ + $WIPEFS_PROG -a $DEV_GOOD > /dev/null 2>&1 + $WIPEFS_PROG -a $DEV_BAD > /dev/null 2>&1 +} + +# If copy1 fsid does not match with primary fail the scan thus the mount as well +check_copy1_fsid() +{ + local bytenr=67108864 + echo -e "\\ncheck_copy1_fsid\\n{" | tee -a $seqres.full
Hmm, I don't think the "{ }" block is necessary in .out file, IMHO it makes the diff context harder to read when test fails. Just echo the test name would be fine.
tests/btrfs/159 line 81
Quoted 10 lines
tests/btrfs/159 new file +10
-0+ + wipe + $MKFS_BTRFS_PROG -fq $DEV_GOOD + $MKFS_BTRFS_PROG -fq $DEV_BAD + _reload_fs_module "btrfs" + + dd status=none of=$DEV_BAD if=$DEV_GOOD ibs=1 obs=1 skip=$bytenr seek=$bytenr count=4K|\ + tee -a $seqres.full + + _mount -o $MNT_OPT $DEV_BAD $SCRATCH_MNT 2>&1 | _filter_scratch_pool
When $MOUNT_OPTIONS is empty, this mount fails as
+mount: can't find /mnt/scratch in /etc/fstab
And I think we need to umount $SCRATCH_MNT here in case a buggy btrfs module allowed the mount, as the next test assumes the device is not mounted anywhere. Otherwise I see failures like:
+ERROR: /dev/loop1 is mounted
+mount failed
Quoted 10 lines
tests/btrfs/159 new file +10
-0+ + echo -e "good\\n}" | tee -a $seqres.full +} + +# As in Linux kernel 4.16 if the primary is corrupted mount will fail. +# Which might change in the long run. +check_primary() +{ + local bytenr=65536 + echo -e "\\ncheck_primary\\n{" | tee -a $seqres.full
tests/btrfs/159 line 101
Quoted 10 lines
tests/btrfs/159 new file +10
-0+ + wipe + _scratch_pool_mkfs "-mraid1 -draid1" + _reload_fs_module "btrfs" + + #To corrupt a disk block, read in hex, write in dec + od -j$bytenr -N1 -An -x $DEV_BAD |\ + dd status=none of=$DEV_BAD ibs=1 obs=1 seek=$bytenr count=1|\ + tee -a $seqres.full + _mount -o $MNT_OPT,device=$DEV_GOOD $DEV_BAD $SCRATCH_MNT 2>&1 | _filter_scratch_pool
Same here, need to umount $SCRATCH_MNT.
Also, if a mount failure is expected (as it's recorded in the golden image file), you need _filter_error_mount here, and _filter_scratch_pool can be dropped, because _filter_error_mount will remove all $SCRATCH_DEV/MNT from the mount output. For more details please see commit 94d3a4f00cbd ("fstests: filter mount error message for EUCLEAN and ESTALE").
Thanks,
Eryu
Quoted 98 lines
tests/btrfs/159 new file +41
-0+ + echo -e "good\\n}" | tee -a $seqres.full +} + +# If copy1 or copy2 is corrupted we still should be able to mount +check_copy1() +{ + local bytenr=67108864 + echo -e "\\ncheck_copy1\\n{" | tee -a $seqres.full + + wipe + _scratch_pool_mkfs "-mraid1 -draid1" + _reload_fs_module "btrfs" + + #corrupt the disk block bytenr, read in hex, write in dec + od -j$bytenr -N1 -An -x $DEV_BAD |\ + dd status=none of=$DEV_BAD ibs=1 obs=1 seek=$bytenr count=1|\ + tee -a $seqres.full + _mount -o $MNT_OPT,device=$DEV_GOOD $DEV_BAD $SCRATCH_MNT 2>&1 | _filter_scratch_pool + + echo -e "good\\n}" | tee -a $seqres.full + + _scratch_unmount +} + +check_copy1_fsid + +check_primary +check_copy1 + +echo -e "\\nReverse the good and bad device" +# Generally devid 1 is used to read tree at the mount time, now reverse the +# devid on which the corrupt superblock will reside. +dev_tmp=$DEV_GOOD +DEV_GOOD=$DEV_BAD +DEV_BAD=$dev_tmp +check_primary +check_copy1 + +status=0 +exittests/btrfs/159.out new file +35
-0@@ -0,0 +1,35 @@ +QA output created by 159 + +check_copy1_fsid +{ +mount: wrong fs type, bad option, bad superblock on SCRATCH_DEV, + missing codepage or helper program, or other error + + In some cases useful info is found in syslog - try + dmesg | tail or so. +good +} + +check_primary +{ +mount: mount SCRATCH_DEV on /scratch failed: Structure needs cleaning +good +} + +check_copy1 +{ +good +} + +Reverse the good and bad device + +check_primary +{ +mount: mount SCRATCH_DEV on /scratch failed: Structure needs cleaning +good +} + +check_copy1 +{ +good +}tests/btrfs/group +1
-0@@ -161,3 +161,4 @@ 156 auto quick trim 157 auto quick raid 158 auto quick raid scrub +159 auto quickSignature · 6 lines
2.7.0 -- To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines
tests/btrfs/159 line 31
Quoted 6 lines
tests/btrfs/159 new file +4
-0+seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" +status=1 # failure is the default!Please use './new btrfs' to generate new test template, which defines variables like 'tmp' and 'here', these variables may not be used in the test explicitly, but they could be used by some helper functions, especially the "$tmp" var. (Or please don't remove them from template :)
Ok. May be its a good idea to have an _init() to set mandatory stuffs?
Quoted 4 lines
Quoted 1 line
+MNT_OPT=$(echo $MOUNT_OPTIONS | cut -d" " -f2-)
I'm not sure about the purpose of this
MNT_OPT, and it could be empty and causes problems in test. Please see below.
Test case here need control of the device(s) used for the mount. Thats awkward I missed no mount-option secnario. Will fix.
Quoted 5 lines
tests/btrfs/159 line 71
Quoted 1 line
tests/btrfs/159 new file +1
-0+ echo -e "\\ncheck_copy1_fsid\\n{" | tee -a $seqres.fullHmm, I don't think the "{ }" block is necessary in .out file, IMHO it makes the diff context harder to read when test fails. Just echo the test name would be fine.
Ok. Will take that out.
Review
Quoted 12 lines
tests/btrfs/159 line 81
Quoted 1 line
tests/btrfs/159 new file +1
-0+ _mount -o $MNT_OPT $DEV_BAD $SCRATCH_MNT 2>&1 | _filter_scratch_poolWhen $MOUNT_OPTIONS is empty, this mount fails as
+mount: can't find
/mnt/scratchin/etc/fstabAnd I think we need to umount $SCRATCH_MNT here in case a buggy btrfs module allowed the mount, as the next test assumes the device is not mounted anywhere. Otherwise I see failures like:
(quoted diff) +2
-0+ERROR: /dev/loop1 is mounted +mount failed
got it.
Quoted 23 lines
Quoted 10 lines
tests/btrfs/159 new file +10
-0+ + echo -e "good\\n}" | tee -a $seqres.full +} + +# As in Linux kernel 4.16 if the primary is corrupted mount will fail. +# Which might change in the long run. +check_primary() +{ + local bytenr=65536 + echo -e "\\ncheck_primary\\n{" | tee -a $seqres.fulltests/btrfs/159 line 101
Quoted 10 lines
tests/btrfs/159 new file +10
-0+ + wipe + _scratch_pool_mkfs "-mraid1 -draid1" + _reload_fs_module "btrfs" + + #To corrupt a disk block, read in hex, write in dec + od -j$bytenr -N1 -An -x $DEV_BAD |\ + dd status=none of=$DEV_BAD ibs=1 obs=1 seek=$bytenr count=1|\ + tee -a $seqres.full + _mount -o $MNT_OPT,device=$DEV_GOOD $DEV_BAD $SCRATCH_MNT 2>&1 | _filter_scratch_poolSame here, need to umount $SCRATCH_MNT.
Quoted 6 lines
Also, if a mount failure is expected (as it's recorded in the golden image file), you need
_filter_error_mounthere, and_filter_scratch_poolcan be dropped, because_filter_error_mountwill remove all $SCRATCH_DEV/MNT from the mount output. For more details please see commit94d3a4f00cbd("fstests: filter mount error message for EUCLEAN and ESTALE").
I am fixing this in v2.
Thanks, Anand
PATCH v2 1/1 fstests: btrfs/159 superblock corruption test case
In reply to Anand JainVerify if the superblock corruption is handled correctly.
---v1->v2:
$subject slightly changed
Added more info about the test-case
Keep the stuff from the ./new btrfs
Add mount_opt_minus_args() to get the options (if) set at the config file Move DEV_GOOD & DEV_BAD to where it starts to use
To help debugging added run_check where possible
Remove {} in the out file
Use _filter_error_mount for mount fail cases other than -EINVAL
tests/btrfs/159 | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/159.out | 23 +++++++ tests/btrfs/group | 1 + 3 files changed, 201 insertions(+) create mode 100755 tests/btrfs/159 create mode 100644 tests/btrfs/159.out
tests/btrfs/159 new file +177 -0
@@ -0,0 +1,177 @@ +#! /bin/bash +# FS QA Test 159 +# +# Test if the superblock corruption is handled correctly: +# - Test fsid miss-match (csum ok) between primary and copy superblock +# Fixed by the ML patch: +# btrfs: check if the fsid in the primary sb and copy sb are same +# - Test if the mount fails if the primary superblock csum is +# corrupted on any disk +# - Test if the mount does not fail if the copy1 sb csum is corrupted +# Fixed by the ML patches: +# btrfs: verify superblock checksum during scan +# btrfs: verify checksum for all devices in mount context +# +#--------------------------------------------------------------------- +# Copyright (c) 2018 Oracle. All Rights Reserved. +# Author: Anand Jain <[email protected]> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* + _scratch_dev_pool_put +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/module + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here + +_supported_fs btrfs +_supported_os Linux +_require_scratch_dev_pool 2 +_require_loadable_fs_module "btrfs" +_require_command "$WIPEFS_PROG" wipefs + +_scratch_dev_pool_get 2 + +mount_opt_minus_args() +{ + local nr + local mnt_opt="" + + nr=`_scratch_mount_options | awk '{print NF}'` + if [ $nr -eq 4 ]; then + #gets only the mount option set in the config file + mnt_opt=`_scratch_mount_options | awk '{print $2}'` + fi + #Append the additional opts provide as func args. + #Make sure -o is not echo-ed if both config file mnt-option + #and the test case mnt-option are null. + if [ -z $mnt_opt ]; then + if [ ! -z $* ]; then + echo "-o $*" + fi + else + if [ -z $* ]; then + echo "-o $mnt_opt" + else + echo "-o $mnt_opt,$*" + fi + fi +} + +wipe() +{ + $WIPEFS_PROG -a $DEV_GOOD > /dev/null 2>&1 + $WIPEFS_PROG -a $DEV_BAD > /dev/null 2>&1 +} + +# Test for fsid miss-match (csum ok) with primary and copy superblock. +check_copy1_fsid() +{ + local bytenr=67108864 + echo -e "\\ncheck_copy1_fsid\\n" | tee -a $seqres.full + + wipe + $MKFS_BTRFS_PROG -fq $DEV_GOOD + $MKFS_BTRFS_PROG -fq $DEV_BAD + _reload_fs_module "btrfs" + + run_check dd status=none of=$DEV_BAD if=$DEV_GOOD ibs=1 obs=1\ + skip=$bytenr seek=$bytenr count=4K + + #must fail + _mount `mount_opt_minus_args` $DEV_BAD $SCRATCH_MNT 2>&1 | _filter_scratch_pool + #If mount didn't fail + _scratch_unmount > /dev/null 2>&1 +} + +# Test if the mount fails if the primary superblock csum is corrupted. +check_primary() +{ + local bytenr=65536 + echo -e "\\ncheck_primary\\n" | tee -a $seqres.full + + wipe + _scratch_pool_mkfs "-mraid1 -draid1" + _reload_fs_module "btrfs" + + #corrupt bytenr DEV_BAD + od -j$bytenr -N1 -An -x $DEV_BAD |\ + dd status=none of=$DEV_BAD ibs=1 obs=1 seek=$bytenr count=1 conv=fsync + + #must fail + _mount `mount_opt_minus_args device=$DEV_GOOD` $DEV_BAD $SCRATCH_MNT 2>&1 |\ + _filter_error_mount + + #If mount didn't fail + _scratch_unmount > /dev/null 2>&1 +} + +# If copy1 is corrupted we still should be able to mount, check that. +check_copy1() +{ + local bytenr=67108864 + echo -e "\\ncheck_copy1" | tee -a $seqres.full + + wipe + _scratch_pool_mkfs "-mraid1 -draid1" + _reload_fs_module "btrfs" + + #corrupt bytenr DEV_BAD + od -j$bytenr -N1 -An -x $DEV_BAD |\ + dd status=none of=$DEV_BAD ibs=1 obs=1 seek=$bytenr count=1 conv=fsync + + _mount `mount_opt_minus_args device=$DEV_GOOD` $DEV_BAD $SCRATCH_MNT 2>&1 |\ + _filter_error_mount + _scratch_unmount +} + +DEV_GOOD=$(echo $SCRATCH_DEV_POOL | awk '{print $1}') +DEV_BAD=$(echo $SCRATCH_DEV_POOL | awk '{print $2}') + +check_copy1_fsid +check_primary +check_copy1 + +echo -e "\\nReverse good and bad devices" +# For csum verification on devid 2, reverse the good and bad disks. +DEV_BAD=$(echo $SCRATCH_DEV_POOL | awk '{print $1}') +DEV_GOOD=$(echo $SCRATCH_DEV_POOL | awk '{print $2}') +check_primary +check_copy1 + +# success, all done +status=0 +exit
tests/btrfs/159.out new file +23 -0
@@ -0,0 +1,23 @@ +QA output created by 159 + +check_copy1_fsid + +mount: wrong fs type, bad option, bad superblock on SCRATCH_DEV, + missing codepage or helper program, or other error + + In some cases useful info is found in syslog - try + dmesg | tail or so. + +check_primary + +mount: Structure needs cleaning + +check_copy1 + +Reverse good and bad devices + +check_primary + +mount: Structure needs cleaning + +check_copy1
tests/btrfs/group +1 -0
@@ -161,3 +161,4 @@ 156 auto quick trim 157 auto quick raid 158 auto quick raid scrub +159 auto quick
Signature · 1 line
2.7.0
Re: [PATCH v2] fstests: btrfs/159 superblock corruption test case
Quoted 91 lines · Anand Jain
Verify if the superblock corruption is handled correctly.
Signed-off-by Anand Jain <[email protected]>---
v1->v2:
$subject slightly changed
Added more info about the test-case
Keep the stuff from the ./new btrfs
Addmount_opt_minus_args()to get the options (if) set at the config file MoveDEV_GOOD&DEV_BADto where it starts to use
To help debugging addedrun_checkwhere possible
Remove {} in the out file
Use_filter_error_mountfor mount fail cases other than-EINVALtests/btrfs/159 | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/159.out | 23 +++++++ tests/btrfs/group | 1 + 3 files changed, 201 insertions(+) create mode 100755 tests/btrfs/159 create mode 100644 tests/btrfs/159.outtests/btrfs/159 new file +64
-0@@ -0,0 +1,177 @@ +#! /bin/bash +# FS QA Test 159 +# +# Test if the superblock corruption is handled correctly: +# - Test fsid miss-match (csum ok) between primary and copy superblock +# Fixed by the ML patch: +# btrfs: check if the fsid in the primary sb and copy sb are same +# - Test if the mount fails if the primary superblock csum is +# corrupted on any disk +# - Test if the mount does not fail if the copy1 sb csum is corrupted +# Fixed by the ML patches: +# btrfs: verify superblock checksum during scan +# btrfs: verify checksum for all devices in mount context +# +#--------------------------------------------------------------------- +# Copyright (c) 2018 Oracle. All Rights Reserved. +# Author: Anand Jain <[email protected]> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* + _scratch_dev_pool_put +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/module + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here + +_supported_fs btrfs +_supported_os Linux +_require_scratch_dev_pool 2 +_require_loadable_fs_module "btrfs" +_require_command "$WIPEFS_PROG" wipefs
tests/btrfs/159 line 74
Quoted 10 lines
tests/btrfs/159 new file +10
-0+ +_scratch_dev_pool_get 2 + +mount_opt_minus_args() +{ + local nr + local mnt_opt="" + + nr=`_scratch_mount_options | awk '{print NF}'` + if [ $nr -eq 4 ]; then
Seems this only works with "scratch_mount_options" returns something like:
"-o opt dev mnt" or "-o opt1,opt2 dev mnt"
but not
"-oopt dev mnt" nor
"-o opt1 -o opt2 dev mnt" nor if $SELINUX_MOUNT_OPTIONS not empty.
Also if MOUNT_OPTIONS is "-oopt1 -oopt2", mount_opt_minus_args would return something like "-o -oopt2,device=<dev>", which are not valid mount options.
Quoted 52 lines
tests/btrfs/159 new file +52
-0+ #gets only the mount option set in the config file + mnt_opt=`_scratch_mount_options | awk '{print $2}'` + fi + #Append the additional opts provide as func args. + #Make sure -o is not echo-ed if both config file mnt-option + #and the test case mnt-option are null. + if [ -z $mnt_opt ]; then + if [ ! -z $* ]; then + echo "-o $*" + fi + else + if [ -z $* ]; then + echo "-o $mnt_opt" + else + echo "-o $mnt_opt,$*" + fi + fi +} + +wipe() +{ + $WIPEFS_PROG -a $DEV_GOOD > /dev/null 2>&1 + $WIPEFS_PROG -a $DEV_BAD > /dev/null 2>&1 +} + +# Test for fsid miss-match (csum ok) with primary and copy superblock. +check_copy1_fsid() +{ + local bytenr=67108864 + echo -e "\\ncheck_copy1_fsid\\n" | tee -a $seqres.full + + wipe + $MKFS_BTRFS_PROG -fq $DEV_GOOD + $MKFS_BTRFS_PROG -fq $DEV_BAD + _reload_fs_module "btrfs" + + run_check dd status=none of=$DEV_BAD if=$DEV_GOOD ibs=1 obs=1\ + skip=$bytenr seek=$bytenr count=4K + + #must fail + _mount `mount_opt_minus_args` $DEV_BAD $SCRATCH_MNT 2>&1 | _filter_scratch_pool + #If mount didn't fail + _scratch_unmount > /dev/null 2>&1 +} + +# Test if the mount fails if the primary superblock csum is corrupted. +check_primary() +{ + local bytenr=65536 + echo -e "\\ncheck_primary\\n" | tee -a $seqres.full + + wipe
tests/btrfs/159 line 136
Quoted 10 lines
tests/btrfs/159 new file +10
-0+ _scratch_pool_mkfs "-mraid1 -draid1" + _reload_fs_module "btrfs" + + #corrupt bytenr DEV_BAD + od -j$bytenr -N1 -An -x $DEV_BAD |\ + dd status=none of=$DEV_BAD ibs=1 obs=1 seek=$bytenr count=1 conv=fsync + + #must fail + _mount `mount_opt_minus_args device=$DEV_GOOD` $DEV_BAD $SCRATCH_MNT 2>&1 |\ + _filter_error_mount
If I read the code correctly, the purpose of mount_opt_minus_args is to remove the device and mount point mount arguments and keep other options if there's any, then append "-o device=<dev>" as mount options.
If so, I think you could use "_common_dev_mount_options", e.g.
_mount _common_dev_mount_options -o device=$DEV_GOOD $DEV_BAD $SCRATCH_MNT ...
But do mount options really matter in this test? Could we just mount with "-o device=<dev>"?
Thanks,
Eryu
Quoted 86 lines
tests/btrfs/159 new file +41
-0+ + #If mount didn't fail + _scratch_unmount > /dev/null 2>&1 +} + +# If copy1 is corrupted we still should be able to mount, check that. +check_copy1() +{ + local bytenr=67108864 + echo -e "\\ncheck_copy1" | tee -a $seqres.full + + wipe + _scratch_pool_mkfs "-mraid1 -draid1" + _reload_fs_module "btrfs" + + #corrupt bytenr DEV_BAD + od -j$bytenr -N1 -An -x $DEV_BAD |\ + dd status=none of=$DEV_BAD ibs=1 obs=1 seek=$bytenr count=1 conv=fsync + + _mount `mount_opt_minus_args device=$DEV_GOOD` $DEV_BAD $SCRATCH_MNT 2>&1 |\ + _filter_error_mount + _scratch_unmount +} + +DEV_GOOD=$(echo $SCRATCH_DEV_POOL | awk '{print $1}') +DEV_BAD=$(echo $SCRATCH_DEV_POOL | awk '{print $2}') + +check_copy1_fsid +check_primary +check_copy1 + +echo -e "\\nReverse good and bad devices" +# For csum verification on devid 2, reverse the good and bad disks. +DEV_BAD=$(echo $SCRATCH_DEV_POOL | awk '{print $1}') +DEV_GOOD=$(echo $SCRATCH_DEV_POOL | awk '{print $2}') +check_primary +check_copy1 + +# success, all done +status=0 +exittests/btrfs/159.out new file +23
-0@@ -0,0 +1,23 @@ +QA output created by 159 + +check_copy1_fsid + +mount: wrong fs type, bad option, bad superblock on SCRATCH_DEV, + missing codepage or helper program, or other error + + In some cases useful info is found in syslog - try + dmesg | tail or so. + +check_primary + +mount: Structure needs cleaning + +check_copy1 + +Reverse good and bad devices + +check_primary + +mount: Structure needs cleaning + +check_copy1tests/btrfs/group +1
-0@@ -161,3 +161,4 @@ 156 auto quick trim 157 auto quick raid 158 auto quick raid scrub +159 auto quickSignature · 6 lines
2.7.0 -- To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2] fstests: btrfs/159 superblock corruption test case
Quoted 15 lines
tests/btrfs/159 line 74
Quoted 9 lines
tests/btrfs/159 new file +7
-0+mount_opt_minus_args() +{ + local nr + local mnt_opt="" + + nr=`_scratch_mount_options | awk '{print NF}'` + if [ $nr -eq 4 ]; thenSeems this only works with "
scratch_mount_options" returns something like:"-o opt dev mnt" or "-o opt1,opt2 dev mnt"
Quoted 8 lines
but not
"-oopt dev mnt" nor
"-o opt1 -o opt2 dev mnt" nor if $SELINUX_MOUNT_OPTIONS not empty.Also if
MOUNT_OPTIONSis "-oopt1 -oopt2",mount_opt_minus_argswould return something like "-o -oopt2,device=<dev>", which are not valid mount options.
Oh. Yes. This function is getting complicated. I have dropped this function in v3 which is kind of much better.
Quoted 22 lines
Quoted 7 lines
tests/btrfs/159 new file +7
-0+# Test if the mount fails if the primary superblock csum is corrupted. +check_primary() +{ + local bytenr=65536 + echo -e "\\ncheck_primary\\n" | tee -a $seqres.full + + wipetests/btrfs/159 line 136
Quoted 10 lines
tests/btrfs/159 new file +10
-0+ _scratch_pool_mkfs "-mraid1 -draid1" + _reload_fs_module "btrfs" + + #corrupt bytenr DEV_BAD + od -j$bytenr -N1 -An -x $DEV_BAD |\ + dd status=none of=$DEV_BAD ibs=1 obs=1 seek=$bytenr count=1 conv=fsync + + #must fail + _mount `mount_opt_minus_args device=$DEV_GOOD` $DEV_BAD $SCRATCH_MNT 2>&1 |\ + _filter_error_mountIf I read the code correctly, the purpose of
mount_opt_minus_argsis to remove the device and mount point mount arguments and keep other options if there's any, then append "-o device=<dev>" as mount options.
Quoted 6 lines
If so, I think you could use "
_common_dev_mount_options", e.g.
_mount_common_dev_mount_options -o device=$DEV_GOOD$DEV_BAD $SCRATCH_MNT ...But do mount options really matter in this test? Could we just mount with "-o device=<dev>"?
In fact for this test it doesn't matter, yes we could just use "-o device=<dev>". But I thought its xfstests rule that it must be used. Anyway in V3, I am changing the device itself on which corrupted-SB would reside, so now we can let the default _scratch_mount do its job as usual. Which means it shall use the config mount options. V3 is in the ML for the review.
Thanks, Anand
Quoted 2 lines
Thanks,
Eryu
PATCH v3 1/1 fstests: btrfs/159 superblock corruption test case
In reply to Anand JainVerify if the superblock corruption is handled correctly.
---v2->v3:
Provide the disk to be corrupted as an arg, instead of swapping the devices,
so drop mount_opt_minus_args().
159.out slightly changed.v1->v2:
$subject slightly changed
Added more info about the test-case
Keep the stuff from the ./new btrfs
Add mount_opt_minus_args() to get the options (if) set at the config file Move DEV_GOOD & DEV_BAD to where it starts to use
To help debugging added run_check where possible
Remove {} in the out file
Use _filter_error_mount for mount fail cases other than -EINVAL
tests/btrfs/159 | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/159.out | 21 ++++++++ tests/btrfs/group | 1 + 3 files changed, 171 insertions(+) create mode 100755 tests/btrfs/159 create mode 100644 tests/btrfs/159.out
tests/btrfs/159 new file +149 -0
@@ -0,0 +1,149 @@ +#! /bin/bash +# FS QA Test 159 +# +# Test if the superblock corruption is handled correctly: +# - Test fsid miss-match (csum ok) between primary and copy superblock +# Fixed by the ML patch: +# btrfs: check if the fsid in the primary sb and copy sb are same +# - Test if the mount fails if the primary superblock csum is +# corrupted on any disk +# - Test if the mount does not fail if the copy1 sb csum is corrupted +# Fixed by the ML patches: +# btrfs: verify superblock checksum during scan +# btrfs: verify checksum for all devices in mount context +# +#--------------------------------------------------------------------- +# Copyright (c) 2018 Oracle. All Rights Reserved. +# Author: Anand Jain <[email protected]> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* + _scratch_dev_pool_put +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/module + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here + +_supported_fs btrfs +_supported_os Linux +_require_scratch_dev_pool 2 +_require_loadable_fs_module "btrfs" +_require_command "$WIPEFS_PROG" wipefs + +_scratch_dev_pool_get 2 + +wipe() +{ + $WIPEFS_PROG -a $SCRATCH_DEV_POOL > /dev/null 2>&1 +} + +# Test for fsid miss-match (csum ok) with primary and copy superblock. +check_copy1_fsid() +{ + local bytenr=67108864 + echo -e "\\ncheck_copy1_fsid\\n" | tee -a $seqres.full + + wipe + $MKFS_BTRFS_PROG -fq $EXTRA_DEV + _scratch_mkfs >> $seqres.full 2>&1 + _reload_fs_module "btrfs" + + run_check dd status=none of=$SCRATCH_DEV if=$EXTRA_DEV ibs=1 obs=1\ + skip=$bytenr seek=$bytenr count=4K + $WIPEFS_PROG -a $EXTRA_DEV > /dev/null 2>&1 + + #must fail + _try_scratch_mount 2>&1 | _filter_scratch_pool + #If mount didn't fail + _scratch_unmount > /dev/null 2>&1 +} + +# Test if the mount fails if the primary superblock csum is corrupted. +# arg 1 is dev to corrupt +check_primary() +{ + local bytenr=65536 + echo -e "\\ncheck_primary\\n" | tee -a $seqres.full + + wipe + _scratch_pool_mkfs "-mraid1 -draid1" + _reload_fs_module "btrfs" + + #corrupt primary superblock bytenr + od -j$bytenr -N1 -An -x $1 |\ + dd status=none of=$1 ibs=1 obs=1 seek=$bytenr count=1 conv=fsync + + #must fail + _try_scratch_mount "-o device=$EXTRA_DEV" 2>&1 | _filter_error_mount + + #If mount didn't fail + _scratch_unmount > /dev/null 2>&1 +} + +# If copy1 is corrupted we still should be able to mount, check that. +# arg 1 is dev to corrupt +check_copy1() +{ + local bytenr=67108864 + echo -e "\\ncheck_copy1" | tee -a $seqres.full + + wipe + _scratch_pool_mkfs "-mraid1 -draid1" + _reload_fs_module "btrfs" + + #corrupt copy1 superrblock bytenr + od -j$bytenr -N1 -An -x $1 |\ + dd status=none of=$1 ibs=1 obs=1 seek=$bytenr count=1 conv=fsync + + _try_scratch_mount "-o device=$EXTRA_DEV" 2>&1 | _filter_error_mount + _scratch_unmount +} + +EXTRA_DEV=$(echo $SCRATCH_DEV_POOL | awk '{print $1}') +if [ $EXTRA_DEV == $SCRATCH_DEV ]; then + EXTRA_DEV=$(echo $SCRATCH_DEV_POOL | awk '{print $2}') +fi +echo SCRATCH_DEV=$SCRATCH_DEV EXTRA_DEV=$EXTRA_DEV >> $seqres.full + +check_copy1_fsid +check_primary $SCRATCH_DEV +check_primary $EXTRA_DEV +check_copy1 $SCRATCH_DEV +check_copy1 $EXTRA_DEV + +# success, all done +status=0 +exit
tests/btrfs/159.out new file +21 -0
@@ -0,0 +1,21 @@ +QA output created by 159 + +check_copy1_fsid + +mount: wrong fs type, bad option, bad superblock on SCRATCH_DEV, + missing codepage or helper program, or other error + + In some cases useful info is found in syslog - try + dmesg | tail or so. + +check_primary + +mount: Structure needs cleaning + +check_primary + +mount: Structure needs cleaning + +check_copy1 + +check_copy1
tests/btrfs/group +1 -0
@@ -161,3 +161,4 @@ 156 auto quick trim 157 auto quick raid 158 auto quick raid scrub +159 auto quick
Signature · 1 line
2.7.0
Re: [PATCH v3] fstests: btrfs/159 superblock corruption test case
Quoted 34 lines · Anand Jain
Verify if the superblock corruption is handled correctly.
Signed-off-by Anand Jain <[email protected]>---
v2->v3:
Provide the disk to be corrupted as an arg, instead of swapping the devices,
so dropmount_opt_minus_args().
159.out slightly changed.v1->v2:
$subject slightly changed
Added more info about the test-case
Keep the stuff from the ./new btrfs
Addmount_opt_minus_args()to get the options (if) set at the config file MoveDEV_GOOD&DEV_BADto where it starts to use
To help debugging addedrun_checkwhere possible
Remove {} in the out file
Use_filter_error_mountfor mount fail cases other than-EINVALtests/btrfs/159 | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/159.out | 21 ++++++++ tests/btrfs/group | 1 + 3 files changed, 171 insertions(+) create mode 100755 tests/btrfs/159 create mode 100644 tests/btrfs/159.outtests/btrfs/159 new file +3
-0@@ -0,0 +1,149 @@ +#! /bin/bash +# FS QA Test 159 +#
tests/btrfs/159 line 13
Quoted 10 lines
tests/btrfs/159 new file +10
-0+# Test if the superblock corruption is handled correctly: +# - Test fsid miss-match (csum ok) between primary and copy superblock +# Fixed by the ML patch: +# btrfs: check if the fsid in the primary sb and copy sb are same +# - Test if the mount fails if the primary superblock csum is +# corrupted on any disk +# - Test if the mount does not fail if the copy1 sb csum is corrupted +# Fixed by the ML patches: +# btrfs: verify superblock checksum during scan +# btrfs: verify checksum for all devices in mount context
Do you have a tree that I can pull from? I want to make sure the test does pass on patched kernel, but the patchset doesn't apply on v4.16 kernel.
Thanks,
Eryu
Re: [PATCH v3] fstests: btrfs/159 superblock corruption test case
Quoted 15 lines
tests/btrfs/159 line 13
Quoted 11 lines
tests/btrfs/159 new file +10
-0+# Test if the superblock corruption is handled correctly: +# - Test fsid miss-match (csum ok) between primary and copy superblock +# Fixed by the ML patch: +# btrfs: check if the fsid in the primary sb and copy sb are same +# - Test if the mount fails if the primary superblock csum is +# corrupted on any disk +# - Test if the mount does not fail if the copy1 sb csum is corrupted +# Fixed by the ML patches: +# btrfs: verify superblock checksum during scan +# btrfs: verify checksum for all devices in mount contextDo you have a tree that I can pull from? I want to make sure the test does pass on patched kernel, but the patchset doesn't apply on v4.16 kernel.
We have new discussions on whether to check for the alien-superblock and the superblock-checksum at the mount and scan time respectively. And depending on its outcome this test-case should be modified as well. So can you please defer this fstest patch, for now, I shall send a revised fstest patch when kernel patches gets integrated.
In any case, if you want to give a try, those patches are base on kdave repo at [1].
[1]
https://github.com/kdave/btrfs-devel.git misc-next
Thanks, Anand
Quoted 7 lines
Thanks,
Eryu
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3] fstests: btrfs/159 superblock corruption test case
Quoted 16 lines · Anand Jain
Quoted 15 lines
tests/btrfs/159 line 13
Quoted 11 lines
tests/btrfs/159 new file +10
-0+# Test if the superblock corruption is handled correctly: +# - Test fsid miss-match (csum ok) between primary and copy superblock +# Fixed by the ML patch: +# btrfs: check if the fsid in the primary sb and copy sb are same +# - Test if the mount fails if the primary superblock csum is +# corrupted on any disk +# - Test if the mount does not fail if the copy1 sb csum is corrupted +# Fixed by the ML patches: +# btrfs: verify superblock checksum during scan +# btrfs: verify checksum for all devices in mount contextDo you have a tree that I can pull from? I want to make sure the test does pass on patched kernel, but the patchset doesn't apply on v4.16 kernel.
Quoted 5 lines
We have new discussions on whether to check for the alien-superblock and the superblock-checksum at the mount and scan time respectively. And depending on its outcome this test-case should be modified as well. So can you please defer this fstest patch, for now, I shall send a revised fstest patch when kernel patches gets integrated.
Thanks for the heads-up, I'll drop it for now.
Quoted 5 lines
In any case, if you want to give a try, those patches are base on kdave repo at [1].
[1]
https://github.com/kdave/btrfs-devel.git misc-next
Thanks!
Eryu