xfs: fix old fuzz test invocations of xfs_repair
[xfstests-dev.git] / tests / generic / 628
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 628
6 #
7 # Make sure that reflink forces the log out if we open the file with O_SYNC or
8 # set FS_XFLAG_SYNC on the file.  We test that it actually forced the log by
9 # using dm-error to shut down the fs without flushing the log and then
10 # remounting to check file contents.  This is a regression test for commit
11 # 5ffce3cc22a0 ("xfs: force the log after remapping a synchronous-writes file")
12
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1    # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26         _dmerror_unmount
27         _dmerror_cleanup
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33 . ./common/reflink
34 . ./common/dmerror
35
36 # real QA test starts here
37 _supported_fs generic
38 _require_dm_target error
39 _require_scratch_reflink
40 _require_xfs_io_command "chattr" "s"
41 _require_cp_reflink
42
43 rm -f $seqres.full
44
45 # Format filesystem and set up quota limits
46 _scratch_mkfs > $seqres.full
47 _require_metadata_journaling $SCRATCH_DEV
48 _dmerror_init
49 _dmerror_mount
50
51 # Test that O_SYNC actually results in file data being written even if the
52 # fs immediately dies
53 echo "test o_sync write"
54 $XFS_IO_PROG -x -f -s -c "pwrite -S 0x58 0 1m -b 1m" $SCRATCH_MNT/0 >> $seqres.full
55 _dmerror_load_error_table
56 _dmerror_unmount
57 _dmerror_load_working_table
58 _dmerror_mount
59 md5sum $SCRATCH_MNT/0 | _filter_scratch
60
61 # Set up initial files for reflink test
62 $XFS_IO_PROG -f -c 'pwrite -S 0x58 0 1m -b 1m' $SCRATCH_MNT/a >> $seqres.full
63 $XFS_IO_PROG -f -c 'pwrite -S 0x59 0 1m -b 1m' $SCRATCH_MNT/c >> $seqres.full
64 _cp_reflink $SCRATCH_MNT/a $SCRATCH_MNT/e
65 _cp_reflink $SCRATCH_MNT/c $SCRATCH_MNT/d
66 touch $SCRATCH_MNT/b
67 sync
68
69 # Test that reflink forces dirty data/metadata to disk when destination file
70 # opened with O_SYNC
71 echo "test reflink flag not set o_sync"
72 $XFS_IO_PROG -x -s -c "reflink $SCRATCH_MNT/a" $SCRATCH_MNT/b >> $seqres.full
73 _dmerror_load_error_table
74 _dmerror_unmount
75 _dmerror_load_working_table
76 _dmerror_mount
77 md5sum $SCRATCH_MNT/a $SCRATCH_MNT/b | _filter_scratch
78
79 # Test that reflink to a shared file forces dirty data/metadata to disk when
80 # destination is opened with O_SYNC
81 echo "test reflink flag already set o_sync"
82 $XFS_IO_PROG -x -s -c "reflink $SCRATCH_MNT/a" $SCRATCH_MNT/d >> $seqres.full
83 _dmerror_load_error_table
84 _dmerror_unmount
85 _dmerror_load_working_table
86 _dmerror_mount
87 md5sum $SCRATCH_MNT/a $SCRATCH_MNT/d | _filter_scratch
88
89 # Set up the two files with chattr +S
90 rm -f $SCRATCH_MNT/b $SCRATCH_MNT/d
91 _cp_reflink $SCRATCH_MNT/c $SCRATCH_MNT/d
92 touch $SCRATCH_MNT/b
93 chattr +S $SCRATCH_MNT/b $SCRATCH_MNT/d
94 sync
95
96 # Test that reflink forces dirty data/metadata to disk when destination file
97 # has the sync iflag set
98 echo "test reflink flag not set iflag"
99 $XFS_IO_PROG -x -c "reflink $SCRATCH_MNT/a" $SCRATCH_MNT/b >> $seqres.full
100 _dmerror_load_error_table
101 _dmerror_unmount
102 _dmerror_load_working_table
103 _dmerror_mount
104 md5sum $SCRATCH_MNT/a $SCRATCH_MNT/b | _filter_scratch
105
106 # Test that reflink to a shared file forces dirty data/metadata to disk when
107 # destination file has the sync iflag set
108 echo "test reflink flag already set iflag"
109 $XFS_IO_PROG -x -c "reflink $SCRATCH_MNT/a" $SCRATCH_MNT/d >> $seqres.full
110 _dmerror_load_error_table
111 _dmerror_unmount
112 _dmerror_load_working_table
113 _dmerror_mount
114 md5sum $SCRATCH_MNT/a $SCRATCH_MNT/d | _filter_scratch
115
116 # success, all done
117 status=0
118 exit