2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Red Hat, Inc. All Rights Reserved.
7 # Regression test for reflink corruption present as of:
8 # 78f0cc9d55cb "xfs: don't use delalloc extents for COW on files with extsize hints"
9 # and (inadvertently) fixed as of:
10 # 36adcbace24e "xfs: fill out the srcmap in iomap_begin"
11 # upstream, and in the 5.4 stable tree with:
12 # aee38af574a1 "xfs: trim IO to found COW extent limit"
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
20 status=1 # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
29 # get standard environment, filters and checks
34 # remove previous $seqres.full before test
37 # real QA test starts here
39 # Modify as appropriate.
44 DIR=$TEST_DIR/dir.$seq
48 # This test essentially creates an existing COW extent which
49 # covers the first 1M, and then does another IO that overlaps it,
50 # but extends beyond it. The bug was that we did not trim the
51 # new IO to the end of the existing COW extent, and so the IO
52 # extended past the COW blocks and corrupted the reflinked files(s).
54 # Make all files w/ 1m hints; create original 2m file
55 $XFS_IO_PROG -c "extsize 1048576" $DIR >/dev/null 2>&1
56 $XFS_IO_PROG -c "cowextsize 1048576" $DIR >/dev/null 2>&1
59 $XFS_IO_PROG -f -c "pwrite -S 0x0 0 2m" -c fsync $DIR/b | _filter_xfs_io
61 # Make a reflinked copy
62 echo "Reflink copy from b to a"
63 cp --reflink=always $DIR/b $DIR/a
68 # Cycle mount to get stuff out of cache
71 # Create a 1m-hinted IO at offset 0, then
72 # do another IO that overlaps but extends past the 1m hint
74 $XFS_IO_PROG -c "pwrite -S 0xa 0k -b 4k 4k" \
75 -c "pwrite -S 0xa 4k -b 1m 1m" \
76 $DIR/a | _filter_xfs_io
78 $XFS_IO_PROG -c fsync $DIR/a
80 echo "Contents of b now:"