2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 The University of Texas at Austin. All Rights Reserved.
7 # Test case created by CrashMonkey
9 # Test if we create a hard link to a file and persist either of the files, all
13 _begin_fstest auto quick log
15 # Override the default cleanup function.
23 # Import common functions.
28 fssize=$((2**20 * 256))
30 # real QA test starts here
32 _require_scratch_nocheck
33 _require_dm_target flakey
35 # initialize scratch device
36 _scratch_mkfs_sized $fssize >> $seqres.full 2>&1
37 _require_metadata_journaling $SCRATCH_DEV
40 stat_opt='-c "blocks: %b size: %s inode: %i links: %h"'
44 # Using _scratch_mkfs instead of cleaning up the working directory,
45 # adds about 10 seconds of delay in total for the 37 tests.
49 rm -rf $(find $SCRATCH_MNT/* | grep -v "lost+found")
55 _flakey_drop_and_remount
58 after=`stat "$stat_opt" $1`
61 if [ "$before" != "$after" ] && [ $2 -ne 1 ]; then
62 echo "Before: $before"
67 _check_scratch_fs $FLAKEY_DEV
70 # create a hard link $2 to file $1, and fsync $3, followed by power-cut
74 local src=$SCRATCH_MNT/$1
75 local dest=$SCRATCH_MNT/$2
79 if [ "$3" == "./" ]; then
85 echo -ne "\n=== link $src $dest with fsync $fsync ===\n" | \
89 # Now execute the workload
90 # Create the directory in which the source and destination files
97 # If the file being persisted is a sibling, create it first
98 if [ ! -f $fsync ]; then
103 $XFS_IO_PROG -c "fsync" $fsync
105 if [ $sibling -ne 1 ]; then
106 before=`stat "$stat_opt" $src`
109 check_consistency $src $sibling
113 # create a hard link $2 to file $1, and sync, followed by power-cut
116 local src=$SCRATCH_MNT/$1
117 local dest=$SCRATCH_MNT/$2
120 echo -ne "\n=== link $src $dest with sync ===\n" | _filter_scratch
123 # now execute the workload
124 # Create the directory in which the source and destination files
127 mkdir -p "${dest%/*}"
131 before=`stat "$stat_opt" $src`
133 check_consistency $src 0
137 # Create different combinations to run the link test
138 # Group 0: Both files within root directory
139 file_names[0]="foo bar"
140 fsync_names[0]="./ foo bar"
142 # Group 1: Create hard link in a sub directory
143 file_names[1]="foo A/bar"
144 fsync_names[1]="./ foo bar A A/bar A/foo"
146 # Group 2: Create hard link in parent directory
147 file_names[2]="A/foo bar"
148 fsync_names[2]="./ foo bar A A/bar A/foo"
150 # Group 3: Both files within a directory other than root
151 file_names[3]="A/foo A/bar"
152 fsync_names[3]="./ A A/bar A/foo"
154 #Group 4: Exercise name reuse : Link file in sub-directory
155 file_names[4]="bar A/bar"
156 fsync_names[4]="./ foo bar A A/bar A/foo"
158 #Group 5: Exercise name reuse : Link file in parent directory
159 file_names[5]="A/bar bar"
160 fsync_names[5]="./ foo bar A A/bar A/foo"
162 for ((test_group = 0; test_group < 6; test_group++)); do
163 for file in ${fsync_names[$test_group]}; do
164 test_link_fsync ${file_names[$test_group]} $file
166 test_link_sync ${file_names[$test_group]}