tests: remove udf/101
[xfstests-dev.git] / tests / generic / 057
1 #! /bin/bash
2 # FS QA Test No. 057
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 _require_metadata_journaling $SCRATCH_DEV
58
59 rm -f $seqres.full
60
61 _scratch_mkfs >> $seqres.full 2>&1
62 _init_flakey
63 _mount_flakey
64
65 # Create our test file with some data.
66 $XFS_IO_PROG -f -c "pwrite -S 0xaa -b 8K 0 8K" \
67         $SCRATCH_MNT/foo | _filter_xfs_io
68
69 # Make sure the file is durably persisted.
70 sync
71
72 # Append some data to our file, to increase its size.
73 $XFS_IO_PROG -f -c "pwrite -S 0xcc -b 4K 8K 4K" \
74         $SCRATCH_MNT/foo | _filter_xfs_io
75
76 # Fsync the file, so from this point on if a crash/power failure happens, our
77 # new data is guaranteed to be there next time the fs is mounted.
78 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
79
80 # Add one hard link to our file. This made btrfs write into the in memory fsync
81 # log a special inode with generation 0 and an i_size of 0 too. Note that this
82 # didn't update the inode in the fsync log on disk.
83 ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link
84
85 # Now make sure the in memory fsync log is durably persisted.
86 # Creating and fsync'ing another file will do it.
87 touch $SCRATCH_MNT/bar
88 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
89
90 # As expected, before the crash/power failure, we should be able to read the
91 # 12Kb of file data.
92 echo "File content before:"
93 od -t x1 $SCRATCH_MNT/foo
94
95 _flakey_drop_and_remount
96
97 # After mounting the fs again, the fsync log was replayed.
98 # The btrfs fsync log replay code didn't update the i_size of the persisted
99 # inode because the inode item in the log had a special generation with a
100 # value of 0 (and it couldn't know the correct i_size, since that inode item
101 # had a 0 i_size too). This made the last 4Kb of file data inaccessible and
102 # effectively lost.
103 echo "File content after:"
104 od -t x1 $SCRATCH_MNT/foo
105
106 status=0
107 exit