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.
42 _require_scratch_reflink
43 _require_xfs_io_command "fiemap"
45 _scratch_mkfs > /dev/null 2>&1
48 blocksize=$((128 * 1024))
49 file="$SCRATCH_MNT/tmp"
51 # Golden output is for $LOAD_FACTOR == 1 case
53 orig_last_extent=$(($orig_nr * $blocksize / 512))
54 orig_end=$(($orig_last_extent + $blocksize / 512 - 1))
57 nr=$(($orig_nr * $LOAD_FACTOR))
58 last_extent=$(($nr * $blocksize / 512))
59 end=$(($last_extent + $blocksize / 512 - 1))
61 # write the initial block for later reflink
62 _pwrite_byte 0xcdcdcdcd 0 $blocksize $file | _filter_xfs_io
64 # use reflink to create the rest of the file, whose all extents are all
65 # pointing to the first extent
66 for i in $(seq 1 $nr); do
67 _reflink_range $file 0 $file $(($i * $blocksize)) $blocksize > /dev/null
70 # then call fiemap on that file to test both the shared flag and if
71 # reserved extent mapping search will cause soft lockup
72 $XFS_IO_PROG -c "fiemap -v" $file | _filter_fiemap_flags > $tmp.out
73 cat $tmp.out >> $seqres.full
75 # refact the $LOAD_FACTOR to 1 to match the golden output
76 sed -i -e "s/$(($last_extent - 1))/$(($orig_last_extent - 1))/" \
77 -e "s/$last_extent/$orig_last_extent/" \
78 -e "s/$end/$orig_end/" $tmp.out