generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 649
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2021 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 649
6 #
7 # Regression test for commit:
8 #
9 # 72a048c1056a ("xfs: only set IOMAP_F_SHARED when providing a srcmap to a write")
10 #
11 # If a user creates a sparse shared region in a file, convinces XFS to create a
12 # copy-on-write delayed allocation reservation spanning both the shared blocks
13 # and the holes, and then calls the fallocate unshare command to unshare the
14 # entire sparse region, XFS incorrectly tells iomap that the delalloc blocks
15 # for the holes are shared, which causes it to error out while trying to
16 # unshare a hole.
17 #
18 . ./common/preamble
19 _begin_fstest auto clone unshare
20
21 # Override the default cleanup function.
22 _cleanup()
23 {
24         cd /
25         rm -r -f $tmp.* $TEST_DIR/$seq
26 }
27
28 # Import common functions.
29 . ./common/reflink
30 . ./common/filter
31
32 # real QA test starts here
33
34 # Modify as appropriate.
35 _supported_fs generic
36 _require_cp_reflink
37 _require_test_reflink
38 _require_test_program "punch-alternating"
39 _require_xfs_io_command "fpunch"        # make sure punch-alt can do its job
40 _require_xfs_io_command "funshare"
41 test "$FSTYP" = "xfs" && _require_xfs_io_command "cowextsize"
42
43 mkdir $TEST_DIR/$seq
44 file1=$TEST_DIR/$seq/a
45 file2=$TEST_DIR/$seq/b
46
47 $XFS_IO_PROG -f -c "pwrite -S 0x58 -b 10m 0 10m" $file1 >> $seqres.full
48
49 f1sum0="$(md5sum $file1 | _filter_test_dir)"
50
51 _cp_reflink $file1 $file2
52 $here/src/punch-alternating -o 1 $file2
53
54 f2sum0="$(md5sum $file2 | _filter_test_dir)"
55
56 # set cowextsize to the defaults (128k) to force delalloc cow preallocations
57 test "$FSTYP" = "xfs" && $XFS_IO_PROG -c 'cowextsize 0' $file2
58 $XFS_IO_PROG -c "funshare 0 10m" $file2
59
60 f1sum1="$(md5sum $file1 | _filter_test_dir)"
61 f2sum1="$(md5sum $file2 | _filter_test_dir)"
62
63 test "${f1sum0}" = "${f1sum1}" || echo "file1 should not have changed"
64 test "${f2sum0}" = "${f2sum1}" || echo "file2 should not have changed"
65
66 _test_cycle_mount
67
68 f1sum2="$(md5sum $file1 | _filter_test_dir)"
69 f2sum2="$(md5sum $file2 | _filter_test_dir)"
70
71 test "${f1sum2}" = "${f1sum1}" || echo "file1 should not have changed ondisk"
72 test "${f2sum2}" = "${f2sum1}" || echo "file2 should not have changed ondisk"
73
74 # success, all done
75 echo Silence is golden
76 status=0
77 exit