From: Darrick J. Wong Date: Sat, 23 Mar 2019 00:35:32 +0000 (-0700) Subject: generic: prohibit fstrim on journalled filesystems with norecovery X-Git-Tag: v2022.05.01~1210 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=8a011c00b524f9ef1281cfdbc79fac41585be0fa;p=users%2Fhch%2Fxfstests-dev.git generic: prohibit fstrim on journalled filesystems with norecovery This test makes sure that we can't use stale unrecovered fs metadata to drive a DISCARD festival on a disk and thereby destroy user data by accident. The following patches fixed the bug on ext4, xfs and btrfs ext4: prohibit fstrim in norecovery mode xfs: prohibit fstrim in norecovery mode Btrfs: do not allow trimming when a fs is mounted with the nologreplay option Signed-off-by: Darrick J. Wong Reviewed-by: Filipe Manana Signed-off-by: Eryu Guan --- diff --git a/tests/generic/537 b/tests/generic/537 new file mode 100755 index 000000000..e9e67082f --- /dev/null +++ b/tests/generic/537 @@ -0,0 +1,67 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2019, Oracle and/or its affiliates. All Rights Reserved. +# +# FS QA Test No. 537 +# +# Ensure that we can't call fstrim on filesystems mounted norecovery, because +# FSTRIM implementations use free space metadata to drive the discard requests +# and we told the filesystem not to make sure the metadata are up to date. +# +# The following patches fixed the bug on ext4, xfs and btrfs +# ext4: prohibit fstrim in norecovery mode +# xfs: prohibit fstrim in norecovery mode +# Btrfs: do not allow trimming when a fs is mounted with the nologreplay option + +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 -rf $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# real QA test starts here +_supported_os Linux +_supported_fs generic +_require_scratch +_require_fstrim + +rm -f $seqres.full + +_scratch_mkfs > $seqres.full 2>&1 +_require_metadata_journaling $SCRATCH_DEV + +echo "fstrim on regular mount" +_scratch_mount >> $seqres.full 2>&1 +$FSTRIM_PROG -v $SCRATCH_MNT >> $seqres.full 2>&1 || \ + _notrun "FSTRIM not supported" +_scratch_unmount + +echo "fstrim on ro mount" +_scratch_mount -o ro >> $seqres.full 2>&1 +$FSTRIM_PROG -v $SCRATCH_MNT >> $seqres.full 2>&1 +_scratch_unmount + +echo "fstrim on ro mount with no log replay" +norecovery="norecovery" +test $FSTYP = "btrfs" && norecovery=nologreplay +_scratch_mount -o ro,$norecovery >> $seqres.full 2>&1 +$FSTRIM_PROG -v $SCRATCH_MNT >> $seqres.full 2>&1 && \ + echo "fstrim with unrecovered metadata just ate your filesystem" +_scratch_unmount + +# success, all done +status=0 +exit diff --git a/tests/generic/537.out b/tests/generic/537.out new file mode 100644 index 000000000..cd3d92b01 --- /dev/null +++ b/tests/generic/537.out @@ -0,0 +1,4 @@ +QA output created by 537 +fstrim on regular mount +fstrim on ro mount +fstrim on ro mount with no log replay diff --git a/tests/generic/group b/tests/generic/group index 7f0434e54..c63035ce0 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -539,3 +539,4 @@ 534 auto quick log 535 auto quick log 536 auto quick rw shutdown +537 auto quick trim