xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[xfstests-dev.git] / tests / xfs / 182
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. 182
6 #
7 # Test fragmentation after a lot of random CoW:
8 # - Create two reflinked files.  Set extsz hint on second file.
9 # - Directio write to random offsets to scatter CoW reservations.
10 # - Rewrite the whole file to use up reservations.
11 # - Check the number of extents.
12 #
13 . ./common/preamble
14 _begin_fstest auto quick clone
15
16 # Import common functions.
17 . ./common/filter
18 . ./common/reflink
19
20 # real QA test starts here
21 _supported_fs xfs
22 _require_scratch_reflink
23 _require_cp_reflink
24 _require_xfs_io_command "fiemap"
25 _require_xfs_io_command "cowextsize"
26 _require_odirect
27
28 echo "Format and mount"
29 _scratch_mkfs > $seqres.full 2>&1
30 _scratch_mount >> $seqres.full 2>&1
31
32 testdir=$SCRATCH_MNT/test-$seq
33 mkdir $testdir
34
35 blksz=65536
36 nr=128
37 filesize=$((blksz * nr))
38 bufnr=16
39 bufsize=$((blksz * bufnr))
40
41 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
42 real_blksz=$(_get_block_size $testdir)
43 internal_blks=$((filesize / real_blksz))
44
45 echo "Create the original files"
46 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
47 $XFS_IO_PROG -f -c "cowextsize $bufsize" $testdir/file2
48 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
49 _scratch_cycle_mount
50
51 echo "Compare files"
52 md5sum $testdir/file1 | _filter_scratch
53 md5sum $testdir/file2 | _filter_scratch
54
55 echo "CoW and unmount"
56 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
57 $XFS_IO_PROG -d -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $((filesize + 1))" \
58         $testdir/file2 2>&1 >> $seqres.full | _filter_xfs_io_error
59 $XFS_IO_PROG -d -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" \
60         $testdir/file2 2>&1 >> $seqres.full | _filter_xfs_io_error
61 _scratch_cycle_mount
62
63 echo "Compare files"
64 md5sum $testdir/file1 | _filter_scratch
65 md5sum $testdir/file2 | _filter_scratch
66
67 echo "Check extent counts"
68 old_extents=$(_count_extents $testdir/file1)
69 new_extents=$(_count_extents $testdir/file2)
70
71 echo "old extents: $old_extents" >> $seqres.full
72 echo "new extents: $new_extents" >> $seqres.full
73 echo "maximum extents: $internal_blks" >> $seqres.full
74 test $new_extents -lt $((internal_blks / 20)) || test $new_extents -lt 15 \
75         || echo "file2 badly fragmented"
76
77 # success, all done
78 status=0
79 exit