generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 535
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Huawei.  All Rights Reserved.
4 #
5 # FS QA Test 535
6 #
7 # This testcase is trying to test recovery flow of generic filesystem,
8 # w/ below steps, once i_mode changes, after we fsync that file, we can
9 # expect that i_mode can be recovered after sudden power-cuts.
10 # 1. touch testfile or mkdir testdir
11 # 2. chmod 777 testfile/testdir
12 # 3. sync
13 # 4. chmod 755 testfile/testdir
14 # 5. fsync testfile/testdir
15 # 6. record last i_mode
16 # 7. flakey drop
17 # 8. remount
18 # 9. check i_mode
19 #
20 . ./common/preamble
21 _begin_fstest auto quick log
22
23 # Override the default cleanup function.
24 _cleanup()
25 {
26         _cleanup_flakey
27         cd /
28         rm -f $tmp.*
29 }
30
31 # Import common functions.
32 . ./common/filter
33 . ./common/dmflakey
34
35 # real QA test starts here
36 _supported_fs generic
37
38 _require_scratch
39 _require_dm_target flakey
40
41 _scratch_mkfs >/dev/null 2>&1
42 _require_metadata_journaling $SCRATCH_DEV
43 _init_flakey
44
45 testfile=$SCRATCH_MNT/testfile
46 testdir=$SCRATCH_MNT/testdir
47
48 do_check()
49 {
50         local target=$1
51         local is_dir=$2
52
53         _mount_flakey
54
55         if [ $is_dir = 1 ]; then
56                 mkdir $target
57         else
58                 touch $target
59         fi
60
61         echo "Test chmod $target" >> $seqres.full
62
63         chmod 777 $target
64         sync
65
66         chmod 755 $target
67         $XFS_IO_PROG $target -c "fsync"
68
69         local before=`stat -c %a $target`
70
71         _flakey_drop_and_remount
72
73         local after=`stat -c %a $target`
74
75         # check inode's i_mode
76         if [ "$before" != "$after" ]; then
77                 echo "Before: $before"
78                 echo "After : $after"
79         fi
80
81         if [ $is_dir = 1 ]; then
82                 rmdir $target
83         else
84                 rm -f $target
85         fi
86         _unmount_flakey
87 }
88
89 echo "Silence is golden"
90
91 do_check $testfile 0
92 do_check $testdir 1
93
94 status=0
95 exit