2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/223
7 # Test that after replacing a device, if we run fstrim against the filesystem
8 # we do not trim/discard allocated chunks in the new device. We verify that
9 # allocated chunks in the new device were not trim/discarded by mounting the
10 # new device only in degraded mode, as this is the easiest way to verify it.
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
26 # get standard environment, filters and checks
30 # real QA test starts here
32 _require_scratch_dev_pool 3
33 _require_command "$WIPEFS_PROG" wipefs
37 _scratch_dev_pool_get 2
39 dev1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $1 }')
40 dev2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $2 }')
42 _scratch_pool_mkfs "-m raid1 -d raid1"
44 _require_batched_discard $SCRATCH_MNT
46 # Add a test file with some data.
47 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 10M" $SCRATCH_MNT/foo | _filter_xfs_io
49 # Replace the first device, $dev1, with a new device.
50 $BTRFS_UTIL_PROG replace start -Bf $dev1 $SPARE_DEV $SCRATCH_MNT
52 # Run fstrim, it should not trim/discard allocated extents in the new device.
53 $FSTRIM_PROG $SCRATCH_MNT
55 # Unmount the filesystem.
58 # Mount the filesystem in degraded mode using the new device and verify that the
59 # mount succeeds and our file exists, with a size of 10Mb and all its bytes have
61 $WIPEFS_PROG -a $dev1 $dev2 >> $seqres.full 2>&1
62 _mount -o degraded $SPARE_DEV $SCRATCH_MNT
65 od -A d -t x1 $SCRATCH_MNT/foo