btrfs: test direct IO write against raid5/6 filesystems
[xfstests-dev.git] / tests / btrfs / 148
1 #! /bin/bash
2 # FS QA Test No. btrfs/148
3 #
4 # Test that direct IO writes work on RAID5 and RAID6 filesystems.
5 #
6 #-----------------------------------------------------------------------
7 #
8 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
9 # Author: Filipe Manana <fdmanana@suse.com>
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         cd /
37         rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43
44 # real QA test starts here
45 _supported_fs btrfs
46 _supported_os Linux
47 _require_scratch
48 _require_scratch_dev_pool 4
49 _require_odirect
50
51 _scratch_dev_pool_get 4
52
53 rm -f $seqres.full
54
55 test_direct_io_write()
56 {
57         local mkfs_options=$1
58
59         _scratch_pool_mkfs $mkfs_options >>$seqres.full 2>&1
60         _scratch_mount
61
62         $XFS_IO_PROG -f -d -c "pwrite -S 0xab 0 1M" $SCRATCH_MNT/foo \
63                 | _filter_xfs_io
64
65         # Now read back the same data, we expect to get what we wrote before.
66         echo "File data after direct IO write:"
67         od -t x1 $SCRATCH_MNT/foo | _filter_scratch
68         _scratch_cycle_mount
69         echo "File data after umounting and mounting again the filesystem:"
70         od -t x1 $SCRATCH_MNT/foo | _filter_scratch
71
72         $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
73         if [ $? -ne 0 ]; then
74                 echo "Scrub found errors" | tee -a $seqres.full
75         fi
76
77         _scratch_unmount
78 }
79
80 echo "Testing RAID5..."
81 test_direct_io_write "-m raid5 -d raid5"
82 echo "Testing RAID6..."
83 test_direct_io_write "-m raid6 -d raid6"
84
85 status=0
86 exit