qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH for-7.1 1/8] nbd: actually implement reply_possible safeguard
Date: Tue, 12 Apr 2022 17:05:53 -0500	[thread overview]
Message-ID: <20220412220553.dheyqpxfgkjkjtqv@redhat.com> (raw)
In-Reply-To: <20220412194204.350889-2-pbonzini@redhat.com>

On Tue, Apr 12, 2022 at 09:41:57PM +0200, Paolo Bonzini wrote:
> The .reply_possible field of s->requests is never set to false.  This is
> not a big problem as it is only a safeguard to detect protocol errors,
> but fix it anyway.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  block/nbd.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/block/nbd.c b/block/nbd.c
> index 567872ac53..6a5e410e5f 100644
> --- a/block/nbd.c
> +++ b/block/nbd.c
> @@ -454,15 +454,16 @@ static coroutine_fn int nbd_receive_replies(BDRVNBDState *s, uint64_t handle)
>              nbd_channel_error(s, -EINVAL);
>              return -EINVAL;
>          }
> -        if (s->reply.handle == handle) {
> -            /* We are done */
> -            return 0;
> -        }
>          ind2 = HANDLE_TO_INDEX(s, s->reply.handle);
>          if (ind2 >= MAX_NBD_REQUESTS || !s->requests[ind2].reply_possible) {
>              nbd_channel_error(s, -EINVAL);
>              return -EINVAL;
>          }
> +        s->requests[ind2].reply_possible = nbd_reply_is_structured(&s->reply);

If the reply is simple (not structured), then we expect no further
replies, so this sets things to false.  But if the reply is
structured, the answer depends on NBD_REPLY_FLAG_DONE, as in:

s->requests[ind2].reply_possible =
  nbd_reply_is_structured(&s->reply) &&
  (s->reply.structured.flags & NBD_REPLY_FLAG_DONE);

> +        if (s->reply.handle == handle) {
> +            /* We are done */
> +            return 0;
> +        }
>          nbd_recv_coroutine_wake_one(&s->requests[ind2]);
>      }
>  }

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



  reply	other threads:[~2022-04-12 22:07 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-12 19:41 [PATCH for-7.1 0/8] nbd: actually make s->state thread-safe Paolo Bonzini
2022-04-12 19:41 ` [PATCH for-7.1 1/8] nbd: actually implement reply_possible safeguard Paolo Bonzini
2022-04-12 22:05   ` Eric Blake [this message]
2022-04-13  7:30     ` Paolo Bonzini
2022-04-12 19:41 ` [PATCH for-7.1 2/8] nbd: mark more coroutine_fns Paolo Bonzini
2022-04-13 12:25   ` Eric Blake
2022-04-13 20:12     ` Paolo Bonzini
2022-04-12 19:41 ` [PATCH for-7.1 3/8] nbd: remove peppering of nbd_client_connected Paolo Bonzini
2022-04-13 12:48   ` Eric Blake
2022-04-12 19:42 ` [PATCH for-7.1 4/8] nbd: keep send_mutex/free_sema handling outside nbd_co_do_establish_connection Paolo Bonzini
2022-04-13 15:42   ` Eric Blake
2022-04-12 19:42 ` [PATCH for-7.1 5/8] nbd: use a QemuMutex to synchronize reconnection with coroutines Paolo Bonzini
2022-04-13  7:35   ` Paolo Bonzini
2022-04-13 15:55   ` Eric Blake
2022-04-13 20:16     ` Paolo Bonzini
2022-04-12 19:42 ` [PATCH for-7.1 6/8] nbd: move s->state under requests_lock Paolo Bonzini
2022-04-13 16:23   ` Eric Blake
2022-04-13 20:21     ` Paolo Bonzini
2022-04-12 19:42 ` [PATCH for-7.1 7/8] nbd: take receive_mutex when reading requests[].receiving Paolo Bonzini
2022-04-13 21:20   ` Eric Blake
2022-04-12 19:42 ` [PATCH for-7.1 8/8] nbd: document what is protected by the CoMutexes Paolo Bonzini
2022-04-13 21:22   ` 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=20220412220553.dheyqpxfgkjkjtqv@redhat.com \
    --to=eblake@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).