generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 321
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Fusion IO. All Rights Reserved.
4 #
5 # FS QA Test No. 321
6 #
7 # Runs various dir fsync tests to cover fsync'ing directory corner cases.
8 #
9 . ./common/preamble
10 _begin_fstest auto quick metadata log
11
12 # Override the default cleanup function.
13 _cleanup()
14 {
15         _cleanup_flakey
16 }
17
18 # Import common functions.
19 . ./common/filter
20 . ./common/dmflakey
21
22 # real QA test starts here
23 _supported_fs generic
24 _require_scratch_nocheck
25 _require_dm_target flakey
26
27 _clean_working_dir()
28 {
29         _mount_flakey
30         rm -rf $SCRATCH_MNT/foo $SCRATCH_MNT/bar
31         _unmount_flakey
32 }
33
34 # Btrfs wasn't making sure the directory survived fsync
35 _directory_test()
36 {
37         echo "fsync new directory"
38         _mount_flakey
39         mkdir $SCRATCH_MNT/bar
40         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
41
42         _flakey_drop_and_remount
43
44         _ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
45         _unmount_flakey
46         _check_scratch_fs $FLAKEY_DEV
47         [ $? -ne 0 ] && _fatal "fsck failed"
48 }
49
50 # Btrfs was losing a rename into a new directory
51 _rename_test()
52 {
53         echo "rename fsync test"
54         _mount_flakey
55         touch $SCRATCH_MNT/foo
56         mkdir $SCRATCH_MNT/bar
57         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
58         mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar/foo
59         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
60         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar/foo
61
62         _flakey_drop_and_remount\
63
64         _ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
65         _ls_l $SCRATCH_MNT/bar | tail -n +2 | awk '{ print $1, $9 }'
66         _unmount_flakey
67         _check_scratch_fs $FLAKEY_DEV
68         [ $? -ne 0 ] && _fatal "fsck failed"
69 }
70
71 # Btrfs was failing to replay a log when we had a inode with a smaller inode
72 # number that is renamed into a directory with a higher inode number
73 _replay_rename_test()
74 {
75         echo "replay rename fsync test"
76         _mount_flakey
77         touch $SCRATCH_MNT/foo
78         mkdir $SCRATCH_MNT/bar
79         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
80         mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar/foo
81         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
82
83         # This is to force btrfs to relog the entire inode including the ref so
84         # we are sure to try and replay the ref along with the dir_index item
85         setfattr -n user.foo -v blah $SCRATCH_MNT/bar/foo >> $seqres.full 2>&1
86
87         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar/foo
88
89         _flakey_drop_and_remount
90
91         _ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
92         _ls_l $SCRATCH_MNT/bar | tail -n +2 | awk '{ print $1, $9 }'
93         _unmount_flakey
94 }
95
96 _scratch_mkfs >> $seqres.full 2>&1
97 _require_metadata_journaling $SCRATCH_DEV
98
99 # Create a basic flakey device that will never error out
100 _init_flakey
101
102 _directory_test
103 _clean_working_dir
104 _rename_test
105 _clean_working_dir
106 _replay_rename_test
107
108 status=0
109 exit