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