generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 333
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 333
6 #
7 # Test for races or FS corruption when trying to hit ENOSPC while DIO writing
8 # to a file that's also the source of a reflink operation.
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=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 7 15
18
19 _cleanup()
20 {
21     cd /
22     rm -rf $tmp.* $finished_file $abort_file
23     wait
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/reflink
30
31 # real QA test starts here
32 _supported_os Linux
33 _require_scratch_reflink
34 _require_cp_reflink
35 _require_odirect
36
37 echo "Format and mount"
38 _scratch_mkfs_sized $((400 * 1048576)) > $seqres.full 2>&1
39 _scratch_mount >> $seqres.full 2>&1
40
41 testdir=$SCRATCH_MNT/test-$seq
42 finished_file=/tmp/finished
43 rm -rf $finished_file
44 abort_file=/tmp/abort
45 rm -rf $abort_file
46 mkdir $testdir
47
48 loops=1024
49 nr_loops=$((loops - 1))
50 blksz=65536
51
52 echo "Initialize file"
53 echo >> $seqres.full
54 _pwrite_byte 0x61 0 $((loops * blksz)) $testdir/file1 >> $seqres.full
55 _scratch_cycle_mount
56
57 # Snapshot creator...
58 snappy() {
59         n=0
60         while [ ! -e $finished_file ]; do
61                 out="$(_cp_reflink $testdir/file1 $testdir/snap_$n 2>&1)"
62                 res=$?
63                 echo $out | grep -q "No space left" && break
64                 test -n "$out" && echo $out
65                 test $res -ne 0 && break
66                 n=$((n + 1))
67         done
68         touch $abort_file
69 }
70
71 echo "Snapshot a file undergoing directio rewrite"
72 snappy &
73 seq 1 1000 | while read j; do
74         seq $nr_loops -1 0 | while read i; do
75                 out="$(_pwrite_byte 0x63 $((i * blksz)) $blksz -d $testdir/file1 2>&1)"
76                 echo $out >> $seqres.full
77                 echo $out | grep -q "No space left" && touch $abort_file
78                 echo $out | grep -qi "error" && touch $abort_file
79                 test -e $abort_file && break
80         done
81         test -e $abort_file && break
82 done
83 touch $finished_file
84 wait
85
86 # success, all done
87 status=0
88 exit