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 _begin_fstest auto quick clone
15 # Override the default cleanup function.
19 _scratch_unmount > /dev/null 2>&1
23 # Import common functions.
28 # real QA test starts here
31 _require_scratch_reflink
32 _require_xfs_io_command "cowextsize"
33 _require_xfs_io_command "fpunch"
34 _require_xfs_io_error_injection "refcount_finish_one"
39 echo "Format filesystem"
40 _scratch_mkfs >/dev/null 2>&1
41 _scratch_mount >> $seqres.full
43 $XFS_IO_PROG -c "cowextsize $sz" $SCRATCH_MNT
46 _pwrite_byte 0x66 0 $sz $SCRATCH_MNT/file1 >> $seqres.full
47 _cp_reflink $SCRATCH_MNT/file1 $SCRATCH_MNT/file2
48 _cp_reflink $SCRATCH_MNT/file1 $SCRATCH_MNT/file3
50 # Punch holes in file3
51 seq 1 2 $blks | while read off; do
52 $XFS_IO_PROG -c "fpunch $((off * blksz)) $blksz" $SCRATCH_MNT/file3 >> $seqres.full
57 md5sum $SCRATCH_MNT/file1 | _filter_scratch
58 md5sum $SCRATCH_MNT/file2 | _filter_scratch
59 md5sum $SCRATCH_MNT/file3 | _filter_scratch
61 $XFS_IO_PROG -c "pwrite -W -S 0x67 $((10 * blksz)) 1" $SCRATCH_MNT/file2 >> $seqres.full
65 _scratch_inject_error "refcount_finish_one"
67 echo "CoW a few blocks"
68 $XFS_IO_PROG -c "pwrite -W -S 0x67 -b $sz $((10 * blksz)) $((10 * blksz))" $SCRATCH_MNT/file2 >> $seqres.full 2>&1
70 echo "FS should be shut down, touch will fail"
71 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
73 echo "Remount to replay log"
74 _scratch_inject_logprint >> $seqres.full
76 echo "FS should be online, touch should succeed"
77 touch $SCRATCH_MNT/goodfs
79 echo "Check files again"
80 md5sum $SCRATCH_MNT/file1 | _filter_scratch
81 md5sum $SCRATCH_MNT/file2 | _filter_scratch
82 md5sum $SCRATCH_MNT/file3 | _filter_scratch