generic: convert tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 415
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Plexistor Ltd. All Rights Reserved.
4 #
5 # FS QA Test No. 415
6 #
7 # test for races between write or fpunch operations on reflinked files
8 # to read operations on the target file
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=0    # success is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/reflink
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33 _supported_fs generic
34 _supported_os Linux
35 _require_scratch_reflink
36 _require_cp_reflink
37
38 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
39 _scratch_mount || _fail "mount failed"
40 _require_fs_space $SCRATCH_MNT $((250 * 1024))
41
42 echo "Silence is golden"
43
44 workfile=${SCRATCH_MNT}/workfile
45 light_clone=${SCRATCH_MNT}/light_clone
46
47 file_size=$((10 * 1024 * 1024))
48 bs=`_get_block_size $SCRATCH_MNT`
49 block_num=$((file_size / bs))
50 reflinks_num=20
51
52 $XFS_IO_PROG -f -c "pwrite 0 $file_size" $workfile >> $seqres.full
53
54 for ((i=1; i<=reflinks_num; i++)); do
55         _cp_reflink $workfile ${light_clone}_$i
56 done
57
58 # for each block simultaneously pwrite (or fpunch) all reflinks
59 # while performing pread from the targted file
60 for ((block_index=0; block_index<block_num; block_index++)); do
61         for ((i=1; i<=reflinks_num; i++)); do
62                 $XFS_IO_PROG -c "pread $((block_index * bs)) $bs" \
63                                         $workfile >> $seqres.full &
64                 if [ $((block_index % 2)) -eq 0 ]; then
65                         $XFS_IO_PROG -c "pwrite $((block_index * bs)) $bs" \
66                                         ${light_clone}_$i  >> $seqres.full &
67                 else
68                         $XFS_IO_PROG -c "fpunch $((block_index * bs)) $bs" \
69                                         ${light_clone}_$i >> $seqres.full &
70                 fi
71         done
72         # wait for all threads to join before moving to next block
73         wait
74 done
75
76 # success, all done
77 status=0
78 exit