qemu-devel.nongnu.org archive mirror
 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: pbonzini@redhat.com, kwolf@redhat.com, mreitz@redhat.com, den@openvz.org
Subject: Re: [Qemu-devel] [PATCH 2/5] nbd/server: add nbd_opt_{read, drop} to track client->optlen
Date: Wed, 22 Nov 2017 14:03:25 -0600	[thread overview]
Message-ID: <a07578ae-f57b-cb82-e87e-23b6c39cbd10@redhat.com> (raw)
In-Reply-To: <20171122101958.17065-3-vsementsov@virtuozzo.com>

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

On 11/22/2017 04:19 AM, Vladimir Sementsov-Ogievskiy wrote:
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  nbd/server.c | 34 ++++++++++++++++++++++------------
>  1 file changed, 22 insertions(+), 12 deletions(-)
> 

Hmm, revisiting my idea about moving more of the error checking into the
helper function.  As of this patch, we only have two clients of
nbd_opt_read:

> @@ -299,7 +312,7 @@ static int nbd_negotiate_handle_export_name(NBDClient *client,
>          error_setg(errp, "Bad length received");
>          return -EINVAL;
>      }
> -    if (nbd_read(client->ioc, name, client->optlen, errp) < 0) {
> +    if (nbd_opt_read(client, name, client->optlen, errp) < 0) {
>          error_prepend(errp, "read failed: ");
>          return -EINVAL;

1. NBD_OPT_EXPORT_NAME, where the length check is based on the maximum
size name we're willing to accept (and NOT on comparison to the header
size, as we request the entire client->optlen).  This call cannot send
an error reply (so if the length is bogus, we can just drop the
connection by returning -EINVAL).  Furthermore, once we handle this
option, option processing is done; we do not reach the assert that
client->optlen == 0.

>      }
> @@ -383,40 +396,36 @@ static int nbd_negotiate_handle_info(NBDClient *client, uint16_t myflags,
>          msg = "overall request too short";
>          goto invalid;
>      }
> -    if (nbd_read(client->ioc, &namelen, sizeof(namelen), errp) < 0) {
> +    if (nbd_opt_read(client, &namelen, sizeof(namelen), errp) < 0) {
>          return -EIO;
>      }

2. Multiple calls within NBD_OPT_INFO/NBD_OPT_GO.  Here, the length
check is based on our read being a subset of client->optlen, and our
desired response on a failed check is whatever is at the invalid: label,
namely:

 invalid:
    if (nbd_opt_drop(client, client->optlen, errp) < 0) {
        return -EIO;
    }
    return nbd_negotiate_send_rep_err(client, NBD_REP_ERR_INVALID,
                                      errp, "%s", msg);

We want to drop all remaining data, reply to the client, and return 0 to
keep the connection alive (or -EIO if the read or write failed).

You are planning on adding more calls withing NBD_OPT_LIST_META_CONTEXT,
which will have semantics more like 2 (if we detect an inconsistent
size, we want to consume the rest of the input and return an EINVAL
reply to the client, but keep the connection alive unless there is an
I/O error in the meantime).

I think that means we need a tri-state return from nbd_opt_read(): < 0
on I/O failure, 0 if the EINVAL message has been sent, and 1 if the read
was successful; I also think it means that the handler for
NBD_OPT_EXPORT_NAME does not really fit the bill for using the same
handler.  Hopefully this explanation will give you more insight into the
counter-proposal patch I'm about to post.

-- 
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 --]

  parent reply	other threads:[~2017-11-22 20:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-22 10:19 [Qemu-devel] [PATCH 0/5] NBD server refactoring before BLOCK_STATUS Vladimir Sementsov-Ogievskiy
2017-11-22 10:19 ` [Qemu-devel] [PATCH 1/5] nbd/server: refactor negotiation functions parameters Vladimir Sementsov-Ogievskiy
2017-11-22 16:39   ` Eric Blake
2017-11-22 10:19 ` [Qemu-devel] [PATCH 2/5] nbd/server: add nbd_opt_{read, drop} to track client->optlen Vladimir Sementsov-Ogievskiy
2017-11-22 17:08   ` Eric Blake
2017-11-22 19:22   ` Eric Blake
2017-11-22 20:03   ` Eric Blake [this message]
2017-12-21  1:38     ` Eric Blake
2017-11-22 10:19 ` [Qemu-devel] [PATCH 3/5] nbd/server: add helper nbd_opt_invalid Vladimir Sementsov-Ogievskiy
2017-11-22 21:59   ` Eric Blake
2017-11-22 23:00   ` Eric Blake
2017-11-22 10:19 ` [Qemu-devel] [PATCH 4/5] nbd: rename nbd_option and nbd_opt_reply Vladimir Sementsov-Ogievskiy
2017-11-22 21:56   ` Eric Blake
2018-01-10 18:11     ` Eric Blake
2017-11-22 10:19 ` [Qemu-devel] [PATCH 5/5] nbd/server: structurize option reply sending Vladimir Sementsov-Ogievskiy
2017-11-22 22:02   ` Eric Blake
2018-01-10 18:14     ` Eric Blake
2017-11-22 11:07 ` [Qemu-devel] [PATCH 0/5] NBD server refactoring before BLOCK_STATUS no-reply
2017-11-22 11:54   ` [Qemu-devel] unrelated " 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=a07578ae-f57b-cb82-e87e-23b6c39cbd10@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).