btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / generic / 304
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 304
6 #
7 # Check that high-offset dedupes work.
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.* $testdir
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 _require_test_dedupe
32 _require_cp_reflink
33
34 rm -f $seqres.full
35
36 echo "Format and mount"
37 testdir=$TEST_DIR/test-$seq
38 mkdir $testdir
39
40 echo "Create the original files"
41 bigoff=9223372036854775806
42 len=9223372036854775807
43 bigoff_64k=9223372036854710272  # bigoff rounded down to 64k
44 $XFS_IO_PROG -f -c "truncate $len" $testdir/file0 >> $seqres.full
45 test -s $testdir/file0 || _notrun "High offset ftruncate failed"
46 _pwrite_byte 0x61 $bigoff 1 $testdir/file1 >> $seqres.full
47 _pwrite_byte 0x61 $bigoff 1 $testdir/file3 >> $seqres.full
48 _pwrite_byte 0x61 1048575 1 $testdir/file2 >> $seqres.full
49
50 echo "Dedupe large single byte file"
51 _dedupe_range $testdir/file1 $bigoff_64k $testdir/file3 $bigoff_64k 65536 \
52         2>&1 >> $seqres.full | _filter_dedupe_error
53
54 echo "Dedupe large empty file"
55 _dedupe_range $testdir/file0 0 $testdir/file4 0 $len \
56         2>&1 >> $seqres.full | _filter_dedupe_error
57
58 echo "Dedupe past maximum file size in dest file (should fail)"
59 _dedupe_range $testdir/file1 0 $testdir/file5 4611686018427322368 $len \
60         2>&1 >> $seqres.full | _filter_dedupe_error
61
62 echo "Dedupe high offset to low offset"
63 _dedupe_range $testdir/file1 $bigoff_64k $testdir/file6 1048576 65535 \
64         2>&1 >> $seqres.full | _filter_dedupe_error
65
66 echo "Dedupe past source file EOF (should fail)"
67 _dedupe_range $testdir/file2 524288 $testdir/file7 0 1048576 \
68         2>&1 >> $seqres.full | _filter_dedupe_error
69
70 echo "Dedupe max size at nonzero offset (should fail)"
71 _dedupe_range $testdir/file2 524288 $testdir/file8 0 $len \
72         2>&1 >> $seqres.full | _filter_dedupe_error
73
74 echo "Dedupe with huge off/len (should fail)"
75 _dedupe_range $testdir/file2 $bigoff_64k $testdir/file9 0 $bigoff_64k \
76         2>&1 >> $seqres.full | _filter_dedupe_error
77
78 echo "Check file creation"
79 _test_cycle_mount
80 echo "file3"
81 $XFS_IO_PROG -c "pread -v -q $bigoff 1" $testdir/file3
82 echo "file4"
83 $XFS_IO_PROG -c "pread -v -q $bigoff 1" $testdir/file4
84 # file5 should fail above
85 echo "file6"
86 $XFS_IO_PROG -c "pread -v -q 1114110 1" $testdir/file6
87 # file7 should fail above
88
89 # success, all done
90 status=0
91 exit