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 block remap to test log recovery.
11 _begin_fstest auto quick clone
13 # Override the default cleanup function.
17 _scratch_unmount > /dev/null 2>&1
21 # Import common functions.
26 # real QA test starts here
29 _require_scratch_reflink
30 _require_xfs_io_command "fpunch"
31 _require_xfs_io_error_injection "bmap_finish_one"
36 echo "Format filesystem"
37 _scratch_mkfs >/dev/null 2>&1
38 _scratch_mount >> $seqres.full
41 _pwrite_byte 0x66 0 $sz $SCRATCH_MNT/file1 >> $seqres.full
42 _cp_reflink $SCRATCH_MNT/file1 $SCRATCH_MNT/file2
43 _cp_reflink $SCRATCH_MNT/file1 $SCRATCH_MNT/file3
45 # Punch holes in file3
46 seq 1 2 $blks | while read off; do
47 $XFS_IO_PROG -c "fpunch $((off * blksz)) $blksz" $SCRATCH_MNT/file3 >> $seqres.full
52 md5sum $SCRATCH_MNT/file1 | _filter_scratch
53 md5sum $SCRATCH_MNT/file2 | _filter_scratch
54 md5sum $SCRATCH_MNT/file3 | _filter_scratch
57 _scratch_inject_error "bmap_finish_one"
59 echo "CoW a few blocks"
60 $XFS_IO_PROG -c "pwrite -W -S 0x67 -b $sz $((10 * blksz)) $((10 * blksz))" $SCRATCH_MNT/file2 >> $seqres.full 2>&1
62 echo "FS should be shut down, touch will fail"
63 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
65 echo "Remount to replay log"
66 _scratch_inject_logprint >> $seqres.full
68 echo "FS should be online, touch should succeed"
69 touch $SCRATCH_MNT/goodfs
71 echo "Check files again"
72 md5sum $SCRATCH_MNT/file1 | _filter_scratch
73 md5sum $SCRATCH_MNT/file2 | _filter_scratch
74 md5sum $SCRATCH_MNT/file3 | _filter_scratch