From patchwork Thu Feb 11 23:40:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 8286631 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AAB0DBEEE5 for ; Thu, 11 Feb 2016 23:58:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D57AE20380 for ; Thu, 11 Feb 2016 23:58:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D917A20364 for ; Thu, 11 Feb 2016 23:57:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751086AbcBKXkg (ORCPT ); Thu, 11 Feb 2016 18:40:36 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:18908 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750970AbcBKXkN (ORCPT ); Thu, 11 Feb 2016 18:40:13 -0500 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u1BNeBVW022979 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 11 Feb 2016 23:40:11 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u1BNeAQQ010353 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Thu, 11 Feb 2016 23:40:10 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u1BNeAAE026084; Thu, 11 Feb 2016 23:40:10 GMT Received: from localhost (/10.145.178.207) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 11 Feb 2016 15:40:10 -0800 Subject: [PATCH 08/32] common: provide a method to repair the scratch fs From: "Darrick J. Wong" To: david@fromorbit.com, darrick.wong@oracle.com Cc: linux-btrfs@vger.kernel.org, fstests@vger.kernel.org, xfs@oss.sgi.com Date: Thu, 11 Feb 2016 15:40:08 -0800 Message-ID: <20160211234008.2202.30511.stgit@birch.djwong.org> In-Reply-To: <20160211233916.2202.40961.stgit@birch.djwong.org> References: <20160211233916.2202.40961.stgit@birch.djwong.org> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Create a wrapper function that repairs any damage to the scratch filesystem and returns a standard result. We will use this to clean up after IO error testing and other weird corruption tests. Signed-off-by: Darrick J. Wong --- common/rc | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/common/rc b/common/rc index 63eb90b..e05df74 100644 --- a/common/rc +++ b/common/rc @@ -953,6 +953,49 @@ _scratch_xfs_repair() $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV } +# Repair scratch filesystem. Returns 0 if the FS is good to go (either no +# errors found or errors were fixed) and nonzero otherwise; also spits out +# a complaint on stderr if fsck didn't tell us that the FS is good to go. +_repair_scratch_fs() +{ + case $FSTYP in + xfs) + _scratch_xfs_repair "$@" 2>&1 + res=$? + if [ "$res" -eq 2 ]; then + echo "xfs_repair returns $res; replay log?" + _scratch_mount + res=$? + if [ "$res" -gt 0 ]; then + echo "mount returns $res; zap log?" + _scratch_xfs_repair -L 2>&1 + echo "log zap returns $?" + else + umount "$SCRATCH_MNT" + fi + _scratch_xfs_repair "$@" 2>&1 + res=$? + fi + test $res -ne 0 && >&2 echo "xfs_repair failed, err=$res" + return $res + ;; + *) + # Let's hope fsck -y suffices... + fsck -t $FSTYP -y $SCRATCH_DEV 2>&1 + res=$? + case $res in + 0|1|2) + res=0 + ;; + *) + >&2 echo "fsck.$FSTYP failed, err=$res" + ;; + esac + return $res + ;; + esac +} + _get_pids_by_name() { if [ $# -ne 1 ]