xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[xfstests-dev.git] / tests / xfs / 243
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. 243
6 #
7 # Ensuring that copy on write in buffered mode works when the CoW
8 # range originally covers multiple extents, some unwritten, some not.
9 #   - Set cowextsize hint.
10 #   - Create a file with the following repeating sequence of blocks:
11 #     1. reflinked
12 #     2. unwritten
13 #     3. hole
14 #     4. regular block
15 #     5. delalloc
16 #   - CoW across the halfway mark, starting with the unwritten extent.
17 #   - Check that the files are now different where we say they're different.
18 #
19 . ./common/preamble
20 _begin_fstest auto quick clone punch
21
22 # Import common functions.
23 . ./common/filter
24 . ./common/reflink
25
26 # real QA test starts here
27 _supported_fs xfs
28 _require_xfs_debug
29 _require_scratch_reflink
30 _require_xfs_io_command "falloc"
31 _require_xfs_io_command "cowextsize"
32 _require_xfs_io_command "fpunch"
33 _require_xfs_io_command "bmap" "-c"
34 _require_cp_reflink
35
36 echo "Format and mount"
37 _scratch_mkfs > $seqres.full 2>&1
38 _scratch_mount >> $seqres.full 2>&1
39
40 testdir=$SCRATCH_MNT/test-$seq
41 mkdir $testdir
42
43 echo "Create the original files"
44 blksz=65536
45 nr=64
46 filesize=$((blksz * nr))
47
48 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
49 _pwrite_byte 0x61 0 $filesize $testdir/file1 >> $seqres.full
50 $XFS_IO_PROG -f -c "truncate $filesize" $testdir/file3 >> $seqres.full
51 # 0 blocks are reflinked
52 seq 0 5 $nr | while read f; do
53         _reflink_range $testdir/file1 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
54         _pwrite_byte 0x61 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
55 done
56 # 1 blocks are unwritten
57 seq 1 5 $nr | while read f; do
58         $XFS_IO_PROG -f -c "falloc $((blksz * f)) $blksz" $testdir/file3 >> $seqres.full
59         _pwrite_byte 0x00 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
60 done
61 # 2 blocks are holes
62 seq 2 5 $nr | while read f; do
63         _pwrite_byte 0x00 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
64 done
65 # 3 blocks are regular
66 seq 3 5 $nr | while read f; do
67         _pwrite_byte 0x71 $((blksz * f)) $blksz $testdir/file3 >> $seqres.full
68         _pwrite_byte 0x71 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
69 done
70 sync
71 # 4 blocks are delalloc (do later)
72 seq 4 5 $nr | while read f; do
73         _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3 >> $seqres.full
74         _pwrite_byte 0x62 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
75 done
76
77 # 10 blocks are cow'd
78 seq 0 10 $((nr/2)) | while read f; do
79         _pwrite_byte 0x61 $((blksz * f)) 1 $testdir/file3 >> $seqres.full
80         _pwrite_byte 0x61 $((blksz * f)) 1 $testdir/file3.chk >> $seqres.full
81 done
82
83 echo "Compare files"
84 md5sum $testdir/file1 | _filter_scratch
85 md5sum $testdir/file3 | _filter_scratch
86 md5sum $testdir/file3.chk | _filter_scratch
87
88 echo "Dump extents"
89 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
90 echo "Delayed allocation CoW extents:"
91 test $(_xfs_bmapx_find cow $testdir/file3 delalloc) -gt 0 || \
92         echo "Expected to find a delalloc CoW extent"
93 echo "Shared data extents:"
94 test $(_xfs_bmapx_find data $testdir/file3 '100000$') -gt 0 || \
95         echo "Expected to find a shared data extent"
96 echo "Unwritten data extents:"
97 test $(_xfs_bmapx_find data $testdir/file3 '10000$') -gt 0 || \
98         echo "Expected to find an unwritten data extent"
99 echo "Hole data extents:"
100 test $(_xfs_bmapx_find data $testdir/file3 hole) -gt 0 || \
101         echo "Expected to find a hole data extent"
102 echo "Regular data extents:"
103 test $(_xfs_bmapx_find data $testdir/file3 '000000$') -gt 0 || \
104         echo "Expected to find a regular data extent"
105
106 sync
107
108 echo "Dump extents after sync"
109 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
110 echo "Delayed allocation CoW extents:"
111 test $(_xfs_bmapx_find cow $testdir/file3 -v hole ) -gt 0 || \
112         echo "Expected to find a regular CoW extent"
113 echo "Real CoW extents:"
114 test $(_xfs_bmapx_find cow $testdir/file3 delalloc ) -eq 0 || \
115         echo "Expected to find zero delalloc CoW extent"
116 echo "Shared data extents:"
117 test $(_xfs_bmapx_find data $testdir/file3 '100000$') -gt 0 || \
118         echo "Expected to find a shared data extent"
119 echo "Unwritten data extents:"
120 test $(_xfs_bmapx_find data $testdir/file3 '10000$') -gt 0 || \
121         echo "Expected to find an unwritten data extent"
122 echo "Hole data extents:"
123 test $(_xfs_bmapx_find data $testdir/file3 hole) -gt 0 || \
124         echo "Expected to find a hole data extent"
125 echo "Regular data extents:"
126 test $(_xfs_bmapx_find data $testdir/file3 '000000$') -gt 0 || \
127         echo "Expected to find a regular data extent"
128
129 _scratch_cycle_mount
130
131 echo "Compare files"
132 md5sum $testdir/file1 | _filter_scratch
133 md5sum $testdir/file3 | _filter_scratch
134 md5sum $testdir/file3.chk | _filter_scratch
135
136 # success, all done
137 status=0
138 exit