generic: test adding filesystem-level fscrypt key via key_id
[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 _supported_os Linux
42 _require_scratch_reflink
43 _require_xfs_io_command "fiemap"
44
45 _scratch_mkfs > /dev/null 2>&1
46 _scratch_mount
47
48 blocksize=$((128 * 1024))
49 file="$SCRATCH_MNT/tmp"
50
51 # Golden output is for $LOAD_FACTOR == 1 case
52 orig_nr=8192
53 orig_last_extent=$(($orig_nr * $blocksize / 512))
54 orig_end=$(($orig_last_extent + $blocksize / 512 - 1))
55
56 # Real output
57 nr=$(($orig_nr * $LOAD_FACTOR))
58 last_extent=$(($nr * $blocksize / 512))
59 end=$(($last_extent + $blocksize / 512 - 1))
60
61 # write the initial block for later reflink
62 _pwrite_byte 0xcdcdcdcd 0 $blocksize $file | _filter_xfs_io
63
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
68 done
69
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
74
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
79 cat $tmp.out
80
81 # success, all done
82 status=0
83 exit