xfstests: remove _need_to_be_root
[xfstests-dev.git] / tests / btrfs / 026
1 #! /bin/bash
2 # FSQA Test No. 026
3 #
4 # Test that doing a direct IO write against a file range that contains one
5 # prealloc extent and one compressed extent works correctly.
6 #
7 #-----------------------------------------------------------------------
8 #
9 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
10 # Author: Filipe Manana <fdmanana@suse.com>
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
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_xfs_io_command "falloc"
49
50 rm -f $seqres.full
51
52 _scratch_mkfs >>$seqres.full 2>&1
53 _scratch_mount "-o compress"
54
55 # Create a compressed extent covering the range [700K, 800K[.
56 $XFS_IO_PROG -f -s -c "pwrite -S 0xaa -b 100K 700K 100K" $SCRATCH_MNT/foo \
57         | _filter_xfs_io
58
59 # Create prealloc extent covering the range [600K, 700K[.
60 $XFS_IO_PROG -c "falloc 600K 100K" $SCRATCH_MNT/foo
61
62 # Write 80K of data to the range [640K, 720K[ using direct IO. This range covers
63 # both the prealloc extent and the compressed extent. Because there's a
64 # compressed extent in the range we are writing to, the DIO write code path ends
65 # up only writing the first 60k of data, which goes to the prealloc extent, and
66 # then falls back to buffered IO for writing the remaining 20K of data - because
67 # that remaining data maps to a file range containing a compressed extent.
68 # When falling back to buffered IO, we used to trigger an assertion when
69 # releasing reserved space due to bad accounting of the inode's outstanding
70 # extents counter, which was set to 1 but we ended up decrementing it by 1 twice,
71 # once through the ordered extent for the 60K of data we wrote using direct IO,
72 # and once through the main direct IO handler (inode.cbtrfs_direct_IO()) because
73 # the direct IO write wrote less than 80K of data (60K).
74 $XFS_IO_PROG -d -c "pwrite -S 0xbb -b 80K 640K 80K" $SCRATCH_MNT/foo \
75         | _filter_xfs_io
76
77 # Now similar test as above but for very large write operations. This triggers
78 # special cases for an inode's outstanding extents accounting, as internally
79 # btrfs logically splits extents into 128Mb units.
80 $XFS_IO_PROG -f -s \
81         -c "pwrite -S 0xaa -b 128M 258M 128M" \
82         -c "falloc 0 258M" \
83         $SCRATCH_MNT/bar | _filter_xfs_io
84 $XFS_IO_PROG -d -c "pwrite -S 0xbb -b 256M 3M 256M" $SCRATCH_MNT/bar \
85         | _filter_xfs_io
86
87 # Now verify the file contents are correct and that they are the same even after
88 # unmounting and mounting the fs again (or evicting the page cache).
89 #
90 # For file foo, all bytes in the range [0, 640K[ must have a value of 0x00, all
91 # bytes in the range [640K, 720K[ must have a value of 0xbb and all bytes in the
92 # range [720K, 800K[ must have a value of 0xaa.
93 #
94 # For file bar, all bytes in the range [0, 3M[ must havea value of 0x00, all
95 # bytes in the range [3M, 259M[ must have a value of 0xbb and all bytes in the
96 # range [259M, 386M[ must have a value of 0xaa.
97 #
98 echo "File digests before remounting the file system:"
99 md5sum $SCRATCH_MNT/foo | _filter_scratch
100 md5sum $SCRATCH_MNT/bar | _filter_scratch
101 _scratch_cycle_mount
102 echo "File digests after remounting the file system:"
103 md5sum $SCRATCH_MNT/foo | _filter_scratch
104 md5sum $SCRATCH_MNT/bar | _filter_scratch
105
106 status=0
107 exit