2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that after syncing the filesystem, adding a hard link to a file,
8 # syncing the filesystem again, doing a write to the file that increases
9 # its size and then doing a fsync against that file, durably persists the
10 # data written to the file. That is, after log/journal replay, the data
13 # This test is motivated by a bug found in btrfs.
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
21 status=1 # failure is the default!
28 trap "_cleanup; exit \$status" 0 1 2 3 15
30 # get standard environment, filters and checks
35 # real QA test starts here
39 _require_dm_target flakey
43 _scratch_mkfs >> $seqres.full 2>&1
44 _require_metadata_journaling $SCRATCH_DEV
48 # Create the test file with some initial data and then fsync it.
49 # The fsync here is only needed to trigger the issue in btrfs, as it causes the
50 # the flag BTRFS_INODE_NEEDS_FULL_SYNC to be removed from the btrfs inode.
51 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 32k" \
53 $SCRATCH_MNT/foo | _filter_xfs_io
56 # Add a hard link to our file.
57 # On btrfs this sets the flag BTRFS_INODE_COPY_EVERYTHING on the btrfs inode,
58 # which is a necessary condition to trigger the issue.
59 ln $SCRATCH_MNT/foo $SCRATCH_MNT/bar
61 # Sync the filesystem to force a commit of the current btrfs transaction, this
62 # is a necessary condition to trigger the bug on btrfs.
65 # Now append more data to our file, increasing its size, and fsync the file.
66 # In btrfs because the inode flag BTRFS_INODE_COPY_EVERYTHING was set and the
67 # write path did not update the inode item in the btree nor the delayed inode
68 # item (in memory structure) in the current transaction (created by the fsync
69 # handler), the fsync did not record the inode's new i_size in the fsync
70 # log/journal. This made the data unavailable after the fsync log/journal is
72 $XFS_IO_PROG -c "pwrite -S 0xbb 32K 32K" \
74 $SCRATCH_MNT/foo | _filter_xfs_io
76 echo "File content after fsync and before crash:"
77 od -t x1 $SCRATCH_MNT/foo
79 _flakey_drop_and_remount
81 echo "File content after crash and log replay:"
82 od -t x1 $SCRATCH_MNT/foo