2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Fujitsu. All Rights Reserved.
7 # Test fiemap ioctl on heavily deduped file
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.
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
28 # get standard environment, filters and checks
34 # remove previous $seqres.full before test
37 # real QA test starts here
39 # Modify as appropriate.
41 _require_scratch_reflink
42 _require_xfs_io_command "fiemap"
44 _scratch_mkfs > /dev/null 2>&1
47 blocksize=$((128 * 1024))
48 file="$SCRATCH_MNT/tmp"
50 # Golden output is for $LOAD_FACTOR == 1 case
52 orig_last_extent=$(($orig_nr * $blocksize / 512))
53 orig_end=$(($orig_last_extent + $blocksize / 512 - 1))
56 nr=$(($orig_nr * $LOAD_FACTOR))
57 last_extent=$(($nr * $blocksize / 512))
58 end=$(($last_extent + $blocksize / 512 - 1))
60 # write the initial block for later reflink
61 _pwrite_byte 0xcdcdcdcd 0 $blocksize $file | _filter_xfs_io
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
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
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