generic/335: explicitly fsync file foo when running on btrfs
[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 # btrfs can not guarantee that when we fsync a directory all its subdirectories
55 # created on past transactions are fsynced as well. It may do it sometimes, but
56 # it's not guaranteed, giving such guarantees would be too expensive for large
57 # directories and posix does not require that recursive behaviour. So if we want
58 # the rename of "foo" to be persisted, explicitly fsync "foo".
59 if [ $FSTYP == "btrfs" ]; then
60         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/c/foo
61 fi
62
63 echo "Filesystem content before power failure:"
64 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/c | _filter_scratch
65
66 # Simulate a power failure / crash and remount the filesystem, so that the
67 # journal/log is replayed.
68 _flakey_drop_and_remount
69
70 # We expect our file foo to exist, have an entry in the new parent
71 # directory (c/) and not have anymore an entry in the old parent directory
72 # (a/b/).
73 # The new file named bar should also exist.
74 echo "Filesystem content after power failure:"
75 # Must match what we had before the power failure.
76 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/c | _filter_scratch
77
78 _unmount_flakey
79
80 status=0
81 exit