generic/520: Remove sync in clean_dir
[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
35 rm -f $seqres.full
36
37 echo "Format and mount"
38 _scratch_mkfs > $seqres.full 2>&1
39 _scratch_mount >> $seqres.full 2>&1
40
41 testdir1="$TEST_DIR/test-$seq"
42 rm -rf $testdir1
43 mkdir $testdir1
44
45 testdir2=$SCRATCH_MNT/test-$seq
46 mkdir $testdir2
47
48 echo "Create the original files"
49 blksz="$(_get_block_size $testdir1)"
50 blks=1000
51 margin='7%'
52 sz=$((blksz * blks))
53 free_blocks0=$(stat -f $testdir1 -c '%f')
54 nr=4
55 filesize=$((blksz * nr))
56 _pwrite_byte 0x61 0 $sz $testdir1/file1 >> $seqres.full
57 _pwrite_byte 0x61 0 $sz $testdir1/file2 >> $seqres.full
58 _pwrite_byte 0x61 0 $sz $testdir1/file3 >> $seqres.full
59 _pwrite_byte 0x61 0 $sz $testdir2/file1 >> $seqres.full
60 _pwrite_byte 0x61 0 $sz $testdir2/file2 >> $seqres.full
61 mkdir $testdir1/dir1
62 seq 1 $((2 * blksz / 250)) | while read f; do
63         touch $testdir1/dir1/$f
64 done
65 mknod $testdir1/dev1 c 1 3
66 mkfifo $testdir1/fifo1
67 sync
68
69 _filter_enotty() {
70         _filter_dedupe_error | \
71         sed -e 's/Inappropriate ioctl for device/Invalid argument/g'
72 }
73
74 _filter_eperm() {
75         _filter_dedupe_error | \
76         sed -e 's/Permission denied/Invalid argument/g'
77 }
78
79 echo "Try cross-device dedupe"
80 _dedupe_range $testdir1/file1 0 $testdir2/file1 0 $blksz \
81         2>&1 | _filter_dedupe_error
82
83 echo "Try unaligned dedupe"
84 _dedupe_range $testdir1/file1 37 $testdir1/file1 59 23 \
85         2>&1 | _filter_dedupe_error
86
87 echo "Try overlapping dedupe"
88 _dedupe_range $testdir1/file1 0 $testdir1/file1 1 $((blksz * 2)) \
89         2>&1 | _filter_dedupe_error
90
91 echo "Try dedupe from past EOF"
92 _dedupe_range $testdir1/file1 $(( (blks + 10) * blksz)) $testdir1/file1 0 $blksz \
93         2>&1 | _filter_dedupe_error
94
95 echo "Try dedupe to past EOF, destination offset beyond EOF"
96 _dedupe_range $testdir1/file1 0 $testdir1/file1 $(( (blks + 10) * blksz)) $blksz \
97         2>&1 | _filter_dedupe_error
98
99 echo "Try dedupe to past EOF, destination offset behind EOF"
100 _dedupe_range $testdir1/file1 0 $testdir1/file1 $(( (blks - 1) * blksz)) $((blksz * 2)) \
101         2>&1 | _filter_dedupe_error
102
103 echo "Try to dedupe a dir"
104 _dedupe_range $testdir1/dir1 0 $testdir1/file2 0 $blksz 2>&1 | _filter_dedupe_error
105
106 echo "Try to dedupe a device"
107 _dedupe_range $testdir1/dev1 0 $testdir1/file2 0 $blksz 2>&1 | _filter_enotty
108
109 echo "Try to dedupe to a dir"
110 _dedupe_range $testdir1/file1 0 $testdir1/dir1 0 $blksz \
111         2>&1 | _filter_test_dir | _filter_dedupe_error
112
113 echo "Try to dedupe to a device"
114 _dedupe_range $testdir1/file1 0 $testdir1/dev1 0 $blksz 2>&1 | _filter_eperm
115
116 echo "Try to dedupe to a fifo"
117 _dedupe_range $testdir1/file1 0 $testdir1/fifo1 0 $blksz -n 2>&1 | _filter_eperm
118
119 echo "Try to dedupe an append-only file"
120 _dedupe_range $testdir1/file1 0 $testdir1/file3 0 $blksz -a \
121         2>&1 >> $seqres.full | _filter_dedupe_error
122
123 echo "Dedupe two files"
124 _dedupe_range $testdir1/file1 0 $testdir1/file2 0 $blksz >> $seqres.full
125 _dedupe_range $testdir2/file1 0 $testdir2/file2 0 $blksz >> $seqres.full
126
127 # success, all done
128 status=0
129 exit