fstests: don't _require_metadata_journaling before _scratch_mkfs
[xfstests-dev.git] / tests / generic / 056
1 #! /bin/bash
2 # FS QA Test No. 056
3 #
4 # This test is motivated by an fsync issue discovered in btrfs.
5 # The issue was that we could lose file data, that was previously fsync'ed
6 # successfully, if we end up adding a hard link to our inode and then persist
7 # the fsync log later via an fsync of other inode for example.
8 #
9 # The btrfs issue was fixed by the following linux kernel patch:
10 #
11 #  Btrfs: fix fsync data loss after adding hard link to inode
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
36 here=`pwd`
37 tmp=/tmp/$$
38 status=1        # failure is the default!
39
40 _cleanup()
41 {
42         _cleanup_flakey
43         rm -f $tmp.*
44 }
45 trap "_cleanup; exit \$status" 0 1 2 3 15
46
47 # get standard environment, filters and checks
48 . ./common/rc
49 . ./common/filter
50 . ./common/dmflakey
51
52 # real QA test starts here
53 _supported_fs generic
54 _supported_os Linux
55 _require_scratch
56 _require_dm_target flakey
57
58 rm -f $seqres.full
59
60 _scratch_mkfs >> $seqres.full 2>&1
61 _require_metadata_journaling $SCRATCH_DEV
62 _init_flakey
63 _mount_flakey
64
65 # Create one file with data and fsync it.
66 # This made the btrfs fsync log persist the data and the inode metadata with
67 # a correct inode->i_size (4096 bytes).
68 $XFS_IO_PROG -f -c "pwrite -S 0xaa -b 4K 0 4K" -c "fsync" \
69         $SCRATCH_MNT/foo | _filter_xfs_io
70
71 # Now add one hard link to our file. This made the btrfs code update the fsync
72 # log, in memory only, with an inode metadata having a size of 0.
73 ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link
74
75 # Now force persistence of the fsync log to disk, for example, by fsyncing some
76 # other file.
77 touch $SCRATCH_MNT/bar
78 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
79
80 # Before a power loss or crash, we could read the 4Kb of data from our file as
81 # expected.
82 echo "File content before:"
83 od -t x1 $SCRATCH_MNT/foo
84
85 _flakey_drop_and_remount
86
87 # After the fsync log replay, because the fsync log had a value of 0 for our
88 # inode's i_size, we couldn't read anymore the 4Kb of data that we previously
89 # wrote and fsync'ed. The size of the file became 0 after the fsync log replay.
90 echo "File content after:"
91 od -t x1 $SCRATCH_MNT/foo
92
93 status=0
94 exit