2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011-2012 Fujitsu, Inc. All Rights Reserved.
7 # The posix write test. When write size is larger than disk free size,
8 # should write as much as possible until ENOSPC.
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
30 # real QA test starts here
34 echo "------------------------------"
35 echo "write until ENOSPC test"
36 echo "------------------------------"
40 _scratch_unmount 2>/dev/null
41 _scratch_mkfs_sized $((2 * 1024 * 1024 * 1024)) >>$seqres.full 2>&1
44 # this file will get removed to create 256k of free space after ENOSPC
45 # conditions are created.
46 dd if=/dev/zero of=$SCRATCH_MNT/tmp1 bs=256K count=1 >>$seqres.full 2>&1
47 [ $? -ne 0 ] && _fail "Error creating file"
49 # Attempt to completely fill fs
50 dd if=/dev/zero of=$SCRATCH_MNT/tmp2 bs=1M >>$seqres.full 2>&1
52 dd if=/dev/zero of=$SCRATCH_MNT/tmp3 bs=4K >>$seqres.full 2>&1
54 # Last effort, use O_SYNC
55 dd if=/dev/zero of=$SCRATCH_MNT/tmp4 bs=4K oflag=sync >>$seqres.full 2>&1
56 # Save space usage info to the full file
57 echo "Pre rm space:" >> $seqres.full
58 $DF_PROG $SCRATCH_MNT >>$seqres.full 2>&1
60 # Should leave approx 256k free
61 rm -f $SCRATCH_MNT/tmp1
63 echo "Post rm space:" >> $seqres.full
64 $DF_PROG $SCRATCH_MNT >>$seqres.full 2>&1
65 _freespace=`$DF_PROG -k $SCRATCH_MNT | tail -n 1 | awk '{print $5}'`
66 [ $_freespace -gt 1024 ] && _fail "could not sufficiently fill filesystem"
68 # Try to write more than available space in chunks that will allow at least one
69 # full write to succeed.
70 dd if=/dev/zero of=$SCRATCH_MNT/tmp1 bs=128k count=8 >>$seqres.full 2>&1
71 echo "Bytes written until ENOSPC:" >>$seqres.full
72 du $SCRATCH_MNT/tmp1 >>$seqres.full
74 # And at least some of it should succeed.
75 _filesize=`_get_filesize $SCRATCH_MNT/tmp1`
76 [ $_filesize -lt $((128 * 1024)) ] && \
77 _fail "Partial write until enospc failed; wrote $_filesize bytes."