xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / xfs / 313
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. 313
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.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1    # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         _scratch_unmount > /dev/null 2>&1
23         rm -rf $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/reflink
30 . ./common/inject
31
32 # real QA test starts here
33 _supported_fs xfs
34 _require_cp_reflink
35 _require_scratch_reflink
36 _require_xfs_io_command "fpunch"
37 _require_xfs_io_error_injection "refcount_finish_one"
38
39 rm -f $seqres.full
40
41 blksz=65536
42 blks=64
43 sz=$((blksz * blks))
44 echo "Format filesystem"
45 _scratch_mkfs >/dev/null 2>&1
46 _scratch_mount >> $seqres.full
47
48 echo "Create files"
49 _pwrite_byte 0x66 0 $sz $SCRATCH_MNT/file1 >> $seqres.full
50 _cp_reflink $SCRATCH_MNT/file1 $SCRATCH_MNT/file2
51 _cp_reflink $SCRATCH_MNT/file1 $SCRATCH_MNT/file3
52
53 # Punch holes in file3
54 seq 1 2 $blks | while read off; do
55         $XFS_IO_PROG -c "fpunch $((off * blksz)) $blksz" $SCRATCH_MNT/file3 >> $seqres.full
56 done
57 sync
58
59 echo "Check files"
60 md5sum $SCRATCH_MNT/file1 | _filter_scratch
61 md5sum $SCRATCH_MNT/file2 | _filter_scratch
62 md5sum $SCRATCH_MNT/file3 | _filter_scratch
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