generic: add test for boundary in xfs_attr_shortform_verify
[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 _supported_os Linux
39 _require_scratch
40 _require_hardlinks
41 _require_dm_target flakey
42
43 rm -f $seqres.full
44
45 _scratch_mkfs >> $seqres.full 2>&1
46 _require_metadata_journaling $SCRATCH_DEV
47 _init_flakey
48 _mount_flakey
49
50 # Create one file with data and fsync it.
51 # This made the btrfs fsync log persist the data and the inode metadata with
52 # a correct inode->i_size (4096 bytes).
53 $XFS_IO_PROG -f -c "pwrite -S 0xaa -b 4K 0 4K" -c "fsync" \
54         $SCRATCH_MNT/foo | _filter_xfs_io
55
56 # Now add one hard link to our file. This made the btrfs code update the fsync
57 # log, in memory only, with an inode metadata having a size of 0.
58 ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link
59
60 # Now force persistence of the fsync log to disk, for example, by fsyncing some
61 # other file.
62 touch $SCRATCH_MNT/bar
63 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
64
65 # Before a power loss or crash, we could read the 4Kb of data from our file as
66 # expected.
67 echo "File content before:"
68 od -t x1 $SCRATCH_MNT/foo
69
70 _flakey_drop_and_remount
71
72 # After the fsync log replay, because the fsync log had a value of 0 for our
73 # inode's i_size, we couldn't read anymore the 4Kb of data that we previously
74 # wrote and fsync'ed. The size of the file became 0 after the fsync log replay.
75 echo "File content after:"
76 od -t x1 $SCRATCH_MNT/foo
77
78 status=0
79 exit