2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011-2012 Fujitsu, Inc. All Rights Reserved.
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.
14 _begin_fstest auto rw prealloc enospc
16 status=0 # success is the default!
18 # Override the default cleanup function.
28 # real QA test starts here
31 _require_xfs_io_command "falloc" "-k"
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
37 echo "------------------------------"
38 echo "preallocation test"
39 echo "------------------------------"
41 _scratch_unmount 2>/dev/null
42 _scratch_mkfs_sized $((2 * 1024 * 1024 * 1024)) >>$seqres.full 2>&1
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"
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
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
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"
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"