fstests: don't _require_metadata_journaling before _scratch_mkfs
[xfstests-dev.git] / tests / generic / 336
1 #! /bin/bash
2 # FSQA Test No. 336
3 #
4 # Test that if we have a file F1 with two links, one in a directory A and the
5 # other in directory B, if we remove the link in directory B, move some other
6 # file F2 from directory B into directory C, fsync inode F1, power fail and
7 # remount the filesystem, file F2 exists and is located only in directory C.
8 #
9 #-----------------------------------------------------------------------
10 #
11 # Copyright (C) 2016 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 _scratch_mkfs >>$seqres.full 2>&1
57 _require_metadata_journaling $SCRATCH_DEV
58 _init_flakey
59 _mount_flakey
60
61 # Create our test directories and the file we will later check if it has
62 # disappeared (file bar).
63 mkdir $SCRATCH_MNT/a
64 mkdir $SCRATCH_MNT/b
65 mkdir $SCRATCH_MNT/c
66 touch $SCRATCH_MNT/a/foo
67 ln $SCRATCH_MNT/a/foo $SCRATCH_MNT/b/foo_link
68 touch $SCRATCH_MNT/b/bar
69
70 # Make sure everything is durably persisted.
71 sync
72
73 # Now delete one of the hard links of file foo and move file bar into c/
74 unlink $SCRATCH_MNT/b/foo_link
75 mv $SCRATCH_MNT/b/bar $SCRATCH_MNT/c/
76
77 # Now fsync file foo.
78 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a/foo
79
80 echo "Filesystem content before power failure:"
81 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/b $SCRATCH_MNT/c | _filter_scratch
82
83 # Simulate a power failure / crash and remount the filesystem, so that the
84 # journal/log is replayed.
85 _flakey_drop_and_remount
86
87 # We expect that after the journal/log was replayed, we no longer have the link
88 # foo_link and file bar was moved from directory b/ to directory c/.
89 echo "Filesystem content after power failure:"
90 # Must match what we had before the power failure.
91 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/b $SCRATCH_MNT/c | _filter_scratch
92
93 _unmount_flakey
94
95 status=0
96 exit