2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle. All Rights Reserved.
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")
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
30 # get standard environment, filters and checks
36 # real QA test starts here
38 _require_dm_target error
39 _require_scratch_reflink
40 _require_xfs_io_command "chattr" "s"
45 # Format filesystem and set up quota limits
46 _scratch_mkfs > $seqres.full
47 _require_metadata_journaling $SCRATCH_DEV
51 # Test that O_SYNC actually results in file data being written even if the
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
57 _dmerror_load_working_table
59 md5sum $SCRATCH_MNT/0 | _filter_scratch
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
69 # Test that reflink forces dirty data/metadata to disk when destination file
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
75 _dmerror_load_working_table
77 md5sum $SCRATCH_MNT/a $SCRATCH_MNT/b | _filter_scratch
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
85 _dmerror_load_working_table
87 md5sum $SCRATCH_MNT/a $SCRATCH_MNT/d | _filter_scratch
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
93 chattr +S $SCRATCH_MNT/b $SCRATCH_MNT/d
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
102 _dmerror_load_working_table
104 md5sum $SCRATCH_MNT/a $SCRATCH_MNT/b | _filter_scratch
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
112 _dmerror_load_working_table
114 md5sum $SCRATCH_MNT/a $SCRATCH_MNT/d | _filter_scratch