2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that if we fsync a directory A, evict A's inode, move one file from
8 # directory A to a directory B, fsync some other inode that is not directory A,
9 # B or any inode inside these two directories, and then power fail, the file
10 # that was moved is not lost.
13 _begin_fstest auto quick log
15 # Override the default cleanup function.
23 # Import common functions.
27 # real QA test starts here
30 _require_dm_target flakey
32 _scratch_mkfs >>$seqres.full 2>&1
33 _require_metadata_journaling $SCRATCH_DEV
37 # Create two test directories, one with a file we will rename later.
40 echo -n "hello world" > $SCRATCH_MNT/A/foo
42 # Persist everything done so far.
45 # Add some new file to directory A and fsync the directory.
46 touch $SCRATCH_MNT/A/bar
47 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/A
49 # Now evict all inodes from memory. To trigger the original problem on btrfs we
50 # actually only needed to trigger eviction of A's inode, but there's no simple
51 # way to evict a single inode, so evict everything.
52 echo 2 > /proc/sys/vm/drop_caches
54 # Now move file foo from directory A to directory B.
55 mv $SCRATCH_MNT/A/foo $SCRATCH_MNT/B/foo
57 # Now make an fsync to anything except A, B or any file inside them, like for
58 # example create a file at the root directory and fsync this new file.
59 touch $SCRATCH_MNT/baz
60 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/baz
62 # Simulate a power failure and then check file foo still exists.
63 _flakey_drop_and_remount
65 # Since file foo was not explicitly fsynced we can not guarantee that, for every
66 # filesystem, after replaying the journal/log we have file foo inside directory A
67 # or inside directory B. The file must exist however, and can only be found in
68 # one of the directories, not on both.
70 # At the moment of this writing, on f2fs file foo exists always at A/foo,
71 # regardless of the fsync-mode mount option ("-o fsync_mode=posix" or
72 # "-o fsync_mode=strict"). On ext4 and xfs it exists at B/foo. It is also
73 # supposed to exist at B/foo on btrfs (at the moment it doesn't exist in
74 # either directory due to a bug).
79 if [ -f $SCRATCH_MNT/A/foo ]; then
80 echo "File foo data: $(cat $SCRATCH_MNT/A/foo)"
84 if [ -f $SCRATCH_MNT/B/foo ]; then
85 echo "File foo data: $(cat $SCRATCH_MNT/B/foo)"
89 if [ $foo_in_a -eq 1 ] && [ $foo_in_b -eq 1 ]; then
90 echo "File foo found in A/ and B/"
91 elif [ $foo_in_a -eq 0 ] && [ $foo_in_b -eq 0 ]; then
92 echo "File foo is missing"
95 # While here, also check that files bar and baz exist.
96 [ -f $SCRATCH_MNT/A/bar ] || echo "File A/bar is missing"
97 [ -f $SCRATCH_MNT/baz ] || echo "File baz is missing"