From patchwork Wed Mar 31 01:08:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12174055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E19E6C433E0 for ; Wed, 31 Mar 2021 01:08:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B668C61954 for ; Wed, 31 Mar 2021 01:08:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231951AbhCaBIR (ORCPT ); Tue, 30 Mar 2021 21:08:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:41798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232401AbhCaBIM (ORCPT ); Tue, 30 Mar 2021 21:08:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9B08E619C1; Wed, 31 Mar 2021 01:08:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617152892; bh=C3LMpm9/bbFKDjD+2lRl6JMrfRT6cK64OYeo4Zre+2w=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=HwYN13ieknTe4veyfvpifMa/fpylxboj0DCJFU4eJvXsowsLu7oxeZmnpN1G0ml3U o1WtYYfp9fvS+t60jepU4ySt+BCyvj1HLk5ITdR/dKYJeTqL331J6i3d9R0qJlTyYH eKr/EwV+vg1lixDRk6ISz6tI9ZNNuisdBPTUokjTrtJjpEcu/DPCwLEd5XeKu1SQOP zZK7FhOPGibv0Iyo3EiSC7zx5qfbJpKn1wereJLqeKmeuyt4EnPg4LZ8qCjM+tSHCO Kjbi2MPZkGHPQpKkGi/3JP9DyaEey4/WoDN2ANXNdbVtWBlp3qOTqavl5IpXQpecy1 57bI1shpftaCA== Subject: [PATCH 1/3] common/xfs: support realtime devices with _scratch_xfs_admin From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me Date: Tue, 30 Mar 2021 18:08:10 -0700 Message-ID: <161715289029.2703773.9509352442264553944.stgit@magnolia> In-Reply-To: <161715288469.2703773.13448230101596914371.stgit@magnolia> References: <161715288469.2703773.13448230101596914371.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong Teach _scratch_xfs_admin to support passing the realtime device to xfs_admin so that we can actually test xfs_admin functionality with those setups. Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster --- common/xfs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/xfs b/common/xfs index 69f76d6e..189da54b 100644 --- a/common/xfs +++ b/common/xfs @@ -269,9 +269,15 @@ _test_xfs_db() _scratch_xfs_admin() { local options=("$SCRATCH_DEV") + local rt_opts=() [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \ options+=("$SCRATCH_LOGDEV") - $XFS_ADMIN_PROG "$@" "${options[@]}" + if [ "$USE_EXTERNAL" = yes ] && [ -n "$SCRATCH_RTDEV" ]; then + $XFS_ADMIN_PROG --help 2>&1 | grep -q 'rtdev' || \ + _notrun 'xfs_admin does not support rt devices' + rt_opts+=(-r "$SCRATCH_RTDEV") + fi + $XFS_ADMIN_PROG "${rt_opts[@]}" "$@" "${options[@]}" } _scratch_xfs_logprint() From patchwork Wed Mar 31 01:08:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12174059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6878C433E0 for ; Wed, 31 Mar 2021 01:09:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FB12619C5 for ; Wed, 31 Mar 2021 01:09:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232893AbhCaBIu (ORCPT ); Tue, 30 Mar 2021 21:08:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:41860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232126AbhCaBIS (ORCPT ); Tue, 30 Mar 2021 21:08:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1D8E46190A; Wed, 31 Mar 2021 01:08:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617152898; bh=CJ82AbyQcnYPHSdtrUNRy/iC/R95GeMCEQatDDi/F5M=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=A7Pd9sCnk0TJlR35bA9djZ2NG+aIj8DuVgKsu1LwAlx0DG6aMi2/lKWHCr5CtpN5M r/pyX15qszt9wn1RWLdGIF1hywu/hQNgsCVIYEKLa/aFM+5GxSRKxaUkU2QhTYRmez 895aEbM+Hdpo9L5hsgSkowm7AB4HGcWUEzdgvVBWyBo6FOi4uPFBEaVixsrapT/fn9 z3mfJh8bUYzwmgWDX8umBWqbAwVwpffFgRngb3w3u4OhogSItb7jXK+zEdyDys3tGm 7I5ZVBq4Q/+2q2qrZ1f4QGWbYHNlP2lodKgz1B10AjBCRvLR8Qr/mrm4jBtau7D5BN UhIUxtnTj8ODQ== Subject: [PATCH 2/3] common/xfs: work around a hang-on-stdin bug in xfs_admin 5.11 From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me Date: Tue, 30 Mar 2021 18:08:15 -0700 Message-ID: <161715289578.2703773.11659648563859531836.stgit@magnolia> In-Reply-To: <161715288469.2703773.13448230101596914371.stgit@magnolia> References: <161715288469.2703773.13448230101596914371.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong xfs_admin in xfsprogs 5.11 has a bug wherein a caller who specifies an external log device forces xfs_db to be invoked, potentially with zero command arguments. When this happens, xfs_db will wait for input on stdin, which causes fstests to hang. Since xfs_admin is not an interactive tool, redirect stdin from /dev/null to prevent this issue. Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster --- common/xfs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/xfs b/common/xfs index 189da54b..c97e08ba 100644 --- a/common/xfs +++ b/common/xfs @@ -277,7 +277,13 @@ _scratch_xfs_admin() _notrun 'xfs_admin does not support rt devices' rt_opts+=(-r "$SCRATCH_RTDEV") fi - $XFS_ADMIN_PROG "${rt_opts[@]}" "$@" "${options[@]}" + + # xfs_admin in xfsprogs 5.11 has a bug where an external log device + # forces xfs_db to be invoked, potentially with zero command arguments. + # When this happens, xfs_db will wait for input on stdin, which causes + # fstests to hang. Since xfs_admin is not an interactive tool, we + # can redirect stdin from /dev/null to prevent this issue. + $XFS_ADMIN_PROG "${rt_opts[@]}" "$@" "${options[@]}" < /dev/null } _scratch_xfs_logprint() From patchwork Wed Mar 31 01:08:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12174067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E15CC433E2 for ; Wed, 31 Mar 2021 01:09:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24C0C619DE for ; Wed, 31 Mar 2021 01:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232905AbhCaBIu (ORCPT ); Tue, 30 Mar 2021 21:08:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:41920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232600AbhCaBIY (ORCPT ); Tue, 30 Mar 2021 21:08:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 99318619C1; Wed, 31 Mar 2021 01:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617152903; bh=V3Ir2HR9Bqa+4K+Dbkak7Wqr7clwpvD3UDTHG1mTut0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Dlx9Lo+LcBFfMXfDhgis/wSdrr7yNS9Z6+qcliQm3Z4tmJjo6a73SJykSpi+HriBo GI/bl1qpaJG6OLwtqYEvoCVLcnVfeh2xcnCdVB5K57O8f2JkX7rgb1ec9ixxlGy9mY OayT3Oo62ZqZrkJbKjhJ0TIRzMt5vJqwgIx14Rr7OqgtgoHIboduOYkp/QODUNvCiE dFy5HjwyAO896oHwlN4Boi6NboaNv50R00tqztH6UdhQXnSSFkn4U+askx6rnSH4Of EF8oyEmYzrCac4Up56T5mDt9BRPUazMAAvEVsuMf1E+2/EfBdKN/IwUyaVyGoB20PH zT1OysFHScuFw== Subject: [PATCH 3/3] xfs: test that the needsrepair feature works as advertised From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me Date: Tue, 30 Mar 2021 18:08:21 -0700 Message-ID: <161715290127.2703773.4292037416016401516.stgit@magnolia> In-Reply-To: <161715288469.2703773.13448230101596914371.stgit@magnolia> References: <161715288469.2703773.13448230101596914371.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong Make sure that the needsrepair feature flag can be cleared only by repair and that mounts are prohibited when the feature is set. Signed-off-by: Darrick J. Wong Reviewed-by: John Smith # xfs/764 only --- common/xfs | 21 +++++++++++ tests/xfs/768 | 82 +++++++++++++++++++++++++++++++++++++++++++ tests/xfs/768.out | 4 ++ tests/xfs/770 | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/770.out | 2 + tests/xfs/group | 2 + 6 files changed, 212 insertions(+) create mode 100755 tests/xfs/768 create mode 100644 tests/xfs/768.out create mode 100755 tests/xfs/770 create mode 100644 tests/xfs/770.out diff --git a/common/xfs b/common/xfs index c97e08ba..051e5652 100644 --- a/common/xfs +++ b/common/xfs @@ -1091,3 +1091,24 @@ _require_xfs_copy() [ "$USE_EXTERNAL" = yes ] && \ _notrun "Cannot xfs_copy with external devices" } + +# Print the status of the given features on the scratch filesystem. +# Returns 0 if all features are found, 1 otherwise. +_check_scratch_xfs_features() +{ + local features="$(_scratch_xfs_db -c 'version')" + local output=("FEATURES:") + local found=0 + + for feature in "$@"; do + local status="NO" + if echo "${features}" | grep -q -w "${feature}"; then + status="YES" + found=$((found + 1)) + fi + output+=("${feature}:${status}") + done + + echo "${output[@]}" + test "${found}" -eq "$#" +} diff --git a/tests/xfs/768 b/tests/xfs/768 new file mode 100755 index 00000000..7b909b76 --- /dev/null +++ b/tests/xfs/768 @@ -0,0 +1,82 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2021 Oracle. All Rights Reserved. +# +# FS QA Test No. 768 +# +# Make sure that the kernel won't mount a filesystem if repair forcibly sets +# NEEDSREPAIR while fixing metadata. Corrupt a directory in such a way as +# to force repair to write an invalid dirent value as a sentinel to trigger a +# repair activity in a later phase. Use a debug knob in xfs_repair to abort +# the repair immediately after forcing the flag on. + +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.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# real QA test starts here +_supported_fs xfs +_require_scratch +grep -q LIBXFS_DEBUG_WRITE_CRASH $XFS_REPAIR_PROG || \ + _notrun "libxfs write failure injection hook not detected?" + +rm -f $seqres.full + +# Set up a real filesystem for our actual test +_scratch_mkfs -m crc=1 >> $seqres.full + +# Create a directory large enough to have a dir data block. 2k worth of +# dirent names ought to do it. +_scratch_mount +mkdir -p $SCRATCH_MNT/fubar +for i in $(seq 0 256 2048); do + fname=$(printf "%0255d" $i) + ln -s -f urk $SCRATCH_MNT/fubar/$fname +done +inum=$(stat -c '%i' $SCRATCH_MNT/fubar) +_scratch_unmount + +# Fuzz the directory +_scratch_xfs_db -x -c "inode $inum" -c "dblock 0" \ + -c "fuzz -d bu[2].inumber add" >> $seqres.full + +# Try to repair the directory, force it to crash after setting needsrepair +LIBXFS_DEBUG_WRITE_CRASH=ddev=2 _scratch_xfs_repair 2>> $seqres.full +test $? -eq 137 || echo "repair should have been killed??" +_scratch_xfs_db -c 'version' >> $seqres.full + +# We can't mount, right? +_check_scratch_xfs_features NEEDSREPAIR +_try_scratch_mount &> $tmp.mount +res=$? +_filter_scratch < $tmp.mount +if [ $res -eq 0 ]; then + echo "Should not be able to mount after needsrepair crash" + _scratch_unmount +fi + +# Repair properly this time and retry the mount +_scratch_xfs_repair 2>> $seqres.full +_scratch_xfs_db -c 'version' >> $seqres.full +_check_scratch_xfs_features NEEDSREPAIR + +_scratch_mount + +# success, all done +status=0 +exit diff --git a/tests/xfs/768.out b/tests/xfs/768.out new file mode 100644 index 00000000..1168ba25 --- /dev/null +++ b/tests/xfs/768.out @@ -0,0 +1,4 @@ +QA output created by 768 +FEATURES: NEEDSREPAIR:YES +mount: SCRATCH_MNT: mount(2) system call failed: Structure needs cleaning. +FEATURES: NEEDSREPAIR:NO diff --git a/tests/xfs/770 b/tests/xfs/770 new file mode 100755 index 00000000..1d0effd9 --- /dev/null +++ b/tests/xfs/770 @@ -0,0 +1,101 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2021 Oracle. All Rights Reserved. +# +# FS QA Test No. 770 +# +# Populate a filesystem with all types of metadata, then run repair with the +# libxfs write failure trigger set to go after a single write. Check that the +# injected error trips, causing repair to abort, that needsrepair is set on the +# fs, the kernel won't mount; and that a non-injecting repair run clears +# needsrepair and makes the filesystem mountable again. +# +# Repeat with the trip point set to successively higher numbers of writes until +# we hit ~200 writes or repair manages to run to completion without tripping. + +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.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/populate +. ./common/filter + +# real QA test starts here +_supported_fs xfs + +_require_scratch_xfs_crc # needsrepair only exists for v5 +_require_populate_commands + +rm -f ${RESULT_DIR}/require_scratch # we take care of checking the fs +rm -f $seqres.full + +max_writes=200 # 200 loops should be enough for anyone +nr_incr=$((13 / TIME_FACTOR)) +test $nr_incr -lt 1 && nr_incr=1 +for ((nr_writes = 1; nr_writes < max_writes; nr_writes += nr_incr)); do + test -w /dev/ttyprintk && \ + echo "fail after $nr_writes writes" >> /dev/ttyprintk + echo "fail after $nr_writes writes" >> $seqres.full + + # Populate the filesystem + _scratch_populate_cached nofill >> $seqres.full 2>&1 + + # Start a repair and force it to abort after some number of writes + LIBXFS_DEBUG_WRITE_CRASH=ddev=$nr_writes _scratch_xfs_repair 2>> $seqres.full + res=$? + if [ $res -ne 0 ] && [ $res -ne 137 ]; then + echo "repair failed with $res??" + break + elif [ $res -eq 0 ]; then + [ $nr_writes -eq 1 ] && \ + echo "ran to completion on the first try?" + break + fi + + _scratch_xfs_db -c 'version' >> $seqres.full + if _check_scratch_xfs_features NEEDSREPAIR > /dev/null; then + # NEEDSREPAIR is set, so check that we can't mount. + _try_scratch_mount &>> $seqres.full + if [ $? -eq 0 ]; then + echo "Should not be able to mount after repair crash" + _scratch_unmount + fi + elif _scratch_xfs_repair -n &>> $seqres.full; then + # NEEDSREPAIR was not set, but repair -n didn't find problems. + # It's possible that the write failure injector triggered on + # the write that clears NEEDSREPAIR. + true + else + # NEEDSREPAIR was not set, but there are errors! + echo "NEEDSREPAIR should be set on corrupt fs" + fi + + # Repair properly this time and retry the mount + _scratch_xfs_repair 2>> $seqres.full + _scratch_xfs_db -c 'version' >> $seqres.full + _check_scratch_xfs_features NEEDSREPAIR > /dev/null && \ + echo "Repair failed to clear NEEDSREPAIR on the $nr_writes writes test" + + # Make sure all the checking tools think this fs is ok + _scratch_mount + _check_scratch_fs + _scratch_unmount +done + +# success, all done +echo Silence is golden. +status=0 +exit diff --git a/tests/xfs/770.out b/tests/xfs/770.out new file mode 100644 index 00000000..725d740b --- /dev/null +++ b/tests/xfs/770.out @@ -0,0 +1,2 @@ +QA output created by 770 +Silence is golden. diff --git a/tests/xfs/group b/tests/xfs/group index fe83f82d..09fddb5a 100644 --- a/tests/xfs/group +++ b/tests/xfs/group @@ -520,3 +520,5 @@ 537 auto quick 538 auto stress 539 auto quick mount +768 auto quick repair +770 auto repair