btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / generic / 352
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Fujitsu.  All Rights Reserved.
4 #
5 # FS QA Test 352
6 #
7 # Test fiemap ioctl on heavily deduped file
8 #
9 # This test case will check if reserved extent map searching go
10 # without problem and return correct SHARED flag.
11 # Which btrfs will soft lock up and return wrong shared flag.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/reflink
32 . ./common/punch
33
34 # remove previous $seqres.full before test
35 rm -f $seqres.full
36
37 # real QA test starts here
38
39 # Modify as appropriate.
40 _supported_fs generic
41 _require_scratch_reflink
42 _require_xfs_io_command "fiemap"
43
44 _scratch_mkfs > /dev/null 2>&1
45 _scratch_mount
46
47 blocksize=$((128 * 1024))
48 file="$SCRATCH_MNT/tmp"
49
50 # Golden output is for $LOAD_FACTOR == 1 case
51 orig_nr=8192
52 orig_last_extent=$(($orig_nr * $blocksize / 512))
53 orig_end=$(($orig_last_extent + $blocksize / 512 - 1))
54
55 # Real output
56 nr=$(($orig_nr * $LOAD_FACTOR))
57 last_extent=$(($nr * $blocksize / 512))
58 end=$(($last_extent + $blocksize / 512 - 1))
59
60 # write the initial block for later reflink
61 _pwrite_byte 0xcdcdcdcd 0 $blocksize $file | _filter_xfs_io
62
63 # use reflink to create the rest of the file, whose all extents are all
64 # pointing to the first extent
65 for i in $(seq 1 $nr); do
66         _reflink_range $file 0 $file $(($i * $blocksize)) $blocksize > /dev/null
67 done
68
69 # then call fiemap on that file to test both the shared flag and if
70 # reserved extent mapping search will cause soft lockup
71 $XFS_IO_PROG -c "fiemap -v" $file | _filter_fiemap_flags > $tmp.out
72 cat $tmp.out >> $seqres.full
73
74 # refact the $LOAD_FACTOR to 1 to match the golden output
75 sed -i -e "s/$(($last_extent - 1))/$(($orig_last_extent - 1))/" \
76         -e "s/$last_extent/$orig_last_extent/" \
77         -e "s/$end/$orig_end/" $tmp.out
78 cat $tmp.out
79
80 # success, all done
81 status=0
82 exit