common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / generic / 562
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 562
6 #
7 # Test that if we clone a file with some large extents into a file that has
8 # many small extents, when the fs is nearly full, the clone operation does
9 # not fail and produces the correct result.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/reflink
28
29 # real QA test starts here
30 _supported_fs generic
31 _supported_os Linux
32 _require_scratch_reflink
33 _require_test_program "punch-alternating"
34 _require_xfs_io_command "fpunch"
35
36 rm -f $seqres.full
37
38 _scratch_mkfs_sized $((512 * 1024 * 1024)) >>$seqres.full 2>&1
39 _scratch_mount
40
41 file_size=$(( 200 * 1024 * 1024 )) # 200Mb
42
43 # Create a file with many small extents.
44 $XFS_IO_PROG -f -c "pwrite -S 0xe5 -b $file_size 0 $file_size" \
45         $SCRATCH_MNT/foo >>/dev/null
46 $here/src/punch-alternating $SCRATCH_MNT/foo >> $seqres.full
47
48 # Create file bar with the same size that file foo has but with large extents.
49 $XFS_IO_PROG -f -c "pwrite -S 0xc7 -b $file_size 0 $file_size" \
50         $SCRATCH_MNT/bar >>/dev/null
51
52 # Fill the fs (For btrfs we are interested in filling all unallocated space
53 # and most of the existing metadata block group(s), so that after this there
54 # will be no unallocated space and metadata space will be mostly full but with
55 # more than enough free space for the clone operation below to succeed, we
56 # create files with 2Kb because that results in extents inlined in the metadata
57 # (btree leafs) and it's the fastest way to fill metadata space on btrfs, by
58 # default btrfs inlines up to 2Kb of data).
59 i=1
60 while true; do
61         $XFS_IO_PROG -f -c "pwrite 0 2K" $SCRATCH_MNT/filler_$i &> /dev/null
62         [ $? -ne 0 ] && break
63         i=$(( i + 1 ))
64 done
65
66 # Now clone file bar into file foo. This is supposed to succeed and not fail
67 # with ENOSPC for example.
68 _reflink $SCRATCH_MNT/bar $SCRATCH_MNT/foo >>$seqres.full
69
70 # Unmount and mount the filesystem again to verify the operation was durably
71 # persisted.
72 _scratch_cycle_mount
73
74 echo "File foo data after cloning and remount:"
75 od -A d -t x1 $SCRATCH_MNT/foo
76
77 status=0
78 exit