From: Paolo Bonzini <pbonzini@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: mreitz@redhat.com, kwolf@redhat.com, eblake@redhat.com, den@openvz.org
Subject: Re: [Qemu-devel] [PATCH v2 3/7] block/nbd-client: refactor reading reply
Date: Tue, 19 Sep 2017 12:01:55 +0200 [thread overview]
Message-ID: <26582eb0-1db3-3aac-3652-44e3fbb1e49c@redhat.com> (raw)
In-Reply-To: <577e29c4-5187-8c6f-aacc-c77282959fdd@virtuozzo.com>
On 19/09/2017 11:25, Vladimir Sementsov-Ogievskiy wrote:
> 18.09.2017 18:43, Paolo Bonzini wrote:
>> On 18/09/2017 15:59, Vladimir Sementsov-Ogievskiy wrote:
>>> Read the whole reply in one place - in nbd_read_reply_entry.
>>>
>>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>>> ---
>>> block/nbd-client.h | 1 +
>>> block/nbd-client.c | 42 ++++++++++++++++++++++++------------------
>>> 2 files changed, 25 insertions(+), 18 deletions(-)
>>>
>>> diff --git a/block/nbd-client.h b/block/nbd-client.h
>>> index b1900e6a6d..3f97d31013 100644
>>> --- a/block/nbd-client.h
>>> +++ b/block/nbd-client.h
>>> @@ -21,6 +21,7 @@ typedef struct {
>>> Coroutine *coroutine;
>>> bool receiving; /* waiting for read_reply_co? */
>>> NBDRequest *request;
>>> + QEMUIOVector *qiov;
>>> } NBDClientRequest;
>>> typedef struct NBDClientSession {
>>> diff --git a/block/nbd-client.c b/block/nbd-client.c
>>> index 5f241ecc22..f7b642f079 100644
>>> --- a/block/nbd-client.c
>>> +++ b/block/nbd-client.c
>>> @@ -98,6 +98,21 @@ static coroutine_fn void nbd_read_reply_entry(void
>>> *opaque)
>>> break;
>>> }
>>> + if (s->reply.error == 0 &&
>>> + s->requests[i].request->type == NBD_CMD_READ)
>>> + {
>>> + QEMUIOVector *qiov = s->requests[i].qiov;
>>> + assert(qiov != NULL);
>>> + assert(s->requests[i].request->len ==
>>> + iov_size(qiov->iov, qiov->niov));
>>> + if (qio_channel_readv_all(s->ioc, qiov->iov, qiov->niov,
>>> + NULL) < 0)
>>> + {
>>> + s->reply.error = EIO;
>>> + break;
>>> + }
>>> + }
>> I am not sure this is an improvement. In principle you could have
>> commands that read replies a bit at a time without using a QEMUIOVector.
>>
>> Paolo
>
> Hm, what do you mean? In this patch I don't change "how do we read it",
> I only move the reading code to one coroutine, to make it simple to
> extend it in future (block status, etc).
I disagree that it is easier to extend it in the future. If some
commands in the future need a different "how do we read it" (e.g. for
structured reply), nbd_read_reply_entry may not have all the information
it needs anymore.
In fact, you're pushing knowledge of the commands from nbd_co_request to
nbd_read_reply_entry:
+ if (s->reply.error == 0 &&
+ s->requests[i].request->type == NBD_CMD_READ)
and knowledge of NBD_CMD_READ simply doesn't belong there. So there is
an example of that right now, it is not some arbitrary bad thing that
could happen in the future.
Paolo
> nbd_read_reply_enty has all
> information it need (s->requests[i].request) to handle the whole reply..
> It's an improvement, because it leads to separating reply_entry
> coroutine - it don't need any synchronization (yield/wake) more with
> request coroutines.
>
>>
>>> /* We're woken up again by the request itself. Note that
>>> there
>>> * is no race between yielding and reentering
>>> read_reply_co. This
>>> * is because:
>>> @@ -118,6 +133,7 @@ static coroutine_fn void
>>> nbd_read_reply_entry(void *opaque)
>>> s->read_reply_co = NULL;
>>> }
>>> +/* qiov should be provided for READ and WRITE */
>>> static int nbd_co_send_request(BlockDriverState *bs,
>>> NBDRequest *request,
>>> QEMUIOVector *qiov)
>>> @@ -145,6 +161,7 @@ static int nbd_co_send_request(BlockDriverState *bs,
>>> request->handle = INDEX_TO_HANDLE(s, i);
>>> s->requests[i].request = request;
>>> + s->requests[i].qiov = qiov;
>>> if (s->quit) {
>>> rc = -EIO;
>>> @@ -155,7 +172,8 @@ static int nbd_co_send_request(BlockDriverState *bs,
>>> goto err;
>>> }
>>> - if (qiov) {
>>> + if (s->requests[i].request->type == NBD_CMD_WRITE) {
>>> + assert(qiov);
>>> qio_channel_set_cork(s->ioc, true);
>>> rc = nbd_send_request(s->ioc, request);
>>> if (rc >= 0 && !s->quit) {
>>> @@ -181,9 +199,7 @@ err:
>>> return rc;
>>> }
>>> -static int nbd_co_receive_reply(NBDClientSession *s,
>>> - NBDRequest *request,
>>> - QEMUIOVector *qiov)
>>> +static int nbd_co_receive_reply(NBDClientSession *s, NBDRequest
>>> *request)
>>> {
>>> int ret;
>>> int i = HANDLE_TO_INDEX(s, request->handle);
>>> @@ -197,14 +213,6 @@ static int nbd_co_receive_reply(NBDClientSession
>>> *s,
>>> } 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));
>>> - if (qio_channel_readv_all(s->ioc, qiov->iov, qiov->niov,
>>> - NULL) < 0) {
>>> - ret = -EIO;
>>> - s->quit = true;
>>> - }
>>> - }
>>> /* Tell the read handler to read another header. */
>>> s->reply.handle = 0;
>>> @@ -232,16 +240,14 @@ static int nbd_co_request(BlockDriverState *bs,
>>> NBDClientSession *client = nbd_get_client_session(bs);
>>> int ret;
>>> - assert(!qiov || request->type == NBD_CMD_WRITE ||
>>> - request->type == NBD_CMD_READ);
>>> - ret = nbd_co_send_request(bs, request,
>>> - request->type == NBD_CMD_WRITE ? qiov
>>> : NULL);
>>> + assert((qiov == NULL) !=
>>> + (request->type == NBD_CMD_WRITE || request->type ==
>>> NBD_CMD_READ));
>>> + ret = nbd_co_send_request(bs, request, qiov);
>>> if (ret < 0) {
>>> return ret;
>>> }
>>> - return nbd_co_receive_reply(client, request,
>>> - request->type == NBD_CMD_READ ? qiov
>>> : NULL);
>>> + return nbd_co_receive_reply(client, request);
>>> }
>>> int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset,
>>>
>
next prev parent reply other threads:[~2017-09-19 10:02 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-18 13:59 [Qemu-devel] [PATCH v2 0/7] nbd client refactoring and fixing Vladimir Sementsov-Ogievskiy
2017-09-18 13:59 ` [Qemu-devel] [PATCH v2 1/7] block/nbd-client: refactor nbd_co_receive_reply Vladimir Sementsov-Ogievskiy
2017-09-18 15:38 ` Eric Blake
2017-09-18 13:59 ` [Qemu-devel] [PATCH v2 2/7] block/nbd-client: exit reply-reading coroutine on incorrect handle Vladimir Sementsov-Ogievskiy
2017-09-18 15:45 ` Eric Blake
2017-09-18 19:50 ` Eric Blake
2017-09-18 13:59 ` [Qemu-devel] [PATCH v2 3/7] block/nbd-client: refactor reading reply Vladimir Sementsov-Ogievskiy
2017-09-18 15:43 ` Paolo Bonzini
2017-09-18 15:54 ` Eric Blake
2017-09-19 9:25 ` Vladimir Sementsov-Ogievskiy
2017-09-19 10:01 ` Paolo Bonzini [this message]
2017-09-19 11:03 ` Vladimir Sementsov-Ogievskiy
2017-09-19 12:50 ` Paolo Bonzini
2017-09-18 13:59 ` [Qemu-devel] [PATCH v2 4/7] block/nbd-client: drop reply field from NBDClientSession Vladimir Sementsov-Ogievskiy
2017-09-18 22:00 ` Eric Blake
2017-09-18 13:59 ` [Qemu-devel] [PATCH v2 5/7] block/nbd-client: nbd_co_send_request: return -EIO if s->quit was set in parallel Vladimir Sementsov-Ogievskiy
2017-09-18 16:01 ` Eric Blake
2017-09-18 19:16 ` Eric Blake
2017-09-20 12:03 ` Vladimir Sementsov-Ogievskiy
2017-09-18 13:59 ` [Qemu-devel] [PATCH v2 6/7] block/nbd-client: early fail nbd_read_reply_entry if s->quit is set Vladimir Sementsov-Ogievskiy
2017-09-18 22:27 ` Eric Blake
2017-09-19 9:43 ` Vladimir Sementsov-Ogievskiy
2017-09-19 10:03 ` Paolo Bonzini
2017-09-19 11:07 ` Vladimir Sementsov-Ogievskiy
2017-09-18 13:59 ` [Qemu-devel] [PATCH v2 7/7] block/nbd-client: do not yield from nbd_read_reply_entry Vladimir Sementsov-Ogievskiy
2017-09-18 22:36 ` Eric Blake
2017-09-19 10:00 ` Vladimir Sementsov-Ogievskiy
2017-09-19 13:45 ` Eric Blake
-- strict thread matches above, loose matches on Subject: below --
2017-10-09 17:27 [Qemu-devel] [PATCH v2 00/10] nbd minimal structured read Vladimir Sementsov-Ogievskiy
2017-10-09 17:27 ` [Qemu-devel] [PATCH v2 3/7] block/nbd-client: refactor reading reply 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=26582eb0-1db3-3aac-3652-44e3fbb1e49c@redhat.com \
--to=pbonzini@redhat.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@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).