generic/563: use a loop device to avoid partition incompatibility
[xfstests-dev.git] / tests / btrfs / 204
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle. All Rights Reserved.
4 #
5 # FS QA Test 204
6 #
7 # Test if the unaligned (by size and offset) punch hole is successful when FS
8 # is at ENOSPC.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33
34 # Modify as appropriate.
35 _supported_fs btrfs
36 _require_scratch
37 _require_xfs_io_command "fpunch"
38
39 _scratch_mkfs_sized $((256 * 1024 *1024)) >> $seqres.full
40
41 # max_inline ensures data is not inlined within metadata extents
42 _scratch_mount "-o max_inline=0,nodatacow"
43
44 cat /proc/self/mounts | grep $SCRATCH_DEV >> $seqres.full
45 $BTRFS_UTIL_PROG filesystem df $SCRATCH_MNT >> $seqres.full
46
47 extent_size=$(_scratch_btrfs_sectorsize)
48 unalign_by=512
49 echo extent_size=$extent_size unalign_by=$unalign_by >> $seqres.full
50
51 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 $((extent_size * 10))" \
52                                         $SCRATCH_MNT/testfile >> $seqres.full
53
54 echo "Fill all space available for data and all unallocated space." >> $seqres.full
55 dd status=none if=/dev/zero of=$SCRATCH_MNT/filler bs=512 >> $seqres.full 2>&1
56
57 hole_offset=0
58 hole_len=$unalign_by
59 $XFS_IO_PROG -c "fpunch $hole_offset $hole_len" $SCRATCH_MNT/testfile
60
61 hole_offset=$(($extent_size + $unalign_by))
62 hole_len=$(($extent_size - $unalign_by))
63 $XFS_IO_PROG -c "fpunch $hole_offset $hole_len" $SCRATCH_MNT/testfile
64
65 hole_offset=$(($extent_size * 2 + $unalign_by))
66 hole_len=$(($extent_size * 5))
67 $XFS_IO_PROG -c "fpunch $hole_offset $hole_len" $SCRATCH_MNT/testfile
68
69 # success, all done
70 echo "Silence is golden"
71 status=0
72 exit