generic: convert tests to SPDX license tags
[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 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         _cleanup_flakey
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/dmflakey
30
31 # real QA test starts here
32 _supported_fs generic
33 _supported_os Linux
34 _require_scratch
35 _require_dm_target flakey
36
37 rm -f $seqres.full
38
39 run_test()
40 {
41         local file_type=$1
42
43         _scratch_mkfs >>$seqres.full 2>&1
44         _require_metadata_journaling $SCRATCH_DEV
45         _init_flakey
46         _mount_flakey
47
48         mkdir $SCRATCH_MNT/testdir
49         case $file_type in
50         symlink)
51                 ln -s xxx $SCRATCH_MNT/testdir/foo
52                 ;;
53         fifo)
54                 mkfifo $SCRATCH_MNT/testdir/foo
55                 ;;
56         dev)
57                 mknod $SCRATCH_MNT/testdir/foo c 0 0
58                 ;;
59         *)
60                 _fail "Invalid file type argument: $file_type"
61         esac
62         # Make sure everything done so far is durably persisted.
63         sync
64
65         # Create a file and fsync it just to create a journal/log. This file
66         # must be in the same directory as our special file "foo".
67         touch $SCRATCH_MNT/testdir/f1
68         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/f1
69
70         # Rename our special file and then create link that has its old name.
71         mv $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/bar
72         ln $SCRATCH_MNT/testdir/bar $SCRATCH_MNT/testdir/foo
73
74         # Create a second file and fsync it. This is just to durably persist the
75         # fsync journal/log which is typically modified by the previous rename
76         # and link operations. This file does not need to be placed in the same
77         # directory as our special file.
78         touch $SCRATCH_MNT/f2
79         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/f2
80
81         # Simulate a power failure and mount the filesystem to check that
82         # replaying the fsync log/journal succeeds, that is the mount operation
83         # does not fail.
84         _flakey_drop_and_remount
85         _unmount_flakey
86         _cleanup_flakey
87 }
88
89 run_test symlink
90 run_test fifo
91 run_test dev
92
93 echo "Silence is golden"
94 status=0
95 exit