generic: test for file loss after mix of rename, fsync and inode eviction
[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 . ./common/preamble
13 _begin_fstest auto quick metadata log
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18         _cleanup_flakey
19         cd /
20         rm -f $tmp.*
21 }
22
23 # Import common functions.
24 . ./common/filter
25 . ./common/dmflakey
26
27 # real QA test starts here
28 _supported_fs generic
29 _require_scratch
30 _require_dm_target flakey
31
32 _scratch_mkfs >>$seqres.full 2>&1
33 _require_metadata_journaling $SCRATCH_DEV
34 _init_flakey
35 _mount_flakey
36
37 mkdir $SCRATCH_MNT/a
38 $XFS_IO_PROG -f -c "pwrite -S 0xf1 0 16K" $SCRATCH_MNT/a/foo | _filter_xfs_io
39 # Make sure everything done so far is durably persisted.
40 sync
41
42 # Now rename file foo to bar and create a new file named foo under the same
43 # directory. After a power failure we must see the two files.
44 mv $SCRATCH_MNT/a/foo $SCRATCH_MNT/a/bar
45 $XFS_IO_PROG -f -c "pwrite -S 0xba 0 16K" $SCRATCH_MNT/a/foo | _filter_xfs_io
46 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a/foo
47
48 echo "File digests before log replay:"
49 md5sum $SCRATCH_MNT/a/foo | _filter_scratch
50 md5sum $SCRATCH_MNT/a/bar | _filter_scratch
51
52 # Simulate a power failure and mount again the filesystem to trigger replay of
53 # its journal/log.
54 _flakey_drop_and_remount
55
56 echo "Directory a/ contents after log replay:"
57 ls -R $SCRATCH_MNT/a | _filter_scratch
58
59 echo "File digests after log replay:"
60 # Must match what we got before the power failure.
61 md5sum $SCRATCH_MNT/a/foo | _filter_scratch
62 md5sum $SCRATCH_MNT/a/bar | _filter_scratch
63
64 _unmount_flakey
65 status=0
66 exit