[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [PATCH v2 2/7] block/nbd-client: exit reply-reading cor
From: |
Eric Blake |
Subject: |
Re: [Qemu-block] [PATCH v2 2/7] block/nbd-client: exit reply-reading coroutine on incorrect handle |
Date: |
Mon, 18 Sep 2017 14:50:13 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 |
On 09/18/2017 08:59 AM, Vladimir Sementsov-Ogievskiy wrote:
> Check reply-handle == request-handle in the same place, where
> recv coroutine number is calculated from reply->handle and it's
> correctness checked - in nbd_read_reply_entry.
>
> Also finish nbd_read_reply_entry in case of reply-handle !=
> request-handle in the same way as in case of incorrect reply-handle.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
> ---
> block/nbd-client.h | 1 +
> block/nbd-client.c | 8 ++++++--
> 2 files changed, 7 insertions(+), 2 deletions(-)
On second thought:
> +++ b/block/nbd-client.c
> @@ -92,7 +92,9 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)
> i = HANDLE_TO_INDEX(s, s->reply.handle);
> if (i >= MAX_NBD_REQUESTS ||
> !s->requests[i].coroutine ||
> - !s->requests[i].receiving) {
> + !s->requests[i].receiving ||
> + s->reply.handle != s->requests[i].request->handle)
How can this condition ever be false? s->reply.handle only ever
contains two values: 0 when it is being reused for the next iteration of
the loop, or the (munged) address of the request pointer. But we are
careful that we never write s->reply.handle = 0 until after
s->requests[i].receiving is false. So we will never see s->reply.handle
equal to 0 here. (It may have been possible prior to the introduction
of reply.receiving, in commit 40f4a218, but I'm not seeing it now)
If I'm right, then this patch can be simplified - we don't need to track
s.requests[i].request, and can merely:
> @@ -189,9 +192,10 @@ static int nbd_co_receive_reply(NBDClientSession *s,
> s->requests[i].receiving = true;
> qemu_coroutine_yield();
> s->requests[i].receiving = false;
> - if (s->reply.handle != request->handle || !s->ioc || s->quit) {
shorten this conditional to remove the now-dead condition.
> + if (!s->ioc || s->quit) {
> ret = -EIO;
> } else {
> + assert(s->reply.handle == request->handle);
> ret = -s->reply.error;
> if (qiov && s->reply.error == 0) {
> assert(request->len == iov_size(qiov->iov, qiov->niov));
>
[Oh, and I just noticed HANDLE_TO_INDEX() and INDEX_TO_HANDLE() are
improperly parenthesized, although to no ill effect with current clients]
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
- Re: [Qemu-block] [PATCH v2 3/7] block/nbd-client: refactor reading reply, (continued)
- Re: [Qemu-block] [PATCH v2 3/7] block/nbd-client: refactor reading reply, Paolo Bonzini, 2017/09/18
- Re: [Qemu-block] [PATCH v2 3/7] block/nbd-client: refactor reading reply, Eric Blake, 2017/09/18
- Re: [Qemu-block] [PATCH v2 3/7] block/nbd-client: refactor reading reply, Vladimir Sementsov-Ogievskiy, 2017/09/19
- Re: [Qemu-block] [PATCH v2 3/7] block/nbd-client: refactor reading reply, Paolo Bonzini, 2017/09/19
- Re: [Qemu-block] [PATCH v2 3/7] block/nbd-client: refactor reading reply, Vladimir Sementsov-Ogievskiy, 2017/09/19
- Re: [Qemu-block] [PATCH v2 3/7] block/nbd-client: refactor reading reply, Paolo Bonzini, 2017/09/19
[Qemu-block] [PATCH v2 1/7] block/nbd-client: refactor nbd_co_receive_reply, Vladimir Sementsov-Ogievskiy, 2017/09/18
[Qemu-block] [PATCH v2 2/7] block/nbd-client: exit reply-reading coroutine on incorrect handle, Vladimir Sementsov-Ogievskiy, 2017/09/18
[Qemu-block] [PATCH v2 6/7] block/nbd-client: early fail nbd_read_reply_entry if s->quit is set, Vladimir Sementsov-Ogievskiy, 2017/09/18
[Qemu-block] [PATCH v2 4/7] block/nbd-client: drop reply field from NBDClientSession, Vladimir Sementsov-Ogievskiy, 2017/09/18