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 _begin_fstest auto quick replace trim
15 # Import common functions.
18 # real QA test starts here
20 _require_scratch_dev_pool 3
21 _require_command "$WIPEFS_PROG" wipefs
23 _scratch_dev_pool_get 2
25 dev1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $1 }')
26 dev2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $2 }')
28 _scratch_pool_mkfs "-m raid1 -d raid1"
30 _require_batched_discard $SCRATCH_MNT
32 # Add a test file with some data.
33 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 10M" $SCRATCH_MNT/foo | _filter_xfs_io
35 # Replace the first device, $dev1, with a new device.
36 $BTRFS_UTIL_PROG replace start -Bf $dev1 $SPARE_DEV $SCRATCH_MNT
38 # Run fstrim, it should not trim/discard allocated extents in the new device.
39 $FSTRIM_PROG $SCRATCH_MNT
41 # Unmount the filesystem.
44 # Mount the filesystem in degraded mode using the new device and verify that the
45 # mount succeeds and our file exists, with a size of 10Mb and all its bytes have
47 $WIPEFS_PROG -a $dev1 $dev2 >> $seqres.full 2>&1
48 _mount -o degraded $SPARE_DEV $SCRATCH_MNT
51 od -A d -t x1 $SCRATCH_MNT/foo