lib/: spdx license conversion
[xfstests-dev.git] / tests / generic / 275
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011-2012 Fujitsu, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 275
6 #
7 # The posix write test.  When write size is larger than disk free size,
8 # should write as much as possible until ENOSPC.
9 #
10 #creator
11
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1    # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         _scratch_unmount
25 }
26
27 . ./common/rc
28 . ./common/filter
29
30 # real QA test starts here
31 _supported_fs generic
32 _supported_os Linux
33 _require_scratch
34
35 echo "------------------------------"
36 echo "write until ENOSPC test"
37 echo "------------------------------"
38
39 rm -f $seqres.full
40
41 _scratch_unmount 2>/dev/null
42 _scratch_mkfs_sized $((2 * 1024 * 1024 * 1024)) >>$seqres.full 2>&1
43 _scratch_mount
44
45 # this file will get removed to create 256k of free space after ENOSPC
46 # conditions are created.
47 dd if=/dev/zero of=$SCRATCH_MNT/tmp1 bs=256K count=1 >>$seqres.full 2>&1
48 [ $? -ne 0 ] && _fail "Error creating file"
49
50 # Attempt to completely fill fs
51 dd if=/dev/zero of=$SCRATCH_MNT/tmp2 bs=1M >>$seqres.full 2>&1
52 sync
53 dd if=/dev/zero of=$SCRATCH_MNT/tmp3 bs=4K >>$seqres.full 2>&1
54 sync
55 # Last effort, use O_SYNC
56 dd if=/dev/zero of=$SCRATCH_MNT/tmp4 bs=4K oflag=sync >>$seqres.full 2>&1
57 # Save space usage info to the full file
58 echo "Pre rm space:" >> $seqres.full
59 $DF_PROG $SCRATCH_MNT >>$seqres.full 2>&1
60
61 # Should leave approx 256k free
62 rm -f $SCRATCH_MNT/tmp1
63 sync
64 echo "Post rm space:" >> $seqres.full
65 $DF_PROG $SCRATCH_MNT >>$seqres.full 2>&1
66 _freespace=`$DF_PROG -k $SCRATCH_MNT | tail -n 1 | awk '{print $5}'`
67 [ $_freespace -gt 1024 ] && _fail "could not sufficiently fill filesystem"
68
69 # Try to write more than available space in chunks that will allow at least one
70 # full write to succeed.
71 dd if=/dev/zero of=$SCRATCH_MNT/tmp1 bs=128k count=8 >>$seqres.full 2>&1
72 echo "Bytes written until ENOSPC:" >>$seqres.full
73 du $SCRATCH_MNT/tmp1 >>$seqres.full
74
75 # And at least some of it should succeed.
76 _filesize=`ls -l $SCRATCH_MNT/tmp1 | awk '{print $5}'`
77 [ $_filesize -lt $((128 * 1024)) ] && \
78         _fail "Partial write until enospc failed; wrote $_filesize bytes."
79
80 echo "done"
81 status=0
82 exit