generic/395: remove workarounds for wrong error codes
[xfstests-dev.git] / tests / generic / 056
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. 056
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 one file with data and fsync it.
50 # This made the btrfs fsync log persist the data and the inode metadata with
51 # a correct inode->i_size (4096 bytes).
52 $XFS_IO_PROG -f -c "pwrite -S 0xaa -b 4K 0 4K" -c "fsync" \
53         $SCRATCH_MNT/foo | _filter_xfs_io
54
55 # Now add one hard link to our file. This made the btrfs code update the fsync
56 # log, in memory only, with an inode metadata having a size of 0.
57 ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link
58
59 # Now force persistence of the fsync log to disk, for example, by fsyncing some
60 # other file.
61 touch $SCRATCH_MNT/bar
62 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
63
64 # Before a power loss or crash, we could read the 4Kb of data from our file as
65 # expected.
66 echo "File content before:"
67 od -t x1 $SCRATCH_MNT/foo
68
69 _flakey_drop_and_remount
70
71 # After the fsync log replay, because the fsync log had a value of 0 for our
72 # inode's i_size, we couldn't read anymore the 4Kb of data that we previously
73 # wrote and fsync'ed. The size of the file became 0 after the fsync log replay.
74 echo "File content after:"
75 od -t x1 $SCRATCH_MNT/foo
76
77 status=0
78 exit