generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 502
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 502
6 #
7 # Test that if we have a file with 2 (or more) hard links in the same parent
8 # directory, rename of the hard links, rename one of the other hard links to
9 # the old name of the hard link we renamed before, create a new file in the
10 # same parent directory with the old name of second hard link we renamed, fsync
11 # fsync this new file and power fail, we will be able to mount again the
12 # filesystem and the new file and all hard links exist.
13 #
14 . ./common/preamble
15 _begin_fstest auto quick log
16
17 # Override the default cleanup function.
18 _cleanup()
19 {
20         _cleanup_flakey
21         cd /
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 our test file with 2 hard links in the same parent directory.
41 mkdir $SCRATCH_MNT/testdir
42 touch $SCRATCH_MNT/testdir/foo
43 ln $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/bar
44
45 # Make sure everything done so far is durably persisted.
46 sync
47
48 # Now rename the first hard link (foo) to a new name and rename the second hard
49 # link (bar) to the old name of the first hard link (foo).
50 mv $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/qwerty
51 mv $SCRATCH_MNT/testdir/bar $SCRATCH_MNT/testdir/foo
52
53 # Create a new file, in the same parent directory, with the old name of the
54 # second hard link (bar) and fsync this new file.
55 touch $SCRATCH_MNT/testdir/bar
56 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/bar
57
58 echo "Contents of test directory before the power failure:"
59 ls -R $SCRATCH_MNT/testdir | _filter_scratch
60
61 # Simulate a power failure and mount the filesystem to check that we are able to
62 # mount it and we have the same files, with the same hard links, that we had
63 # before the power failure and in the same order.
64 _flakey_drop_and_remount
65
66 echo "Contents of test directory after the power failure:"
67 ls -R $SCRATCH_MNT/testdir | _filter_scratch
68
69 _unmount_flakey
70 _cleanup_flakey
71
72 status=0
73 exit