xfs: force file creation to the data device for certain layout tests
[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 _require_scratch_reflink
36
37 #btrfs needs 256mb to create default blockgroup fs
38 _scratch_mkfs_sized $((256 * 1024 * 1024)) >> $seqres.full 2>&1
39 _scratch_mount
40
41 testfile=$SCRATCH_MNT/testfile
42 dummyfile=$SCRATCH_MNT/dummyfile
43 blocksize=$((128 * 1024))
44
45 # create a dummy file, which is used to occupy some fs space first.
46 _pwrite_byte 0xcdcdcdcd 0 $((1 * 1024 * 1024)) $dummyfile > /dev/null
47 _pwrite_byte 0xcdcdcdcd 0 $blocksize  $testfile > /dev/null
48
49 echo "Silence is golden"
50 for ((i = 0; i < 16384; i++)); do
51         _reflink_range $testfile 0 $testfile $(($i * $blocksize)) \
52                 $blocksize > /dev/null 2>&1
53 done
54
55 # consume all remaining free space
56 dd if=/dev/zero of=$SCRATCH_MNT/space >/dev/null 2>&1
57 sync
58
59 # fs is full now and fs internal operations may need some free space, for
60 # example, in btrfs, transaction will need to reserve space first, so here free
61 # 1MB space.
62 rm -f $dummyfile
63 $XFS_IO_PROG -f -c "truncate 0" $testfile
64
65 status=0
66 exit