c43f3de39bec178d70f1846b71f2cf9a31e10275
[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 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1    # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 _cleanup()
34 {
35         stop_workers
36         cd /
37         rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42
43 # real QA test starts here
44 _supported_fs generic
45 _require_scratch
46 test "$FSTYP" = "overlay" && _notrun "Test does not apply to overlayfs."
47 _require_extra_fs overlay
48
49 rm -f $seqres.full
50
51 _scratch_mkfs >> $seqres.full
52 _scratch_mount
53 _supports_filetype $SCRATCH_MNT || _notrun "overlayfs test requires d_type"
54
55 mkdir $SCRATCH_MNT/lowerdir
56 mkdir $SCRATCH_MNT/lowerdir1
57 mkdir $SCRATCH_MNT/lowerdir/etc
58 mkdir $SCRATCH_MNT/workers
59 echo salts > $SCRATCH_MNT/lowerdir/etc/access.conf
60 touch $SCRATCH_MNT/running
61
62 stop_workers() {
63         test -e $SCRATCH_MNT/running || return
64         rm -f $SCRATCH_MNT/running
65
66         while [ "$(ls $SCRATCH_MNT/workers/ | wc -l)" -gt 0 ]; do
67                 wait
68         done
69 }
70
71 worker() {
72         local tag="$1"
73         local mergedir="$SCRATCH_MNT/merged$tag"
74         local l="lowerdir=$SCRATCH_MNT/lowerdir:$SCRATCH_MNT/lowerdir1"
75         local u="upperdir=$SCRATCH_MNT/upperdir$tag"
76         local w="workdir=$SCRATCH_MNT/workdir$tag"
77         local i="index=off,nfs_export=off"
78
79         touch $SCRATCH_MNT/workers/$tag
80         while test -e $SCRATCH_MNT/running; do
81                 rm -rf $SCRATCH_MNT/merged$tag
82                 rm -rf $SCRATCH_MNT/upperdir$tag
83                 rm -rf $SCRATCH_MNT/workdir$tag
84                 mkdir $SCRATCH_MNT/merged$tag
85                 mkdir $SCRATCH_MNT/workdir$tag
86                 mkdir $SCRATCH_MNT/upperdir$tag
87
88                 mount -t overlay overlay -o "$l,$u,$w,$i" $mergedir
89                 mv $mergedir/etc/access.conf $mergedir/etc/access.conf.bak
90                 touch $mergedir/etc/access.conf
91                 mv $mergedir/etc/access.conf $mergedir/etc/access.conf.bak
92                 touch $mergedir/etc/access.conf
93                 umount $mergedir
94         done
95         rm -f $SCRATCH_MNT/workers/$tag
96 }
97
98 for i in $(seq 0 $((4 + LOAD_FACTOR)) ); do
99         worker $i &
100 done
101
102 sleep $((30 * TIME_FACTOR))
103 stop_workers
104
105 echo Silence is golden.
106 # success, all done
107 status=0
108 exit