xref: /freebsd/tests/sys/geom/class/multipath/failloop.sh (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1#!/bin/sh
2# Copyright (c) 2019 Axcient
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8#    notice, this list of conditions and the following disclaimer.
9# 2. Redistributions in binary form must reproduce the above copyright
10#    notice, this list of conditions and the following disclaimer in the
11#    documentation and/or other materials provided with the distribution.
12#
13# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23# SUCH DAMAGE.
24#
25
26. $(atf_get_srcdir)/conf.sh
27
28# See also https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=178473
29atf_test_case failloop cleanup
30failloop_head()
31{
32	atf_set "descr" "A persistent failure in the provider should not cause an infinite loop, nor restore any providers that were faulted by the same bio"
33	atf_set "require.user" "root"
34	atf_set "require.config" "allow_sysctl_side_effects"
35}
36failloop_body()
37{
38	sysctl -n kern.geom.notaste > kern.geom.notaste.txt
39	load_gnop
40	load_gmultipath
41	load_dtrace
42
43	md0=$(alloc_md)
44	md1=$(alloc_md)
45	name=$(mkname)
46	atf_check gnop create /dev/${md0}
47	atf_check gnop create /dev/${md1}
48	atf_check -s exit:0 gmultipath create "$name" ${md0}.nop ${md1}.nop
49	sysctl kern.geom.notaste=1
50
51	atf_check gnop configure -r 100 -w 100  ${md0}.nop
52	atf_check gnop configure -r 100 -w 100  ${md1}.nop
53	dd_status=`dtrace \
54		-o restore_count \
55		-i 'geom:multipath:config:restore {@restore = count()}' \
56		-c "dd if=/dev/zero of=/dev/multipath/"$name" bs=4096 count=1" \
57		2>&1 | awk '/exited with status/ {print $NF}'`
58	if [ ! -f restore_count ]; then
59		atf_skip "dtrace didn't execute successfully"
60	fi
61	# The dd command should've failed ...
62	atf_check_equal 1 $dd_status
63	# and triggered 1 or 2 path restores
64	if [ `cat restore_count` -gt 2 ]; then
65		atf_fail "gmultipath restored paths too many times"
66	fi
67}
68failloop_cleanup()
69{
70	if [ -f kern.geom.notaste.txt ]; then
71		sysctl kern.geom.notaste=`cat kern.geom.notaste.txt`
72	fi
73	common_cleanup
74}
75
76atf_init_test_cases()
77{
78	atf_add_test_case failloop
79}
80