generic/629: add missing copy_range command check
[xfstests-dev.git] / tests / generic / 629
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. 629
6 #
7 # Make sure that copy_file_range forces the log out if we open the file with
8 # O_SYNC or set FS_XFLAG_SYNC on the file.  We test that it actually forced the
9 # log by 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/dmerror
34
35 # real QA test starts here
36 _supported_fs generic
37 _require_dm_target error
38 _require_xfs_io_command "chattr" "s"
39 _require_xfs_io_command "copy_range"
40 _require_scratch
41
42 rm -f $seqres.full
43
44 # Format filesystem and set up quota limits
45 _scratch_mkfs > $seqres.full
46 _require_metadata_journaling $SCRATCH_DEV
47 _dmerror_init
48 _dmerror_mount
49
50 # Test that O_SYNC actually results in file data being written even if the
51 # fs immediately dies
52 echo "test o_sync write"
53 $XFS_IO_PROG -x -f -s -c "pwrite -S 0x58 0 1m -b 1m" $SCRATCH_MNT/0 >> $seqres.full
54 _dmerror_load_error_table
55 _dmerror_unmount
56 _dmerror_load_working_table
57 _dmerror_mount
58 md5sum $SCRATCH_MNT/0 | _filter_scratch
59
60 # Set up initial files for copy test
61 $XFS_IO_PROG -f -c 'pwrite -S 0x58 0 1m -b 1m' $SCRATCH_MNT/a >> $seqres.full
62 touch $SCRATCH_MNT/b
63 sync
64
65 # Test that unaligned copy file range forces dirty data/metadata to disk when
66 # destination file opened with O_SYNC
67 echo "test unaligned copy range o_sync"
68 $XFS_IO_PROG -x -s -c "copy_range -s 13 -d 13 -l 1048550 $SCRATCH_MNT/a" $SCRATCH_MNT/b >> $seqres.full
69 _dmerror_load_error_table
70 _dmerror_unmount
71 _dmerror_load_working_table
72 _dmerror_mount
73 md5sum $SCRATCH_MNT/a $SCRATCH_MNT/b | _filter_scratch
74
75 # Set up dest file with chattr +S
76 rm -f $SCRATCH_MNT/b
77 touch $SCRATCH_MNT/b
78 chattr +S $SCRATCH_MNT/b
79 sync
80
81 # Test that unaligned copy file range forces dirty data/metadata to disk when
82 # destination file has the sync iflag set
83 echo "test unaligned copy range iflag"
84 $XFS_IO_PROG -x -c "copy_range -s 13 -d 13 -l 1048550 $SCRATCH_MNT/a" $SCRATCH_MNT/b >> $seqres.full
85 _dmerror_load_error_table
86 _dmerror_unmount
87 _dmerror_load_working_table
88 _dmerror_mount
89 md5sum $SCRATCH_MNT/a $SCRATCH_MNT/b | _filter_scratch
90
91 # success, all done
92 status=0
93 exit