fstests: move test group info to test files
[xfstests-dev.git] / tests / xfs / 326
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 326
6 #
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.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick clone
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18         cd /
19         _scratch_unmount > /dev/null 2>&1
20         rm -rf $tmp.*
21 }
22
23 # Import common functions.
24 . ./common/filter
25 . ./common/reflink
26 . ./common/inject
27
28 # real QA test starts here
29 _supported_fs xfs
30 _require_cp_reflink
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"
35
36 blksz=65536
37 blks=64
38 sz=$((blksz * blks))
39 echo "Format filesystem"
40 _scratch_mkfs >/dev/null 2>&1
41 _scratch_mount >> $seqres.full
42
43 $XFS_IO_PROG -c "cowextsize $sz" $SCRATCH_MNT
44
45 echo "Create files"
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
49
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
53 done
54 sync
55
56 echo "Check files"
57 md5sum $SCRATCH_MNT/file1 | _filter_scratch
58 md5sum $SCRATCH_MNT/file2 | _filter_scratch
59 md5sum $SCRATCH_MNT/file3 | _filter_scratch
60
61 $XFS_IO_PROG -c "pwrite -W -S 0x67 $((10 * blksz)) 1" $SCRATCH_MNT/file2 >> $seqres.full
62 sync
63
64 echo "Inject error"
65 _scratch_inject_error "refcount_finish_one"
66
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
69
70 echo "FS should be shut down, touch will fail"
71 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
72
73 echo "Remount to replay log"
74 _scratch_inject_logprint >> $seqres.full
75
76 echo "FS should be online, touch should succeed"
77 touch $SCRATCH_MNT/goodfs
78
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
83
84 echo "Done"
85
86 # success, all done
87 status=0
88 exit