2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Check that various invalid dedupe scenarios are rejected.
10 _begin_fstest auto quick clone dedupe
12 # Override the default cleanup function.
16 rm -rf $tmp.* $testdir1
19 # Import common functions.
24 # real QA test starts here
26 _require_scratch_dedupe
29 echo "Format and mount"
30 _scratch_mkfs > $seqres.full 2>&1
31 _scratch_mount >> $seqres.full 2>&1
33 testdir1="$TEST_DIR/test-$seq"
37 testdir2=$SCRATCH_MNT/test-$seq
40 echo "Create the original files"
41 blksz="$(_get_block_size $testdir1)"
45 free_blocks0=$(stat -f $testdir1 -c '%f')
47 filesize=$((blksz * nr))
48 _pwrite_byte 0x61 0 $sz $testdir1/file1 >> $seqres.full
49 _pwrite_byte 0x61 0 $sz $testdir1/file2 >> $seqres.full
50 _pwrite_byte 0x61 0 $sz $testdir1/file3 >> $seqres.full
51 _pwrite_byte 0x61 0 $sz $testdir2/file1 >> $seqres.full
52 _pwrite_byte 0x61 0 $sz $testdir2/file2 >> $seqres.full
54 seq 1 $((2 * blksz / 250)) | while read f; do
55 touch $testdir1/dir1/$f
57 mknod $testdir1/dev1 c 1 3
58 mkfifo $testdir1/fifo1
62 _filter_dedupe_error | \
63 sed -e 's/Inappropriate ioctl for device/Invalid argument/g'
67 _filter_dedupe_error | \
68 sed -e 's/Permission denied/Invalid argument/g'
71 echo "Try cross-device dedupe"
72 _dedupe_range $testdir1/file1 0 $testdir2/file1 0 $blksz \
73 2>&1 | _filter_dedupe_error
75 echo "Try unaligned dedupe"
76 _dedupe_range $testdir1/file1 37 $testdir1/file1 59 23 \
77 2>&1 | _filter_dedupe_error
79 echo "Try overlapping dedupe"
80 _dedupe_range $testdir1/file1 0 $testdir1/file1 1 $((blksz * 2)) \
81 2>&1 | _filter_dedupe_error
83 echo "Try dedupe from past EOF"
84 _dedupe_range $testdir1/file1 $(( (blks + 10) * blksz)) $testdir1/file1 0 $blksz \
85 2>&1 | _filter_dedupe_error
87 echo "Try dedupe to past EOF, destination offset beyond EOF"
88 _dedupe_range $testdir1/file1 0 $testdir1/file1 $(( (blks + 10) * blksz)) $blksz \
89 2>&1 | _filter_dedupe_error
91 echo "Try dedupe to past EOF, destination offset behind EOF"
92 _dedupe_range $testdir1/file1 0 $testdir1/file1 $(( (blks - 1) * blksz)) $((blksz * 2)) \
93 2>&1 | _filter_dedupe_error
95 echo "Try to dedupe a dir"
96 _dedupe_range $testdir1/dir1 0 $testdir1/file2 0 $blksz 2>&1 | _filter_dedupe_error
98 echo "Try to dedupe a device"
99 _dedupe_range $testdir1/dev1 0 $testdir1/file2 0 $blksz 2>&1 | _filter_enotty
101 echo "Try to dedupe to a dir"
102 _dedupe_range $testdir1/file1 0 $testdir1/dir1 0 $blksz \
103 2>&1 | _filter_test_dir | _filter_dedupe_error
105 echo "Try to dedupe to a device"
106 _dedupe_range $testdir1/file1 0 $testdir1/dev1 0 $blksz 2>&1 | _filter_eperm
108 echo "Try to dedupe to a fifo"
109 _dedupe_range $testdir1/file1 0 $testdir1/fifo1 0 $blksz -n 2>&1 | _filter_eperm
111 echo "Try to dedupe an append-only file"
112 _dedupe_range $testdir1/file1 0 $testdir1/file3 0 $blksz -a \
113 2>&1 >> $seqres.full | _filter_dedupe_error
115 echo "Dedupe two files"
116 _dedupe_range $testdir1/file1 0 $testdir1/file2 0 $blksz >> $seqres.full
117 _dedupe_range $testdir2/file1 0 $testdir2/file2 0 $blksz >> $seqres.full