Eric Blake
2019-Sep-17 13:15 UTC
[Libguestfs] [libnbd PATCH] api: Add nbd_get_structured_replies_negotiated
Similar to nbd_get_tls_negotiated, for observing what we actually settled on with the server, rather than what was requested. --- generator/generator | 30 +++++++++++++++++++++++++----- lib/handle.c | 6 ++++++ tests/meta-base-allocation.c | 15 +++++++++++++++ tests/oldstyle.c | 7 ++++++- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/generator/generator b/generator/generator index 5f538b2..3b63665 100755 --- a/generator/generator +++ b/generator/generator @@ -1312,6 +1312,7 @@ rather than find a way to alter the server to fail the negotiation request."; see_also = ["L<nbd_get_request_structured_replies(3)>"; "L<nbd_set_handshake_flags(3)>"; + "L<nbd_get_structured_replies_negotiated(3)>"; "L<nbd_can_meta_context(3)>"; "L<nbd_can_df(3)>"]; }; @@ -1322,10 +1323,26 @@ request."; shortdesc = "see if structured replies are attempted"; longdesc = "\ Return the state of the request structured replies flag on this -handle. Note that this only reports whether the client attempts -to negotiate structured replies, and not whether the server was -able to honor that request"; - see_also = ["L<nbd_set_request_structured_replies(3)>"]; +handle. + +B<Note:> If you want to find out if structured replies were actually +negotiated on a particular connection use +C<nbd_get_structured_replies_negotiated> instead."; + see_also = ["L<nbd_set_request_structured_replies(3)>"; + "L<nbd_get_structured_replies_negotiated(3)>"]; + }; + + "get_structured_replies_negotiated", { + default_call with + args = []; ret = RBool; + permitted_states = [ Connected; Closed ]; + shortdesc = "see if structured replies are in use"; + longdesc = "\ +After connecting you may call this to find out if the connection is +using structured replies."; + see_also = ["L<nbd_set_request_structured_replies(3)>"; + "L<nbd_get_request_structured_replies(3)>"; + "L<nbd_get_protocol(3)>"]; }; "set_handshake_flags", { @@ -1673,7 +1690,9 @@ be returned in the future. Most modern NBD servers use C<\"newstyle-fixed\">. " ^ non_blocking_test_call_description; - see_also = ["L<nbd_get_handshake_flags(3)>"]; + see_also = ["L<nbd_get_handshake_flags(3)>"; + "L<nbd_get_structured_replies_negotiated(3)>"; + "L<nbd_get_tls_negotiated(3)>"]; }; "get_size", { @@ -2654,6 +2673,7 @@ let first_version = [ "can_fast_zero", (1, 2); "set_request_structured_replies", (1, 2); "get_request_structured_replies", (1, 2); + "get_structured_replies_negotiated", (1, 2); "get_tls_negotiated", (1, 2); "get_protocol", (1, 2); "set_handshake_flags", (1, 2); diff --git a/lib/handle.c b/lib/handle.c index 36e6434..2af25fe 100644 --- a/lib/handle.c +++ b/lib/handle.c @@ -260,6 +260,12 @@ nbd_unlocked_get_request_structured_replies (struct nbd_handle *h) return h->request_sr; } +int +nbd_unlocked_get_structured_replies_negotiated (struct nbd_handle *h) +{ + return h->structured_replies; +} + int nbd_unlocked_set_handshake_flags (struct nbd_handle *h, uint32_t flags) diff --git a/tests/meta-base-allocation.c b/tests/meta-base-allocation.c index f6be463..3de4c34 100644 --- a/tests/meta-base-allocation.c +++ b/tests/meta-base-allocation.c @@ -41,6 +41,8 @@ main (int argc, char *argv[]) struct nbd_handle *nbd; char plugin_path[256]; int id; + int r; + const char *s; snprintf (plugin_path, sizeof plugin_path, "%s/meta-base-allocation.sh", getenv ("srcdir") ? : "."); @@ -77,6 +79,19 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } + /* Protocol should be "newstyle-fixed", with structured replies. */ + s = nbd_get_protocol (nbd); + if (strcmp (s, "newstyle-fixed") != 0) { + fprintf (stderr, + "incorrect protocol \"%s\", expected \"newstyle-fixed\"\n", s); + exit (EXIT_FAILURE); + } + if ((r = nbd_get_structured_replies_negotiated (nbd)) != 1) { + fprintf (stderr, + "incorrect structured replies %d, expected 1\n", r); + exit (EXIT_FAILURE); + } + switch (nbd_can_meta_context (nbd, "x-libnbd:nosuch")) { case -1: fprintf (stderr, "%s\n", nbd_get_error ()); diff --git a/tests/oldstyle.c b/tests/oldstyle.c index b90b775..c9c01f8 100644 --- a/tests/oldstyle.c +++ b/tests/oldstyle.c @@ -115,13 +115,18 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } - /* Protocol should be "oldstyle". */ + /* Protocol should be "oldstyle", with no structured replies. */ s = nbd_get_protocol (nbd); if (strcmp (s, "oldstyle") != 0) { fprintf (stderr, "incorrect protocol \"%s\", expected \"oldstyle\"\n", s); exit (EXIT_FAILURE); } + if ((r = nbd_get_structured_replies_negotiated (nbd)) != 0) { + fprintf (stderr, + "incorrect structured replies %" PRId64 ", expected 0\n", r); + exit (EXIT_FAILURE); + } if ((r = nbd_get_size (nbd)) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); -- 2.21.0
Richard W.M. Jones
2019-Sep-17 16:25 UTC
Re: [Libguestfs] [libnbd PATCH] api: Add nbd_get_structured_replies_negotiated
ACK (Was pushed already after discussion on IRC) Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Maybe Matching Threads
- [libnbd PATCH] api: Add set_handshake_flags for integration
- ANNOUNCE: libnbd 1.2 & nbdkit 1.16 - high performance NBD client and server
- [libnbd PATCH] api: Add way to avoid structured replies
- [libnbd PATCH v2 06/13] api: Add nbd_opt_abort and nbd_aio_opt_abort
- [PATCH libnbd 1/2] api: Add new API to read whether TLS was negotiated.