From patchwork Mon Apr 9 05:28:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 10330591 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AF0906020F for ; Mon, 9 Apr 2018 05:26:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D54D28A64 for ; Mon, 9 Apr 2018 05:26:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F8CA28A68; Mon, 9 Apr 2018 05:26:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C863E28A64 for ; Mon, 9 Apr 2018 05:26:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752264AbeDIF0l (ORCPT ); Mon, 9 Apr 2018 01:26:41 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:35144 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751630AbeDIF0k (ORCPT ); Mon, 9 Apr 2018 01:26:40 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w3953fKT164544; Mon, 9 Apr 2018 05:26:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=/C21dZQmP1467/Mtat/o2zecV+hhJg8pW7dR5ScbVnM=; b=njUNEQi/zXX/UjSeL5E3K9/Zhu5PZy0wP/EtgR9C279328bStU4e+D0qumBRMq5VuJb9 5kEw60lVEfd3qpeIj9SbVPXiU3RtS3WJpG6G3MKcayNbPOBjXSo2HnjYHJ2zO121LTk/ q92JfNImR308zwW9azfitIa4l+wupbADncBba0z7NQqJXBOlYOiOK5j8qKaadLp2CGOx D7YwVvblQSGJZJES9Y9s/h1XkynnmHzwi4vf34myNUIk3isdJF+Sq5KG11F6ubtssZwS okNh+0roMnfu41k+BFeP9dP96QjY8xWAMqymwFKEvFfiQTETjXYw/klQIlgFWKhJfwT2 5w== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2h6kgt3qhf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 09 Apr 2018 05:26:39 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w395QcYN025010 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Apr 2018 05:26:39 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w395QcSo027404; Mon, 9 Apr 2018 05:26:38 GMT Received: from tp.sg.oracle.com (/10.186.53.63) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 08 Apr 2018 22:26:37 -0700 From: Anand Jain To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org Subject: [PATCH v3] fstests: btrfs/159 superblock corruption test case Date: Mon, 9 Apr 2018 13:28:30 +0800 Message-Id: <20180409052830.4772-1-anand.jain@oracle.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20180329102848.12669-1-anand.jain@oracle.com> References: <20180329102848.12669-1-anand.jain@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8857 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=13 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804090057 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Verify if the superblock corruption is handled correctly. Signed-off-by: Anand Jain --- 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 diff --git a/tests/btrfs/159 b/tests/btrfs/159 new file mode 100755 index 000000000000..c3a50b58b0b9 --- /dev/null +++ b/tests/btrfs/159 @@ -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 +# +# 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 diff --git a/tests/btrfs/159.out b/tests/btrfs/159.out new file mode 100644 index 000000000000..9daf9f515e87 --- /dev/null +++ b/tests/btrfs/159.out @@ -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 diff --git a/tests/btrfs/group b/tests/btrfs/group index 8007e07e9cbd..ba766f6b84f8 100644 --- a/tests/btrfs/group +++ b/tests/btrfs/group @@ -161,3 +161,4 @@ 156 auto quick trim 157 auto quick raid 158 auto quick raid scrub +159 auto quick