summaryrefslogtreecommitdiff
path: root/tests/generic/631
blob: ff1bb11301b62976de079f9e633187ca0d888e5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) 2021 Oracle.  All Rights Reserved.
#
# FS QA Test No. 631
#
# Reproducer for a deadlock in xfs_rename reported by Wenli Xie.
#
# When overlayfs is running on top of xfs and the user unlinks a file in the
# overlay, overlayfs will create a whiteout inode and ask us to "rename" the
# whiteout file atop the one being unlinked.  If the file being unlinked loses
# its one nlink, we then have to put the inode on the unlinked list.
#
# This requires us to grab the AGI buffer of the whiteout inode to take it
# off the unlinked list (which is where whiteouts are created) and to grab
# the AGI buffer of the file being deleted.  If the whiteout was created in
# a higher numbered AG than the file being deleted, we'll lock the AGIs in
# the wrong order and deadlock.
#
# Note that this test doesn't do anything xfs-specific so it's a generic test.
# This is a regression test for commit 6da1b4b1ab36 ("xfs: fix an ABBA deadlock
# in xfs_rename").

. ./common/preamble
_begin_fstest auto rw whiteout rename

# Override the default cleanup function.
_cleanup()
{
	stop_workers
	cd /
	rm -f $tmp.*
}

# Import common functions.
. ./common/attr

# real QA test starts here
_require_scratch
_require_attrs trusted
_supported_fs ^overlay
_require_extra_fs overlay
_fixed_by_kernel_commit 6da1b4b1ab36 \
	"xfs: fix an ABBA deadlock in xfs_rename"

_scratch_mkfs >> $seqres.full
_scratch_mount
_supports_filetype $SCRATCH_MNT || _notrun "overlayfs test requires d_type"

mkdir $SCRATCH_MNT/lowerdir
mkdir $SCRATCH_MNT/lowerdir1
mkdir $SCRATCH_MNT/lowerdir/etc
mkdir $SCRATCH_MNT/workers
echo salts > $SCRATCH_MNT/lowerdir/etc/access.conf
touch $SCRATCH_MNT/running

stop_workers() {
	test -e $SCRATCH_MNT/running || return
	rm -f $SCRATCH_MNT/running

	while [ "$(ls $SCRATCH_MNT/workers/ | wc -l)" -gt 0 ]; do
		wait
	done
}

worker() {
	local tag="$1"
	local mergedir="$SCRATCH_MNT/merged$tag"
	local l="lowerdir=$SCRATCH_MNT/lowerdir:$SCRATCH_MNT/lowerdir1"
	local u="upperdir=$SCRATCH_MNT/upperdir$tag"
	local w="workdir=$SCRATCH_MNT/workdir$tag"
	local i="index=off"

	touch $SCRATCH_MNT/workers/$tag
	while test -e $SCRATCH_MNT/running; do
		rm -rf $SCRATCH_MNT/merged$tag
		rm -rf $SCRATCH_MNT/upperdir$tag
		rm -rf $SCRATCH_MNT/workdir$tag
		mkdir $SCRATCH_MNT/merged$tag
		mkdir $SCRATCH_MNT/workdir$tag
		mkdir $SCRATCH_MNT/upperdir$tag

		mount -t overlay overlay -o "$l,$u,$w,$i" $mergedir
		mv $mergedir/etc/access.conf $mergedir/etc/access.conf.bak
		touch $mergedir/etc/access.conf
		mv $mergedir/etc/access.conf $mergedir/etc/access.conf.bak
		touch $mergedir/etc/access.conf
		umount $mergedir
	done
	rm -f $SCRATCH_MNT/workers/$tag
}

for i in $(seq 0 $((4 + LOAD_FACTOR)) ); do
	worker $i &
done

sleep $((30 * TIME_FACTOR))
stop_workers

echo Silence is golden.
# success, all done
status=0
exit