generic: test for file loss after mix of rename, fsync and inode eviction
[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 . ./common/preamble
13 _begin_fstest auto rw enospc
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18         cd /
19         _scratch_unmount
20 }
21
22 . ./common/filter
23
24 # real QA test starts here
25 _supported_fs generic
26 _require_scratch
27
28 echo "------------------------------"
29 echo "write until ENOSPC test"
30 echo "------------------------------"
31
32 _scratch_unmount 2>/dev/null
33 _scratch_mkfs_sized $((2 * 1024 * 1024 * 1024)) >>$seqres.full 2>&1
34 _scratch_mount
35
36 # this file will get removed to create 256k of free space after ENOSPC
37 # conditions are created.
38 dd if=/dev/zero of=$SCRATCH_MNT/tmp1 bs=256K count=1 >>$seqres.full 2>&1
39 [ $? -ne 0 ] && _fail "Error creating file"
40
41 # Attempt to completely fill fs
42 dd if=/dev/zero of=$SCRATCH_MNT/tmp2 bs=1M >>$seqres.full 2>&1
43 sync
44 dd if=/dev/zero of=$SCRATCH_MNT/tmp3 bs=4K >>$seqres.full 2>&1
45 sync
46 # Last effort, use O_SYNC
47 dd if=/dev/zero of=$SCRATCH_MNT/tmp4 bs=4K oflag=sync >>$seqres.full 2>&1
48 # Save space usage info to the full file
49 echo "Pre rm space:" >> $seqres.full
50 $DF_PROG $SCRATCH_MNT >>$seqres.full 2>&1
51
52 # Should leave approx 256k free
53 rm -f $SCRATCH_MNT/tmp1
54 sync
55 echo "Post rm space:" >> $seqres.full
56 $DF_PROG $SCRATCH_MNT >>$seqres.full 2>&1
57 _freespace=`$DF_PROG -k $SCRATCH_MNT | tail -n 1 | awk '{print $5}'`
58 [ $_freespace -gt 1024 ] && _fail "could not sufficiently fill filesystem"
59
60 # Try to write more than available space in chunks that will allow at least one
61 # full write to succeed.
62 dd if=/dev/zero of=$SCRATCH_MNT/tmp1 bs=128k count=8 >>$seqres.full 2>&1
63 echo "Bytes written until ENOSPC:" >>$seqres.full
64 du $SCRATCH_MNT/tmp1 >>$seqres.full
65
66 # And at least some of it should succeed.
67 _filesize=`_get_filesize $SCRATCH_MNT/tmp1`
68 [ $_filesize -lt $((128 * 1024)) ] && \
69         _fail "Partial write until enospc failed; wrote $_filesize bytes."
70
71 echo "done"
72 status=0
73 exit