generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 335
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. 335
6 #
7 # Test that if we move one file between directories, fsync the parent directory
8 # of the old directory, power fail and remount the filesystem, the file is not
9 # lost and it's located at the destination directory.
10 #
11 . ./common/preamble
12 _begin_fstest auto quick metadata log
13
14 # Override the default cleanup function.
15 _cleanup()
16 {
17         _cleanup_flakey
18         cd /
19         rm -f $tmp.*
20 }
21
22 # Import common functions.
23 . ./common/filter
24 . ./common/dmflakey
25
26 # real QA test starts here
27 _supported_fs generic
28 _require_scratch
29 _require_dm_target flakey
30
31 _scratch_mkfs >>$seqres.full 2>&1
32 _require_metadata_journaling $SCRATCH_DEV
33 _init_flakey
34 _mount_flakey
35
36 # Create our test directories and the file we will later check if it has
37 # disappeared.
38 mkdir -p $SCRATCH_MNT/a/b
39 mkdir $SCRATCH_MNT/c
40 touch $SCRATCH_MNT/a/b/foo
41
42 # Make sure everything is durably persisted.
43 sync
44
45 # Now move our test file into a new parent directory.
46 mv $SCRATCH_MNT/a/b/foo $SCRATCH_MNT/c/
47
48 # Create a new file inside the parent directory of the directory where our test
49 # file foo was previously at. This is just to ensure the fsync we do next
50 # against that parent directory actually does something and it's not a noop.
51 touch $SCRATCH_MNT/a/bar
52 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a
53
54 echo "Filesystem content before power failure:"
55 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/c | _filter_scratch
56
57 # Simulate a power failure / crash and remount the filesystem, so that the
58 # journal/log is replayed.
59 _flakey_drop_and_remount
60
61 # We expect our file foo to exist, have an entry in the new parent
62 # directory (c/) and not have anymore an entry in the old parent directory
63 # (a/b/).
64 # The new file named bar should also exist.
65 echo "Filesystem content after power failure:"
66 # Must match what we had before the power failure.
67 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/c | _filter_scratch
68
69 _unmount_flakey
70
71 status=0
72 exit