2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # Test mmap CoW behavior when the write temporarily fails but the userspace
8 # program writes again.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
22 rm -rf $tmp.* $TEST_DIR/mwrite.out
26 # get standard environment, filters and checks
32 # real QA test starts here
34 _require_scratch_reflink
36 _require_dm_target error
41 echo "Format and mount"
42 _scratch_mkfs > $seqres.full 2>&1
44 _dmerror_mount >> $seqres.full 2>&1
46 testdir=$SCRATCH_MNT/test-$seq
52 filesize=$((blksz * nr))
53 bufsize=$((blksz * bufnr))
55 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
57 echo "Create the original files"
58 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
59 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
64 md5sum $testdir/file1 | _filter_scratch
65 md5sum $testdir/file2 | _filter_scratch
67 echo "CoW and unmount"
69 _dmerror_load_error_table
70 # Insulate ourselves against bash reporting the SIGBUS when we try to modify
72 cat > $tmp.run << ENDL
74 $XFS_IO_PROG -f -c "mmap -rw 0 $filesize" -c "mwrite -S 0x63 0 $filesize" \
75 -c "msync -s 0 $filesize" $testdir/file2 2>&1
77 bash $tmp.run > $tmp.output 2>&1
78 cat $tmp.output >> $seqres.full
79 grep -q error $tmp.output || _fail "mwrite did not fail"
80 _dmerror_load_working_table
83 $XFS_IO_PROG -f -c "mmap -rw 0 $filesize" -c "mwrite -S 0x63 0 $filesize" -c "msync 0 $filesize" $testdir/file2 >> $seqres.full 2>&1
88 md5sum $testdir/file1 | _filter_scratch
90 echo "Check for damage"
93 _repair_scratch_fs >> $seqres.full