lib/: spdx license conversion
[xfstests-dev.git] / tests / generic / 342
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. 342
6 #
7 # Test that if we rename a file, create a new file that has the old name of the
8 # other file and is a child of the same parent directory, fsync the new inode,
9 # power fail and mount the filesystem, we do not lose the first file and that
10 # file has the name it was renamed to.
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 $SCRATCH_MNT/a
45 $XFS_IO_PROG -f -c "pwrite -S 0xf1 0 16K" $SCRATCH_MNT/a/foo | _filter_xfs_io
46 # Make sure everything done so far is durably persisted.
47 sync
48
49 # Now rename file foo to bar and create a new file named foo under the same
50 # directory. After a power failure we must see the two files.
51 mv $SCRATCH_MNT/a/foo $SCRATCH_MNT/a/bar
52 $XFS_IO_PROG -f -c "pwrite -S 0xba 0 16K" $SCRATCH_MNT/a/foo | _filter_xfs_io
53 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a/foo
54
55 echo "File digests before log replay:"
56 md5sum $SCRATCH_MNT/a/foo | _filter_scratch
57 md5sum $SCRATCH_MNT/a/bar | _filter_scratch
58
59 # Simulate a power failure and mount again the filesystem to trigger replay of
60 # its journal/log.
61 _flakey_drop_and_remount
62
63 echo "Directory a/ contents after log replay:"
64 ls -R $SCRATCH_MNT/a | _filter_scratch
65
66 echo "File digests after log replay:"
67 # Must match what we got before the power failure.
68 md5sum $SCRATCH_MNT/a/foo | _filter_scratch
69 md5sum $SCRATCH_MNT/a/bar | _filter_scratch
70
71 _unmount_flakey
72 status=0
73 exit