generic: test deadlock on O_DIRECT|O_DSYNC
[xfstests-dev.git] / tests / generic / 158
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 158
6 #
7 # Check that various invalid dedupe scenarios are rejected.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1    # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20     cd /
21     rm -rf $tmp.* $testdir1
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/attr
28 . ./common/reflink
29
30 # real QA test starts here
31 _supported_os Linux
32 _require_test_dedupe
33 _require_scratch_dedupe
34 _require_mknod
35
36 rm -f $seqres.full
37
38 echo "Format and mount"
39 _scratch_mkfs > $seqres.full 2>&1
40 _scratch_mount >> $seqres.full 2>&1
41
42 testdir1="$TEST_DIR/test-$seq"
43 rm -rf $testdir1
44 mkdir $testdir1
45
46 testdir2=$SCRATCH_MNT/test-$seq
47 mkdir $testdir2
48
49 echo "Create the original files"
50 blksz="$(_get_block_size $testdir1)"
51 blks=1000
52 margin='7%'
53 sz=$((blksz * blks))
54 free_blocks0=$(stat -f $testdir1 -c '%f')
55 nr=4
56 filesize=$((blksz * nr))
57 _pwrite_byte 0x61 0 $sz $testdir1/file1 >> $seqres.full
58 _pwrite_byte 0x61 0 $sz $testdir1/file2 >> $seqres.full
59 _pwrite_byte 0x61 0 $sz $testdir1/file3 >> $seqres.full
60 _pwrite_byte 0x61 0 $sz $testdir2/file1 >> $seqres.full
61 _pwrite_byte 0x61 0 $sz $testdir2/file2 >> $seqres.full
62 mkdir $testdir1/dir1
63 seq 1 $((2 * blksz / 250)) | while read f; do
64         touch $testdir1/dir1/$f
65 done
66 mknod $testdir1/dev1 c 1 3
67 mkfifo $testdir1/fifo1
68 sync
69
70 _filter_enotty() {
71         _filter_dedupe_error | \
72         sed -e 's/Inappropriate ioctl for device/Invalid argument/g'
73 }
74
75 _filter_eperm() {
76         _filter_dedupe_error | \
77         sed -e 's/Permission denied/Invalid argument/g'
78 }
79
80 echo "Try cross-device dedupe"
81 _dedupe_range $testdir1/file1 0 $testdir2/file1 0 $blksz \
82         2>&1 | _filter_dedupe_error
83
84 echo "Try unaligned dedupe"
85 _dedupe_range $testdir1/file1 37 $testdir1/file1 59 23 \
86         2>&1 | _filter_dedupe_error
87
88 echo "Try overlapping dedupe"
89 _dedupe_range $testdir1/file1 0 $testdir1/file1 1 $((blksz * 2)) \
90         2>&1 | _filter_dedupe_error
91
92 echo "Try dedupe from past EOF"
93 _dedupe_range $testdir1/file1 $(( (blks + 10) * blksz)) $testdir1/file1 0 $blksz \
94         2>&1 | _filter_dedupe_error
95
96 echo "Try dedupe to past EOF, destination offset beyond EOF"
97 _dedupe_range $testdir1/file1 0 $testdir1/file1 $(( (blks + 10) * blksz)) $blksz \
98         2>&1 | _filter_dedupe_error
99
100 echo "Try dedupe to past EOF, destination offset behind EOF"
101 _dedupe_range $testdir1/file1 0 $testdir1/file1 $(( (blks - 1) * blksz)) $((blksz * 2)) \
102         2>&1 | _filter_dedupe_error
103
104 echo "Try to dedupe a dir"
105 _dedupe_range $testdir1/dir1 0 $testdir1/file2 0 $blksz 2>&1 | _filter_dedupe_error
106
107 echo "Try to dedupe a device"
108 _dedupe_range $testdir1/dev1 0 $testdir1/file2 0 $blksz 2>&1 | _filter_enotty
109
110 echo "Try to dedupe to a dir"
111 _dedupe_range $testdir1/file1 0 $testdir1/dir1 0 $blksz \
112         2>&1 | _filter_test_dir | _filter_dedupe_error
113
114 echo "Try to dedupe to a device"
115 _dedupe_range $testdir1/file1 0 $testdir1/dev1 0 $blksz 2>&1 | _filter_eperm
116
117 echo "Try to dedupe to a fifo"
118 _dedupe_range $testdir1/file1 0 $testdir1/fifo1 0 $blksz -n 2>&1 | _filter_eperm
119
120 echo "Try to dedupe an append-only file"
121 _dedupe_range $testdir1/file1 0 $testdir1/file3 0 $blksz -a \
122         2>&1 >> $seqres.full | _filter_dedupe_error
123
124 echo "Dedupe two files"
125 _dedupe_range $testdir1/file1 0 $testdir1/file2 0 $blksz >> $seqres.full
126 _dedupe_range $testdir2/file1 0 $testdir2/file2 0 $blksz >> $seqres.full
127
128 # success, all done
129 status=0
130 exit