generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 270
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2006 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FSQA Test No. 270
6 #
7 # Run fsstress and ENSPC hitters in parallel, check quota and 
8 # fs consistency an the end
9 #
10 . ./common/preamble
11 _begin_fstest auto quota rw prealloc ioctl enospc stress
12
13 # Import common functions.
14 . ./common/filter
15 . ./common/quota
16
17 # Disable all sync operations to get higher load
18 FSSTRESS_AVOID="$FSSTRESS_AVOID -ffsync=0 -fsync=0 -ffdatasync=0"
19 _workout()
20 {
21         echo ""
22         echo "Run fsstress"
23         echo ""
24         num_iterations=10
25         enospc_time=2
26         out=$SCRATCH_MNT/fsstress.$$
27         args=`_scale_fsstress_args -p128 -n999999999 -f setattr=1 $FSSTRESS_AVOID -d $out`
28         echo "fsstress $args" >> $seqres.full
29         # Grant chown capability 
30         cp $FSSTRESS_PROG  $tmp.fsstress.bin
31         $SETCAP_PROG cap_chown=epi  $tmp.fsstress.bin
32
33         # io_uring accounts memory it needs under the rlimit memlocked option,
34         # which can be quite low on some setups (especially 64K pagesize). root
35         # isn't under this restriction, but regular users are. To avoid the
36         # io_uring_queue_init fail on ENOMEM, set max locked memory to unlimited
37         # temporarily.
38         ulimit -l unlimited
39         (su $qa_user -c "$tmp.fsstress.bin $args" &) > /dev/null 2>&1
40
41         echo "Run dd writers in parallel"
42         for ((i=0; i < num_iterations; i++))
43         do
44                 # File will be opened with O_TRUNC each time
45                 su $qa_user -c "dd if=/dev/zero \
46                         of=$SCRATCH_MNT/SPACE_CONSUMER bs=1M " \
47                         >> $seqres.full 2>&1
48                 sleep $enospc_time
49         done
50
51         $KILLALL_PROG -w $tmp.fsstress.bin
52 }
53
54 # real QA test starts here
55 _supported_fs generic
56 _require_quota
57 _require_user
58 _require_scratch
59 _require_command "$KILLALL_PROG" killall
60 _require_command "$SETCAP_PROG" setcap
61
62 _scratch_mkfs_sized $((512 * 1024 * 1024)) >> $seqres.full 2>&1
63 _scratch_mount "-o usrquota,grpquota"
64 chmod 777 $SCRATCH_MNT
65 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
66 quotaon -u -g $SCRATCH_MNT 2>/dev/null
67
68 if ! _workout; then
69         _scratch_unmount 2>/dev/null
70         exit
71 fi
72
73 if ! _check_quota_usage; then
74         _scratch_unmount 2>/dev/null
75         status=1
76         exit
77 fi
78
79 echo Comparing filesystem consistency
80 if ! _scratch_unmount; then
81         echo "failed to umount"
82         status=1
83         exit
84 fi
85 status=0
86 exit