xfs: convert tests to SPDX license tags
[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 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1    # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         _scratch_unmount > /dev/null 2>&1
25         rm -rf $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/reflink
32 . ./common/inject
33
34 # real QA test starts here
35 _supported_os Linux
36 _supported_fs xfs
37 _require_cp_reflink
38 _require_scratch_reflink
39 _require_xfs_io_command "cowextsize"
40 _require_xfs_io_error_injection "refcount_finish_one"
41
42 rm -f $seqres.full
43
44 blksz=65536
45 blks=64
46 sz=$((blksz * blks))
47 echo "Format filesystem"
48 _scratch_mkfs >/dev/null 2>&1
49 _scratch_mount >> $seqres.full
50
51 $XFS_IO_PROG -c "cowextsize $sz" $SCRATCH_MNT
52
53 echo "Create files"
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
57
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
61 done
62 sync
63
64 echo "Check files"
65 md5sum $SCRATCH_MNT/file1 | _filter_scratch
66 md5sum $SCRATCH_MNT/file2 | _filter_scratch
67 md5sum $SCRATCH_MNT/file3 | _filter_scratch
68
69 $XFS_IO_PROG -c "pwrite -W -S 0x67 $((10 * blksz)) 1" $SCRATCH_MNT/file2 >> $seqres.full
70 sync
71
72 echo "Inject error"
73 _scratch_inject_error "refcount_finish_one"
74
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
77
78 echo "FS should be shut down, touch will fail"
79 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
80
81 echo "Remount to replay log"
82 _scratch_inject_logprint >> $seqres.full
83
84 echo "FS should be online, touch should succeed"
85 touch $SCRATCH_MNT/goodfs
86
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
91
92 echo "Done"
93
94 # success, all done
95 status=0
96 exit