common/xfs: refactor commands to select a particular xfs backing device
[xfstests-dev.git] / tests / xfs / 230
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. 230
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 seq=`basename $0`
20 seqres=$RESULT_DIR/$seq
21 echo "QA output created by $seq"
22
23 here=`pwd`
24 tmp=/tmp/$$
25 status=1    # failure is the default!
26 trap "_cleanup; exit \$status" 0 1 2 3 15
27
28 _cleanup()
29 {
30     cd /
31     rm -rf $tmp.*
32 }
33
34 # get standard environment, filters and checks
35 . ./common/rc
36 . ./common/filter
37 . ./common/reflink
38
39 # real QA test starts here
40 _require_scratch_reflink
41 _require_xfs_io_command "falloc"
42 _require_xfs_io_command "cowextsize"
43 _require_xfs_io_command "fpunch"
44 _require_cp_reflink
45 _require_odirect
46
47 rm -f $seqres.full
48
49 echo "Format and mount"
50 _scratch_mkfs > $seqres.full 2>&1
51 _scratch_mount >> $seqres.full 2>&1
52
53 testdir=$SCRATCH_MNT/test-$seq
54 mkdir $testdir
55
56 echo "Create the original files"
57 blksz=65536
58 nr=64
59 filesize=$((blksz * nr))
60 real_blksz=$(_get_block_size $testdir)
61 internal_blks=$((filesize / real_blksz))
62 $XFS_IO_PROG -c "cowextsize $((blksz * 16))" $testdir >> $seqres.full
63 _weave_reflink_rainbow $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
64 _scratch_cycle_mount
65
66 echo "Compare files"
67 md5sum $testdir/file1 | _filter_scratch
68 md5sum $testdir/file3 | _filter_scratch
69 md5sum $testdir/file3.chk | _filter_scratch
70
71 echo "directio CoW across the transition"
72 cowoff=$((filesize / 4))
73 cowsz=$((filesize / 2))
74 _weave_reflink_rainbow_delalloc $blksz $nr $testdir/file3 >> $seqres.full
75 # now cow
76 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
77 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
78 _scratch_cycle_mount
79
80 echo "Compare files"
81 md5sum $testdir/file1 | _filter_scratch
82 md5sum $testdir/file3 | _filter_scratch
83 md5sum $testdir/file3.chk | _filter_scratch
84
85 echo "Check extent counts"
86 old_extents=$(_count_extents $testdir/file1)
87 new_extents=$(_count_extents $testdir/file3)
88
89 echo "old extents: $old_extents" >> $seqres.full
90 echo "new extents: $new_extents" >> $seqres.full
91 echo "maximum extents: $internal_blks" >> $seqres.full
92 test $((new_extents - (nr * 4 / 10))) -lt $((internal_blks / 2)) || echo "file3 badly fragmented"
93
94 # success, all done
95 status=0
96 exit