fstests: move test group info to test files
[xfstests-dev.git] / tests / generic / 527
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. 527
6 #
7 # Test that after a combination of file renames, deletions, linking and creating
8 # new files with names that were previously deleted, if we fsync the new file,
9 # after a power failure we are able to mount the filesystem and all file names
10 # correspond to the correct inodes.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick 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 mkdir $SCRATCH_MNT/testdir
39 echo -n "foo" > $SCRATCH_MNT/testdir/fname1
40 echo -n "hello" > $SCRATCH_MNT/testdir/fname2
41
42 # For a different variant of the same test but when files have hardlinks too.
43 mkdir $SCRATCH_MNT/testdir2
44 echo -n "foo" > $SCRATCH_MNT/testdir2/zz
45 ln $SCRATCH_MNT/testdir2/zz $SCRATCH_MNT/testdir2/zz_link
46 echo -n "hello" > $SCRATCH_MNT/testdir2/a
47
48 # Make sure everything done so far is durably persisted.
49 sync
50
51 # Rename, remove and link files such that one new name corresponds to the name
52 # of a deleted file and one new file has the old name of the renamed file. Then
53 # fsync only the new file.
54 mv $SCRATCH_MNT/testdir/fname1 $SCRATCH_MNT/testdir/fname3
55 rm -f $SCRATCH_MNT/testdir/fname2
56 ln $SCRATCH_MNT/testdir/fname3 $SCRATCH_MNT/testdir/fname2
57 echo -n "bar" > $SCRATCH_MNT/testdir/fname1
58 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/fname1
59
60 # A second variant, more complex, that involves files with hardlinks too.
61
62 # The following 3 renames are equivalent to a rename exchange (zz_link to a), but
63 # without the atomicity which isn't required here.
64 mv $SCRATCH_MNT/testdir2/a $SCRATCH_MNT/testdir2/tmp
65 mv $SCRATCH_MNT/testdir2/zz_link $SCRATCH_MNT/testdir2/a
66 mv $SCRATCH_MNT/testdir2/tmp $SCRATCH_MNT/testdir2/zz_link
67
68 # The following rename and file creation are equivalent to a rename whiteout.
69 mv $SCRATCH_MNT/testdir2/zz $SCRATCH_MNT/testdir2/a2
70 echo -n "bar" > $SCRATCH_MNT/testdir2/zz
71
72 # Fsync of zz should work and produce correct results after a power failure.
73 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir2/zz
74
75 # Simulate a power failure and mount the filesystem to check that all file names
76 # exist and correspond to the correct inodes.
77 _flakey_drop_and_remount
78
79 echo "File fname1 data after power failure: $(cat $SCRATCH_MNT/testdir/fname1)"
80 echo "File fname2 data after power failure: $(cat $SCRATCH_MNT/testdir/fname2)"
81 echo "File fname3 data after power failure: $(cat $SCRATCH_MNT/testdir/fname3)"
82
83 echo "File a data after power failure: $(cat $SCRATCH_MNT/testdir2/a)"
84 echo "File a2 data after power failure: $(cat $SCRATCH_MNT/testdir2/a2)"
85 echo "File zz data after power failure: $(cat $SCRATCH_MNT/testdir2/zz)"
86 echo "File zz_link data after power failure: $(cat $SCRATCH_MNT/testdir2/zz_link)"
87
88 _unmount_flakey
89
90 status=0
91 exit