generic/223: make sure all files get created on the data device
[xfstests-dev.git] / tests / generic / 515
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 515
6 #
7 # Ensure that reflinking into a file well beyond EOF zeroes everything between
8 # the old EOF and the start of the newly linked chunk.  This is an adaptation
9 # of a reproducer script that Eric Sandeen formulated from a stale data
10 # exposure bug uncovered by shared/010.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/reflink
29
30 # real QA test starts here
31 _supported_fs generic
32 _require_scratch_reflink
33 _require_xfs_io_command "falloc"
34
35 rm -f $seqres.full
36
37 # Fill disk with a well known pattern so that stale data exposure becomes much
38 # more obvious.
39 $XFS_IO_PROG -c "pwrite -S 0x58 -b 1m 0 300m" $SCRATCH_DEV >> $seqres.full
40 _scratch_mkfs_sized $((300 * 1048576)) >>$seqres.full 2>&1
41 _scratch_mount
42
43 DONOR1=$SCRATCH_MNT/a
44 TARGET=$SCRATCH_MNT/b
45 blksz=65536
46
47 $XFS_IO_PROG -f -c "pwrite -S 0x72 0 $blksz" $DONOR1 >> $seqres.full
48
49 $XFS_IO_PROG -f \
50         -c "falloc -k $((blksz*2)) $blksz"        \
51         -c "pwrite -S 0x57 $((blksz*16)) 8192" \
52         -c "fdatasync" \
53         -c 'stat' \
54         -c "reflink $DONOR1 0 $((blksz*17)) $blksz" \
55                 $TARGET >> $seqres.full
56
57 od -tx1 -Ad -c $TARGET >> $seqres.full
58 md5sum $DONOR1 | _filter_scratch
59 md5sum $TARGET | _filter_scratch
60
61 _scratch_cycle_mount
62
63 od -tx1 -Ad -c $TARGET >> $seqres.full
64 md5sum $DONOR1 | _filter_scratch
65 md5sum $TARGET | _filter_scratch
66
67 status=0
68 exit