This is a per-connection setting, rather than per-export; and becomes
more interesting in light of future extensions to the NBD protocol
that will add 64-bit support needing similar output, to make it easier
to quickly determine whether a given server supports particular NBD
extensions.
---
info/nbdinfo.pod | 3 ++-
info/Makefile.am | 3 ++-
info/info-packets.sh | 38 ++++++++++++++++++++++++++++++++++++++
info/main.c | 7 +++++++
4 files changed, 49 insertions(+), 2 deletions(-)
create mode 100755 info/info-packets.sh
diff --git a/info/nbdinfo.pod b/info/nbdinfo.pod
index c3ec3ee7..a95b64f2 100644
--- a/info/nbdinfo.pod
+++ b/info/nbdinfo.pod
@@ -47,7 +47,7 @@ The single required parameter can be the NBD URI of the server (see
L<https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md>):
$ nbdinfo nbd://localhost
- protocol: newstyle-fixed without TLS
+ protocol: newstyle-fixed without TLS, using structured packets
export="":
export-size: 1048576 (1M)
content: data
@@ -85,6 +85,7 @@ the I<--json> parameter:
{
"protocol": "newstyle-fixed",
"TLS": false,
+ "structured": true,
"exports": [
{
"export-name": "",
diff --git a/info/Makefile.am b/info/Makefile.am
index 88e1e21b..5c830226 100644
--- a/info/Makefile.am
+++ b/info/Makefile.am
@@ -1,5 +1,5 @@
# nbd client library in userspace
-# Copyright (C) 2020 Red Hat Inc.
+# Copyright (C) 2020-2022 Red Hat Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -33,6 +33,7 @@ info_sh_files = \
info-list-uris.sh \
info-json.sh \
info-oldstyle.sh \
+ info-packets.sh \
info-null.sh \
info-size.sh \
info-text.sh \
diff --git a/info/info-packets.sh b/info/info-packets.sh
new file mode 100755
index 00000000..60b01865
--- /dev/null
+++ b/info/info-packets.sh
@@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+# nbd client library in userspace
+# Copyright (C) 2020-2022 Red Hat Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+. ../tests/functions.sh
+
+set -e
+set -x
+
+requires nbdkit --version
+requires nbdkit memory --version
+
+out=info-packets.out
+cleanup_fn rm -f $out
+
+nbdkit --no-sr -U - memory size=1M \
+ --run '$VG nbdinfo "nbd+unix:///?socket=$unixsocket"' > $out
+cat $out
+grep "protocol: .*using simple packets" $out
+
+nbdkit -U - memory size=1M \
+ --run '$VG nbdinfo "nbd+unix:///?socket=$unixsocket"' > $out
+cat $out
+grep "protocol: .*using structured packets" $out
diff --git a/info/main.c b/info/main.c
index 5ea23928..47fb1799 100644
--- a/info/main.c
+++ b/info/main.c
@@ -302,10 +302,12 @@ main (int argc, char *argv[])
else { /* not --size or --map */
const char *protocol;
int tls_negotiated;
+ int sr_negotiated;
/* Print per-connection fields. */
protocol = nbd_get_protocol (nbd);
tls_negotiated = nbd_get_tls_negotiated (nbd);
+ sr_negotiated = nbd_get_structured_replies_negotiated (nbd);
if (!json_output) {
if (protocol) {
@@ -313,6 +315,9 @@ main (int argc, char *argv[])
fprintf (fp, "protocol: %s", protocol);
if (tls_negotiated >= 0)
fprintf (fp, " %s TLS", tls_negotiated ? "with" :
"without");
+ if (sr_negotiated >= 0)
+ fprintf (fp, ", using %s packets",
+ sr_negotiated ? "structured" : "simple");
fprintf (fp, "\n");
ansi_restore (fp);
}
@@ -327,6 +332,8 @@ main (int argc, char *argv[])
if (tls_negotiated >= 0)
fprintf (fp, "\"TLS\": %s,\n", tls_negotiated ?
"true" : "false");
+ if (sr_negotiated >= 0)
+ fprintf (fp, "\"structured\": %s,\n", sr_negotiated ?
"true" : "false");
}
if (!list_all)
--
2.37.3