| #! /bin/bash |
| # SPDX-License-Identifier: GPL-2.0 |
| # Copyright (c) 2011-2012 Fujitsu, Inc. All Rights Reserved. |
| # |
| # FS QA Test No. 275 |
| # |
| # The posix write test. When write size is larger than disk free size, |
| # should write as much as possible until ENOSPC. |
| # |
| #creator |
| |
| . ./common/preamble |
| _begin_fstest auto rw enospc |
| |
| # Override the default cleanup function. |
| _cleanup() |
| { |
| cd / |
| _scratch_unmount |
| } |
| |
| . ./common/filter |
| |
| _require_scratch |
| |
| # This test requires specific data space usage, skip if we have compression |
| # enabled. |
| _require_no_compress |
| |
| echo "------------------------------" |
| echo "write until ENOSPC test" |
| echo "------------------------------" |
| |
| _scratch_unmount 2>/dev/null |
| _scratch_mkfs_sized $((2 * 1024 * 1024 * 1024)) >>$seqres.full 2>&1 |
| _scratch_mount |
| |
| # Certain filesystems such as XFS require sufficient free blocks to handle the |
| # worst-case directory expansion as a result of a creat() call. If the fs |
| # block size is very large (e.g. 64k) then the number of blocks required for |
| # the creat() call can represent far more free space than the 256K left at the |
| # end of this test. Therefore, create the file that the last dd will write to |
| # now when we know there's enough free blocks. |
| later_file=$SCRATCH_MNT/later |
| touch $later_file |
| for i in 1 2 3 4; do |
| touch $SCRATCH_MNT/tmp$i |
| done |
| |
| # this file will get removed to create 256k of free space after ENOSPC |
| # conditions are created. |
| dd if=/dev/zero of=$SCRATCH_MNT/tmp1 bs=256K count=1 >>$seqres.full 2>&1 |
| [ $? -ne 0 ] && _fail "Error creating file" |
| |
| # Attempt to completely fill fs |
| dd if=/dev/zero of=$SCRATCH_MNT/tmp2 bs=1M >>$seqres.full 2>&1 |
| _scratch_sync |
| dd if=/dev/zero of=$SCRATCH_MNT/tmp3 bs=4K >>$seqres.full 2>&1 |
| _scratch_sync |
| # Last effort, use O_SYNC |
| dd if=/dev/zero of=$SCRATCH_MNT/tmp4 bs=4K oflag=sync >>$seqres.full 2>&1 |
| # Save space usage info to the full file |
| echo "Pre rm space:" >> $seqres.full |
| $DF_PROG $SCRATCH_MNT >>$seqres.full 2>&1 |
| |
| # Should leave approx 256k free |
| rm -f $SCRATCH_MNT/tmp1 |
| _scratch_sync |
| echo "Post rm space:" >> $seqres.full |
| $DF_PROG $SCRATCH_MNT >>$seqres.full 2>&1 |
| _freespace=`$DF_PROG -k $SCRATCH_MNT | tail -n 1 | awk '{print $5}'` |
| [ $_freespace -gt 1024 ] && _fail "could not sufficiently fill filesystem" |
| |
| # Try to write more than available space in chunks that will allow at least one |
| # full write to succeed. |
| dd if=/dev/zero of=$later_file bs=128k count=8 >>$seqres.full 2>&1 |
| echo "Bytes written until ENOSPC:" >>$seqres.full |
| du $later_file >>$seqres.full |
| |
| # And at least some of it should succeed. |
| _filesize=`_get_filesize $later_file` |
| [ $_filesize -lt $((128 * 1024)) ] && \ |
| _fail "Partial write until enospc failed; wrote $_filesize bytes." |
| |
| echo "done" |
| status=0 |
| exit |