xfs: fix old fuzz test invocations of xfs_repair
[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 _require_scratch_reflink
32 _require_test_program "punch-alternating"
33 _require_xfs_io_command "fpunch"
34
35 rm -f $seqres.full
36
37 _scratch_mkfs_sized $((512 * 1024 * 1024)) >>$seqres.full 2>&1
38 _scratch_mount
39
40 file_size=$(( 200 * 1024 * 1024 )) # 200Mb
41
42 # Create a file with many small extents.
43 $XFS_IO_PROG -f -c "pwrite -S 0xe5 -b $file_size 0 $file_size" \
44         $SCRATCH_MNT/foo >>/dev/null
45 $here/src/punch-alternating $SCRATCH_MNT/foo >> $seqres.full
46
47 # Create file bar with the same size that file foo has but with large extents.
48 $XFS_IO_PROG -f -c "pwrite -S 0xc7 -b $file_size 0 $file_size" \
49         $SCRATCH_MNT/bar >>/dev/null
50
51 # Fill the fs (For btrfs we are interested in filling all unallocated space
52 # and most of the existing metadata block group(s), so that after this there
53 # will be no unallocated space and metadata space will be mostly full but with
54 # more than enough free space for the clone operation below to succeed, we
55 # create files with 2Kb because that results in extents inlined in the metadata
56 # (btree leafs) and it's the fastest way to fill metadata space on btrfs, by
57 # default btrfs inlines up to 2Kb of data).
58 i=1
59 while true; do
60         $XFS_IO_PROG -f -c "pwrite 0 2K" $SCRATCH_MNT/filler_$i &> /dev/null
61         [ $? -ne 0 ] && break
62         i=$(( i + 1 ))
63 done
64
65 # Now clone file bar into file foo. This is supposed to succeed and not fail
66 # with ENOSPC for example.
67 _reflink $SCRATCH_MNT/bar $SCRATCH_MNT/foo >>$seqres.full
68
69 # Unmount and mount the filesystem again to verify the operation was durably
70 # persisted.
71 _scratch_cycle_mount
72
73 echo "File foo data after cloning and remount:"
74 od -A d -t x1 $SCRATCH_MNT/foo
75
76 status=0
77 exit