xref: /freebsd/tests/sys/geom/class/multipath/failloop.sh (revision 18f21f0355481283ceef0ec10e99554f44c205c2)
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# $FreeBSD$
26
27. $(atf_get_srcdir)/conf.sh
28
29# See also https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=178473
30atf_test_case failloop cleanup
31failloop_head()
32{
33	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"
34	atf_set "require.user" "root"
35	atf_set "require.config" "allow_sysctl_side_effects"
36}
37failloop_body()
38{
39	sysctl -n kern.geom.notaste > kern.geom.notaste.txt
40	load_gnop
41	load_gmultipath
42	load_dtrace
43
44	md0=$(alloc_md)
45	md1=$(alloc_md)
46	name=$(mkname)
47	atf_check gnop create /dev/${md0}
48	atf_check gnop create /dev/${md1}
49	atf_check -s exit:0 gmultipath create "$name" ${md0}.nop ${md1}.nop
50	sysctl kern.geom.notaste=1
51
52	atf_check gnop configure -r 100 -w 100  ${md0}.nop
53	atf_check gnop configure -r 100 -w 100  ${md1}.nop
54	dd_status=`dtrace \
55		-o restore_count \
56		-i 'geom:multipath:config:restore {@restore = count()}' \
57		-c "dd if=/dev/zero of=/dev/multipath/"$name" bs=4096 count=1" \
58		2>&1 | awk '/exited with status/ {print $NF}'`
59	# The dd command should've failed ...
60	atf_check_equal 1 $dd_status
61	# and triggered 1 or 2 path restores
62	if [ `cat restore_count` -gt 2 ]; then
63		atf_fail "gmultipath restored paths too many times"
64	fi
65}
66failloop_cleanup()
67{
68	if [ -f kern.geom.notaste.txt ]; then
69		sysctl kern.geom.notaste=`cat kern.geom.notaste.txt`
70	fi
71	common_cleanup
72}
73
74atf_init_test_cases()
75{
76	atf_add_test_case failloop
77}
78