generic: test adding filesystem-level fscrypt key via key_id
[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 _require_xfs_io_command "fpunch"
38
39 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
40 _scratch_mount || _fail "mount failed"
41 _require_fs_space $SCRATCH_MNT $((250 * 1024))
42
43 echo "Silence is golden"
44
45 workfile=${SCRATCH_MNT}/workfile
46 light_clone=${SCRATCH_MNT}/light_clone
47
48 file_size=$((10 * 1024 * 1024))
49 bs=`_get_block_size $SCRATCH_MNT`
50 block_num=$((file_size / bs))
51 reflinks_num=20
52
53 $XFS_IO_PROG -f -c "pwrite 0 $file_size" $workfile >> $seqres.full
54
55 for ((i=1; i<=reflinks_num; i++)); do
56         _cp_reflink $workfile ${light_clone}_$i
57 done
58
59 # for each block simultaneously pwrite (or fpunch) all reflinks
60 # while performing pread from the targted file
61 for ((block_index=0; block_index<block_num; block_index++)); do
62         for ((i=1; i<=reflinks_num; i++)); do
63                 $XFS_IO_PROG -c "pread $((block_index * bs)) $bs" \
64                                         $workfile >> $seqres.full &
65                 if [ $((block_index % 2)) -eq 0 ]; then
66                         $XFS_IO_PROG -c "pwrite $((block_index * bs)) $bs" \
67                                         ${light_clone}_$i  >> $seqres.full &
68                 else
69                         $XFS_IO_PROG -c "fpunch $((block_index * bs)) $bs" \
70                                         ${light_clone}_$i >> $seqres.full &
71                 fi
72         done
73         # wait for all threads to join before moving to next block
74         wait
75 done
76
77 # success, all done
78 status=0
79 exit