fstests: move test group info to test files
[xfstests-dev.git] / tests / generic / 479
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 479
6 #
7 # Test that when a fsync journal/log exists, if we rename a special file (fifo,
8 # symbolic link or device), create a hard link for it with its old name and then
9 # commit the journal/log, if a power loss happens the filesystem will not fail
10 # to replay the journal/log when it is mounted the next time.
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_symlinks
31 _require_mknod
32 _require_dm_target flakey
33
34 run_test()
35 {
36         local file_type=$1
37
38         _scratch_mkfs >>$seqres.full 2>&1
39         _require_metadata_journaling $SCRATCH_DEV
40         _init_flakey
41         _mount_flakey
42
43         mkdir $SCRATCH_MNT/testdir
44         case $file_type in
45         symlink)
46                 ln -s xxx $SCRATCH_MNT/testdir/foo
47                 ;;
48         fifo)
49                 mkfifo $SCRATCH_MNT/testdir/foo
50                 ;;
51         dev)
52                 mknod $SCRATCH_MNT/testdir/foo c 0 0
53                 ;;
54         *)
55                 _fail "Invalid file type argument: $file_type"
56         esac
57         # Make sure everything done so far is durably persisted.
58         sync
59
60         # Create a file and fsync it just to create a journal/log. This file
61         # must be in the same directory as our special file "foo".
62         touch $SCRATCH_MNT/testdir/f1
63         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/f1
64
65         # Rename our special file and then create link that has its old name.
66         mv $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/bar
67         ln $SCRATCH_MNT/testdir/bar $SCRATCH_MNT/testdir/foo
68
69         # Create a second file and fsync it. This is just to durably persist the
70         # fsync journal/log which is typically modified by the previous rename
71         # and link operations. This file does not need to be placed in the same
72         # directory as our special file.
73         touch $SCRATCH_MNT/f2
74         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/f2
75
76         # Simulate a power failure and mount the filesystem to check that
77         # replaying the fsync log/journal succeeds, that is the mount operation
78         # does not fail.
79         _flakey_drop_and_remount
80         _unmount_flakey
81         _cleanup_flakey
82 }
83
84 run_test symlink
85 run_test fifo
86 run_test dev
87
88 echo "Silence is golden"
89 status=0
90 exit