overlay: run unionmount testsuite test cases
[xfstests-dev.git] / tests / xfs / 232
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. 232
6 #
7 # Test non-recovery of unused CoW reservations for dirty files:
8 # - Create two reflinked files.  Set extsz hint on second file.
9 # - Dirty a single byte on a number of CoW reservations in the second file.
10 # - Fsync to flush out the dirty pages.
11 # - Dirty a single byte anywhere in the second file.
12 # - Wait for the reclaim to run.
13 # - Write more and see how bad fragmentation is.
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1    # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 _cleanup()
25 {
26     cd /
27     echo $old_cow_lifetime > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
28     rm -rf $tmp.*
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34 . ./common/reflink
35
36 # real QA test starts here
37 _supported_os Linux
38 _supported_fs xfs
39 _require_xfs_io_command "cowextsize"
40 _require_scratch_reflink
41 _require_cp_reflink
42 _require_xfs_io_command "falloc"
43 _require_xfs_io_command "fiemap"
44
45 old_cow_lifetime=$(cat /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime)
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 blksz=65536
57 nr=64
58 filesize=$((blksz * nr))
59 bufnr=2
60 bufsize=$((blksz * bufnr))
61
62 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
63 real_blksz=$(_get_block_size $testdir)
64 internal_blks=$((filesize / real_blksz))
65
66 echo "Create the original files"
67 $XFS_IO_PROG -c "cowextsize $bufsize" $testdir
68 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
69 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file2.chk >> $seqres.full
70 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
71 _scratch_cycle_mount
72
73 echo "Compare files"
74 md5sum $testdir/file1 | _filter_scratch
75 md5sum $testdir/file2 | _filter_scratch
76 md5sum $testdir/file2.chk | _filter_scratch
77
78 echo "CoW and leave leftovers"
79 echo 2 > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
80 seq 2 2 $((nr - 1)) | while read f; do
81         $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2 >> $seqres.full
82         $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2.chk >> $seqres.full
83 done
84 sync
85
86 echo "Wait for CoW expiration"
87 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * 2)) 1" $testdir/file2 >> $seqres.full
88 sleep 3
89
90 echo "Allocate free space"
91 for i in $(seq 1 32); do
92         $XFS_IO_PROG -f -c "falloc 0 1" $testdir/junk.$i >> $seqres.full
93 done
94 $XFS_IO_PROG -f -c "falloc 0 $filesize" $testdir/junk >> $seqres.full
95
96 echo "CoW and leave leftovers"
97 echo $old_cow_lifetime > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
98 seq 2 2 $((nr - 1)) | while read f; do
99         $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2 >> $seqres.full
100         $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2.chk >> $seqres.full
101 done
102 sync
103
104 echo "Compare files"
105 md5sum $testdir/file1 | _filter_scratch
106 md5sum $testdir/file2 | _filter_scratch
107 md5sum $testdir/file2.chk | _filter_scratch
108
109 echo "Check extent counts"
110 old_extents=$(_count_extents $testdir/file1)
111 new_extents=$(_count_extents $testdir/file2)
112
113 echo "old extents: $old_extents" >> $seqres.full
114 echo "new extents: $new_extents" >> $seqres.full
115 echo "maximum extents: $internal_blks" >> $seqres.full
116 test $new_extents -le $((2 * nr / bufnr)) || echo "file2 more fragmented than expected"
117
118 # success, all done
119 status=0
120 exit