generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 414
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 414
6 #
7 # Check that reflinking adjacent blocks in a file produces a single
8 # block mapping extent.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 7 15
18
19 _cleanup()
20 {
21         cd /
22         rm -rf $tmp.*
23         wait
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/reflink
30
31 # real QA test starts here
32 _supported_os Linux
33 _supported_fs generic
34 _require_scratch_reflink
35 _require_xfs_io_command "falloc"
36 _require_xfs_io_command "fiemap"
37
38 echo "Format and mount"
39 _scratch_mkfs > $seqres.full 2>&1
40 _scratch_mount >> $seqres.full 2>&1
41
42 testdir=$SCRATCH_MNT/test-$seq
43 mkdir $testdir
44
45 blocks=32
46 blksz=65536
47 sz=$((blocks * blksz))
48
49 echo "Create the original files"
50 $XFS_IO_PROG -f -c "falloc 0 $sz" $testdir/file1 >> $seqres.full
51 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
52 seq 0 $blksz $((sz - blksz)) | while read offset; do
53         _reflink_range $testdir/file1 $offset $testdir/file2 $offset $blksz >> $seqres.full
54 done
55
56 echo "Compare files"
57 md5sum $testdir/file1 | _filter_scratch
58 md5sum $testdir/file2 | _filter_scratch
59
60 echo "Check extent counts"
61 f1=$(_count_extents $testdir/file1)
62 f2=$(_count_extents $testdir/file2)
63 s1=$($XFS_IO_PROG -c 'fiemap -v' $testdir/file1 | awk '{print $5}' | grep -c '0x.*[2367aAbBfF]...$')
64 s2=$($XFS_IO_PROG -c 'fiemap -v' $testdir/file2 | awk '{print $5}' | grep -c '0x.*[2367aAbBfF]...$')
65
66 # Did the fs combine the extent mappings when we made f2?
67 test $f1 -eq $f2 || echo "f1 ($f1) != f2 ($f2)"
68 test $s1 -eq $s2 || echo "s1 ($s1) != s2 ($s2)"
69 test $f1 -eq $s1 || echo "f1 ($f1) != s1 ($f1)"
70 test $f2 -eq $s2 || echo "f2 ($f2) != s2 ($f2)"
71
72 _scratch_cycle_mount
73
74 echo "Compare files after remounting"
75 md5sum $testdir/file1 | _filter_scratch
76 md5sum $testdir/file2 | _filter_scratch
77
78 echo "Check extent counts"
79 f1=$(_count_extents $testdir/file1)
80 f2=$(_count_extents $testdir/file2)
81 s1=$($XFS_IO_PROG -c 'fiemap -v' $testdir/file1 | awk '{print $5}' | grep -c '0x.*[2367aAbBfF]...$')
82 s2=$($XFS_IO_PROG -c 'fiemap -v' $testdir/file2 | awk '{print $5}' | grep -c '0x.*[2367aAbBfF]...$')
83
84 # Are the mappings still combined?
85 test $f1 -eq $f2 || echo "f1 ($f1) != f2 ($f2)"
86 test $s1 -eq $s2 || echo "s1 ($s1) != s2 ($s2)"
87 test $f1 -eq $s1 || echo "f1 ($f1) != s1 ($f1)"
88 test $f2 -eq $s2 || echo "f2 ($f2) != s2 ($f2)"
89
90 # success, all done
91 status=0
92 exit