generic: test for file fsync after moving it to a new parent directory
[xfstests-dev.git] / tests / generic / 322
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. 322
6 #
7 # Runs various rename fsync tests to cover some rename fsync corner cases.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 status=1        # failure is the default!
15
16 _cleanup()
17 {
18         _cleanup_flakey
19 }
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 # get standard environment, filters and checks
23 . ./common/rc
24 . ./common/filter
25 . ./common/dmflakey
26
27 # real QA test starts here
28 _supported_fs generic
29 _supported_os Linux
30 _require_scratch_nocheck
31 _require_dm_target flakey
32
33 rm -f $seqres.full
34
35 _clean_working_dir()
36 {
37         _mount_flakey
38         rm -rf $SCRATCH_MNT/foo $SCRATCH_MNT/bar
39         _unmount_flakey
40 }
41
42 # Btrfs wasn't making sure the new file after rename survived the fsync
43 _rename_test()
44 {
45         echo "fsync rename test"
46         _mount_flakey
47         $XFS_IO_PROG -f -c "pwrite 0 1M" -c "fsync" $SCRATCH_MNT/foo \
48                 > $seqres.full 2>&1 || _fail "xfs_io failed"
49         mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar
50         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
51         md5sum $SCRATCH_MNT/bar | _filter_scratch
52
53         _flakey_drop_and_remount
54
55         md5sum $SCRATCH_MNT/bar | _filter_scratch
56         _unmount_flakey
57         _check_scratch_fs $FLAKEY_DEV
58         [ $? -ne 0 ] && _fatal "fsck failed"
59 }
60
61 # Btrfs was dropping some of the modified extents in between fsyncs if we
62 # renamed.
63 _write_after_fsync_rename_test()
64 {
65         echo "fsync rename test"
66         _mount_flakey
67         $XFS_IO_PROG -f -c "pwrite 0 1M" -c "fsync" -c "pwrite 2M 1M" \
68                 -c "sync_range -b" $SCRATCH_MNT/foo > $seqres.full 2>&1 || _fail "xfs_io failed"
69         mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar
70         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
71         md5sum $SCRATCH_MNT/bar | _filter_scratch
72
73         _flakey_drop_and_remount
74
75         md5sum $SCRATCH_MNT/bar | _filter_scratch
76         _unmount_flakey
77 }
78
79 _scratch_mkfs >> $seqres.full 2>&1
80 _require_metadata_journaling $SCRATCH_DEV
81
82 # Create a basic flakey device that will never error out
83 _init_flakey
84
85 _rename_test
86 _clean_working_dir
87 _write_after_fsync_rename_test
88
89 status=0
90 exit