All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: mreitz@redhat.com, kwolf@redhat.com, pbonzini@redhat.com, den@openvz.org
Subject: Re: [Qemu-devel] [PATCH v3 10/13] nbd/client: refactor nbd_receive_starttls
Date: Fri, 13 Oct 2017 12:58:28 -0500	[thread overview]
Message-ID: <af788c65-e7f5-65f4-07e4-1978807d40e4@redhat.com> (raw)
In-Reply-To: <20171012095319.136610-11-vsementsov@virtuozzo.com>

[-- Attachment #1: Type: text/plain, Size: 7347 bytes --]

On 10/12/2017 04:53 AM, Vladimir Sementsov-Ogievskiy wrote:
> Split out nbd_receive_simple_option to be reused for structured reply

s/receive/request/, but see [1]

> option.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  nbd/client.c     | 64 ++++++++++++++++++++++++++++++++++++++++----------------
>  nbd/trace-events |  7 ++++---
>  2 files changed, 50 insertions(+), 21 deletions(-)
> 
> diff --git a/nbd/client.c b/nbd/client.c
> index cd5a2c80ac..c8702a80b1 100644
> --- a/nbd/client.c
> +++ b/nbd/client.c
> @@ -540,35 +540,63 @@ static int nbd_receive_query_exports(QIOChannel *ioc,
>      }
>  }
>  
> -static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
> -                                        QCryptoTLSCreds *tlscreds,
> -                                        const char *hostname, Error **errp)
> +/* nbd_request_simple_option
> + * return 1 for successful negotiation,
> + *        0 if operation is unsupported,
> + *        -1 with errp set for any other error
> + */
> +static int nbd_request_simple_option(QIOChannel *ioc, int opt, Error **errp)
>  {
>      nbd_opt_reply reply;

Unrelated, but a potential cleanup for a future patch: we really should
be using our preferred naming scheme, where this would be NBDOptReply or
similar.

> -    QIOChannelTLS *tioc;
> -    struct NBDTLSHandshakeData data = { 0 };
>  
> -    trace_nbd_receive_starttls_request();
> -    if (nbd_send_option_request(ioc, NBD_OPT_STARTTLS, 0, NULL, errp) < 0) {
> -        return NULL;
> +    trace_nbd_receive_simple_option_request(opt, nbd_opt_lookup(opt));

Naming of the trace doesn't quite match the naming of the function...

> +    if (nbd_send_option_request(ioc, opt, 0, NULL, errp) < 0) {
> +        return -1;
>      }
>  
> -    trace_nbd_receive_starttls_reply();
> -    if (nbd_receive_option_reply(ioc, NBD_OPT_STARTTLS, &reply, errp) < 0) {
> -        return NULL;
> +    trace_nbd_receive_simple_option_reply(opt, nbd_opt_lookup(opt));

[1] ...However, trace_nbd_request_simple_option_request sounds silly.
Can we get by with the shorter nbd_simple_option() as the function name,
then have two traces nbd_simple_option_request and
nbd_simple_option_reply?  Or, recognize that nbd_receive_option_reply()
already traces everything, so this trace is redundant with that one.  In
fact, nbd_send_option_request also traces everything (it doesn't trace
payload, but we aren't sending payload; the only time we need two traces
instead of one is if the local trace can document payload before the
common trace documents everything else.  Another reason for redundant
traces is if you envision needing to trace one local thing without being
overwhelmed by the noise of a common trace firing for unrelated events,
but NBD startup is not that frequent to need fine-grained filtering on
the traces).

> +    if (nbd_receive_option_reply(ioc, opt, &reply, errp) < 0) {
> +        return -1;
>      }
>  
> -    if (reply.type != NBD_REP_ACK) {
> -        error_setg(errp, "Server rejected request to start TLS %" PRIx32,
> -                   reply.type);
> +    if (reply.length != 0) {
> +        error_setg(errp, "Option %d ('%s') response length is %" PRIu32
> +                   " (it should be zero)", opt, nbd_opt_lookup(opt),
> +                   reply.length);
>          nbd_send_opt_abort(ioc);

Just thinking aloud here. For starttls, the NBD spec already says
payload must be 0 length. But for NBD_OPT_STRUCTURED_REPLY, which is not
yet standardized, it is conceivable that in the future, we might have a
way for the server to return a payload to the ACK reply, which informs
the client what additional options have been unlocked by negotiating
structured reply (after all, we document that some options should not be
negotiated unless structured reply is negotiated first).  We don't have
that in the spec now, but writing our client to reject any payload from
the server (rather than silently ignoring the payload) means that we
can't ever write a server with that extended reply.  So it's worth
discussing on the NBD list whether we want to make any guarantees about
forcing a 0-length payload vs. allowing clients to ignore an
unrecognized non-empty payload.  Depending on what the NBD community
decides, the easiest approach here would be a 'bool ignore_payload'
parameter, true when requesting OPT_STRUCTURED_REPLY, false when
requesting OPT_STARTTLS.  But as this is all speculation, I'm also fine
with checking in your stricter version as-is for now; we have until qemu
2.11 is released to tweak our implementation as followups based on
conversations on the NBD list.

> +
> +    trace_nbd_receive_simple_option_approved(opt, nbd_opt_lookup(opt));

Another trace that doesn't add much value.

So, here's what I'm squashing, before I give:
Reviewed-by: Eric Blake <eblake@redhat.com>

diff --git i/nbd/client.c w/nbd/client.c
index c8702a80b1..fa64ec1c5b 100644
--- i/nbd/client.c
+++ w/nbd/client.c
@@ -540,7 +540,7 @@ static int nbd_receive_query_exports(QIOChannel *ioc,
     }
 }

-/* nbd_request_simple_option
+/* nbd_request_simple_option: Send an option request, and parse the reply
  * return 1 for successful negotiation,
  *        0 if operation is unsupported,
  *        -1 with errp set for any other error
@@ -549,12 +549,10 @@ static int nbd_request_simple_option(QIOChannel
*ioc, int opt, Error **errp)
 {
     nbd_opt_reply reply;

-    trace_nbd_receive_simple_option_request(opt, nbd_opt_lookup(opt));
     if (nbd_send_option_request(ioc, opt, 0, NULL, errp) < 0) {
         return -1;
     }

-    trace_nbd_receive_simple_option_reply(opt, nbd_opt_lookup(opt));
     if (nbd_receive_option_reply(ioc, opt, &reply, errp) < 0) {
         return -1;
     }
@@ -579,7 +577,6 @@ static int nbd_request_simple_option(QIOChannel
*ioc, int opt, Error **errp)
         return -1;
     }

-    trace_nbd_receive_simple_option_approved(opt, nbd_opt_lookup(opt));
     return 1;
 }

diff --git i/nbd/trace-events w/nbd/trace-events
index 0c8138ab92..59c0718a6b 100644
--- i/nbd/trace-events
+++ w/nbd/trace-events
@@ -9,9 +9,6 @@ nbd_opt_go_info_unknown(int info, const char *name)
"Ignoring unknown info %d (%
 nbd_opt_go_info_block_size(uint32_t minimum, uint32_t preferred,
uint32_t maximum) "Block sizes are 0x%" PRIx32 ", 0x%" PRIx32 ", 0x%" PRIx32
 nbd_receive_query_exports_start(const char *wantname) "Querying export
list for '%s'"
 nbd_receive_query_exports_success(const char *wantname) "Found desired
export name '%s'"
-nbd_receive_simple_option_request(int opt, const char *name)
"Requesting option %d (%s) from server"
-nbd_receive_simple_option_reply(int opt, const char *name) "Getting
reply for option %d (%s) from server"
-nbd_receive_simple_option_approved(int opt, const char *name) "Option
%d (%s) approved"
 nbd_receive_starttls_new_client(void) "Setting up TLS"
 nbd_receive_starttls_tls_handshake(void) "Starting TLS handshake"
 nbd_receive_negotiate(void *tlscreds, const char *hostname) "Receiving
negotiation tlscreds=%p hostname=%s"


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

  reply	other threads:[~2017-10-13 17:58 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-12  9:53 [Qemu-devel] [PATCH v3 00/13] nbd minimal structured read Vladimir Sementsov-Ogievskiy
2017-10-12  9:53 ` [Qemu-devel] [PATCH v3 01/13] block/nbd-client: assert qiov len once in nbd_co_request Vladimir Sementsov-Ogievskiy
2017-10-12 21:16   ` Eric Blake
2017-10-12  9:53 ` [Qemu-devel] [PATCH v3 02/13] block/nbd-client: refactor nbd_co_receive_reply Vladimir Sementsov-Ogievskiy
2017-10-12  9:53 ` [Qemu-devel] [PATCH v3 03/13] nbd: rename some simple-request related objects to be _simple_ Vladimir Sementsov-Ogievskiy
2017-10-12 21:26   ` Eric Blake
2017-10-12  9:53 ` [Qemu-devel] [PATCH v3 04/13] nbd/server: structurize simple reply header sending Vladimir Sementsov-Ogievskiy
2017-10-12 21:42   ` Eric Blake
2017-10-12 21:47     ` Eric Blake
2017-10-12 21:52   ` Eric Blake
2017-10-12  9:53 ` [Qemu-devel] [PATCH v3 05/13] nbd/server: do not use NBDReply structure Vladimir Sementsov-Ogievskiy
2017-10-12 22:03   ` Eric Blake
2017-10-12  9:53 ` [Qemu-devel] [PATCH v3 06/13] nbd/server: refactor nbd_co_send_simple_reply parameters Vladimir Sementsov-Ogievskiy
2017-10-12 22:21   ` Eric Blake
2017-10-12  9:53 ` [Qemu-devel] [PATCH v3 07/13] nbd-server: simplify reply transmission Vladimir Sementsov-Ogievskiy
2017-10-12 22:27   ` Eric Blake
2017-10-12 22:31     ` Eric Blake
2017-10-12 22:35     ` Eric Blake
2017-10-12  9:53 ` [Qemu-devel] [PATCH v3 08/13] nbd: header constants indenting Vladimir Sementsov-Ogievskiy
2017-10-12  9:53 ` [Qemu-devel] [PATCH v3 09/13] nbd: Minimal structured read for server Vladimir Sementsov-Ogievskiy
2017-10-13 16:00   ` Eric Blake
2017-10-13 16:15     ` Eric Blake
2017-10-13 16:34       ` Vladimir Sementsov-Ogievskiy
2017-10-13 16:23     ` Vladimir Sementsov-Ogievskiy
2017-10-12  9:53 ` [Qemu-devel] [PATCH v3 10/13] nbd/client: refactor nbd_receive_starttls Vladimir Sementsov-Ogievskiy
2017-10-13 17:58   ` Eric Blake [this message]
2017-10-12  9:53 ` [Qemu-devel] [PATCH v3 11/13] nbd: share some nbd entities to be reused in block/nbd-client.c Vladimir Sementsov-Ogievskiy
2017-10-13 18:47   ` Eric Blake
2017-10-13 18:52     ` Vladimir Sementsov-Ogievskiy
2017-10-13 19:03   ` Eric Blake
2017-10-13 22:34   ` Eric Blake
2017-10-12  9:53 ` [Qemu-devel] [PATCH v3 12/13] nbd/client: prepare nbd_receive_reply for structured reply Vladimir Sementsov-Ogievskiy
2017-10-13 19:20   ` Eric Blake
2017-10-12  9:53 ` [Qemu-devel] [PATCH v3 13/13] nbd: Minimal structured read for client Vladimir Sementsov-Ogievskiy
2017-10-13 20:51   ` Eric Blake
2017-10-16 16:54     ` Vladimir Sementsov-Ogievskiy
2017-10-12 10:49 ` [Qemu-devel] [PATCH v3 00/13] nbd minimal structured read no-reply
2017-10-12 11:15   ` Vladimir Sementsov-Ogievskiy
2017-10-12 13:28     ` Eric Blake
2017-10-12 22:39 ` Eric Blake
2017-10-13  7:57   ` Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=af788c65-e7f5-65f4-07e4-1978807d40e4@redhat.com \
    --to=eblake@redhat.com \
    --cc=den@openvz.org \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.