btrfs: test case to fstrim on a degraded filesystem
[xfstests-dev.git] / tests / btrfs / 242
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 Oracle. All Rights Reserved.
4 #
5 # FS QA Test 242
6 #
7 # Test that fstrim can run on the degraded filesystem
8 #   Kernel requires fix for the null pointer deref in btrfs_trim_fs()
9 #     [patch] btrfs: check for missing device in btrfs_trim_fs
10
11 . ./common/preamble
12 _begin_fstest auto quick volume trim
13
14 # Import common functions.
15 . ./common/filter
16
17 # real QA test starts here
18 _supported_fs btrfs
19 _require_btrfs_forget_or_module_loadable
20 _require_scratch_dev_pool 2
21
22 _scratch_dev_pool_get 2
23 dev1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $1 }')
24
25 _scratch_pool_mkfs "-m raid1 -d raid1"
26 _scratch_mount
27 _require_batched_discard $SCRATCH_MNT
28
29 # Add a test file with some data.
30 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 10M" $SCRATCH_MNT/foo | _filter_xfs_io
31
32 # Unmount the filesystem.
33 _scratch_unmount
34
35 # Mount the filesystem in degraded mode
36 _btrfs_forget_or_module_reload
37 _mount -o degraded $dev1 $SCRATCH_MNT
38
39 # Run fstrim, it should skip on the missing device.
40 $FSTRIM_PROG $SCRATCH_MNT
41
42 # Verify data integrity as in the golden output.
43 echo "File foo data:"
44 od -A d -t x1 $SCRATCH_MNT/foo
45
46 _scratch_dev_pool_put
47
48 status=0
49 exit