xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / btrfs / 026
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 026
6 #
7 # Test that doing a direct IO write against a file range that contains one
8 # prealloc extent and one compressed extent works correctly.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
16
17 _cleanup()
18 {
19         cd /
20         rm -f $tmp.*
21 }
22
23 # get standard environment, filters and checks
24 . ./common/rc
25 . ./common/filter
26
27 # real QA test starts here
28 _supported_fs btrfs
29 _require_scratch
30 _require_xfs_io_command "falloc"
31
32 rm -f $seqres.full
33
34 _scratch_mkfs >>$seqres.full 2>&1
35 _scratch_mount "-o compress"
36
37 # Create a compressed extent covering the range [700K, 800K[.
38 $XFS_IO_PROG -f -s -c "pwrite -S 0xaa -b 100K 700K 100K" $SCRATCH_MNT/foo \
39         | _filter_xfs_io
40
41 # Create prealloc extent covering the range [600K, 700K[.
42 $XFS_IO_PROG -c "falloc 600K 100K" $SCRATCH_MNT/foo
43
44 # Write 80K of data to the range [640K, 720K[ using direct IO. This range covers
45 # both the prealloc extent and the compressed extent. Because there's a
46 # compressed extent in the range we are writing to, the DIO write code path ends
47 # up only writing the first 60k of data, which goes to the prealloc extent, and
48 # then falls back to buffered IO for writing the remaining 20K of data - because
49 # that remaining data maps to a file range containing a compressed extent.
50 # When falling back to buffered IO, we used to trigger an assertion when
51 # releasing reserved space due to bad accounting of the inode's outstanding
52 # extents counter, which was set to 1 but we ended up decrementing it by 1 twice,
53 # once through the ordered extent for the 60K of data we wrote using direct IO,
54 # and once through the main direct IO handler (inode.cbtrfs_direct_IO()) because
55 # the direct IO write wrote less than 80K of data (60K).
56 $XFS_IO_PROG -d -c "pwrite -S 0xbb -b 80K 640K 80K" $SCRATCH_MNT/foo \
57         | _filter_xfs_io
58
59 # Now similar test as above but for very large write operations. This triggers
60 # special cases for an inode's outstanding extents accounting, as internally
61 # btrfs logically splits extents into 128Mb units.
62 $XFS_IO_PROG -f -s \
63         -c "pwrite -S 0xaa -b 128M 258M 128M" \
64         -c "falloc 0 258M" \
65         $SCRATCH_MNT/bar | _filter_xfs_io
66 $XFS_IO_PROG -d -c "pwrite -S 0xbb -b 256M 3M 256M" $SCRATCH_MNT/bar \
67         | _filter_xfs_io
68
69 # Now verify the file contents are correct and that they are the same even after
70 # unmounting and mounting the fs again (or evicting the page cache).
71 #
72 # For file foo, all bytes in the range [0, 640K[ must have a value of 0x00, all
73 # bytes in the range [640K, 720K[ must have a value of 0xbb and all bytes in the
74 # range [720K, 800K[ must have a value of 0xaa.
75 #
76 # For file bar, all bytes in the range [0, 3M[ must havea value of 0x00, all
77 # bytes in the range [3M, 259M[ must have a value of 0xbb and all bytes in the
78 # range [259M, 386M[ must have a value of 0xaa.
79 #
80 echo "File digests before remounting the file system:"
81 md5sum $SCRATCH_MNT/foo | _filter_scratch
82 md5sum $SCRATCH_MNT/bar | _filter_scratch
83 _scratch_cycle_mount
84 echo "File digests after remounting the file system:"
85 md5sum $SCRATCH_MNT/foo | _filter_scratch
86 md5sum $SCRATCH_MNT/bar | _filter_scratch
87
88 status=0
89 exit