generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 274
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011-2012 Fujitsu, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 274
6 #
7 # preallocation test:
8 # Preallocate space to a file, and fill the rest of the fs to 100%.
9 # Then test a write into that preallocated space, which should succeed.
10 #
11 #creator
12
13 . ./common/preamble
14 _begin_fstest auto rw prealloc enospc
15
16 status=0    # success is the default!
17
18 # Override the default cleanup function.
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23         _scratch_unmount
24 }
25
26 . ./common/filter
27
28 # real QA test starts here
29 _supported_fs generic
30 _require_scratch
31 _require_xfs_io_command "falloc" "-k"
32
33 # Compression can exhaust metadata space here for btrfs and cause spurious
34 # failurs because we hit a metadata ENOSPC, skip if we have compression enabled
35 _require_no_compress
36
37 echo "------------------------------"
38 echo "preallocation test"
39 echo "------------------------------"
40
41 _scratch_unmount 2>/dev/null
42 _scratch_mkfs_sized $((2 * 1024 * 1024 * 1024)) >>$seqres.full 2>&1
43 _scratch_mount
44
45 # Create a 4k file and Allocate 4M past EOF on that file
46 $XFS_IO_PROG -f -c "pwrite 0 4k" -c "falloc -k 4k 4m" $SCRATCH_MNT/test \
47         >>$seqres.full 2>&1 || _fail "failed to create test file"
48
49 # Fill the rest of the fs completely
50 # Note, this will show ENOSPC errors in $seqres.full, that's ok.
51 echo "Fill fs with 1M IOs; ENOSPC expected" >> $seqres.full
52 dd if=/dev/zero of=$SCRATCH_MNT/tmp1 bs=1M >>$seqres.full 2>&1
53 echo "Fill fs with 4K IOs; ENOSPC expected" >> $seqres.full
54 dd if=/dev/zero of=$SCRATCH_MNT/tmp2 bs=4K >>$seqres.full 2>&1
55 sync
56 # Last effort, use O_SYNC
57 echo "Fill fs with 4K DIOs; ENOSPC expected" >> $seqres.full
58 dd if=/dev/zero of=$SCRATCH_MNT/tmp3 bs=4K oflag=sync >>$seqres.full 2>&1
59 # Save space usage info
60 echo "Post-fill space:" >> $seqres.full
61 df $SCRATCH_MNT >>$seqres.full 2>&1
62
63 # Now attempt a write into all of the preallocated space -
64 # in a very nasty way, badly fragmenting it and then filling it in.
65 echo "Fill in prealloc space; fragment at offsets:" >> $seqres.full
66 for i in `seq 1 2 1023`; do
67         echo -n "$i " >> $seqres.full
68         dd if=/dev/zero of=$SCRATCH_MNT/test seek=$i bs=4K count=1 conv=notrunc \
69                 >>$seqres.full 2>/dev/null || _fail "failed to write to test file"
70 done
71 sync
72 echo >> $seqres.full
73 echo "Fill in prealloc space; fill holes at offsets:" >> $seqres.full
74 for i in `seq 2 2 1023`; do
75         echo -n "$i " >> $seqres.full
76         dd if=/dev/zero of=$SCRATCH_MNT/test seek=$i bs=4K count=1 conv=notrunc \
77                 >>$seqres.full 2>/dev/null || _fail "failed to fill test file"
78 done
79 sync
80 echo >> $seqres.full
81
82 echo "done"
83 exit