[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]