2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2019, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that we can't call fstrim on filesystems mounted norecovery, because
8 # FSTRIM implementations use free space metadata to drive the discard requests
9 # and we told the filesystem not to make sure the metadata are up to date.
11 # The following patches fixed the bug on ext4, xfs and btrfs
12 # ext4: prohibit fstrim in norecovery mode
13 # xfs: prohibit fstrim in norecovery mode
14 # Btrfs: do not allow trimming when a fs is mounted with the nologreplay option
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
22 status=1 # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
31 # get standard environment, filters and checks
35 # real QA test starts here
43 _scratch_mkfs > $seqres.full 2>&1
44 _require_metadata_journaling $SCRATCH_DEV
46 echo "fstrim on regular mount"
47 _scratch_mount >> $seqres.full 2>&1
48 $FSTRIM_PROG -v $SCRATCH_MNT >> $seqres.full 2>&1 || \
49 _notrun "FSTRIM not supported"
52 echo "fstrim on ro mount"
53 _scratch_mount -o ro >> $seqres.full 2>&1
54 $FSTRIM_PROG -v $SCRATCH_MNT >> $seqres.full 2>&1
57 echo "fstrim on ro mount with no log replay"
58 norecovery="norecovery"
59 test $FSTYP = "btrfs" && norecovery=nologreplay
60 _scratch_mount -o ro,$norecovery >> $seqres.full 2>&1
61 $FSTRIM_PROG -v $SCRATCH_MNT >> $seqres.full 2>&1 && \
62 echo "fstrim with unrecovered metadata just ate your filesystem"