fsx/fsstress: round blocksize properly
[xfstests-dev.git] / tests / generic / 520
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 The University of Texas at Austin.  All Rights Reserved.
4 #
5 # FS QA Test 520
6 #
7 # Test case created by CrashMonkey
8 #
9 # Test if we create a hard link to a file and persist either of the files, all
10 # the names persist.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         _cleanup_flakey
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/dmflakey
32
33 # 256MB in byte
34 fssize=$((2**20 * 256))
35
36 # remove previous $seqres.full before test
37 rm -f $seqres.full
38
39 # real QA test starts here
40 _supported_fs generic
41 _require_scratch_nocheck
42 _require_dm_target flakey
43
44 # initialize scratch device
45 _scratch_mkfs_sized $fssize >> $seqres.full 2>&1
46 _require_metadata_journaling $SCRATCH_DEV
47 _init_flakey
48
49 stat_opt='-c "blocks: %b size: %s inode: %i links: %h"'
50 before=""
51 after=""
52
53
54 # Using _scratch_mkfs instead of cleaning up the  working directory,
55 # adds about 10 seconds of delay in total for the 37 tests.
56 clean_dir()
57 {
58         _mount_flakey
59         rm -rf $(find $SCRATCH_MNT/* | grep -v "lost+found")
60         _unmount_flakey
61 }
62
63 check_consistency()
64 {
65         _flakey_drop_and_remount
66
67         if [ -f $1 ]; then
68                 after=`stat "$stat_opt" $1`
69         fi
70
71         if [ "$before" != "$after" ] && [ $2 -ne 1 ]; then
72                 echo "Before: $before"
73                 echo "After: $after"
74         fi
75
76         _unmount_flakey
77         _check_scratch_fs $FLAKEY_DEV
78 }
79
80 # create a hard link $2 to file $1, and fsync $3, followed by power-cut
81 test_link_fsync()
82 {
83         local sibling=0
84         local src=$SCRATCH_MNT/$1
85         local dest=$SCRATCH_MNT/$2
86         before=""
87         after=""
88
89         if [ "$3" == "./" ]; then
90                 fsync=$SCRATCH_MNT
91         else
92                 fsync=$SCRATCH_MNT/$3
93         fi
94
95         echo -ne "\n=== link $src $dest  with fsync $fsync ===\n" | \
96                 _filter_scratch
97         _mount_flakey
98
99         # Now execute the workload
100         # Create the directory in which the source and destination files
101         # will be created
102         mkdir -p "${src%/*}"
103         mkdir -p "${dest%/*}"
104         touch $src
105         ln $src $dest
106
107         # If the file being persisted is a sibling, create it first
108         if [ ! -f $fsync ]; then
109                 sibling=1
110                 touch $fsync
111         fi
112
113         $XFS_IO_PROG -c "fsync" $fsync
114
115         if [ $sibling -ne 1 ]; then
116                 before=`stat "$stat_opt" $src`
117         fi
118
119         check_consistency $src $sibling
120         clean_dir
121 }
122
123 # create a hard link $2 to file $1, and sync, followed by power-cut
124 test_link_sync()
125 {
126         local src=$SCRATCH_MNT/$1
127         local dest=$SCRATCH_MNT/$2
128         before=""
129         after=""
130         echo -ne "\n=== link $src $dest  with sync ===\n" | _filter_scratch
131         _mount_flakey
132
133         # now execute the workload
134         # Create the directory in which the source and destination files
135         # will be created
136         mkdir -p "${src%/*}"
137         mkdir -p "${dest%/*}"
138         touch $src
139         ln $src $dest
140         sync
141         before=`stat "$stat_opt" $src`
142
143         check_consistency $src 0
144         clean_dir
145 }
146
147
148 # Create different combinations to run the link test
149 # Group 0: Both files within root directory
150 file_names[0]="foo bar"
151 fsync_names[0]="./ foo bar"
152
153 # Group 1: Create hard link in a sub directory
154 file_names[1]="foo A/bar"
155 fsync_names[1]="./ foo bar A A/bar A/foo"
156
157 # Group 2: Create hard link in parent directory
158 file_names[2]="A/foo bar"
159 fsync_names[2]="./ foo bar A A/bar A/foo"
160
161 # Group 3: Both files within a directory other than root
162 file_names[3]="A/foo A/bar"
163 fsync_names[3]="./ A A/bar A/foo"
164
165 #Group 4: Exercise name reuse : Link file in sub-directory
166 file_names[4]="bar A/bar"
167 fsync_names[4]="./ foo bar A A/bar A/foo"
168
169 #Group 5: Exercise name reuse : Link file in parent directory
170 file_names[5]="A/bar bar"
171 fsync_names[5]="./ foo bar A A/bar A/foo"
172
173 for ((test_group = 0; test_group < 6; test_group++)); do
174         for file in ${fsync_names[$test_group]}; do
175                 test_link_fsync ${file_names[$test_group]} $file
176         done
177         test_link_sync ${file_names[$test_group]}
178 done
179
180 # success, all done
181 status=0
182 exit