target/arm: Clean excReturn bits when tail chaining
[qemu/ar7.git] / tests / qemu-iotests / common.nbd
blob25fc9ffaa46b3411983a35288c5ffdd75b8a4eae
1 #!/usr/bin/env bash
2 # -*- shell-script-mode -*-
4 # Helpers for NBD server related config
6 # Copyright (C) 2018 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 nbd_unix_socket="${TEST_DIR}/qemu-nbd.sock"
23 nbd_tcp_addr="127.0.0.1"
24 nbd_pid_file="${TEST_DIR}/qemu-nbd.pid"
26 nbd_server_stop()
28 local NBD_PID
29 if [ -f "$nbd_pid_file" ]; then
30 read NBD_PID < "$nbd_pid_file"
31 rm -f "$nbd_pid_file"
32 if [ -n "$NBD_PID" ]; then
33 kill "$NBD_PID"
36 rm -f "$nbd_unix_socket"
39 nbd_server_wait_for_unix_socket()
41 pid=$1
43 for ((i = 0; i < 300; i++))
45 if [ -r "$nbd_unix_socket" ]; then
46 return
48 kill -s 0 $pid 2>/dev/null
49 if test $? != 0
50 then
51 echo "qemu-nbd unexpectedly quit"
52 exit 1
54 sleep 0.1
55 done
56 echo "Failed in check of unix socket created by qemu-nbd"
57 exit 1
60 nbd_server_start_unix_socket()
62 nbd_server_stop
63 $QEMU_NBD -v -t -k "$nbd_unix_socket" "$@" &
64 nbd_server_wait_for_unix_socket $!
67 nbd_server_set_tcp_port()
69 (ss --help) >/dev/null 2>&1 || _notrun "ss utility not found, skipping test"
71 for ((port = 10809; port <= 10909; port++))
73 if ! ss -tln | grep -sqE ":$port\b"; then
74 nbd_tcp_port=$port
75 return
77 done
79 echo "Cannot find free TCP port for nbd in range 10809-10909"
80 exit 1
83 nbd_server_wait_for_tcp_socket()
85 pid=$1
87 for ((i = 0; i < 300; i++))
89 if ss -tln | grep -sqE ":$nbd_tcp_port\b"; then
90 return
92 kill -s 0 $pid 2>/dev/null
93 if test $? != 0
94 then
95 echo "qemu-nbd unexpectedly quit"
96 exit 1
98 sleep 0.1
99 done
100 echo "Failed in check of TCP socket created by qemu-nbd"
101 exit 1
104 nbd_server_start_tcp_socket()
106 nbd_server_stop
107 $QEMU_NBD -v -t -b $nbd_tcp_addr -p $nbd_tcp_port "$@" &
108 nbd_server_wait_for_tcp_socket $!