xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / btrfs / 234
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/234
6 #
7 # Test cases where a direct IO write, with O_DSYNC, can not be done and has to
8 # fallback to a buffered write.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/attr
28
29 # real QA test starts here
30 _supported_fs btrfs
31 _require_scratch
32 _require_odirect
33 _require_chattr c
34
35 rm -f $seqres.full
36
37 _scratch_mkfs >>$seqres.full 2>&1
38 _scratch_mount
39
40 # Create a test file with compression enabled (chattr +c).
41 touch $SCRATCH_MNT/foo
42 $CHATTR_PROG +c $SCRATCH_MNT/foo
43
44 # Now do a buffered write to create compressed extents.
45 $XFS_IO_PROG -s -c "pwrite -S 0xab -b 1M 0 1M" $SCRATCH_MNT/foo | _filter_xfs_io
46
47 # Now do the direct IO write with O_DSYNC into a file range that contains
48 # compressed extents. It should fallback to buffered IO and succeed.
49 $XFS_IO_PROG -d -s -c "pwrite -S 0xcd 512K 512K" $SCRATCH_MNT/foo | _filter_xfs_io
50
51 # Now try doing a direct IO write, with O_DSYNC, for a range that starts with
52 # non-aligned offset. It should also fallback to buffered IO and succeed.
53 $XFS_IO_PROG -f -d -s -c "pwrite -S 0xef 1111 512K" $SCRATCH_MNT/bar | _filter_xfs_io
54
55 # Unmount, mount again, and verify we have the expected data.
56 _scratch_cycle_mount
57
58 echo "File foo data:"
59 od -A d -t x1 $SCRATCH_MNT/foo
60 echo "File bar data:"
61 od -A d -t x1 $SCRATCH_MNT/bar
62
63 status=0
64 exit