btrfs: test ENOSPC caused by many orphan items
[xfstests-dev.git] / tests / generic / 479
1 #! /bin/bash
2 # FSQA Test No. 479
3 #
4 # Test that when a fsync journal/log exists, if we rename a special file (fifo,
5 # symbolic link or device), create a hard link for it with its old name and then
6 # commit the journal/log, if a power loss happens the filesystem will not fail
7 # to replay the journal/log when it is mounted the next time.
8 #
9 #-----------------------------------------------------------------------
10 #
11 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
12 # Author: Filipe Manana <fdmanana@suse.com>
13 #
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License as
16 # published by the Free Software Foundation.
17 #
18 # This program is distributed in the hope that it would be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26 #-----------------------------------------------------------------------
27 #
28
29 seq=`basename $0`
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38         _cleanup_flakey
39         cd /
40         rm -f $tmp.*
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46 . ./common/dmflakey
47
48 # real QA test starts here
49 _supported_fs generic
50 _supported_os Linux
51 _require_scratch
52 _require_dm_target flakey
53
54 rm -f $seqres.full
55
56 run_test()
57 {
58         local file_type=$1
59
60         _scratch_mkfs >>$seqres.full 2>&1
61         _require_metadata_journaling $SCRATCH_DEV
62         _init_flakey
63         _mount_flakey
64
65         mkdir $SCRATCH_MNT/testdir
66         case $file_type in
67         symlink)
68                 ln -s xxx $SCRATCH_MNT/testdir/foo
69                 ;;
70         fifo)
71                 mkfifo $SCRATCH_MNT/testdir/foo
72                 ;;
73         dev)
74                 mknod $SCRATCH_MNT/testdir/foo c 0 0
75                 ;;
76         *)
77                 _fail "Invalid file type argument: $file_type"
78         esac
79         # Make sure everything done so far is durably persisted.
80         sync
81
82         # Create a file and fsync it just to create a journal/log. This file
83         # must be in the same directory as our special file "foo".
84         touch $SCRATCH_MNT/testdir/f1
85         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/f1
86
87         # Rename our special file and then create link that has its old name.
88         mv $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/bar
89         ln $SCRATCH_MNT/testdir/bar $SCRATCH_MNT/testdir/foo
90
91         # Create a second file and fsync it. This is just to durably persist the
92         # fsync journal/log which is typically modified by the previous rename
93         # and link operations. This file does not need to be placed in the same
94         # directory as our special file.
95         touch $SCRATCH_MNT/f2
96         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/f2
97
98         # Simulate a power failure and mount the filesystem to check that
99         # replaying the fsync log/journal succeeds, that is the mount operation
100         # does not fail.
101         _flakey_drop_and_remount
102         _unmount_flakey
103         _cleanup_flakey
104 }
105
106 run_test symlink
107 run_test fifo
108 run_test dev
109
110 echo "Silence is golden"
111 status=0
112 exit