generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 336
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 336
6 #
7 # Test that if we have a file F1 with two links, one in a directory A and the
8 # other in directory B, if we remove the link in directory B, move some other
9 # file F2 from directory B into directory C, fsync inode F1, power fail and
10 # remount the filesystem, file F2 exists and is located only in directory C.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick metadata log
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18         _cleanup_flakey
19         cd /
20         rm -f $tmp.*
21 }
22
23 # Import common functions.
24 . ./common/filter
25 . ./common/dmflakey
26
27 # real QA test starts here
28 _supported_fs generic
29 _require_scratch
30 _require_hardlinks
31 _require_dm_target flakey
32
33 _scratch_mkfs >>$seqres.full 2>&1
34 _require_metadata_journaling $SCRATCH_DEV
35 _init_flakey
36 _mount_flakey
37
38 # Create our test directories and the file we will later check if it has
39 # disappeared (file bar).
40 mkdir $SCRATCH_MNT/a
41 mkdir $SCRATCH_MNT/b
42 mkdir $SCRATCH_MNT/c
43 touch $SCRATCH_MNT/a/foo
44 ln $SCRATCH_MNT/a/foo $SCRATCH_MNT/b/foo_link
45 touch $SCRATCH_MNT/b/bar
46
47 # Make sure everything is durably persisted.
48 sync
49
50 # Now delete one of the hard links of file foo and move file bar into c/
51 unlink $SCRATCH_MNT/b/foo_link
52 mv $SCRATCH_MNT/b/bar $SCRATCH_MNT/c/
53
54 # Now fsync file foo.
55 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a/foo
56
57 echo "Filesystem content before power failure:"
58 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/b $SCRATCH_MNT/c | _filter_scratch
59
60 # Simulate a power failure / crash and remount the filesystem, so that the
61 # journal/log is replayed.
62 _flakey_drop_and_remount
63
64 # We expect that after the journal/log was replayed, we no longer have the link
65 # foo_link and file bar was moved from directory b/ to directory c/.
66 echo "Filesystem content after power failure:"
67 # Must match what we had before the power failure.
68 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/b $SCRATCH_MNT/c | _filter_scratch
69
70 _unmount_flakey
71
72 status=0
73 exit