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 and we unmount.
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
21 rm -rf $tmp.* $TEST_DIR/mwrite.out
25 # get standard environment, filters and checks
31 # real QA test starts here
32 _require_scratch_reflink
34 _require_dm_target error
39 echo "Format and mount"
40 _scratch_mkfs > $seqres.full 2>&1
42 _dmerror_mount >> $seqres.full 2>&1
44 testdir=$SCRATCH_MNT/test-$seq
50 filesize=$((blksz * nr))
51 bufsize=$((blksz * bufnr))
53 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
55 echo "Create the original files"
56 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
57 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
62 md5sum $testdir/file1 | _filter_scratch
63 md5sum $testdir/file2 | _filter_scratch
65 echo "CoW and unmount"
67 _dmerror_load_error_table
68 # Insulate ourselves against bash reporting the SIGBUS when we try to modify
70 cat > $tmp.run << ENDL
72 $XFS_IO_PROG -f -c "mmap -rw 0 $filesize" \
73 -c "mwrite -S 0x63 0 $filesize" $testdir/file2 >> $seqres.full 2>&1
75 bash $tmp.run 2> /dev/null
76 _dmerror_load_working_table
77 rm -rf $testdir/file2 >> $seqres.full 2>&1
82 md5sum $testdir/file1 | _filter_scratch
84 echo "Check for damage"
87 _repair_scratch_fs >> $seqres.full