af072ede173203953c23e307f7984d207da2a9e7
[xfstests-dev.git] / tests / btrfs / 223
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/223
6 #
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.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick replace trim
14
15 # Import common functions.
16 . ./common/filter
17
18 # real QA test starts here
19 _supported_fs btrfs
20 _require_scratch_dev_pool 3
21 _require_command "$WIPEFS_PROG" wipefs
22
23 _scratch_dev_pool_get 2
24 _spare_dev_get
25 dev1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $1 }')
26 dev2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $2 }')
27
28 _scratch_pool_mkfs "-m raid1 -d raid1"
29 _scratch_mount
30 _require_batched_discard $SCRATCH_MNT
31
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
34
35 # Replace the first device, $dev1, with a new device.
36 $BTRFS_UTIL_PROG replace start -Bf $dev1 $SPARE_DEV $SCRATCH_MNT
37
38 # Run fstrim, it should not trim/discard allocated extents in the new device.
39 $FSTRIM_PROG $SCRATCH_MNT
40
41 # Unmount the filesystem.
42 _scratch_unmount
43
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
46 # a value of 0xab.
47 $WIPEFS_PROG -a $dev1 $dev2 >> $seqres.full 2>&1
48 _mount -o degraded $SPARE_DEV $SCRATCH_MNT
49
50 echo "File foo data:"
51 od -A d -t x1 $SCRATCH_MNT/foo
52
53 _spare_dev_put
54 _scratch_dev_pool_put
55
56 status=0
57 exit