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 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=0 # success is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
32 # real QA test starts here
36 _require_xfs_io_command "falloc" "-k"
38 echo "------------------------------"
39 echo "preallocation test"
40 echo "------------------------------"
44 _scratch_unmount 2>/dev/null
45 _scratch_mkfs_sized $((2 * 1024 * 1024 * 1024)) >>$seqres.full 2>&1
48 # Create a 4k file and Allocate 4M past EOF on that file
49 $XFS_IO_PROG -f -c "pwrite 0 4k" -c "falloc -k 4k 4m" $SCRATCH_MNT/test \
50 >>$seqres.full 2>&1 || _fail "failed to create test file"
52 # Fill the rest of the fs completely
53 # Note, this will show ENOSPC errors in $seqres.full, that's ok.
54 echo "Fill fs with 1M IOs; ENOSPC expected" >> $seqres.full
55 dd if=/dev/zero of=$SCRATCH_MNT/tmp1 bs=1M >>$seqres.full 2>&1
56 echo "Fill fs with 4K IOs; ENOSPC expected" >> $seqres.full
57 dd if=/dev/zero of=$SCRATCH_MNT/tmp2 bs=4K >>$seqres.full 2>&1
59 # Last effort, use O_SYNC
60 echo "Fill fs with 4K DIOs; ENOSPC expected" >> $seqres.full
61 dd if=/dev/zero of=$SCRATCH_MNT/tmp3 bs=4K oflag=sync >>$seqres.full 2>&1
62 # Save space usage info
63 echo "Post-fill space:" >> $seqres.full
64 df $SCRATCH_MNT >>$seqres.full 2>&1
66 # Now attempt a write into all of the preallocated space -
67 # in a very nasty way, badly fragmenting it and then filling it in.
68 echo "Fill in prealloc space; fragment at offsets:" >> $seqres.full
69 for i in `seq 1 2 1023`; do
70 echo -n "$i " >> $seqres.full
71 dd if=/dev/zero of=$SCRATCH_MNT/test seek=$i bs=4K count=1 conv=notrunc \
72 >>$seqres.full 2>/dev/null || _fail "failed to write to test file"
76 echo "Fill in prealloc space; fill holes at offsets:" >> $seqres.full
77 for i in `seq 2 2 1023`; do
78 echo -n "$i " >> $seqres.full
79 dd if=/dev/zero of=$SCRATCH_MNT/test seek=$i bs=4K count=1 conv=notrunc \
80 >>$seqres.full 2>/dev/null || _fail "failed to fill test file"