generic: convert tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 416
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Fujitsu.  All Rights Reserved.
4 #
5 # FS QA Test 416
6 #
7 # Test fs behavior when large write request can't be met by one single extent
8 #
9 # Inspired by a bug in a btrfs fix, which doesn't get exposed by current test
10 # cases
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 # remove previous $seqres.full before test
32 rm -f $seqres.full
33
34 # real QA test starts here
35
36 # Modify as appropriate.
37 _supported_fs generic
38 _supported_os Linux
39 _require_scratch
40
41 fs_size=$((128 * 1024 * 1024))
42 page_size=$(get_page_size)
43
44 # We will never reach this number though
45 nr_files=$(($fs_size / $page_size))
46
47 # Use small fs to make the fill more faster
48 _scratch_mkfs_sized $fs_size >> $seqres.full 2>&1
49
50 _scratch_mount
51
52 fill_fs()
53 {
54         dir=$1
55         for i in $(seq -w $nr_files); do
56                 # xfs_io can't return correct value when it hit ENOSPC, use
57                 # dd here to detect ENOSPC
58                 dd if=/dev/zero of=$SCRATCH_MNT/$i bs=$page_size count=1 \
59                         &> /dev/null
60                 if [ $? -ne 0 ]; then
61                         break
62                 fi
63         done
64 }
65
66 fill_fs $SCRATCH_MNT
67
68 # remount to sync every thing into fs, and drop all cache
69 _scratch_remount
70
71 # remove all files with odd file names, which should free near half
72 # of the space
73 rm $SCRATCH_MNT/*[13579]
74 sync
75
76 # We should be able to write at least 1/8 of the whole fs size
77 # The number 1/8 is for btrfs, which only has about 47M for data.
78 # And half of the 47M is already taken up, so only 1/8 is safe here
79 $XFS_IO_PROG -f -c "pwrite 0 $(($fs_size / 8))" $SCRATCH_MNT/large_file | \
80         _filter_xfs_io
81
82 # success, all done
83 status=0
84 exit