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"
29 if [ -f "$nbd_pid_file" ]; then
30 read NBD_PID
< "$nbd_pid_file"
32 if [ -n "$NBD_PID" ]; then
36 rm -f "$nbd_unix_socket"
39 nbd_server_wait_for_unix_socket
()
43 for ((i
= 0; i
< 300; i
++))
45 if [ -r "$nbd_unix_socket" ]; then
48 kill -s 0 $pid 2>/dev
/null
51 echo "qemu-nbd unexpectedly quit"
56 echo "Failed in check of unix socket created by qemu-nbd"
60 nbd_server_start_unix_socket
()
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
79 echo "Cannot find free TCP port for nbd in range 10809-10909"
83 nbd_server_wait_for_tcp_socket
()
87 for ((i
= 0; i
< 300; i
++))
89 if ss
-tln |
grep -sqE ":$nbd_tcp_port\b"; then
92 kill -s 0 $pid 2>/dev
/null
95 echo "qemu-nbd unexpectedly quit"
100 echo "Failed in check of TCP socket created by qemu-nbd"
104 nbd_server_start_tcp_socket
()
107 $QEMU_NBD -v -t -b $nbd_tcp_addr -p $nbd_tcp_port "$@" &
108 nbd_server_wait_for_tcp_socket $
!