Make sure the initial handle is closed if it is not already dead,
before attempting to open further handles, to avoid deadlocks if the
server serializes connections. Reverts the hack of needing 'qemu-nbd
-e2' to avoid deadlock in the previous patch.
---
info/info-list-json.sh | 2 +-
info/info-list.sh | 2 +-
info/nbdinfo.c | 6 ++++++
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/info/info-list-json.sh b/info/info-list-json.sh
index 1cafb39..fcba0dd 100755
--- a/info/info-list-json.sh
+++ b/info/info-list-json.sh
@@ -34,7 +34,7 @@ cleanup_fn rm -f $img $out $pid $sock
rm -f $img $out $pid $sock
truncate -s 1M $img
-qemu-nbd -e2 -t --socket=$sock --pid-file=$pid -x "hello" -D "world"
$img &
+qemu-nbd -t --socket=$sock --pid-file=$pid -x "hello" -D "world" $img
&
cleanup_fn kill $!
# Wait for qemu-nbd to start up.
diff --git a/info/info-list.sh b/info/info-list.sh
index 62e5724..3550adc 100755
--- a/info/info-list.sh
+++ b/info/info-list.sh
@@ -33,7 +33,7 @@ cleanup_fn rm -f $img $out $pid $sock
rm -f $img $out $pid $sock
truncate -s 1M $img
-qemu-nbd -e2 -t --socket=$sock --pid-file=$pid -x "hello" -D "world"
$img &
+qemu-nbd -t --socket=$sock --pid-file=$pid -x "hello" -D "world" $img
&
cleanup_fn kill $!
# Wait for qemu-nbd to start up.
diff --git a/info/nbdinfo.c b/info/nbdinfo.c
index 1aca548..b18cebc 100644
--- a/info/nbdinfo.c
+++ b/info/nbdinfo.c
@@ -222,6 +222,12 @@ main (int argc, char *argv[])
protocol = nbd_get_protocol (nbd);
tls_negotiated = nbd_get_tls_negotiated (nbd);
+ /* Disconnect from the server to move the handle into a closed
+ * state, in case the server serializes further connections; but
+ * ignore errors as the connection may already be dead.
+ */
+ nbd_shutdown (nbd, 0);
+
if (!json_output) {
if (protocol) {
printf ("protocol: %s", protocol);
--
2.28.0