5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of Red Hat nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 # Check shutdown/disconnect behavior triggered by special status values
42 sock
=$
(mktemp
-u /tmp
/nbdkit-test-sock.XXXXXX
)
43 files
="eval-disconnect.pid $sock"
45 cleanup_fn
rm -f $files
47 # Start nbdkit with a plugin that fails writes according to the export
48 # name which must be numeric: a positive value leaves stderr empty, a
49 # non-positive one outputs EPERM first. Serve multiple clients.
53 start_nbdkit
-P eval-disconnect.pid
-U $sock eval \
54 get_size
=' echo 1024 ' \
55 open
=' if test $3 -le 0; then \
56 echo EPERM > $tmpdir/err; echo $((-$3)); \
58 : > $tmpdir/err; echo $3; \
61 pwrite
=' cat >/dev/null; cat $tmpdir/err >&2; exit $2 '
65 # Server should die shortly, if not already dead at this point.
66 for (( i
=0; i
< 5; i
++ )); do
67 kill -s 0 "$(cat eval-disconnect.pid)" ||
break
71 echo "nbdkit didn't exit fast enough"
77 # Noisy status 0 (OK) succeeds, despite text to stderr
78 nbdsh
-u "nbd+unix:///0?socket=$sock" -c - <<\EOF
84 # Silent status 1 (ERROR) fails; nbdkit turns lack of error into EIO
85 nbdsh
-u "nbd+unix:///1?socket=$sock" -c - <<\EOF
90 except nbd.Error as ex
:
91 assert ex.errnum
== errno.EIO
96 # Noisy status 1 (ERROR) fails with supplied EPERM
97 nbdsh
-u "nbd+unix:///-1?socket=$sock" -c - <<\EOF
102 except nbd.Error as ex
:
103 assert ex.errnum
== errno.EPERM
108 # Silent status 4 (SHUTDOWN_OK) kills the server. It is racy whether client
109 # sees success or if the connection is killed with libnbd giving ENOTCONN
110 nbdsh
-u "nbd+unix:///4?socket=$sock" -c - <<\EOF
114 except nbd.Error as ex
:
115 assert ex.errnum
== errno.ENOTCONN
120 # Noisy status 4 (SHUTDOWN_OK) kills the server. It is racy whether client
121 # sees success or if the connection is killed with libnbd giving ENOTCONN
122 nbdsh
-u "nbd+unix:///-4?socket=$sock" -c - <<\EOF
126 except nbd.Error as ex
:
127 assert ex.errnum
== errno.ENOTCONN
132 # Silent status 5 (SHUTDOWN_ERR) kills the server. It is racy whether client
133 # sees implied ESHUTDOWN or if the connection dies with libnbd giving ENOTCONN
134 nbdsh
-u "nbd+unix:///5?socket=$sock" -c - <<\EOF
139 except nbd.Error as ex
:
140 assert ex.errnum
== errno.ESHUTDOWN or ex.errnum
== errno.ENOTCONN
145 # Noisy status 5 (SHUTDOWN_ERR) kills the server. It is racy whether client
146 # sees EPERM or if the connection is killed with libnbd giving ENOTCONN
147 nbdsh
-u "nbd+unix:///-5?socket=$sock" -c - <<\EOF
152 except nbd.Error as ex
:
153 assert ex.errnum
== errno.EPERM or ex.errnum
== errno.ENOTCONN
158 # Silent status 6 (DISC_FORCE) kills socket; libnbd detects as ENOTCONN
159 nbdsh
-u "nbd+unix:///6?socket=$sock" -c - <<\EOF
164 except nbd.Error as ex
:
165 assert ex.errnum
== errno.ENOTCONN
166 assert h.aio_is_ready
() is False
169 # Noisy status 6 (DISC_FORCE) kills socket; libnbd detects as ENOTCONN
170 nbdsh
-u "nbd+unix:///-6?socket=$sock" -c - <<\EOF
175 except nbd.Error as ex
:
176 assert ex.errnum
== errno.ENOTCONN
177 assert h.aio_is_ready
() is False
180 # Silent status 7 (DISC_SOFT_OK) succeeds, but next command gives ESHUTDOWN
181 nbdsh
-u "nbd+unix:///7?socket=$sock" -c - <<\EOF
187 except nbd.Error as ex
:
188 assert ex.errnum
== errno.ESHUTDOWN
192 # Noisy status 7 (DISC_SOFT_OK) succeeds, but next command gives ESHUTDOWN
193 nbdsh
-u "nbd+unix:///-7?socket=$sock" -c - <<\EOF
199 except nbd.Error as ex
:
200 assert ex.errnum
== errno.ESHUTDOWN
204 # Silent status 8 (DISC_SOFT_ERR) fails with implied ESHUTDOWN, then next
205 # command gives ESHUTDOWN
206 nbdsh
-u "nbd+unix:///8?socket=$sock" -c - <<\EOF
211 except nbd.Error as ex
:
212 assert ex.errnum
== errno.ESHUTDOWN
216 except nbd.Error as ex
:
217 assert ex.errnum
== errno.ESHUTDOWN
221 # Noisy status 8 (DISC_SOFT_ERR) fails with explicit EPERM, then next
222 # command gives ESHUTDOWN
223 nbdsh
-u "nbd+unix:///-8?socket=$sock" -c - <<\EOF
228 except nbd.Error as ex
:
229 assert ex.errnum
== errno.EPERM
233 except nbd.Error as ex
:
234 assert ex.errnum
== errno.ESHUTDOWN