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