summaryrefslogtreecommitdiff
path: root/tests/generic/275
blob: 7cef2b505564bc3610512408620ddbc695d45554 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#! /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

# real QA test starts here
_supported_fs generic
_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

# this file will get removed to create 256k of free space after ENOSPC
# conditions are created.
reserve=256k

if [[ $FSTYP = "bcachefs" ]]; then
    # bcachefs btree nodes default to 256k, we need more:
    reserve=512k
    # ensure one truncate has been done so that the logged ops btree has been allocated:
    dd if=/dev/zero of=$SCRATCH_MNT/tmp1 bs=$reserve count=1 >/dev/null 2>&1
    truncate --size=0 $later_file
fi

dd if=/dev/zero of=$SCRATCH_MNT/tmp1 bs=$reserve 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
sync
dd if=/dev/zero of=$SCRATCH_MNT/tmp3 bs=4K >>$seqres.full 2>&1
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
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