From patchwork Thu Mar 29 10:28:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 10314865 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 278AB605B4 for ; Thu, 29 Mar 2018 10:27:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CB042A2E3 for ; Thu, 29 Mar 2018 10:27:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11A8F2A2E7; Thu, 29 Mar 2018 10:27:04 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable 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 8718A2A2E5 for ; Thu, 29 Mar 2018 10:27:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752286AbeC2K1B (ORCPT ); Thu, 29 Mar 2018 06:27:01 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:52316 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751179AbeC2K06 (ORCPT ); Thu, 29 Mar 2018 06:26:58 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2TAI1n6081429; Thu, 29 Mar 2018 10:26:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2017-10-26; bh=xKVJAPf3bYD/3PwZ2nkeZO8+L8g4uuR3mXDF/0GekBY=; b=ntf4u3pXILGWaDonJpDs3qm17JIM6S5aEY8gtqxH4rERdWZyyAt4FPSiGR4AgoZ/eeul CcdIBos7m0AR8cEQhHgYWcjFVKf26qd4Kih36sQ3CvDxDHYBF2pl1RXCCZaJGCSakgzx 0/gf/QDZUDMsvK7cZudJSL8Baq+4eED3h2l+9RrniChA1E7TL9hScfSx99iGILjPMPhp OuEjQojOM+ET4/fnzjrc90ub0qlOASN3dOokJjNUqvQ6fRAo6NbokfjZDLrpvMoVbp8U GzlxSDG1XbbshYq69DMVy5MjmnmnlmzCn4Iq7NFNqIity5d+5rYhxc+OJTCmXjn1H82+ Ew== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2h0x94g0x5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 29 Mar 2018 10:26:57 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w2TAQvph019380 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 29 Mar 2018 10:26:57 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w2TAQuFK002053; Thu, 29 Mar 2018 10:26:57 GMT Received: from tp.sg.oracle.com (/10.186.49.52) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 29 Mar 2018 03:26:56 -0700 From: Anand Jain To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org Subject: [PATCH typo-fixed] fstests: btrfs: 159 superblock corruption test case Date: Thu, 29 Mar 2018 18:28:48 +0800 Message-Id: <20180329102848.12669-1-anand.jain@oracle.com> X-Mailer: git-send-email 2.15.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8846 signatures=668695 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-1803290109 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 --- 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 diff --git a/tests/btrfs/159 b/tests/btrfs/159 new file mode 100755 index 000000000000..f42ba4b777e7 --- /dev/null +++ b/tests/btrfs/159 @@ -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 +# +# 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 diff --git a/tests/btrfs/159.out b/tests/btrfs/159.out new file mode 100644 index 000000000000..f8f776f28870 --- /dev/null +++ b/tests/btrfs/159.out @@ -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 +} 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