generic: shutdown fs after log recovery
[xfstests-dev.git] / tests / generic / 387
1 #! /bin/bash
2 # FS QA Test 387
3 #
4 # Create a heavily reflinked file, then check whether we can truncate
5 # it correctly.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2016 Fujitsu.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         cd /
37         rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43 . ./common/reflink
44
45 # remove previous $seqres.full before test
46 rm -f $seqres.full
47
48 # Modify as appropriate.
49 _supported_fs generic
50 _supported_os Linux
51 _require_scratch_reflink
52
53 _scratch_mkfs_sized $((32 * 1024 * 1024)) >> $seqres.full 2>&1
54 _scratch_mount
55
56 testfile=$SCRATCH_MNT/testfile
57 dummyfile=$SCRATCH_MNT/dummyfile
58 blocksize=$((128 * 1024))
59
60 # create a dummy file, which is used to occupy some fs space first.
61 _pwrite_byte 0xcdcdcdcd 0 $((1 * 1024 * 1024)) $dummyfile > /dev/null
62 _pwrite_byte 0xcdcdcdcd 0 $blocksize  $testfile > /dev/null
63
64 echo "Silence is golden"
65 for ((i = 0; i < 16384; i++)); do
66         _reflink_range $testfile 0 $testfile $(($i * $blocksize)) \
67                 $blocksize > /dev/null 2>&1
68 done
69
70 # consume all remaining free space
71 dd if=/dev/zero of=$SCRATCH_MNT/space >/dev/null 2>&1
72 sync
73
74 # fs is full now and fs internal operations may need some free space, for
75 # example, in btrfs, transaction will need to reserve space first, so here free
76 # 1MB space.
77 rm -f $dummyfile
78 $XFS_IO_PROG -f -c "truncate 0" $testfile
79
80 status=0
81 exit