generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 027
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. generic/027
6 #
7 # Run 8 processes writing 1k files to seperate files in seperate dirs to
8 # hit ENOSPC on small fs with little free space. Loop for 100 iterations.
9 #
10 # Regression test for
11 # 34cf865 ext4: fix deadlock when writing in ENOSPC conditions
12 #
13 . ./common/preamble
14 _begin_fstest auto enospc
15
16 create_file()
17 {
18         local dir=$1
19         local direct=$2
20         local i=0
21
22         mkdir -p $dir >/dev/null 2>&1
23         while $XFS_IO_PROG -f $direct -c "pwrite 0 1k" $dir/file_$i >/dev/null 2>&1; do
24                 let i=$i+1
25         done
26 }
27
28 # Import common functions.
29 . ./common/filter
30
31 # real QA test starts here
32 _supported_fs generic
33
34 _require_scratch
35
36 echo "Silence is golden"
37
38 _scratch_mkfs_sized $((256 * 1024 * 1024)) >>$seqres.full 2>&1
39 _scratch_mount
40
41 echo "Reserve 2M space" >>$seqres.full
42 $XFS_IO_PROG -f -c "pwrite 0 2m" $SCRATCH_MNT/testfile >>$seqres.full 2>&1
43 echo "Fulfill the fs" >>$seqres.full
44 $XFS_IO_PROG -f -c "pwrite 0 254m" $SCRATCH_MNT/bigfile >>$seqres.full 2>&1
45 echo "Remove reserved file" >>$seqres.full
46 rm -f $SCRATCH_MNT/testfile
47
48 loop=100
49 # btrfs takes much longer time, reduce the loop count
50 if [ "$FSTYP" == "btrfs" ]; then
51         loop=10
52 fi
53
54 dir=$SCRATCH_MNT/testdir
55 echo -n "iteration" >>$seqres.full
56 i=1
57 while [ $i -le $loop ]; do
58         echo -n " $i" >>$seqres.full
59         nr_worker=8
60         while [ $nr_worker -gt 0 ]; do
61                 # half buffered I/O half direct I/O
62                 if [ `expr $nr_worker % 2` -eq 0 ]; then
63                         create_file $dir/$nr_worker -d >>$seqres.full &
64                 else
65                         create_file $dir/$nr_worker >>$seqres.full &
66                 fi
67                 let nr_worker=$nr_worker-1
68         done
69         wait
70         rm -rf $dir
71         let i=$i+1
72 done
73 _scratch_unmount
74
75 status=0
76 exit