Our nbd_can_FOO APIs are allowed when Connected and Closed, but not
when Dead (which makes sense: they tell what the server answered while
connecting, and are valid whether we are still talking to the server
or cleanly disconnected, but if we are in Dead, we cannot tell if the
server answered us). But our recent addition of list export APIs were
originally only allowed when Closed or Dead. Dead makes sense here
(that is our default state if NBD_OPT_GO fails, but failure is likely
if the server did not like our export name; but the point of listing
was to figure out what export name to pass), but we also need to
permit Connected (because the list is accurate even if we did manage
to successfully connect).
The testsuite changes demonstrate why this change is needed (changing
just the tests without the generator causes the tests to fail), but
also highlights another issue: we are holding open two connections at
once to the same server, which deadlocks if the server in question
only permits one client at a time.
---
generator/API.ml | 6 +++---
info/info-list-json.sh | 11 ++++++++++-
info/info-list.sh | 11 ++++++++++-
3 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/generator/API.ml b/generator/API.ml
index 3ba7223..82fdf75 100644
--- a/generator/API.ml
+++ b/generator/API.ml
@@ -649,7 +649,7 @@ Return true if list exports mode was enabled on this handle.";
"get_nr_list_exports", {
default_call with
args = []; ret = RInt;
- permitted_states = [ Closed; Dead ];
+ permitted_states = [ Connected; Closed; Dead ];
shortdesc = "return the number of exports returned by the server";
longdesc = "\
If list exports mode was enabled on the handle and you connected
@@ -663,7 +663,7 @@ C<nbd_set_list_exports>.";
"get_list_export_name", {
default_call with
args = [ Int "i" ]; ret = RString;
- permitted_states = [ Closed; Dead ];
+ permitted_states = [ Connected; Closed; Dead ];
shortdesc = "return the i'th export name";
longdesc = "\
If list exports mode was enabled on the handle and you connected
@@ -675,7 +675,7 @@ from the list returned by the server.";
"get_list_export_description", {
default_call with
args = [ Int "i" ]; ret = RString;
- permitted_states = [ Closed; Dead ];
+ permitted_states = [ Connected; Closed; Dead ];
shortdesc = "return the i'th export description";
longdesc = "\
If list exports mode was enabled on the handle and you connected
diff --git a/info/info-list-json.sh b/info/info-list-json.sh
index 8a07dcc..1cafb39 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 -t --socket=$sock --pid-file=$pid -x "hello" -D "world" $img
&
+qemu-nbd -e2 -t --socket=$sock --pid-file=$pid -x "hello" -D "world"
$img &
cleanup_fn kill $!
# Wait for qemu-nbd to start up.
@@ -49,9 +49,18 @@ if ! test -f $pid; then
exit 1
fi
+# Test twice, once with an export name not on the list,...
$VG nbdinfo "nbd+unix://?socket=$sock" --list --json > $out
jq . < $out
grep '"export-name": "hello"' $out
grep '"description": "world"' $out
grep '"export-size": 1048576' $out
+
+# ...and again with the export name included
+$VG nbdinfo "nbd+unix:///hello?socket=$sock" --list --json > $out
+jq . < $out
+
+grep '"export-name": "hello"' $out
+grep '"description": "world"' $out
+grep '"export-size": 1048576' $out
diff --git a/info/info-list.sh b/info/info-list.sh
index d51a6ff..62e5724 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 -t --socket=$sock --pid-file=$pid -x "hello" -D "world" $img
&
+qemu-nbd -e2 -t --socket=$sock --pid-file=$pid -x "hello" -D "world"
$img &
cleanup_fn kill $!
# Wait for qemu-nbd to start up.
@@ -48,9 +48,18 @@ if ! test -f $pid; then
exit 1
fi
+# Test twice, once with an export name not on the list,...
$VG nbdinfo "nbd+unix://?socket=$sock" --list > $out
cat $out
grep 'export="hello":' $out
grep 'description: world' $out
grep 'export-size: 1048576' $out
+
+# ...and again with the export name included
+$VG nbdinfo "nbd+unix:///hello?socket=$sock" --list > $out
+cat $out
+
+grep 'export="hello":' $out
+grep 'description: world' $out
+grep 'export-size: 1048576' $out
--
2.28.0