generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 631
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 631
6 #
7 # Reproducer for a deadlock in xfs_rename reported by Wenli Xie.
8 #
9 # When overlayfs is running on top of xfs and the user unlinks a file in the
10 # overlay, overlayfs will create a whiteout inode and ask us to "rename" the
11 # whiteout file atop the one being unlinked.  If the file being unlinked loses
12 # its one nlink, we then have to put the inode on the unlinked list.
13 #
14 # This requires us to grab the AGI buffer of the whiteout inode to take it
15 # off the unlinked list (which is where whiteouts are created) and to grab
16 # the AGI buffer of the file being deleted.  If the whiteout was created in
17 # a higher numbered AG than the file being deleted, we'll lock the AGIs in
18 # the wrong order and deadlock.
19 #
20 # Note that this test doesn't do anything xfs-specific so it's a generic test.
21 # This is a regression test for commit 6da1b4b1ab36 ("xfs: fix an ABBA deadlock
22 # in xfs_rename").
23
24 . ./common/preamble
25 _begin_fstest auto rw whiteout rename
26
27 # Override the default cleanup function.
28 _cleanup()
29 {
30         stop_workers
31         cd /
32         rm -f $tmp.*
33 }
34
35 # Import common functions.
36 . ./common/attr
37
38 # real QA test starts here
39 _supported_fs generic
40 _require_scratch
41 _require_attrs
42 test "$FSTYP" = "overlay" && _notrun "Test does not apply to overlayfs."
43 _require_extra_fs overlay
44
45 _scratch_mkfs >> $seqres.full
46 _scratch_mount
47 _supports_filetype $SCRATCH_MNT || _notrun "overlayfs test requires d_type"
48
49 mkdir $SCRATCH_MNT/lowerdir
50 mkdir $SCRATCH_MNT/lowerdir1
51 mkdir $SCRATCH_MNT/lowerdir/etc
52 mkdir $SCRATCH_MNT/workers
53 echo salts > $SCRATCH_MNT/lowerdir/etc/access.conf
54 touch $SCRATCH_MNT/running
55
56 stop_workers() {
57         test -e $SCRATCH_MNT/running || return
58         rm -f $SCRATCH_MNT/running
59
60         while [ "$(ls $SCRATCH_MNT/workers/ | wc -l)" -gt 0 ]; do
61                 wait
62         done
63 }
64
65 worker() {
66         local tag="$1"
67         local mergedir="$SCRATCH_MNT/merged$tag"
68         local l="lowerdir=$SCRATCH_MNT/lowerdir:$SCRATCH_MNT/lowerdir1"
69         local u="upperdir=$SCRATCH_MNT/upperdir$tag"
70         local w="workdir=$SCRATCH_MNT/workdir$tag"
71         local i="index=off"
72
73         touch $SCRATCH_MNT/workers/$tag
74         while test -e $SCRATCH_MNT/running; do
75                 rm -rf $SCRATCH_MNT/merged$tag
76                 rm -rf $SCRATCH_MNT/upperdir$tag
77                 rm -rf $SCRATCH_MNT/workdir$tag
78                 mkdir $SCRATCH_MNT/merged$tag
79                 mkdir $SCRATCH_MNT/workdir$tag
80                 mkdir $SCRATCH_MNT/upperdir$tag
81
82                 mount -t overlay overlay -o "$l,$u,$w,$i" $mergedir
83                 mv $mergedir/etc/access.conf $mergedir/etc/access.conf.bak
84                 touch $mergedir/etc/access.conf
85                 mv $mergedir/etc/access.conf $mergedir/etc/access.conf.bak
86                 touch $mergedir/etc/access.conf
87                 umount $mergedir
88         done
89         rm -f $SCRATCH_MNT/workers/$tag
90 }
91
92 for i in $(seq 0 $((4 + LOAD_FACTOR)) ); do
93         worker $i &
94 done
95
96 sleep $((30 * TIME_FACTOR))
97 stop_workers
98
99 echo Silence is golden.
100 # success, all done
101 status=0
102 exit