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 _begin_fstest auto clone
16 # Import common functions.
21 # real QA test starts here
23 # Modify as appropriate.
25 _require_scratch_reflink
26 _require_xfs_io_command "fiemap"
28 _scratch_mkfs > /dev/null 2>&1
31 blocksize=$((128 * 1024))
32 file="$SCRATCH_MNT/tmp"
34 # Golden output is for $LOAD_FACTOR == 1 case
36 orig_last_extent=$(($orig_nr * $blocksize / 512))
37 orig_end=$(($orig_last_extent + $blocksize / 512 - 1))
40 nr=$(($orig_nr * $LOAD_FACTOR))
41 last_extent=$(($nr * $blocksize / 512))
42 end=$(($last_extent + $blocksize / 512 - 1))
44 # write the initial block for later reflink
45 _pwrite_byte 0xcdcdcdcd 0 $blocksize $file | _filter_xfs_io
47 # use reflink to create the rest of the file, whose all extents are all
48 # pointing to the first extent
49 for i in $(seq 1 $nr); do
50 _reflink_range $file 0 $file $(($i * $blocksize)) $blocksize > /dev/null
53 # then call fiemap on that file to test both the shared flag and if
54 # reserved extent mapping search will cause soft lockup
55 $XFS_IO_PROG -c "fiemap -v" $file | _filter_fiemap_flags > $tmp.out
56 cat $tmp.out >> $seqres.full
58 # refact the $LOAD_FACTOR to 1 to match the golden output
59 sed -i -e "s/$(($last_extent - 1))/$(($orig_last_extent - 1))/" \
60 -e "s/$last_extent/$orig_last_extent/" \
61 -e "s/$end/$orig_end/" $tmp.out