fstests: use _require_symlinks on all necessary tests
[xfstests-dev.git] / tests / generic / 341
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 341
6 #
7 # Test that if we rename a directory, create a new file or directory that has
8 # the old name of our former directory and is a child of the same parent
9 # directory, fsync the new inode, power fail and mount the filesystem, we see
10 # our first directory with the new name and no files under it were lost.
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 _scratch_mkfs >>$seqres.full 2>&1
40 _require_metadata_journaling $SCRATCH_DEV
41 _init_flakey
42 _mount_flakey
43
44 mkdir -p $SCRATCH_MNT/a/x
45 $XFS_IO_PROG -f -c "pwrite -S 0xaf 0 32K" $SCRATCH_MNT/a/x/foo | _filter_xfs_io
46 $XFS_IO_PROG -f -c "pwrite -S 0xba 0 32K" $SCRATCH_MNT/a/x/bar | _filter_xfs_io
47 # Make sure everything done so far is durably persisted.
48 sync
49
50 echo "File digests before power failure:"
51 md5sum $SCRATCH_MNT/a/x/foo | _filter_scratch
52 md5sum $SCRATCH_MNT/a/x/bar | _filter_scratch
53
54 # Now rename directory x to y and create a new directory that is also named x.
55 # Then fsync the new directory. After a power failure, we must see directories
56 # y and x and directory y has the same files (and with the same content) it had
57 # before the power failure.
58 mv $SCRATCH_MNT/a/x $SCRATCH_MNT/a/y
59 mkdir $SCRATCH_MNT/a/x
60 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a/x
61
62 # Simulate a power failure and mount again the filesystem to trigger replay of
63 # its journal/log.
64 _flakey_drop_and_remount
65
66 echo "Directory a/ contents after log replay:"
67 ls -R $SCRATCH_MNT/a | _filter_scratch
68
69 echo "File digests after log replay:"
70 # Must match what we got before the power failure.
71 md5sum $SCRATCH_MNT/a/y/foo | _filter_scratch
72 md5sum $SCRATCH_MNT/a/y/bar | _filter_scratch
73
74 _unmount_flakey
75 status=0
76 exit