2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that after a combination of file renames, deletions, linking and creating
8 # new files with names that were previously deleted, if we fsync the new file,
9 # after a power failure we are able to mount the filesystem and all file names
10 # correspond to the correct inodes.
13 _begin_fstest auto quick log
15 # Override the default cleanup function.
23 # Import common functions.
27 # real QA test starts here
31 _require_dm_target flakey
33 _scratch_mkfs >>$seqres.full 2>&1
34 _require_metadata_journaling $SCRATCH_DEV
38 mkdir $SCRATCH_MNT/testdir
39 echo -n "foo" > $SCRATCH_MNT/testdir/fname1
40 echo -n "hello" > $SCRATCH_MNT/testdir/fname2
42 # For a different variant of the same test but when files have hardlinks too.
43 mkdir $SCRATCH_MNT/testdir2
44 echo -n "foo" > $SCRATCH_MNT/testdir2/zz
45 ln $SCRATCH_MNT/testdir2/zz $SCRATCH_MNT/testdir2/zz_link
46 echo -n "hello" > $SCRATCH_MNT/testdir2/a
48 # Make sure everything done so far is durably persisted.
51 # Rename, remove and link files such that one new name corresponds to the name
52 # of a deleted file and one new file has the old name of the renamed file. Then
53 # fsync only the new file.
54 mv $SCRATCH_MNT/testdir/fname1 $SCRATCH_MNT/testdir/fname3
55 rm -f $SCRATCH_MNT/testdir/fname2
56 ln $SCRATCH_MNT/testdir/fname3 $SCRATCH_MNT/testdir/fname2
57 echo -n "bar" > $SCRATCH_MNT/testdir/fname1
58 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/fname1
60 # A second variant, more complex, that involves files with hardlinks too.
62 # The following 3 renames are equivalent to a rename exchange (zz_link to a), but
63 # without the atomicity which isn't required here.
64 mv $SCRATCH_MNT/testdir2/a $SCRATCH_MNT/testdir2/tmp
65 mv $SCRATCH_MNT/testdir2/zz_link $SCRATCH_MNT/testdir2/a
66 mv $SCRATCH_MNT/testdir2/tmp $SCRATCH_MNT/testdir2/zz_link
68 # The following rename and file creation are equivalent to a rename whiteout.
69 mv $SCRATCH_MNT/testdir2/zz $SCRATCH_MNT/testdir2/a2
70 echo -n "bar" > $SCRATCH_MNT/testdir2/zz
72 # Fsync of zz should work and produce correct results after a power failure.
73 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir2/zz
75 # Simulate a power failure and mount the filesystem to check that all file names
76 # exist and correspond to the correct inodes.
77 _flakey_drop_and_remount
79 echo "File fname1 data after power failure: $(cat $SCRATCH_MNT/testdir/fname1)"
80 echo "File fname2 data after power failure: $(cat $SCRATCH_MNT/testdir/fname2)"
81 echo "File fname3 data after power failure: $(cat $SCRATCH_MNT/testdir/fname3)"
83 echo "File a data after power failure: $(cat $SCRATCH_MNT/testdir2/a)"
84 echo "File a2 data after power failure: $(cat $SCRATCH_MNT/testdir2/a2)"
85 echo "File zz data after power failure: $(cat $SCRATCH_MNT/testdir2/zz)"
86 echo "File zz_link data after power failure: $(cat $SCRATCH_MNT/testdir2/zz_link)"