2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
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.
12 _begin_fstest auto quick metadata log
14 # Override the default cleanup function.
22 # Import common functions.
26 # real QA test starts here
29 _require_dm_target flakey
31 _scratch_mkfs >>$seqres.full 2>&1
32 _require_metadata_journaling $SCRATCH_DEV
36 # Create our test directories and the file we will later check if it has
38 mkdir -p $SCRATCH_MNT/a/b
40 touch $SCRATCH_MNT/a/b/foo
42 # Make sure everything is durably persisted.
45 # Now move our test file into a new parent directory.
46 mv $SCRATCH_MNT/a/b/foo $SCRATCH_MNT/c/
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
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
63 echo "Filesystem content before power failure:"
64 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/c | _filter_scratch
66 # Simulate a power failure / crash and remount the filesystem, so that the
67 # journal/log is replayed.
68 _flakey_drop_and_remount
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
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