generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 090
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. 090
6 #
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
11 # is available.
12 #
13 # This test is motivated by a bug found in btrfs.
14 #
15 . ./common/preamble
16 _begin_fstest metadata auto quick log
17
18 # Override the default cleanup function.
19 _cleanup()
20 {
21         _cleanup_flakey
22         rm -f $tmp.*
23 }
24
25 # Import common functions.
26 . ./common/filter
27 . ./common/dmflakey
28
29 # real QA test starts here
30 _supported_fs generic
31 _require_scratch
32 _require_hardlinks
33 _require_dm_target flakey
34
35 _scratch_mkfs >> $seqres.full 2>&1
36 _require_metadata_journaling $SCRATCH_DEV
37 _init_flakey
38 _mount_flakey
39
40 # Create the test file with some initial data and then fsync it.
41 # The fsync here is only needed to trigger the issue in btrfs, as it causes the
42 # the flag BTRFS_INODE_NEEDS_FULL_SYNC to be removed from the btrfs inode.
43 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 32k" \
44                 -c "fsync" \
45                 $SCRATCH_MNT/foo | _filter_xfs_io
46 sync
47
48 # Add a hard link to our file.
49 # On btrfs this sets the flag BTRFS_INODE_COPY_EVERYTHING on the btrfs inode,
50 # which is a necessary condition to trigger the issue.
51 ln $SCRATCH_MNT/foo $SCRATCH_MNT/bar
52
53 # Sync the filesystem to force a commit of the current btrfs transaction, this
54 # is a necessary condition to trigger the bug on btrfs.
55 sync
56
57 # Now append more data to our file, increasing its size, and fsync the file.
58 # In btrfs because the inode flag BTRFS_INODE_COPY_EVERYTHING was set and the
59 # write path did not update the inode item in the btree nor the delayed inode
60 # item (in memory structure) in the current transaction (created by the fsync
61 # handler), the fsync did not record the inode's new i_size in the fsync
62 # log/journal. This made the data unavailable after the fsync log/journal is
63 # replayed.
64 $XFS_IO_PROG -c "pwrite -S 0xbb 32K 32K" \
65                 -c "fsync" \
66                 $SCRATCH_MNT/foo | _filter_xfs_io
67
68 echo "File content after fsync and before crash:"
69 od -t x1 $SCRATCH_MNT/foo
70
71 _flakey_drop_and_remount
72
73 echo "File content after crash and log replay:"
74 od -t x1 $SCRATCH_MNT/foo
75
76 status=0
77 exit