613699e1c57693f64fb0cb1ba36d723c9d35898e
[xfstests-dev.git] / tests / xfs / 114
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 114
6 #
7 # Make sure that we can handle insert-range followed by collapse-range.
8 # In particular, make sure that fcollapse works for rmap when the
9 # extents on either side of the collapse area are mergeable.
10 #
11 seq=`basename "$0"`
12 seqres="$RESULT_DIR/$seq"
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1    # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -rf "$tmp".*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/reflink
30
31 # real QA test starts here
32 _supported_os Linux
33 _supported_fs xfs
34 _require_test_program "punch-alternating"
35 _require_xfs_scratch_rmapbt
36 _require_xfs_io_command "fcollapse"
37 _require_xfs_io_command "finsert"
38
39 rm -f "$seqres.full"
40
41 echo "Format and mount"
42 _scratch_mkfs > "$seqres.full" 2>&1
43 _scratch_mount
44 blksz=65536
45 blocks1=150     # enough extents to force btree format
46 blocks2=16      # local format
47 len1=$((blocks1 * blksz))
48 len2=$((blocks2 * blksz))
49 file_blksz=$(_get_file_block_size $SCRATCH_MNT)
50
51 echo "Create some files"
52 $XFS_IO_PROG -f \
53         -c "falloc 0 $len1" \
54         -c "pwrite -S 0x68 -b 1048576 0 $len1" \
55         $SCRATCH_MNT/f1 >> $seqres.full
56 $XFS_IO_PROG -f \
57         -c "falloc 0 $len2" \
58         -c "pwrite -S 0x68 -b 1048576 0 $len2" \
59         $SCRATCH_MNT/f2 >> $seqres.full
60
61 ./src/punch-alternating -o $((16 * blksz / file_blksz)) \
62         -s $((blksz / file_blksz)) \
63         -i $((blksz * 2 / file_blksz)) \
64         $SCRATCH_MNT/f1 >> "$seqres.full"
65
66 echo "Insert and write file range"
67 $XFS_IO_PROG \
68         -c "finsert $((8 * blksz)) $blksz" \
69         -c "pwrite -S 0x69 $((8 * blksz)) $blksz" \
70         -c "fsync" \
71         $SCRATCH_MNT/f1 >> $seqres.full
72 $XFS_IO_PROG \
73         -c "finsert $((8 * blksz)) $blksz" \
74         -c "pwrite -S 0x69 $((8 * blksz)) $blksz" \
75         -c "fsync" \
76         $SCRATCH_MNT/f2 >> $seqres.full
77
78 # Make reflink copies to force it to use the fancy rmap operations.
79 # The test's functionality doesn't depend on the fs supporting reflink.
80 _cp_reflink $SCRATCH_MNT/f1 $SCRATCH_MNT/e1 >> $seqres.full 2>&1
81 _cp_reflink $SCRATCH_MNT/f2 $SCRATCH_MNT/e2 >> $seqres.full 2>&1
82
83 echo "f1 bmap" >> $seqres.full
84 $XFS_IO_PROG -c 'bmap -elpv' $SCRATCH_MNT/f1 >> $seqres.full
85 echo "f2 bmap" >> $seqres.full
86 $XFS_IO_PROG -c 'bmap -elpv' $SCRATCH_MNT/f2 >> $seqres.full
87 echo "fsmap" >> $seqres.full
88 $XFS_IO_PROG -c 'fsmap -v' $SCRATCH_MNT >> $seqres.full
89
90 echo "Remount"
91 _scratch_unmount
92 _scratch_xfs_check
93 _scratch_mount
94
95 echo "Collapse file"
96 $XFS_IO_PROG -c "fcollapse $((8 * blksz)) $blksz" $SCRATCH_MNT/f1 >> $seqres.full
97 $XFS_IO_PROG -c "fcollapse $((8 * blksz)) $blksz" $SCRATCH_MNT/f2 >> $seqres.full
98
99 echo "f1 bmap" >> $seqres.full
100 $XFS_IO_PROG -c 'bmap -elpv' $SCRATCH_MNT/f1 >> $seqres.full
101 echo "f2 bmap" >> $seqres.full
102 $XFS_IO_PROG -c 'bmap -elpv' $SCRATCH_MNT/f2 >> $seqres.full
103 echo "fsmap" >> $seqres.full
104 $XFS_IO_PROG -c 'fsmap -v' $SCRATCH_MNT >> $seqres.full
105
106 echo "Check file"
107 md5sum $SCRATCH_MNT/f1 | _filter_scratch
108 md5sum $SCRATCH_MNT/f2 | _filter_scratch
109 od -tx1 -Ad -c $SCRATCH_MNT/f1 >> $seqres.full
110 od -tx1 -Ad -c $SCRATCH_MNT/f2 >> $seqres.full
111
112 # success, all done
113 status=0
114 exit