generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 043
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2006 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FSQA Test No. 043
6 #
7 # Test for NULL files problem
8 #
9 . ./common/preamble
10 _begin_fstest shutdown metadata log auto
11
12 # Import common functions.
13 . ./common/filter
14
15 # real QA test starts here
16 _supported_fs generic
17
18 _require_scratch
19 _require_scratch_shutdown
20 _require_xfs_io_command "fiemap"
21 _scratch_mkfs >/dev/null 2>&1
22 _require_metadata_journaling $SCRATCH_DEV
23 _scratch_mount
24
25 # create files
26 i=1;
27 while [ $i -lt 1000 ]
28 do
29         file=$SCRATCH_MNT/$i
30         $XFS_IO_PROG -f -c "pwrite -b 64k -S 0xff 0 64k" $file > /dev/null
31         if [ $? -ne 0 ]
32         then
33                 echo error creating/writing file $file
34                 exit
35         fi
36         let i=$i+1
37 done
38
39 # give the system a chance to write something out
40 sleep 10
41
42 _scratch_shutdown
43
44 _scratch_unmount
45 _scratch_mount
46 _scratch_unmount
47 if [ ! _check_scratch_fs ]
48 then
49         echo error detected in filesystem
50         exit
51 fi
52 _scratch_mount
53
54 # check file size and contents
55 i=1;
56 while [ $i -lt 1000 ]
57 do
58         file=$SCRATCH_MNT/$i
59         # if file does not exist, the create was not logged, skip it
60         if [ -e $file ]
61         then
62                 # if file size is zero it cannot be corrupt, skip it
63                 if [ -s $file ]
64                 then
65                         # if file has non-zero size but no extents then it's contents will be NULLs, bad.
66                         num_extents=`_count_extents $file`
67                         num_holes=`_count_holes $file`
68                         if [ $num_extents -eq 0 ]; then
69                                 echo corrupt file $file - non-zero size but no extents
70                         elif [ $num_holes -ne 0 ]; then
71                                 echo corrupt file $file - contains holes
72                         else
73                                 rm -f $file
74                         fi
75                 else
76                         rm -f $file
77                 fi
78         fi
79         let i=$i+1
80 done
81
82 status=0
83 exit