xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / generic / 606
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Fujitsu.  All Rights Reserved.
4 #
5 # FS QA Test 606
6 #
7 # By the following cases, verify if statx() can query S_DAX flag
8 # on regular file correctly.
9 # 1) With dax=always option, FS_XFLAG_DAX is ignored and S_DAX flag
10 #    always exists on regular file.
11 # 2) With dax=inode option, setting/clearing FS_XFLAG_DAX can change
12 #    S_DAX flag on regular file.
13 # 3) With dax=never option, FS_XFLAG_DAX is ignored and S_DAX flag
14 #    never exists on regular file.
15 #
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 here=`pwd`
21 tmp=/tmp/$$
22 status=1        # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 _cleanup()
26 {
27         cd /
28         rm -f $tmp.*
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34
35 # remove previous $seqres.full before test
36 rm -f $seqres.full
37
38 _supported_fs generic
39 _require_scratch_dax_mountopt "dax=always"
40 _require_dax_iflag
41 _require_xfs_io_command "statx" "-r"
42
43 PARENT_DIR=$SCRATCH_MNT/testdir
44 TEST_FILE=$PARENT_DIR/testfile
45
46 test_s_dax()
47 {
48         local dax_option=$1
49         local exp_s_dax1=$2
50         local exp_s_dax2=$3
51
52         # Mount with specified dax option
53         _scratch_mount "$dax_option"
54
55         # Prepare directory
56         mkdir -p $PARENT_DIR
57
58         rm -f $TEST_FILE
59         $XFS_IO_PROG -c "chattr +x" $PARENT_DIR
60         touch $TEST_FILE
61         # Check if setting FS_XFLAG_DAX changes S_DAX flag
62         _check_s_dax $TEST_FILE $exp_s_dax1
63
64         rm -f $TEST_FILE
65         $XFS_IO_PROG -c "chattr -x" $PARENT_DIR
66         touch $TEST_FILE
67         # Check if clearing FS_XFLAG_DAX changes S_DAX flag
68         _check_s_dax $TEST_FILE $exp_s_dax2
69
70         _scratch_unmount
71 }
72
73 do_tests()
74 {
75         _scratch_mkfs >> $seqres.full 2>&1
76
77         # Mount with specified dax option
78         test_s_dax "-o dax=always" 1 1
79         test_s_dax "-o dax=never" 0 0
80         test_s_dax "-o dax=inode" 1 0
81         # Mount without dax option
82         export MOUNT_OPTIONS=""
83         test_s_dax "" 1 0
84 }
85
86 do_tests
87
88 # success, all done
89 echo "Silence is golden"
90 status=0
91 exit