generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 387
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Fujitsu.  All Rights Reserved.
4 #
5 # FS QA Test 387
6 #
7 # Create a heavily reflinked file, then check whether we can truncate
8 # it correctly.
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 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/reflink
29
30 # remove previous $seqres.full before test
31 rm -f $seqres.full
32
33 # Modify as appropriate.
34 _supported_fs generic
35 _supported_os Linux
36 _require_scratch_reflink
37
38 #btrfs needs 256mb to create default blockgroup fs
39 _scratch_mkfs_sized $((256 * 1024 * 1024)) >> $seqres.full 2>&1
40 _scratch_mount
41
42 testfile=$SCRATCH_MNT/testfile
43 dummyfile=$SCRATCH_MNT/dummyfile
44 blocksize=$((128 * 1024))
45
46 # create a dummy file, which is used to occupy some fs space first.
47 _pwrite_byte 0xcdcdcdcd 0 $((1 * 1024 * 1024)) $dummyfile > /dev/null
48 _pwrite_byte 0xcdcdcdcd 0 $blocksize  $testfile > /dev/null
49
50 echo "Silence is golden"
51 for ((i = 0; i < 16384; i++)); do
52         _reflink_range $testfile 0 $testfile $(($i * $blocksize)) \
53                 $blocksize > /dev/null 2>&1
54 done
55
56 # consume all remaining free space
57 dd if=/dev/zero of=$SCRATCH_MNT/space >/dev/null 2>&1
58 sync
59
60 # fs is full now and fs internal operations may need some free space, for
61 # example, in btrfs, transaction will need to reserve space first, so here free
62 # 1MB space.
63 rm -f $dummyfile
64 $XFS_IO_PROG -f -c "truncate 0" $testfile
65
66 status=0
67 exit