2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # Reflink a file with a few dozen extents, CoW a few blocks, and rm.
8 # Inject an error during refcount updates to test log recovery. Use
9 # cowextsize so that the refcount failure is somewhere in the CoW remap
10 # instead of when we're stashing the CoW orphan record.
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
24 _scratch_unmount > /dev/null 2>&1
28 # get standard environment, filters and checks
34 # real QA test starts here
37 _require_scratch_reflink
38 _require_xfs_io_command "cowextsize"
39 _require_xfs_io_command "fpunch"
40 _require_xfs_io_error_injection "refcount_finish_one"
47 echo "Format filesystem"
48 _scratch_mkfs >/dev/null 2>&1
49 _scratch_mount >> $seqres.full
51 $XFS_IO_PROG -c "cowextsize $sz" $SCRATCH_MNT
54 _pwrite_byte 0x66 0 $sz $SCRATCH_MNT/file1 >> $seqres.full
55 _cp_reflink $SCRATCH_MNT/file1 $SCRATCH_MNT/file2
56 _cp_reflink $SCRATCH_MNT/file1 $SCRATCH_MNT/file3
58 # Punch holes in file3
59 seq 1 2 $blks | while read off; do
60 $XFS_IO_PROG -c "fpunch $((off * blksz)) $blksz" $SCRATCH_MNT/file3 >> $seqres.full
65 md5sum $SCRATCH_MNT/file1 | _filter_scratch
66 md5sum $SCRATCH_MNT/file2 | _filter_scratch
67 md5sum $SCRATCH_MNT/file3 | _filter_scratch
69 $XFS_IO_PROG -c "pwrite -W -S 0x67 $((10 * blksz)) 1" $SCRATCH_MNT/file2 >> $seqres.full
73 _scratch_inject_error "refcount_finish_one"
75 echo "CoW a few blocks"
76 $XFS_IO_PROG -c "pwrite -W -S 0x67 -b $sz $((10 * blksz)) $((10 * blksz))" $SCRATCH_MNT/file2 >> $seqres.full 2>&1
78 echo "FS should be shut down, touch will fail"
79 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
81 echo "Remount to replay log"
82 _scratch_inject_logprint >> $seqres.full
84 echo "FS should be online, touch should succeed"
85 touch $SCRATCH_MNT/goodfs
87 echo "Check files again"
88 md5sum $SCRATCH_MNT/file1 | _filter_scratch
89 md5sum $SCRATCH_MNT/file2 | _filter_scratch
90 md5sum $SCRATCH_MNT/file3 | _filter_scratch