3 # Test NBD client unexpected disconnect
5 # Copyright Red Hat, Inc. 2014
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 owner
=stefanha@redhat.com
25 echo "QA output created by $seq"
28 status
=1 # failure is the default!
33 rm -f nbd-fault-injector.out
34 rm -f nbd-fault-injector.conf
36 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
42 _supported_fmt generic
47 local event export_name
=foo extra_args nbd_addr nbd_url proto when
51 --classic-negotiation)
53 extra_args
=--classic-negotiation
72 echo "=== Check disconnect $when $event ==="
75 cat > "$TEST_DIR/nbd-fault-injector.conf" <<EOF
81 if [ "$proto" = "tcp" ]; then
82 nbd_addr
="127.0.0.1:0"
84 nbd_addr
="$TEST_DIR/nbd.sock"
87 rm -f "$TEST_DIR/nbd.sock"
89 echo > "$TEST_DIR/nbd-fault-injector.out"
90 $PYTHON nbd-fault-injector.py
$extra_args "$nbd_addr" "$TEST_DIR/nbd-fault-injector.conf" >"$TEST_DIR/nbd-fault-injector.out" 2>&1 &
92 # Wait for server to be ready
93 while ! grep -q 'Listening on ' "$TEST_DIR/nbd-fault-injector.out"; do
97 # Extract the final address (port number has now been assigned in tcp case)
98 nbd_addr
=$
(sed -n 's/^Listening on //p' \
99 "$TEST_DIR/nbd-fault-injector.out")
101 if [ "$proto" = "tcp" ]; then
102 nbd_url
="nbd+tcp://$nbd_addr/$export_name"
104 nbd_url
="nbd+unix:///$export_name?socket=$nbd_addr"
107 $QEMU_IO -c "read 0 512" "$nbd_url" 2>&1 | _filter_qemu_io | _filter_nbd
112 for proto
in tcp unix
; do
113 for event
in neg1
"export" neg2 request reply data
; do
114 for when
in before after
; do
115 check_disconnect
"--$proto" "$event" "$when"
118 # Also inject short replies from the NBD server
122 check_disconnect
"--$proto" "$event" "$when"
126 for when
in 4 12 16; do
127 check_disconnect
"--$proto" "$event" "$when"
132 check_disconnect
"--$proto" "$event" "$when"
137 check_disconnect
"--$proto" "$event" "$when"
143 # Also check classic negotiation without export information
144 for when
in before
8 16 24 28 after
; do
145 check_disconnect
"--$proto" --classic-negotiation "neg-classic" "$when"