generic: shutdown fs after log recovery
[xfstests-dev.git] / tests / generic / 098
1 #! /bin/bash
2 # FSQA Test No. 098
3 #
4 # Test that after truncating a file into the middle of a hole causes the new
5 # size of the file to be persisted after a clean unmount of the filesystem (or
6 # after the inode is evicted). This is for the case where all the data following
7 # the hole is not yet durably persisted, that is, that data is only present in
8 # the page cache.
9 #
10 # This test is motivated by an issue found in btrfs.
11 #
12 #-----------------------------------------------------------------------
13 #
14 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
15 # Author: Filipe Manana <fdmanana@suse.com>
16 #
17 # This program is free software; you can redistribute it and/or
18 # modify it under the terms of the GNU General Public License as
19 # published by the Free Software Foundation.
20 #
21 # This program is distributed in the hope that it would be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write the Free Software Foundation,
28 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
29 #-----------------------------------------------------------------------
30 #
31
32 seq=`basename $0`
33 seqres=$RESULT_DIR/$seq
34 echo "QA output created by $seq"
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41         rm -f $tmp.*
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47
48 # real QA test starts here
49 _supported_fs generic
50 _supported_os Linux
51 _require_scratch
52
53 # This test was motivated by an issue found in btrfs when the btrfs no-holes
54 # feature is enabled (introduced in kernel 3.14). So enable the feature if the
55 # fs being tested is btrfs.
56 if [ $FSTYP == "btrfs" ]; then
57         _require_btrfs_fs_feature "no_holes"
58         _require_btrfs_mkfs_feature "no-holes"
59         MKFS_OPTIONS="$MKFS_OPTIONS -O no-holes"
60 fi
61
62 rm -f $seqres.full
63
64 _scratch_mkfs >>$seqres.full 2>&1
65 _scratch_mount
66
67 # Create our test file with some data and durably persist it.
68 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 128K" $SCRATCH_MNT/foo | _filter_xfs_io
69 sync
70
71 # Append some data to the file, increasing its size, and leave a hole between
72 # the old size and the start offset if the following write. So our file gets
73 # a hole in the range [128Kb, 256Kb[.
74 $XFS_IO_PROG -c "pwrite -S 0xbb 256K 32K" $SCRATCH_MNT/foo | _filter_xfs_io
75
76 # Now truncate our file to a smaller size that is in the middle of the hole we
77 # previously created. On most truncate implementations the data we appended
78 # before gets discarded from memory (with truncate_setsize()) and never ends
79 # up being written to disk.
80 $XFS_IO_PROG -c "truncate 160K" $SCRATCH_MNT/foo
81
82 _scratch_cycle_mount
83
84 # We expect to see a file with a size of 160Kb, with the first 128Kb of data all
85 # having the value 0xaa and the remaining 32Kb of data all having the value 0x00
86 echo "File content after remount:"
87 od -t x1 $SCRATCH_MNT/foo
88
89 status=0
90 exit