generic/554: hide permision warning on exfat
[xfstests-dev.git] / tests / generic / 057
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 057
6 #
7 # This test is motivated by an fsync issue discovered in btrfs.
8 # The issue was that we could lose file data, that was previously fsync'ed
9 # successfully, if we end up adding a hard link to our inode and then persist
10 # the fsync log later via an fsync of other inode for example.
11 #
12 # The btrfs issue was fixed by the following linux kernel patch:
13 #
14 #  Btrfs: fix fsync data loss after adding hard link to inode
15 #
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 here=`pwd`
21 tmp=/tmp/$$
22 status=1        # failure is the default!
23
24 _cleanup()
25 {
26         _cleanup_flakey
27         rm -f $tmp.*
28 }
29 trap "_cleanup; exit \$status" 0 1 2 3 15
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34 . ./common/dmflakey
35
36 # real QA test starts here
37 _supported_fs generic
38 _require_scratch
39 _require_hardlinks
40 _require_dm_target flakey
41
42 rm -f $seqres.full
43
44 _scratch_mkfs >> $seqres.full 2>&1
45 _require_metadata_journaling $SCRATCH_DEV
46 _init_flakey
47 _mount_flakey
48
49 # Create our test file with some data.
50 $XFS_IO_PROG -f -c "pwrite -S 0xaa -b 8K 0 8K" \
51         $SCRATCH_MNT/foo | _filter_xfs_io
52
53 # Make sure the file is durably persisted.
54 sync
55
56 # Append some data to our file, to increase its size.
57 $XFS_IO_PROG -f -c "pwrite -S 0xcc -b 4K 8K 4K" \
58         $SCRATCH_MNT/foo | _filter_xfs_io
59
60 # Fsync the file, so from this point on if a crash/power failure happens, our
61 # new data is guaranteed to be there next time the fs is mounted.
62 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
63
64 # Add one hard link to our file. This made btrfs write into the in memory fsync
65 # log a special inode with generation 0 and an i_size of 0 too. Note that this
66 # didn't update the inode in the fsync log on disk.
67 ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link
68
69 # Now make sure the in memory fsync log is durably persisted.
70 # Creating and fsync'ing another file will do it.
71 touch $SCRATCH_MNT/bar
72 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
73
74 # As expected, before the crash/power failure, we should be able to read the
75 # 12Kb of file data.
76 echo "File content before:"
77 od -t x1 $SCRATCH_MNT/foo
78
79 _flakey_drop_and_remount
80
81 # After mounting the fs again, the fsync log was replayed.
82 # The btrfs fsync log replay code didn't update the i_size of the persisted
83 # inode because the inode item in the log had a special generation with a
84 # value of 0 (and it couldn't know the correct i_size, since that inode item
85 # had a 0 i_size too). This made the last 4Kb of file data inaccessible and
86 # effectively lost.
87 echo "File content after:"
88 od -t x1 $SCRATCH_MNT/foo
89
90 status=0
91 exit