All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Cc: qemu-devel@nongnu.org, libguestfs@redhat.com,
	 Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
	 "open list:Network Block Dev..." <qemu-block@nongnu.org>
Subject: Re: [PATCH v3 10/14] nbd/client: Initial support for extended headers
Date: Wed, 7 Jun 2023 13:22:27 -0500	[thread overview]
Message-ID: <6acudhjle7jke537s7hxbit4t3wikk325ewnzjvb5poqm3ndlr@wibmfb7w6o2j> (raw)
In-Reply-To: <b9dba014-3df4-e87e-8341-3653895d9e9b@yandex-team.ru>

The subject lines are confusing: 9/14 enables extended headers in the
server, while this one does not yet enable the headers but is merely a
preliminary step.  I'll probably retitle one or the other in v4.

On Wed, May 31, 2023 at 06:26:17PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> On 15.05.23 22:53, Eric Blake wrote:
> > Update the client code to be able to send an extended request, and
> > parse an extended header from the server.  Note that since we reject
> > any structured reply with a too-large payload, we can always normalize
> > a valid header back into the compact form, so that the caller need not
> > deal with two branches of a union.  Still, until a later patch lets
> > the client negotiate extended headers, the code added here should not
> > be reached.  Note that because of the different magic numbers, it is
> > just as easy to trace and then tolerate a non-compliant server sending
> > the wrong header reply as it would be to insist that the server is
> > compliant.
> > 
> > The only caller to nbd_receive_reply() always passed NULL for errp;
> > since we are changing the signature anyways, I decided to sink the
> > decision to ignore errors one layer lower.
> 
> This way nbd_receive_simple_reply() and nbd_receive_structured_reply_chunk() are called now only with explicit NULL last argument.. And we start to drop all errors.
> 
> Also, actually, we'd better add errp parameter to the caller - nbd_receive_replies(), because its caller (nbd_co_do_receive_one_chunk()) will benefit of it, as it already has errp.

I can explore plumbing errp back through for v4.

> > @@ -1394,28 +1401,34 @@ static int nbd_receive_simple_reply(QIOChannel *ioc, NBDSimpleReply *reply,
> > 
> >   /* nbd_receive_structured_reply_chunk
> >    * Read structured reply chunk except magic field (which should be already
> > - * read).
> > + * read).  Normalize into the compact form.
> >    * Payload is not read.
> >    */
> > -static int nbd_receive_structured_reply_chunk(QIOChannel *ioc,
> > -                                              NBDStructuredReplyChunk *chunk,
> > +static int nbd_receive_structured_reply_chunk(QIOChannel *ioc, NBDReply *chunk,
> >                                                 Error **errp)
> 
> Hmm, _structured_or_extened_ ? Or at least in comment above the function we should mention this.

I'm going with 'nbd_receive_reply_chunk', since both structured and
extended modes receive chunks.

> 
> >   {
> >       int ret;
> > +    size_t len;
> > +    uint64_t payload_len;
> > 
> > -    assert(chunk->magic == NBD_STRUCTURED_REPLY_MAGIC);
> > +    if (chunk->magic == NBD_STRUCTURED_REPLY_MAGIC) {
> > +        len = sizeof(chunk->structured);
> > +    } else {
> > +        assert(chunk->magic == NBD_EXTENDED_REPLY_MAGIC);
> > +        len = sizeof(chunk->extended);
> > +    }
> > 
> >       ret = nbd_read(ioc, (uint8_t *)chunk + sizeof(chunk->magic),
> > -                   sizeof(*chunk) - sizeof(chunk->magic), "structured chunk",
> 
> Would be good to print "extended chunk" in error message for EXTENDED case.

Or even just "chunk header", which covers both modes.

> >   int coroutine_fn nbd_receive_reply(BlockDriverState *bs, QIOChannel *ioc,
> > -                                   NBDReply *reply, Error **errp)
> > +                                   NBDReply *reply, NBDHeaderStyle hdr)
> >   {
> >       int ret;
> >       const char *type;
> > 
> > -    ret = nbd_read_eof(bs, ioc, &reply->magic, sizeof(reply->magic), errp);
> > +    ret = nbd_read_eof(bs, ioc, &reply->magic, sizeof(reply->magic), NULL);
> >       if (ret <= 0) {
> >           return ret;
> >       }
> > 
> >       reply->magic = be32_to_cpu(reply->magic);
> > 
> > +    /* Diagnose but accept wrong-width header */
> >       switch (reply->magic) {
> >       case NBD_SIMPLE_REPLY_MAGIC:
> > -        ret = nbd_receive_simple_reply(ioc, &reply->simple, errp);
> > +        if (hdr >= NBD_HEADER_EXTENDED) {
> > +            trace_nbd_receive_wrong_header(reply->magic);
> 
> maybe, trace also expected style

Sure, I can give that a shot.

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



  reply	other threads:[~2023-06-07 18:22 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-15 19:53 [PATCH v3 00/14] qemu patches for 64-bit NBD extensions Eric Blake
2023-05-15 19:53 ` [PATCH v3 01/14] nbd/client: Use smarter assert Eric Blake
2023-05-29  8:20   ` Vladimir Sementsov-Ogievskiy
2023-05-15 19:53 ` [PATCH v3 02/14] nbd/client: Add safety check on chunk payload length Eric Blake
2023-05-29  8:25   ` Vladimir Sementsov-Ogievskiy
2023-05-15 19:53 ` [PATCH v3 03/14] nbd/server: Prepare for alternate-size headers Eric Blake
2023-05-29 14:26   ` Vladimir Sementsov-Ogievskiy
2023-05-30 16:29     ` Eric Blake
2023-05-31  7:28       ` Vladimir Sementsov-Ogievskiy
2023-05-15 19:53 ` [PATCH v3 04/14] nbd: Prepare for 64-bit request effect lengths Eric Blake
2023-05-30 13:05   ` Vladimir Sementsov-Ogievskiy
2023-05-30 18:23     ` Eric Blake
2023-05-15 19:53 ` [PATCH v3 05/14] nbd: Add types for extended headers Eric Blake
2023-05-30 13:23   ` Vladimir Sementsov-Ogievskiy
2023-05-30 18:22     ` [Libguestfs] " Eric Blake
2023-05-31  7:30       ` Vladimir Sementsov-Ogievskiy
2023-05-15 19:53 ` [PATCH v3 06/14] nbd/server: Refactor handling of request payload Eric Blake
2023-05-31  8:04   ` Vladimir Sementsov-Ogievskiy
2023-05-15 19:53 ` [PATCH v3 07/14] nbd/server: Refactor to pass full request around Eric Blake
2023-05-31  8:13   ` Vladimir Sementsov-Ogievskiy
2023-05-15 19:53 ` [PATCH v3 08/14] nbd/server: Support 64-bit block status Eric Blake
2023-05-31 14:10   ` Vladimir Sementsov-Ogievskiy
2023-05-15 19:53 ` [PATCH v3 09/14] nbd/server: Initial support for extended headers Eric Blake
2023-05-31 14:46   ` Vladimir Sementsov-Ogievskiy
2023-06-07 11:39     ` Eric Blake
2023-05-15 19:53 ` [PATCH v3 10/14] nbd/client: " Eric Blake
2023-05-31 15:26   ` Vladimir Sementsov-Ogievskiy
2023-06-07 18:22     ` Eric Blake [this message]
2023-05-15 19:53 ` [PATCH v3 11/14] nbd/client: Accept 64-bit block status chunks Eric Blake
2023-05-31 17:00   ` Vladimir Sementsov-Ogievskiy
2023-05-15 19:53 ` [PATCH v3 12/14] nbd/client: Request extended headers during negotiation Eric Blake
     [not found]   ` <1af7f692-b5de-c767-2568-1fc024a57133@yandex-team.ru>
     [not found]     ` <cqb3yww5ceeinh2pb5nqaljrsllu3ejkjsdueuw32cwcocumsn@okgujto2lzmn>
     [not found]       ` <cd83b0bc-0e6b-fc94-1cc2-9bf00d516140@yandex-team.ru>
     [not found]         ` <hbjtjovry4e5kb6oyii4g2hncetfo2uic67r5ipufcikvgyb5x@idenexfxits4>
2023-06-01  8:43           ` Vladimir Sementsov-Ogievskiy
2023-05-15 19:53 ` [PATCH v3 13/14] nbd/server: Prepare for per-request filtering of BLOCK_STATUS Eric Blake
2023-06-01  9:57   ` Vladimir Sementsov-Ogievskiy
2023-05-15 19:53 ` [PATCH v3 14/14] nbd/server: Add FLAG_PAYLOAD support to CMD_BLOCK_STATUS Eric Blake
2023-06-02  9:13   ` Vladimir Sementsov-Ogievskiy
2023-06-02 13:14     ` [Libguestfs] " Eric Blake
2023-05-15 21:05 ` [Libguestfs] [PATCH v3 00/14] qemu patches for 64-bit NBD extensions Eric Blake

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=6acudhjle7jke537s7hxbit4t3wikk325ewnzjvb5poqm3ndlr@wibmfb7w6o2j \
    --to=eblake@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=libguestfs@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@yandex-team.ru \
    /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.